Skip to content

feat: disable dsh native auto-compaction in web profiles at load time (#3354) - #3451

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-17_dsh-compaction-disable-vendor
Oct 17, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-17_dsh-compaction-disable-vendor

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #3354

What

Vendors the key mechanism of deshark42/dsh-compaction-basic-disable (v0.1.1, MIT © 2026 deshark42) into bili's own bundle layer — ported into src/agent/dsh-compaction-disable.ts at the author's suggestion (their repo issue #1) and per owner decision on #3354 ("直接 include 进来关键代码,并在备注中写明出处").

In profiles bundling @deepseek-ai/dsh-web-app the running compaction-basic instance lives inside an agent preset (preset-standard.config.plugins) where no patch layer can address the nested row by id (#1772/#2360). The bundled - id: compaction-basic / auto: false lands on web-app's already-disabled host-plane row and changes nothing — so dsh native auto-compaction stayed ON while bili owns the lane, protected only by the wire-level refusal guard (#1729): any checkpoint that lands outside bili's knowledge durably shadows the raw history and destroys the compression substrate. The #2474 full-snapshot recipe closed the gap but freezes the preset roster until re-copied after every dsh preset update.

This change removes the producer at load time instead:

  • src/agent/dsh-compaction-disable.ts (new, ~90 lines, zero deps): pure recursive row marking (compaction-basic + command-compact → disabled: true, detached copies), a cordis internal/config middleware registered {global: true} that applies it to every @deepseek-ai/dsh-agent-preset resolved config, and a gate service (biliBasicCompactionPolicy) provided AFTER the middleware registers.
  • src/agent/dsh-native.ts: apply() calls registerCompactionDisable(ctx) right after the kill-switch early return (a kill-switched bili hands the lane back to stock dsh); boot note rewritten (still one durable [dsh-client] line, now naming both paths).
  • dsh.bundle.patch.yml + launcher overlay (writeDshAcpPatch, single source of truth compactionDisablePatchRows() pinned by test): four preset gate rows (preset-standard/-ptc/-minimal/-cordis inject: [biliBasicCompactionPolicy]). Entry inject lists are REPLACED by patches, not concatenated — if a future dsh ships its own inject list on these entries, merge manually in both layers (commented in both).
  • Docs: CLIENTS en/zh, CONFIGURATION en/zh (recipe demoted to fallback, scope note updated), README en/zh.

Behavior changes (old → new)

Surface Old New
Web profiles, bili ON native auto-compaction ON (wire guard only); manual /compact available OFF at load time (preset rows disabled: true); /compact unavailable there; ACP compression unaffected
Non-web profiles, bili ON host plane auto: false; manual /compact available unchanged
Kill-switched bili stock dsh (no preset handling existed) unchanged — overlay not registered when plan.mode === "off"
Boot log in web profiles one-time warning naming the #2474 recipe one-time note confirming the load-time stance + #2474 fallback

Fail-safe degradation per layer: no internal/config hook (older/newer dsh builds where the internal hook moved) → pre-#3354 behavior, wire guard stays the backstop, documented #2474 recipe remains the manual path; no service registry → presets boot as before. If bili's own bundle entry fails to load, the inject gate leaves the four presets pending rather than starting unprotected (same validated design as the upstream plugin).

Coexistence with the upstream plugin is safe: different gate service name, both overlays idempotent (disabled: true twice = disabled: true).

Config surface

No change — no new env var, config key, or CLI flag.

Tests

  • New tests/issue3354-dsh-compaction-disable.test.ts: row-marking depth/purity/degenerate inputs, per-layer degradation, entry-predicate transform, and byte-exact agreement between the root bundle yml and the launcher overlay.
  • tests/dsh-native.test.ts: mockCtx gains registry/event-bus capture; kill-switch test asserts NO overlay registration and NO gate publish; web-profile boot-note assertions updated; new attach-mode test asserts middleware registered + gate published (provide after register).
  • Local targeted runs green: typecheck, build, tests/issue3354-*, tests/dsh-native.test.ts, tests/launcher.test.ts, tests/issue2605-dsh-retry-patch.test.ts (357 tests, 0 failures). Full-suite verdict = CI.

No changes under kernel/ or pi-subagents/; no version bump.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重:不重复 —— 按「dsh compaction disable / deshark42 / web profile preset compaction / load-time overlay」等关键词检索了 open+closed issue 与近期 PR,无同症状+同机制的在途条目。本 PR(#3451,Closes #3354)是该机制的唯一实现;近邻项 #3294(把 #2474 手工配方收紧为 disabled: true)+ closed #2476/#1786 都是手工 fallback 配方的打磨,与本 PR 的自动化加载期主路径互补不重复。

审核初步结论:

现在把分支 rebase 到当前 master 解掉冲突,本地跑定向验证(typecheck + 相关测试文件),push 回 PR 分支,再给完整八问结论。

@ranxianglei
ranxianglei force-pushed the 2026-10-17_dsh-compaction-disable-vendor branch from a788b47 to 4253b41 Compare October 16, 2026 20:32
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-17_dsh-compaction-disable-vendor (8e110a6)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4068-pr.3451.2684a02

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr3451.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

冲突已解决,PR 恢复可合并(mergeable: true,当前 blocked 状态是新 head 的 CI 检查还在跑)。

做了什么:把分支 2026-10-17_dsh-compaction-disable-vendor rebase 到最新 master(ce9bc90a),解决冲突后 --force-with-lease 推回。新 head:4253b41b6。

冲突原因:本分支切出后,master 合入了 dsh 增量轮次标记系列(#3248 phase 2、#3369/#3370/#3378 修复),与本 PR 在三个文件的同一处 import 区各自加了新行——纯并行添加,无语义交叉:

文件 冲突内容 解法
src/agent/dsh-native.ts master 加 incremental-client.js import vs 本 PR 加 dsh-compaction-disable.js import 两边都保留
src/launcher.ts master 加 host-log.js import vs 本 PR 加 compactionDisablePatchRows import 两边都保留
tests/dsh-native.test.ts master 加了 #3370 原子性测试及其新 import vs 本 PR 加 BILI_COMPACTION_DISABLE_SERVICE import 并集(master 的完整 import 列表是超集)+ 保留 #3370 测试 + 加上本 PR 的 import

验证:rebase 后 diff stat 与 rebase 前完全一致(12 文件,+415/-74,内容零改动);本地 typecheck 通过;定向跑 tests/dsh-native.test.ts + tests/issue3354-dsh-compaction-disable.test.ts 共 61/61 全绿。全量回归以远程 CI 为准。

八问:

  1. 是什么问题:PR 分支与 master 合并冲突(GitHub 判 dirty),无法合并。
  2. 什么原因导致的:master 在本分支切出后合入了 dsh 增量轮次工作,与本 PR 在同一 import 区并行新增行,产生文本冲突。
  3. 影响范围与严重程度:仅该 PR 的可合并性受阻,无用户行为影响、无线上影响。
  4. 怎么修复的:rebase 到最新 master,三处冲突全部按「意图并集」解决(保留双方新增),未改任何语义。
  5. 是否有回归问题:无——冲突均为 import 行的并行追加,并集解法不丢任一侧行为;typecheck + 定向测试(含 master 侧新增的 dsh 增量轮次:标记竞态可让增量体不带标记直发,模型在无历史状态下静默答错(需开启 rollout 才触发) #3370 原子性测试)全绿。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及。

收工判定:冲突已清,等 CI 转绿后即可人工合并。

… gate

The four package-name/preset-id constants in dsh-compaction-disable.ts are
consumed only within that module; dropping their leading export satisfies the
unused-exports CI gate without changing any behavior or public surface.

Refs #3451
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

审核结论:方向正确,可合。 我把分支 rebase 到了当前 master,并修掉了 CI 唯一红门(unused-exports),已 push 到 PR 分支 8e110a696。下面按八问答。

查重:不重复(首条已述——#3294 与已关闭的 #2476/#1786 都是「手动 fallback 配方」打磨,与本 PR「load-time 摘除生产者」机制不同,互补不重复)。


① 是什么问题:dsh web profile 里内置的 compaction-basic 实例嵌在 agent preset 里,dsh 的 patch 引擎按 id 够不到嵌套行(#1772/#2360),旧的 #2474 全量快照配方还会冻住 roster——需要在 load-time 把它摘掉,而不是在 wire 层拒绝。

② 什么原因导致的(根因):web profile 的 compaction-basic 实例嵌套在 agent preset 的 config.plugins 下,patch 引擎只能索引顶层行 → 无法按 id 定位嵌套行,所以只能在 load-time「疏」(递归标记 disabled:true)而非 wire 层「堵」。本 PR 把上游 deshark42/dsh-compaction-basic-disable v0.1.1(MIT,作者授权)的关键代码 vendor 进 bili bundle 层来落地这一点。

③ 影响范围与严重程度:bili ON + dsh web profile(preset-standard/ptc/minimal/cordis)→ dsh 原生 auto-compaction 从 ON 变 OFF(load-time),该 profile 内 /compact 不可用;ACP 压缩不受影响;非 web profile、kill-switch(bili off)路径不变。属有意行为变更,PR 已披露。

④ 怎么修的(方案):vendor 一个纯函数模块 src/agent/dsh-compaction-disable.ts(递归行标记、幂等、返回 detached copy);gate service 在内置/config middleware 注册之后才发布(fail-safe:overlay 加载失败则 4 个 preset 保持 pending,不会裸启动);与上游插件共存安全(service 名不同、双 overlay 都幂等)。launcher overlay 与 dsh.bundle.patch.yml 共用单一 source-of-truth(compactionDisablePatchRows),测试钉住两层一致。

⑤ 是否有回归问题:审了触碰路径的既有行为——dsh-native.ts 的 apply() 在 plan.mode==="off" 提前 return 后才调 registerCompactionDisable(kill-switch 不注册 → lane 交还 stock dsh,已有测试);launcher writeDshAcpPatch 只是追加 overlay 行;docs 中英同步。无意外回归。rebase 时三处冲突(src/agent/dsh-native.ts import、src/launcher.ts import、tests/dsh-native.test.ts)均按 union-of-imports / union-of-tests 解决,完整保留了 master 侧 #3378/#3369(incremental marker/ack)、#3332(threads-reforge)以及 #3370 的 atomic-conversion 测试块。

⑥ 是否破坏缓存:不涉及(无缓存/重试/增量游标/去重键改动)。

⑦ 是否改了设计方向:不转向,是在既有「load-time 疏 vs wire 层堵」框架内落地,符合你「直接 include 关键代码并注明出处」的决策。

⑧ 是否引入新配置:不涉及(无新 env/config/CLI flag;那个 service 名是内部常量,不是配置面)。


我这轮实际做的事:

  1. rebase 到当前 master(ce9bc90a3):原分支落后 master 几十个 commit,mergeable=dirty,三个同文件冲突按 union 解决。(注:另一个并发会话几乎同时做了逐字节相同的 rebase,我没有 force-push 覆盖它。)
  2. 发现并修复 CI 唯一红门 unused-exports:dsh-compaction-disable.ts 里 4 个常量(DSH_COMPACTION_BASIC_PACKAGE / DSH_COMMAND_COMPACT_PACKAGE / DSH_AGENT_PRESET_PACKAGE / DSH_WEB_PRESET_IDS)只在文件内部使用却被 export,被 gate 判为 INTERNAL_ONLY。我 grep 确认没有任何 src/test 外部 import 后,去掉这 4 个常量的 export(不改变任何行为或公共面)。本地复跑:check-unused-exports.mjs=clean、npm run typecheck=clean、定向测试(issue3354 / dsh-native / launcher / issue2605)= 365 pass / 0 fail / 1 skip。已 fast-forward push 到 PR 分支 8e110a696(未覆盖任何人)。
  3. CI(新 head 8e110a696):之前红的 unused-exports 已转 success;所有静态 gate(static-gates / test-import-graph / config-surface-guard / version-guard / kernel-guard / pi-subagents-guard / lane-guard / lock-sync / docs-* / plan / build-artifact)全部 success,0 failure;full test 分片仍在跑。

收工判定:方向正确、可合。 唯一阻塞项 unused-exports 已修并 push,等 full test 分片确认即可由你合并(合并我只提醒、不代做)。

@ranxianglei
ranxianglei merged commit baffc28 into master Oct 17, 2026
43 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.511-master.baffc28 (rolling master tag).

npm install -g billion-context@0.0.511-master.baffc28  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

See how to integrate the plugin that automatically disables dsh compression. | 自动关闭 dsh 压缩的插件看如何集成

1 participant