Skip to content

[PR] dsh authored client compaction: answer the #1729 guard locally with the bili snapshot (#3733) - #3737

Merged
ranxianglei merged 7 commits into
masterfrom
2026-10-19_dsh-authored-compaction
Oct 19, 2026
Merged

ranxianglei merged 7 commits into
masterfrom
2026-10-19_dsh-authored-compaction

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #3733. Follow-up to the #3644 snapshot doctrine; closes the growth loop from #3723.

What

When BILI_DSH_AUTHORED_COMPACTION=1 (env-only rollout window, read per-request — no restart) and a dsh compaction summarize call hits the #1729 guard while the session holds an ACTIVE fold block, bili answers the call locally instead of refusing:

Landing recognition

The identity tag rides in the message text (clients resend content verbatim), so replay recognition is declarative: carriesBiliSnapshotCheckpoint with the #2621 carrier+novelty discipline (user plain-text carrier, fresh id only). The #2432 rebase handles the landing on all four wires exactly like a foreign checkpoint, but records metadata.dshAuthoredCheckpointLanded and logs info instead of warn.

Precedence & guards

situation behavior
knob on + active blocks authored local answer (200, forged body)
knob on + NO active blocks falls through to the same 422 (nothing to checkpoint)
allowDshCompaction (explicit) native forward wins — the user asked for dsh's own behavior
knob off the #1729 refusal, unchanged (status quo pinned by test)
passthrough lane (no session) guard untouched — no session, no snapshot to author

dshCompactionRefusedBytes (raw-ledger high-water) is recorded on authored answers too, so the #2490 output-clamp regimes keep planning against the raw scale. Originals stay recoverable via CCR / export / fork at all times.

Tests

tests/dsh-authored-compaction.test.ts — 15 tests: checkpoint render (header + kernel format, inactive skipped), forge bodies for all three wires (JSON + SSE frame/event-order parsing), unknown protocol → null, carrier+novelty gates, and six e2e lanes through a real proxy + mock upstream: zero-egress authored answer (+ counters dshAuthoredCompactions, no dshCompactionRefusals), stream:false JSON, knob-off 422 pinned, no-active-blocks 422, allowDshCompaction precedence, and full landing→replay→rebase→dshAuthoredCheckpointLanded. Affected families re-run green: dsh-compaction-guard 19, issue2432 11, issue2028 4, issue2709 5, issue3354 6, codex-compact-e2e 20, fold-reconcile 66, lane-decisions-matrix 58, codex-local-compaction 5.

Docs

CONFIGURATION.md: summary-table row + full description (both language copies). CHANGELOG entry.

…he bili snapshot (#3733)

Post-#3644 the substrate concern behind the #1729 refusal is gone, but the
refusal itself keeps dsh's context gauge growing and its session file
ballooning unboundedly (#3723). When BILI_DSH_AUTHORED_COMPACTION=1 (env-only
rollout, per-request) and the session holds an active fold block, the guard
answers the compaction summarize call locally — zero egress, autoModeForge
discipline — with the folded snapshot: identity header <bili-snapshot v1
conv/seq/blocks /> + kernel-rendered block summaries (byte-identical to what
the model already reads upstream). dsh records it as its checkpoint; the file
shrinks; display/context/server agree.

Landing recognition is declarative (tag in the message text, #2621
carrier+novelty discipline) and flows the same #2432 rebase as a foreign
checkpoint, recorded as dshAuthoredCheckpointLanded (info, not warn).
Precedence: allowDshCompaction (forward native) wins; no active blocks falls
through to the 422; passthrough-lane guard untouched. dshCompactionRefusedBytes
high-water still recorded on authored answers (#2490 output-clamp regimes).

Fixes #3733
@ranxianglei ranxianglei changed the title dsh authored client compaction: answer the #1729 guard locally with the bili snapshot (#3733) [PR] dsh authored client compaction: answer the #1729 guard locally with the bili snapshot (#3733) Oct 18, 2026
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-19_dsh-authored-compaction (a887c16)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4567-pr.3737.f6d178a

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-pr3737.tgz
npm install -g package

Install instructions are refreshed on each push.

ranxianglei and others added 2 commits October 19, 2026 00:34
…N.md

In-passing fix found while reviewing #3737: since the #3540 merge, master has
carried two adjacent BILI_ALLOW_DSH_COMPACTION detail rows — one with the
#3384/#2490 output-budget paragraph but a stale pre-#3354 scope note, one with
the current #3354-overlay scope note (the overlay marks preset-nested rows at
any depth, pinned by tests/issue3354-dsh-compaction-disable.test.ts). Merge
them into one canonical row keeping both unique paragraphs; the new
BILI_DSH_AUTHORED_COMPACTION row from #3733 now sits in a single place.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复。 按失败签名与主题检索了 open+closed issue/PR(dsh-authored-compaction、authored compaction、bili-snapshot、DshAuthoredCompaction):#3737 是唯一实现该设计的 PR。相关但在途、机制不同的条目:#3672(移除 allowDshCompaction 逃生门——与本 PR 的优先级行有交互,若先合入需回头核对本 PR 该行的措辞与行为)、#3712(rebase 恢复静默全损——同一 checkpoint 家族,不同症状/机制)。无并行重复工作可并入。

标签: dsh + scope/wiring + p2(env 开关后的功能,落在 dsh 客户端通道 × 服务端协议边界;对应 #3723 的 p2 增长环)。非缺陷报告,不打 bug。

审核进行中:分支已 checkout(74ba783,12 文件 +652/−12),完整 diff 已通读,CI 各 lane 运行中(截至现在无失败)。正式结论按结构化八问发第二条评论。

awork added 3 commits October 19, 2026 01:15
…up row; add DSH_AUTHORED_COMPACTION long-form entry)

Review follow-up on #3737: commit 74ba783 merged the duplicated
BILI_ALLOW_DSH_COMPACTION rows in CONFIGURATION.md but left the zh-CN
copy with both rows still present (one carrying the #3384 output-budget
sentence, the other the newer #3354 scope note). Merged them into one
row mirroring the EN union, and added the missing long-form
BILI_DSH_AUTHORED_COMPACTION paragraph so the zh file matches the EN
coverage (summary-table row + full description).
Review follow-up on #3737: the module-header example rendered the
identity tag with literal angle brackets, unlike every other bili-tag
example in the codebase (tag-echo-filter.ts / chain-checkpoint.ts write
\x3c/\x3e even inside comments) — tooling that strips well-formed tags
would mangle the example. Comment-only, zero behavior change.
Reviewer follow-up on #3737: the landing->replay->rebase e2e covered only
the openai wire, but dsh desktop's compaction actually rides /v1/responses
(#2360) — an untested prepare-responses OR-branch wiring mistake (wrong
knownIds space or message view) would pass CI silently. Add a self-contained
responses harness (function_call SSE arm turn folding m00001..m00008) that
pins: authored answer on the production wire (zero egress, identity header +
kernel-format summary in the prompt-forge stream), and replay through
x-bili-plugin: dsh recognized via response.output_text.done extraction ->
dshAuthoredCheckpointLanded.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

PR #3737 审核结论(八问)

1. 是什么问题
dsh 的原生压缩 summarize 调用被 #1729 guard 拒绝(422),dsh 每次被拒就重试,session 文件无限增长(#3723:39.7 MB / 9001 条消息,渲染器最终熔掉)。本 PR 让 bili 在会话持有 active fold block 时本地应答这类调用:零出口流量,payload = 我们的折叠快照(身份头 <bili-snapshot v1 …/> + kernel 格式摘要),客户端显示、模型上下文、服务器状态第一次三方一致。

2. 什么原因导致的
#1729 guard 的原始目的是阻止「外来摘要」进入服务器状态。但 #3644 快照教义已确立:落地的客户端 checkpoint 对服务器基底无害——真正有害的只是「一份不是我们造的摘要」。所以正解不是继续拒绝,而是把拒绝变成「我们自己造」:同一个调用由 bili 用自己的快照应答,dsh 把它记为 checkpoint,#3723 的增长环就此闭合。这是「疏」不是「堵」:修的是摘要的生产者,不是在传输层过滤症状。

3. 影响范围与严重程度
默认 OFF(env-only BILI_DSH_AUTHORED_COMPACTION,每请求读取,运行中的代理免重启翻转)→ 现有用户行为零变化。开启后只影响「会话有 active block 的 dsh compaction summarize 调用」:原 422 → 现 200 forged body。所修问题本身 p2(能用但 session 文件无界增长、需绕行)。

4. 怎么修复的
三层机制:

5. 是否有回归问题
逐项清点触碰路径的既有行为:

  • 开关关闭路径字节级不变(测试钉死:422 + error.code=dsh_compaction_refused + never-forwarded);
  • 无 active block → 422 不变(钉死);
  • 显式 allowDshCompaction 优先权不变(测试断言双向:forwarded natively 且不计入 authored);
  • passthrough 车道不动;
  • dshCompactionRefusedBytes 高水位在 authored 路径同样记录——dsh压缩与bili压缩冲突 #2490 output-clamp 继续按原始规模规划(有意设计,披露);
  • 新增 metadata key(dshAuthoredCompactions / dshAuthoredCheckpointLanded)不影响既有消费者。
    高危模式逐项过:无语义漂移(默认 OFF 下拒绝语义完整保留)、无 fail-fast 变吞错、无阈值/时序/输出格式漂移、缓存与重试策略未动。验证:本地定向 14 个受影响文件 233 例全绿;远程 CI 最终 head 4ce219647 全绿(44 项检查 0 失败);分支与 master 零落后。

6. 是否破坏缓存
否。fold 状态、前缀缓存、增量游标语义未动;去重键未变;高水位单调性保持。

7. 是否改了设计方向
无架构转向。是 #3644 快照教义的延伸一步:教义说「落地的 checkpoint 无害」,本 PR 让「checkpoint 由我们制造」。wire 协议边界不变(responses 复用 codex prompt-forge 体)。

8. 是否引入了新的配置
有——env-only BILI_DSH_AUTHORED_COMPACTION(默认 off,每请求读取,灰度窗口语义)。CONFIGURATION.md 中英双份 + website/config-reference/env-only.yaml seed 均已文档化(符合 #2030 env-only 类别:host-side posture / rollout window)。若日后转正,可迁移为 config-file key,本期不需要。


审核中直接推上 PR 分支的三个 commit(均已随最终 head 过 CI)

  1. e726bcb0c docs:zh-CN 环境表补全——BILI_DSH_AUTHORED_COMPACTION 长格式段落中文缺失(EN 有),补齐(ework-translate 对照后按仓库文风润色);顺手合并了 zh 里两行重复的 BILI_ALLOW_DSH_COMPACTION(该重复早于本 PR 存在,master 双语各两份;PR 自己合并了 EN 侧,zh 侧遗留)。
  2. 5e0ba2a53 docs:模块头注释里的 snapshot tag 示例改为 hex escape(\x3c/\x3e)——KDD fix: address all code review findings (condense, routing, session-id, dead code) #2 约定连注释都要转义,字面 tag 会被工具链剥掉。
  3. 4ce219647 test:补 responses-wire e2e 车道。原 15 个测试的 landing→replay→rebase 只覆盖 openai 线路,而文档明确写着 dsh 桌面端压缩实际走 /v1/responses(bili 插件模式下 allowDshCompaction 在 responses 线路上完全失效 —— DSH 原生压缩落地、折叠基底被摧毁、compress 连片失败 #2360)——prepare-responses 那个 OR 分支若接线有误(knownIds 空间传错之类),CI 会静默通过。新车道自包含 harness(function_call SSE arm 轮折叠 m00001..m00008),钉死:生产线路上零出口 authored 应答(身份头+kernel 格式摘要在 prompt-forge 流内)+ 经 response.output_text.done 从真实流帧提取 payload 重放 → dshAuthoredCheckpointLanded=true。文件现 16/16 绿。

测试有效性

断言有牙:零出口用 mock upstream 计数器实证(非 mock 形状)、422 双向钉死(gate 纪律 #3617)、优先权双向断言、landing 解析真实 SSE 流帧而非重放 fixture;确定性达标(listen(0)、finally 清 env、store 禁用)。无恒真断言。

备注

判定:可合。 默认 OFF 保证零现状变更,opt-in 路径双向钉死,生产线路(responses)落地识别已有回归兜底。等人工合并 https://github.com/ranxianglei/billion-context/pull/3737。

@ranxianglei ranxianglei added ci:full Run the FULL CI matrix (all e2e lanes + 12-leg test matrix) on this PR review中 labels Oct 18, 2026
@ranxianglei
ranxianglei merged commit 39fb841 into master Oct 19, 2026
31 of 35 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.627-master.39fb841 (rolling master tag).

npm install -g billion-context@0.0.627-master.39fb841  # 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

ci:full Run the FULL CI matrix (all e2e lanes + 12-leg test matrix) on this PR dsh p2 review中 scope/wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bili-authored client compaction: let the host's own compaction flow run, but bili writes the checkpoint

1 participant