Skip to content
Draft
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b85e797
feat(dsh): select models for native compaction with safe handoff
bluesmilery Nov 10, 2026
a0ece87
fix(dsh): meter summary tool schemas in host tokens
bluesmilery Nov 10, 2026
cd7b492
test(dsh): cover partial summary failure and concurrent ownership
bluesmilery Nov 11, 2026
c07914f
fix(dsh): preserve complementary facts across summary merges
bluesmilery Nov 11, 2026
5f82651
fix(dsh): keep model routing transparent to native compaction
bluesmilery Nov 11, 2026
c4a91e9
test(dsh): register isolated parity proxy workers for CI
bluesmilery Nov 11, 2026
9368f61
Merge remote-tracking branch 'origin/master' into wt-pr6123-conflict
Nov 12, 2026
08bf768
test: mask wall-clock timestamps in the dsh compaction parity test
Nov 12, 2026
d98db52
merge: sync origin/master into PR #6123 branch
Nov 14, 2026
88dea57
merge: sync origin/master (f648217cb8) into PR #6123 branch
Nov 15, 2026
ee64ad4
Merge remote-tracking branch 'origin/master' into wt-pr6123-conflict-r3
Nov 16, 2026
f9225e0
Merge remote-tracking branch 'origin/master' into 2026-11-10_dsh-mode…
Nov 18, 2026
7bb2966
docs: regenerate docs/configuration.ja.md for dsh.nativeCompactionMod…
Nov 18, 2026
15efcee
Merge remote-tracking branch 'origin/master' into 2026-11-10_dsh-mode…
Nov 19, 2026
d313e83
Merge remote-tracking branch 'origin/master' into 2026-11-10_dsh-mode…
Nov 23, 2026
d48bd5d
Merge remote-tracking branch 'origin/master' into pr-6123
Nov 24, 2026
1aae293
Merge remote-tracking branch 'origin/master' into pr-6123
Dec 1, 2026
fb4e82c
Keep selective compaction intact for runtime presets and scoped auxil…
bluesmilery Dec 2, 2026
8ecd662
Merge remote-tracking branch 'origin/master' into pr-6123
Dec 2, 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
2 changes: 2 additions & 0 deletions docs/README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 文档导航

- [DSH 按模型使用原生压缩](dsh-native-compaction.zh-CN.md):配置、同会话切换、兼容性与补丁维护。[English](dsh-native-compaction.md)

**billion-context** 的全部系统文档都集中在这个目录。仓库根目录只保留四个核心入口文件——`README.md`、`README.zh-CN.md`、`AGENTS.md`、`CHANGELOG.md`——外加受认可的社区 README 译本(`README.<locale>.md`,如 `README.ja.md`,批准于 2026-11-09 / #6000)。原根路径保留单行重定向占位(记账见 [lifecycle §5](lifecycle.md#5-卫生记录))。

> **全量目录:** [index.zh-CN.md](index.zh-CN.md) / [index.md](index.md) —— 每篇文档一行说明。本页是目录落地页:东西在哪、什么规则让它们保持新鲜。
Expand Down
2 changes: 2 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Architecture

DSH's opt-in [native model policy](dsh-native-compaction.md) branches before bili's HTTP/WS transforms. Its adapter owns the preset-local native backend; host replacement generations isolate later bili folds. The kernel and provider adapters are unchanged.

> One hub for the system's architecture. This page holds the **overall diagram** and the **module ledger**; each module gets its own page (en + `.zh-CN` + `.ja`) in this directory, each with its own diagram.
> 中文: [architecture.zh-CN.md](./architecture.zh-CN.md)
> 日本語: [architecture.ja.md](./architecture.ja.md)
Expand Down
2 changes: 2 additions & 0 deletions docs/architecture.zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 架构总览

DSH 可选的[原生模型策略](dsh-native-compaction.zh-CN.md)在 bili HTTP/WS 改写前分流。适配器控制预设内的原生压缩后端,用宿主持久化替换代数隔离后续 bili 压缩状态;kernel 与供应商适配器保持原样。

> 系统架构的唯一枢纽。本页放**整体架构图**与**模块总表**;每个模块在本目录下有独立页面(中英各一份),每页配自己的图。
> English: [architecture.md](./architecture.md)
> 日本語: [architecture.ja.md](./architecture.ja.md)
Expand Down
5 changes: 4 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed
| `compat.streamErrorShape` | "protocol" \| "completion" | protocol | BILI_STREAM_ERROR_SHAPE | How upstream stream failures are presented after the 200 is committed: protocol-native error frames (default) or the legacy synthesized-completion shape. |
| `compat.noCacheControl` | boolean | false | BILI_NO_CACHE_CONTROL | Stop stamping Anthropic-lane cache_control breakpoints entirely (escape hatch for upstreams/relays with their own breakpoint policy). |
| `compat.keepResponseId` | boolean | false | ACP_KEEP_RESPONSE_ID | Preserve previous_response_id on kernel-rebuilt Responses requests (default strips it so rebuilt bodies never reference ids the upstream never issued). |
| `dsh` | object | {} | BILI_ALLOW_DSH_COMPACTION | Section recognized but its former escape hatch is gone (#3666, superseding #2028): the allowDshCompaction key and the BILI_ALLOW_DSH_COMPACTION env var no longer exist — dsh native compaction is refused unconditionally by the wire guard on every lane. Leftover dsh.allowDshCompaction values are ignored with a one-time deprecation warning; apply host-side suppression instead (#3354/#2474). The live keys — dsh.authoredCompaction, dsh.contextTab, dsh.contextTabLabel — are documented in the following entries. |
| `dsh` | object | {} | BILI_ALLOW_DSH_COMPACTION | Section recognized but its former escape hatch is gone (#3666, superseding #2028): the allowDshCompaction key and the BILI_ALLOW_DSH_COMPACTION env var no longer exist — the wire guard refuses unmanaged native compaction. Explicit dsh.nativeCompactionModels rules coordinate host ownership and bypass that wire lane. Leftover dsh.allowDshCompaction values are ignored with a one-time deprecation warning; apply host-side suppression instead (#3354/#2474). The live keys — dsh.authoredCompaction, dsh.contextTab, dsh.contextTabLabel — are documented in the following entries. |
| `dsh.nativeCompactionModels` | { provider?: string, model: string }[] | [] | — | Opt selected DSH Web-preset models into native compaction (#6121). Exact provider ID is optional; model matches exactly or by a trailing * prefix, e.g. gpt-* or codex/gpt-*. Unmatched models keep bili. Requires a host restart. Native summaries bypass bili and host replacement generations isolate later bili state; see docs/dsh-native-compaction.md for supported profiles, handoff limits and update guidance. |
| `dsh.nativeCompactionModels.model` | string | required per rule | — | Each native-compaction rule's exact model ID or prefix ending in *. Display names and other wildcard forms are not accepted. |
| `dsh.nativeCompactionModels.provider` | string | omitted (all providers) | — | Optional exact DSH provider ID restricting one native-compaction model rule. |
| `dsh.authoredCompaction` | boolean | true (on, #3901 flip) | BILI_DSH_AUTHORED_COMPACTION | bili answers dsh compaction summarize calls locally with the folded snapshot instead of refusing (#3723/#3733). ON by default since the 0.1.203 dogfood window held; false (or env BILI_DSH_AUTHORED_COMPACTION=0) restores the #1729 refusal path. |
| `dsh.contextTab` | boolean | true | BILI_DSH_CONTEXT_TAB | Registers the DSH top-bar 「上下文」/「Context」 conversation tab at all (#3862/#4237): false removes ONLY that tab — compression, the settings section and every other surface keep working. Hiding never disables compression; the ledger stays reachable via the settings section (会话 subpage), the plugin bundle config face, the Web UI and the /acp command. Takes effect on the next page load / dsh restart (slot registration happens at page load); default true = today's behavior unchanged. |
| `dsh.contextTabLabel` | string | unset (built-in 「上下文」/「Context」) | — | Custom display name for the DSH top-bar Context tab (#4237), e.g. "压缩账本" when another plugin (dsh-context) owns the name 「上下文」. Trimmed non-empty string wins over the built-in label; blank or absent falls back to the built-in. File-only tier (display preference, no env knob per #2030). Default unset = built-in label unchanged. |
Expand Down
5 changes: 4 additions & 1 deletion docs/configuration.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@
| `compat.streamErrorShape` | "protocol" \| "completion" | protocol | BILI_STREAM_ERROR_SHAPE | 200 已提交后上游流失败的呈现方式:协议原生错误帧(默认)或旧版合成完成形态。 |
| `compat.noCacheControl` | boolean | false | BILI_NO_CACHE_CONTROL | 完全停止 Anthropic 通道的 cache_control 断点打标(面向拒收该字段或有自有断点策略的上游/中继的逃生门)。 |
| `compat.keepResponseId` | boolean | false | ACP_KEEP_RESPONSE_ID | 在内核重建的 Responses 请求上保留 previous_response_id(默认剔除,使重建请求体永不引用上游从未签发过的响应 id)。 |
| `dsh` | object | {} | BILI_ALLOW_DSH_COMPACTION | 段仍被识别,但其原逃生门已移除(#3666,取代 #2028):allowDshCompaction 键与 BILI_ALLOW_DSH_COMPACTION 环境变量已不存在——dsh 原生压缩现在在所有线路上被无条件拒绝。遗留的 dsh.allowDshCompaction 取值会被忽略(一次性弃用警告);请改用宿主侧抑制(#3354/#2474)。存活的键——dsh.authoredCompaction、dsh.contextTab、dsh.contextTabLabel——见接下来的条目。 |
| `dsh` | object | {} | BILI_ALLOW_DSH_COMPACTION | 段仍被识别,但其原逃生门已移除(#3666,取代 #2028):allowDshCompaction 键与 BILI_ALLOW_DSH_COMPACTION 环境变量已不存在——线级守卫拒绝未受管理的原生压缩。显式 dsh.nativeCompactionModels 规则协调宿主压缩归属并绕过该线路。遗留的 dsh.allowDshCompaction 取值会被忽略(一次性弃用警告);请改用宿主侧抑制(#3354/#2474)。存活的键——dsh.authoredCompaction、dsh.contextTab、dsh.contextTabLabel——见接下来的条目。 |
| `dsh.nativeCompactionModels` | { provider?: string, model: string }[] | [] | — | 指定 DSH Web 预设中的模型使用原生压缩(#6121)。可选 provider 精确匹配;model 精确匹配或使用末尾 * 表示前缀,例如 gpt-*、codex/gpt-*。未匹配模型继续使用 bili,需重启宿主生效。原生摘要绕过 bili,宿主替换代数隔离后续 bili 状态;支持范围、切换边界和更新方式见 docs/dsh-native-compaction.zh-CN.md。 |
| `dsh.nativeCompactionModels.model` | string | required per rule | — | 每条原生压缩规则的模型 ID,精确匹配或末尾 * 前缀匹配,不使用显示名或其他通配形式。 |
| `dsh.nativeCompactionModels.provider` | string | omitted (all providers) | — | 可选的 DSH 供应商 ID,精确限定该条原生压缩模型规则。 |
| `dsh.authoredCompaction` | boolean | true (on, #3901 flip) | BILI_DSH_AUTHORED_COMPACTION | bili 用折叠快照本地应答 dsh 压缩摘要请求而非拒绝(#3723/#3733)。0.1.203 狗粮窗口守住后默认开启;false(或环境变量 BILI_DSH_AUTHORED_COMPACTION=0)恢复 #1729 拒绝路径。 |
| `dsh.contextTab` | boolean | true | BILI_DSH_CONTEXT_TAB | 是否注册 DSH 顶栏「上下文」会话标签页(#3862/#4237):false 只移除该标签页——压缩、设置页一节及其余所有入口不受影响。隐藏绝不关闭压缩;账本仍可从设置页(会话子页)、插件 bundle 配置面、Web UI 与 /acp 命令查看。下次页面加载 / dsh 重启生效(槽位注册发生在页面加载时);默认 true = 现状不变。 |
| `dsh.contextTabLabel` | string | unset (built-in 「上下文」/「Context」) | — | DSH 顶栏上下文标签页的自定义显示名(#4237),例如另一插件(dsh-context)已占用「上下文」时改为"压缩账本"。去空白后的非空字符串优先于内置名;留空或缺省回退内置名。仅文件层(显示偏好,按 #2030 不设 env 开关)。默认缺省 = 内置名不变。 |
Expand Down
62 changes: 62 additions & 0 deletions docs/dsh-native-compaction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# DSH model-selective native compaction

Proposed in #6121. This opt-in feature targets DSH Web agent presets containing `@deepseek-ai/dsh-compaction-basic` (standard, ptc, cordis, and equivalent custom presets). Default configuration `[]` preserves bili's existing behavior. Restart the host after changing the list; existing preset instances retain their original composition.

```json
{
"dsh": {
"nativeCompactionModels": [
{ "model": "gpt-*" },
{ "model": "codex/gpt-*" }
]
}
}
```

Rules match the actual DSH **model ID**, case-sensitively, not its display label. A trailing `*` means prefix matching; other wildcards and a standalone `*` are rejected. Optional `provider` is an exact DSH provider ID. Omit it to match the model across providers. All unmatched models keep bili. `codex/gpt-*` is needed when a gateway includes that namespace in the model ID. `passthrough` alone cannot enable the native backend.

```mermaid
flowchart LR
A[DSH selected model] --> B{Native rule matches?}
B -->|yes| C[Unmodified DSH compaction]
C --> D[Direct provider call]
B -->|no| E[Durable host replacement generation]
E --> F[Bili conversation namespace]
F --> G[Existing bili compression]
```

Native thresholds, retention settings, summary prompts and summary-model resolution remain DSH-owned. On a model switch DSH can summarize using its previous routed model unless its own summary-model configuration overrides that choice. Those summary requests still bypass bili, independently of the summarization model's membership in the rules.

This adapter only selects the compaction owner. DSH retains control of summary input, tools, output budget, model selection, prompts, call count and failure handling. The patch performs no extra budget validation, history splitting, intermediate summarization or merge prompting. An asynchronous scope marks native summary requests for direct transport without changing their content or affecting concurrent bili sessions.

Native steps do not expose bili compression tools; bili steps do not trigger host compaction. Native HTTP requests preserve their bodies, headers and provider transport. A WebSocket reused across ownership modes rejects that frame and closes so the existing host transport recovery can reconnect.

When switching bili → native, DSH uses its own durable history and checkpoints with its existing compaction strategy. Bili fold summaries are not assembled into a replacement native summary. If the selected history exceeds the summary model window, the native request and native failure/recovery behavior are preserved, without secretly splitting history or switching models. A switch cannot guarantee successful compaction of arbitrarily long history. Consecutive native compactions remain controlled by the stock pressure strategy.

When switching native → bili, the host's durable `surface.replaceGeneration` changes the bili conversation namespace. New folds cannot reuse an earlier substrate. The value survives replay/restart and does not change on ordinary appends or model switches without a host replacement. Original DSH session IDs and append-only history are unchanged. After a replacement, negotiated aliases, fork adoption and incremental conversion are disabled for that substrate; full sends plus a fresh watermark seed provide a conservative boundary. Other sessions retain their existing path. The Context tab and `/acp` follow the active namespace; native mode reports its ownership rather than showing stale bili data.

## Compatibility and validation

Validated with DSH `0.2.2-rc.1`. The integration script uses the real Cordis loader, isolated compaction realm, token meter, Session replay and native checkpoint engine, with a deterministic fake LLM (no account traffic). Run after building:

```sh
node scripts/test-dsh-native-compaction.mjs /absolute/path/to/isolated-dsh-runtime
```

The caller must supply a detached runtime directory, not a running profile. No credentials, live sessions or production files are used by this test. The actual upstream model's summary quality and provider billing are not validated by a fake LLM.

Native requests fail closed when their preset has not attached the adapter. The stock minimal preset has no compaction backend: native rules preserve that behavior and do not add compression. Root-plane CLI compositions and unknown future DSH APIs require compatibility work before enabling rules there. This feature does not silently promise native compression on those profiles.

## Behavioral parity acceptance

The real DSH engine integration script replays identical events through the stock engine without the routing adapter and through the routed native engine. It compares actual summary requests, compaction events, generations and token results; only newly generated host identifiers are normalized, preserving original message and tool IDs. Cases cover below-threshold, automatic/manual/region compaction, model switches, configured summary models, provider failure, cancellation and oversized histories/tool catalogs. Overflow must fail the same way in both arms rather than succeed through a new adapter fallback.

The bili comparison uses real plugin request interception, proxy and compression tools to compare bili-only mode with an unmatched model under selective routing: tool lists, fold results and provider requests must match. Separate coverage checks round trips, checkpoint-generation replay and asynchronous isolation. A deterministic upstream removes random model-output differences; this verifies routing behavior, not summary quality or losslessness. Earlier batch-merge A/B results describe removed code and are not acceptance evidence for this revision.

## Carrying a patch across updates

Keep the source commit/patch and tests in version control. Build candidates from the desired upstream release, apply the patch with `git apply --check`, then run typecheck, focused tests, build, and the real-DSH integration script before packaging. Use a profile-owned local `file:` package pin so the registry updater cannot overwrite the patch. Updates become an explicit rebuild-and-install workflow, not automatic registry replacement. Preserve the original package, profile manifest/lockfile and config for rollback. Never apply an old compiled `dist` over a newer upstream tree.

Unknown future upstream versions can conflict or change behavior even when a patch applies. Stop on conflicts or failed compatibility checks, retain the installed version, and review/rebase the patch. No finite test suite guarantees compatibility with every future release.

To return every model to bili after using this feature, keep the key and set `nativeCompactionModels: []`. An explicitly present empty list retains generation isolation; deleting the key or removing the patch is a separate migration and can expose an earlier bili namespace.
Loading
Loading