Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5577169
feat: add isolated external-summary execution foundation (#2163)
Oct 5, 2026
aa8b81f
feat: add isolated external summary HTTP candidates
Oct 5, 2026
677148c
Merge remote-tracking branch 'origin/master' into 2026-10-05_external…
Oct 5, 2026
6aa00d0
fix: share external summary deadline across ranges
Oct 5, 2026
3cb193f
test: exercise shared HTTP summary batches across callers
Oct 5, 2026
bcf4011
feat: add configurable external summary service
Oct 5, 2026
24d32a9
Merge upstream master and preserve external summary wiring
Oct 5, 2026
43bf59f
fix(launcher): keep cold-start rollout paths readable after exit
Oct 5, 2026
d6593dc
test: isolate local proxy fixtures and summary deadline clock
Oct 5, 2026
8f6159b
docs: describe complete external summary review implementation
Oct 5, 2026
2e4860d
Merge remote-tracking branch 'origin/master' into 2026-10-05_external…
Oct 6, 2026
64bec0c
Merge branch 'master' into 2026-10-05_external-summary-executor
yingzhongshuoqi Oct 6, 2026
0c24ae9
Merge remote-tracking branch 'origin/master' into 2026-10-05_external…
Oct 6, 2026
92d1ed4
fix: harden external summary configuration loading
Oct 6, 2026
1d1d62d
Merge remote-tracking branch 'origin/master' into pr-2167-rework
ranxianglei Oct 6, 2026
5eedfbf
Merge origin/master into external summary executor
Oct 6, 2026
99a4350
refactor: externalSummary joins the three-level compress ladder (#2163)
ranxianglei Oct 6, 2026
c60abcd
Merge contributor head (master sync) into pr-2167-rework
ranxianglei Oct 6, 2026
0b283fb
feat: externalSummary chain references named provider recipes (#2163)
ranxianglei Oct 7, 2026
2b2029a
Merge origin/master into pr-2167-rework (chain-refs rework)
ranxianglei Oct 7, 2026
e9d1f30
fix: inert-routing models exemption applies only to dial recipes
ranxianglei Oct 7, 2026
2095cc8
Merge origin/master into pr-2167-rework (admin-route extract + dead-c…
ranxianglei Oct 7, 2026
d607146
fix: satisfy unused-exports gate (drop internal-only exports, delete …
ranxianglei Oct 7, 2026
b6cad25
Merge branch 'master' into 2026-10-05_external-summary-executor
ranxianglei Oct 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,42 @@ A key that is not a URL (e.g. `"claude-bridge"`) is a **named** entry. On its ow

Compression behaviour is controlled by the `compress` block, which can appear at three levels. They merge **per-field, deepest wins**: a field set at a deeper level overrides the same field higher up, but an *unset* field at a deeper level never clears a value set higher up. In other words, the child covers the parent field-by-field — it never replaces the whole object.

### Shared external summary service

The optional `compress.externalSummary` block sends compression summaries to one or more separately configured models. It lives at all three `compress` levels like every other field, with whole-chain semantics: a chain set at a deeper level (provider or model) **replaces** the entire chain above it — there is no per-target or per-budget sub-merge, exactly like `tiers`. It is disabled unless `enabled` is `true`; when enabled, targets are tried in order and a failed or unusable target falls through to the next one. The main request provider, model, and authorization are never reused for these calls. This feature changes the compression tool contract so `summary` is an optional non-authoritative hint; the proxy keeps the original messages recoverable and commits only a validated returned summary.

Targets are **references into the `providers` table**: each entry is the string `"provider/model"`, where `provider` is a *named provider recipe* (a non-URL `providers` entry carrying dial fields) and `model` is a key of its `models` map. The endpoint, protocol, and credential are derived from the recipe — no URLs are repeated per target:

```json
{
"providers": {
"glm": {
"baseUrl": "https://open.bigmodel.cn/api/paas/v4",
"api": "openai",
"apiKeyEnv": "GLM_API_KEY",
"models": { "glm-4.9-flash": { "outputTokens": 4096 } }
},
"claude": {
"baseUrl": "https://api.anthropic.com",
"api": "anthropic",
"credentialRef": "primary",
"models": { "claude-haiku-4.5": {} }
}
},
"compress": {
"externalSummary": {
"enabled": true,
"targets": ["glm/glm-4.9-flash", "claude/claude-haiku-4.5"],
"budget": { "totalTimeoutMs": 50000, "targetTimeoutMs": 25000, "maxSummaryBytes": 65536 }
}
}
}
```

A recipe carries: `baseUrl` (HTTPS; loopback HTTP allowed for local development; no embedded credentials, proxy-recursion paths, or arbitrary query parameters), `api` (one of `openai` | `anthropic` | `responses` | `google`; selects the wire protocol and derives the request path from `baseUrl`), exactly one credential reference — `apiKeyEnv: "VAR_NAME"` (an environment variable read at call time) or `credentialRef: "NAME"` (a value stored via the Web UI) — and a `models` map whose per-model fields are `contextWindow` (default 128000), `outputTokens` (default `min(8192, window/4)`), and `stream` (default false). Recipes can also be split into `recipe`/`bind` routing form like URL entries; a named entry is routing-inert unless bound.

Up to 16 targets per chain are supported. Saving an enabled chain through the Web API validates that every reference resolves (unknown provider or model → HTTP 400). At runtime an unresolvable reference is logged once and disables the chain until fixed — it never falls back to summarizing with the main model. `secret:` values are stored separately from the main JSON configuration in the private `billion-context.json.summary-credentials.json` file and are never returned by the configuration API. On Windows, protect this file and its parent directory with an administrator-only ACL; stale `.lock` files require manual removal after confirming no proxy process is writing the store. The total budget is shared across all targets and compression entry points, and cancellation or session-state changes discard generated results without folding.

The three levels, from broadest to most specific:

1. **Global** — a top-level `"compress": { … }` key. Applies to every request. This is the only level where the `injectTool` / `injectNudge` toggles are honoured.
Expand Down
36 changes: 36 additions & 0 deletions CONFIGURATION.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,42 @@

压缩行为由 `compress` 块控制,它可以出现在三个层级。它们按**逐字段、最深层胜出**的方式合并:在更深层设置的字段会覆盖上层同名字段,但更深层*未设置*的字段**永远不会**清除上层已设置的值。换言之,子级按字段覆盖父级 —— 它绝不是整体替换对象。

### 共享外部摘要服务

可选的 `compress.externalSummary` 会把压缩摘要交给一个或多个独立配置的模型。它与其余 `compress` 字段一样存在于全部三个层级,采用整链替换语义:在更深层级(provider 或 model)设置的链会**整体替换**上层链,不做按目标或按预算的子字段合并,与 `tiers` 完全一致。只有 `enabled` 为 `true` 时才启用;启用后按顺序调用目标,目标失败或返回不可用摘要时继续使用下一个目标。摘要请求不会复用主请求的 provider、模型或认证信息。启用该功能后,压缩工具中的 `summary` 变为可选的、非权威提示;代理仍保留原文可恢复,只提交通过校验的外部摘要。

目标是**对 `providers` 表的引用**:每个条目是字符串 `"provider/model"`,其中 `provider` 是一张*具名拨号配方*(`providers` 表中带拨号字段的非 URL 条目),`model` 是其 `models` 表中的一个键。端点、协议与凭据均由配方推导,不需要在每个目标里重复 URL:

```json
{
"providers": {
"glm": {
"baseUrl": "https://open.bigmodel.cn/api/paas/v4",
"api": "openai",
"apiKeyEnv": "GLM_API_KEY",
"models": { "glm-4.9-flash": { "outputTokens": 4096 } }
},
"claude": {
"baseUrl": "https://api.anthropic.com",
"api": "anthropic",
"credentialRef": "primary",
"models": { "claude-haiku-4.5": {} }
}
},
"compress": {
"externalSummary": {
"enabled": true,
"targets": ["glm/glm-4.9-flash", "claude/claude-haiku-4.5"],
"budget": { "totalTimeoutMs": 50000, "targetTimeoutMs": 25000, "maxSummaryBytes": 65536 }
}
}
}
```

配方包含:`baseUrl`(必须 HTTPS,本地开发可用回环 HTTP;拒绝内嵌凭据、代理递归路径与任意 query 参数);`api`(`openai` | `anthropic` | `responses` | `google` 四选一,决定线上协议并从 `baseUrl` 推导请求路径);恰好一个凭据引用 —— `apiKeyEnv: "变量名"`(调用时读环境变量)或 `credentialRef: "名字"`(通过 Web UI 存储的值);以及 `models` 表,每个模型可设 `contextWindow`(默认 128000)、`outputTokens`(默认 `min(8192, 窗口/4)`)、`stream`(默认 false)。配方也可以像 URL 条目一样拆成 `recipe`/`bind` 路由形态;具名条目未绑定时对路由不生效(routing-inert)。

每条链最多 16 个目标。通过 Web API 保存启用的链时会校验每个引用可解析(未知 provider 或 model → HTTP 400)。运行时遇到不可解析的引用会记录一次警告并禁用整条链直至修复 —— 绝不会回退用主模型写摘要。`secret:` 值单独存储在私有的 `billion-context.json.summary-credentials.json` 文件中,不随主 JSON 配置下发,配置 API 也不会返回。Windows 上请用仅管理员的 ACL 保护该文件及其父目录;确认没有代理进程在写存储后,残留的 `.lock` 文件需手工删除。总预算由全部目标与压缩入口共享;取消或会话状态变化会丢弃已生成但未落盘的结果。

三个层级,从最宽泛到最具体:

1. **全局(Global)** —— 顶层 `"compress": { … }` 键。应用于每个请求。这是唯一会生效 `injectTool` / `injectNudge` 开关的层级。
Expand Down
1 change: 0 additions & 1 deletion TECHNICAL-NOTES.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,3 @@ bili 永不拥有用户数据:每个被启动的客户端都跑在**真实 home*
4. **用户发送的消息永不被改写。** 用户自己片段的逐字回声在武装清洗下也保留(#463 豁免,按请求文本匹配,不按形状)。

出口审计网(#2248)保持仅记日志:裸出口(未识别帧、解析失败)原样转发并打 `[tag-echo] raw exit` 日志,新泄漏形状可见而不改线上行为。由 `tests/unified-acp-invariants.test.ts` 钉住(8 个测试,两条 lane)。

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions reference/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ billion-context/
│ ├── encrypt.ts # At-rest encoding: AES-256-GCM (#708) + zstd (#1080), independent
│ ├── export.ts # Session export (block summaries + originals)
│ ├── preflight.ts # Preflight compression gate (hold grace, dead-end cooldown)
│ ├── external-summary.ts # Isolated summary executor (ordered failover, deadlines, capacity)
│ ├── external-summary-http.ts # Internal single-attempt HTTP candidates using existing summary codecs
│ ├── external-summary-settings.ts # Global external-summary target and budget validation
│ ├── external-summary-config.ts # Strict external-summary config loading
│ ├── external-summary-credentials.ts # Separate atomic credential store
│ ├── external-summary-runtime.ts # Configured candidate plan and shared executor
│ ├── external-summary-compress.ts # External summary fold coordinator and state checks
│ ├── external-summary-surface.ts # Tool/schema and client-facing summary contract
│ ├── update.ts # Self-updater (load-bearing — no-op release protocol) + install lanes
│ ├── advisory.ts # Critical-defect advisory watcher (#1481)
│ ├── update-notes.ts # Tiered release-notes visibility (#1870/#1977)
Expand Down
35 changes: 35 additions & 0 deletions reference/external-summary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# External Summary Development Contract

Design discussion: [#2163](https://github.com/ranxianglei/billion-context/issues/2163), related to [#1640](https://github.com/ranxianglei/billion-context/issues/1640).

## Current Stage

The implementation in PR #2167 wires the isolated executor in `src/external-summary.ts` into the host's compression paths through `src/external-summary-runtime.ts` and `src/external-summary-compress.ts`. `compress.externalSummary` settings are opt-in and disabled by default; the chain is three-level like every other `compress` field (whole-chain replace at provider/model level, no sub-merge) and rides the request Config rail (`ctx.config` / `effectiveConfig`, #833) — there is no side configuration file. This is a review-branch implementation, not a published release or production deployment; repository-owner approval of the configuration surface remains outstanding.

The chain is expressed as **references** (`"glm/glm-4.9-flash"`) into named provider *recipes* in the `providers` table (non-URL entries carrying `baseUrl`/`api`/credential/`models`, see `CONFIGURATION.md`). Parsing is split: `src/external-summary-settings.ts` does syntax-level chain parsing at config load (`parseExternalSummaryChain`) and reference expansion at request-apply time (`expandExternalSummaryChain` / `expandExternalSummaryChainTolerant` in `src/compress-settings.ts`), producing the expanded `ExternalSummarySettings` the executor rail consumes. An unresolvable reference in an enabled chain logs one warning and disables the chain — never a fallback to the main model. The Web API saves reject unresolvable enabled chains with HTTP 400; recipes are collected from the about-to-be-saved `providers` section (`collectNamedProviders` in `src/config.ts`).

The executor accepts immutable task text, instructions and optional read-only reference text; an ordered list of injected asynchronous candidates; and explicit internal budgets. Wire protocols, authentication and range selection remain caller responsibilities. No provider request or fold occurs without a caller.

`src/external-summary-http.ts` provides single-attempt HTTP candidates for Anthropic, OpenAI Chat, Responses and Google. It reuses the existing summary codecs, with unchanged preflight behavior when disabled. An explicit resolved endpoint/model/header snapshot is used instead of main-request credentials. Reference data is carried separately from the selected content. Redirects, invalid UTF-8, excessive response bytes, missing completion markers, truncation and tool calls are rejected. SSE framing and completion are checked even when a relay changes the requested response format. HTTP and stream failures advance through the executor's existing target chain, with no independent retry loop. Hermetic tests use local mock upstreams; an opt-in live Responses smoke test also verified fact retention and exact original restoration. That smoke test is not a multi-provider quality or cost benchmark.

## Execution Contract

- Each candidate is invoked at most once per selected range, in order; the first valid result wins. Transport errors, empty output and excessive UTF-8 byte length advance to the next target. Byte-length validation is not semantic quality or token-window validation.
- Queue waiting consumes the total deadline; the per-target deadline starts after a permit is acquired. Both timers and monotonic elapsed-time checks reject late results. Blocking synchronous code cannot be preempted.
- Caller cancellation or the total deadline stops the chain. No partial/late summary is returned as success. Exhaustion never silently falls back to the main model.
- A shared executor bounds aggregate active calls across operations. A timed-out call that ignores abort retains its permit until it settles; this fails closed instead of launching unbounded background calls. Production adapters must actually cancel transport and release its resources.
- Reports include only target indexes and categorized outcomes, never raw provider error strings, keys, URLs or source history. The caller alone validates session revisions and commits successful ranges through the existing compression authority.

## Final Acceptance Scope

The internal `executeBatch` operation shares one monotonic deadline across queueing, all ranges and every fallback attempt. Results remain in input order; `finished` means every range was evaluated, not that every range succeeded. Cancellation or deadline stops later ranges and retains earlier results for an eventual caller to validate and commit. This operation does not commit folds or renew the timeout per range.

- An opt-in configuration-page section manages custom summary targets and ordered backups. The requester authorized implementation in the fork for review; this does not replace repository-owner approval of its public schema and secret storage before merge.
- Active `compress`, preflight, MCP/official thin-plugin execution and supported native-compaction summary generators use the common external service when enabled. A preflight-only implementation is not final delivery.
- The original main model continues its normal task after a successful fold; non-summary requests and the disabled mode preserve existing behavior.
- Multi-client/multi-host tests prove session separation, cancellation, stale-revision rejection, failure safety, credential isolation and tool-call byte fidelity in both proxy and plugin modes.
- Real API quality/cost comparisons require dedicated credentials and an approved spending limit; hermetic tests cannot substitute for those measurements.

The feature does not connect previously unrouted client history by itself. Model traffic and session identity must already reach Billion; MCP alone is insufficient. Credential setup for the shared summary service need not be duplicated for every main provider.

Stage completion requires reviewing new issue/PR feedback. In-goal refinements may proceed; changes that permanently remove a core requirement need renewed requester approval. No agent merge, npm publish or production deployment is part of this development stage.
Loading
Loading