Repository navigation
Description
bili-authored client compaction: let the host's own compaction flow run, but bili writes the checkpoint
Follow-up to #3723. Design discussion happened there (see also #3641 — the snapshot doctrine that makes this safe).
The problem, in one paragraph
Hosts (dsh today, others later) get crushed by their own session files: dsh keeps every message forever because its compaction is refused by us (the #1729 guard 422s it), so the file only grows — #3723 shows a 39.7 MB / 9001-message session file melting the renderer. That refusal made sense before #3644: back then a landed host checkpoint shadowed the raw history we relied on, which genuinely destroyed our substrate. Post-#3644 that premise is gone — the substrate is our server-side snapshot, and any client-side deletion is classified benign (blocks snooze, originals stay in CCR). What we still don't want is a foreign checkpoint landing: text we didn't write, that we'd have to recognize by fuzzy matching, and that may not match what the upstream actually has.
The proposal
Use the host's own compaction flow, but fill it with our content:
- Intercept the host's compaction call — the existing marker-decisive detectors (nudge 死锁无检测:同一 session 交替收到两种结构互斥的请求流(巨型单消息 ↔ 多轮)时不告警 #1729 family) stay, their purpose inverts from "refuse" to "answer".
- Answer locally, zero egress — the autoModeForge discipline (auto mode 状态丢失,会话累计输入了593.44M tokens #2740): we already forge Claude Code auto-mode verdicts the same way. The response we hand back is our own folded snapshot:
- an identity header line:
<bili-snapshot v1 conv=... seq=... refs=...> - the standard summaries the upstream already sees (minus protocol tags)
- an identity header line:
- Recognize it declaratively on resend — the tag travels in message content, and clients resend message content verbatim, so the tag survives every round trip (personaTag v2.2 is the standing precedent). The
refsmap straight to our server-side blocks; no word-bag guessing. - Recoverability — originals never leave our hands: CCR retrieve,
bili export, the fork endpoint. A client-facing "expand this summary" endpoint is the only missing piece (small, built on the existing canonical cache). - Client display = truth — what the host shows after compaction is exactly the compressed history the upstream has. Three views (client / upstream / server) agree for the first time.
- Single-author discipline — a host compaction that does NOT carry our tag still gets 422. Nobody else's checkpoint ever lands.
- Trigger — bili's own meters decide when: resent-history bytes / message count / token estimate (media priced correctly since fix: count custom-shape media parts in context-size decisions (images no longer invisible to folding) #3412).
Coverage per client
| Client | Mechanism |
|---|---|
| pi-native | true pruning (the session files are ours) |
| dsh | compaction-basic / command-compact flows, we author the response — fixes #3723's file growth |
| Claude Code | /compact and auto-compact already flow through the wire and are tolerated post-#3644; upgrading to authored keeps display = truth |
| codex | compact intercept mode already exists (codexCompactMode() === "intercept", src/server.ts) — extend it to author the checkpoint |
| opencode | its summarize flow rides our lane; same treatment |
| plain proxy/MITM third-party | we can't touch their files; irrelevant — the tag lives in the resent content, which is all we ever see |
Rolling loop
prune at threshold → iterate on top of the snapshot → hit threshold again → prune again. The identity header is stable across cycles. Snoozed blocks never re-inject over the client's checkpoint (no double history, no double billing).
Acceptance
- after an authored compaction, the host's file shrinks (dsh: renderer recovers)
- the resent checkpoint is recognized declaratively (no fuzzy path); blocks stay claimed
- CCR retrieval by header refs works; export/fork unaffected
- un-tagged host compaction still 422s
- upstream wire stays small across the whole loop
Relation to #1790
#1790 (external contribution, review-green twice) is the no-proxy sibling of this: same philosophy (host compaction stays the fold mechanism, bili-side supplies the content), inserted via Claude Code hooks instead of the wire. It serves users who cannot route through bili at all — a different audience, not superseded by this. Its documented host-side mechanics (PreCompact gating, post-compact restore injection, transcript formats, overflow self-heal) are directly useful references for the wire-side work here. Recommend merging it as contrib in the same window.
Implementation notes
- interception point:
src/server/handle.ts(nudge 死锁无检测:同一 session 交替收到两种结构互斥的请求流(巨型单消息 ↔ 多轮)时不告警 #1729 guard sites —isDshCompactionCall+allowDshCompaction) - forged-response precedent:
src/auto-mode-forge.tsconsumers insrc/server/handle.ts - snapshot source: the folded view the prepares already build; identity header modeled on personaTag v2.2
- meters: existing threshold machinery (image/text pricing post-fix: count custom-shape media parts in context-size decisions (images no longer invisible to folding) #3412)
Activity
ranxianglei commentedon Oct 18, 2026
No-wire lane inclusion note (why this design also covers #1790's approach)
The audience #1790 serves refuses traffic routing (base-URL change = rewritten requests = subscription account risk), not running a local service. A local bili engine that only receives hook uploads and serves MCP recall never touches a byte of traffic — zero account risk. So the same engine covers them:
Absorption map for #1790: its archive store → unified store + CCR; its recall tools → thin MCP proxies over CCR; its vendored prompts → our compression engine (kills its version-skew pain); what stays host-side is exactly what requires host presence (PreCompact gate, post-compact injection).
The one physical boundary (no wire = no request rewriting): in-place range folding / prefix-cache preservation / reasoning drop / image stripping stay unreachable — same list #1790 documents. What the no-wire lane does get: recoverable, restorable, non-drifting, three-way-consistent.
ranxianglei commentedon Oct 18, 2026
Implementation delivered in #3737: the #1729 guard now answers dsh's compaction calls locally with the folded snapshot (zero egress) when
BILI_DSH_AUTHORED_COMPACTION=1— identity header + kernel-rendered block summaries, declarative replay recognition through the #2432 rebase, explicitallowDshCompactionstill wins, originals recoverable via CCR/export/fork. 15 dedicated tests + all affected families green.ranxianglei commentedon Oct 18, 2026
[bot] 🏷
(ai: vllm-qwen/qwen3.8-27b)
查重:不重复——本 issue 是 owner 设计方案,其实现已在 PR #3737(body 带
Fixes #3733)在途,本会话按自审路径做验证与评审,不重做。相关但不同的条目:#1790(CC hooks 无代理侧生兄弟实现,受众不同,不互相取代)、#3666/#3672(移除 allowDshCompaction 逃生门——影响本开关的未来形态)、#3723(本方案要修的无限增长 bug)。标签:dsh / scope/wiring / p2(功能请求;dsh 长会话文件膨胀真实存在但 bili 侧一直可用、渲染器退化是渐进的,p2 合适)
当前进展(PR #3737 @ 66e6130,两个提交:核心实现 + docs-coverage 门禁修复):
<bili-snapshot v1 conv=… seq=… blocks=… />+ 内核渲染格式的活跃块摘要、重放经 [bug] DSH 桌面端 0.1.188:宿主原生压缩落地摧毁折叠基底 → 同一区间永久不可锚定、compress 连片失败并熔断(compaction-basic auto:false 仍无效) #2432 rebase 声明式识别(无 fuzzy 路径)、未标记/判不出的宿主压缩仍 422、显式allowDshCompaction优先于 authored。BILI_ALLOW_DSH_COMPACTION(一新一旧 scope note,合并残留),PR 的新行正好插在中间。我会按「小问题直接修」在 PR 分支补一个标注 commit 把重复行合并。docs: merge duplicated BILI_ALLOW_DSH_COMPACTION rows in CONFIGURATIO…
test: responses-wire landing lane for authored checkpoints (#3733)
ranxianglei commentedon Oct 18, 2026
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)
#3737 审核收尾——全部验证完成,结论:可合(等人工合并)。以下是完整判定。
结构化八问
allowDshCompaction=true或重启),所以不是 p1。<bili-snapshot v1 conv=… seq=… blocks=…>+ 内核渲染格式的活跃块摘要。重放识别是声明式的(tag 随消息内容走,refs 直映服务端块),不走 words-bag 模糊匹配;无 tag 的外来 compaction 仍 422。显式allowDshCompaction优先级保留(checked-first)。dsh_compaction_refused全部原样,e2e 双向钉死);[bug] DSH 桌面端 0.1.188:宿主原生压缩落地摧毁折叠基底 → 同一区间永久不可锚定、compress 连片失败并熔断(compaction-basic auto:false 仍无效) #2432/[Bug] dsh 原生压缩检测误报:历史里引用过 <compacted-summary> 即判为宿主压缩落地并 rebase ACP 状态(0.1.190) #2621 landed-checkpoint 检测在四个 wire 上以 OR 扩展接入,负向门全部保留(相邻家族 55/55 绿);无 fail-fast→吞错、无阈值/时序/输出格式漂移。BILI_DSH_AUTHORED_COMPACTION(env-only,默认 OFF,逐请求读取无需重启;file/web toggle 有意推迟,CONFIGURATION.md 已注明)。默认值下行为零变化。验收标准对照(issue 五条)
dshAuthoredCheckpointLanded记录并走 #2432 rebase证据链
74ba7835c核心矩阵全绿(run 39148682041:ubuntu-22 三分片 + ubuntu-24 单腿 + windows-22 两分片 + 双 static-gates + 全部门禁)。此前一次 PR 事件触发的矩阵在我 push 时被同 ref 并发组取消(infra 时序,非代码问题),已用 workflow_dispatch 补跑完整核心矩阵取得正式判定。74ba7835c,已在分支上):master 自 fix: native lanes reuse the shared proxy instead of spawning one per process (#3436) #3540 合并起在 CONFIGURATION.md 里带了两行重复的BILI_ALLOW_DSH_COMPACTION详注行(stack 分支产物,两版 scope note 互相矛盾)。合并为一行规范条目:保留 A 变体独有的 dsh native compaction guard refuses 100% → client ledger never shrinks → every step fails from turn 8, last 4 turns output empty | dsh 原生压缩守卫 100% 拒绝 → 客户端本地账本只增不减 → 会话第 8 轮起每步失败、后 4 轮输出全空 #3384/dsh压缩与bili压缩冲突 #2490 输出预算段 + B 变体的现行 See how to integrate the plugin that automatically disables dsh compression. | 自动关闭 dsh 压缩的插件看如何集成 #3354-overlay scope note(以 tests/issue3354-dsh-compaction-disable.test.ts 证明 B 为真)。diff 净 +1/-2,docs-coverage 门禁绿。备注
判定:#3737 可合。 设计逐条符合 issue 规格,验收 4/5 满足(第 3 条的部分性为 issue 自身点名的后续件),回归面审毕无破坏,CI 核心矩阵在真实 head 上全绿。
ranxianglei commentedon Oct 18, 2026
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)
增量复审:分支在我上一轮结论后又落了 3 个 review follow-up commit(
e726bcb0c→5e0ba2a53→4ce219647),已逐个过完并重新验证,结论维持可合,另发现并处理了一个合并机械阻塞。新提交复审(3 个,均通过)
e726bcb0cdocs: zh-CN env 表补全——与我在英文版做的重复行合并完全镜像:zh-CN 里同样的两行BILI_ALLOW_DSH_COMPACTION残留(一新一旧 scope note)合成一行规范条目(dsh native compaction guard refuses 100% → client ledger never shrinks → every step fails from turn 8, last 4 turns output empty | dsh 原生压缩守卫 100% 拒绝 → 客户端本地账本只增不减 → 会话第 8 轮起每步失败、后 4 轮输出全空 #3384/dsh压缩与bili压缩冲突 #2490 段 + See how to integrate the plugin that automatically disables dsh compression. | 自动关闭 dsh 压缩的插件看如何集成 #3354-overlay scope note 取并集),并新增BILI_DSH_AUTHORED_COMPACTION长格式条目。内容与英文版一致,无漂移。5e0ba2a53docs: KDD fix: address all code review findings (condense, routing, session-id, dead code) #2 hex-escape——模块头示例的身份头从字面尖括号改为\x3c/\x3e,与仓库内其他 bili-tag 示例(tag-echo-filter.ts / chain-checkpoint.ts)一致。纯注释,零行为变化(diff 确认仅一行注释)。4ce219647test: responses-wire landing lane(+134 行)——补真实覆盖缺口:此前落点→重放→rebase 的 e2e 只测了 openai wire,而 dsh 桌面端压缩实际走/v1/responses。新 lane 断言:responses wire 上零出站应答含身份头+块摘要、伪造流的output_text.done帧、从真实流提取 checkpoint payload、重放后dshAuthoredCheckpointLanded===true。这是对我上一轮「验收第 2 条」覆盖面的实质加强。重新验证(最终 head
4ce219647)合并阻塞(机械,已处理)
查
merge_state: blocked的原因:master 分支保护要求全部 12 个 full-matrix test leg 名 + 人工 review 批准,而 #3295 三层 CI 下普通 PR 事件只跑 core 6 leg——缺 ubuntu-24 shard 2/3、windows-22 shard 3、windows-24 全部 3 leg 六项必需检查,合并被卡。(ci.yml 注释称保护只钉 6 个 core 名,与实际保护配置 12 名不一致,属 #3295 落地时保护配置未同步;是否要把保护收紧到 6 名由你定,不在本 PR 范围。)处置:已给 PR 打上仓库既有的
ci:full标签(plan job 对 ci:full 标签事件放行 full scope)→ full 12-leg 矩阵已在跑(run 39152048757 @4ce219647)。跑绿后合并只剩你的批准这一步。判定
代码面:最终 head 全部验证通过,无需再改。等 full 矩阵跑绿 + 你批准后即可合;我会在矩阵完成后回一条确认。
ranxianglei commentedon Oct 18, 2026
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)
full 矩阵确认:run 39152048757 @
4ce219647completed / success——28 个 job 中 27 绿、1 skip(red-signal,仅 cron 事件跑,设计如此),零失败。全部 12 条 test leg(ubuntu-22×3 / ubuntu-24×3 / windows-22×3 / windows-24×3)+ 4 条 static-gates + 全部门禁通过。分支保护要求的 12 个必需检查名现已在最终 head 上齐备且全绿。合并只剩你的 review 批准这一步(保护配置要求人工批准,我无权代批)。
#3737 侧我的工作至此完结:核心实现与文档缺陷已审、3 个 follow-up commit 已增量复审、本地定向 16/16、core + full 两轮矩阵全绿、合并机械阻塞已清除。
ranxianglei commentedon Oct 18, 2026
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)
No-wire lane 设计注记已消化。判定与两个明确建议如下。
与 #3737 已交付设计的兼容性:无需改动,同构性成立
carriesBiliSnapshotCheckpoint只看消息内容里的 tag 前缀 + novelty 门([Bug] dsh 原生压缩检测误报:历史里引用过 <compacted-summary> 即判为宿主压缩落地并 rebase ACP 状态(0.1.190) #2621 纪律),字节怎么到达(wire 重放 vs hook 上传)无所谓。no-wire lane 里宿主把含 checkpoint 的 transcript 推上来,走的是同一条 [bug] DSH 桌面端 0.1.188:宿主原生压缩落地摧毁折叠基底 → 同一区间永久不可锚定、compress 连片失败并熔断(compaction-basic auto:false 仍无效) #2432 rebase 识别路径。conv=字段即会话键。只要两条 lane 都以宿主会话 id 为键(现状如此),no-wire → wire 升级时同一份被识别的会话直接延续——注记里的「isomorphic」是构造上成立的,不是需要额外保证的性质。范围与状态
#3737 保持 wire-lane 范围不变(已交付、已全验)。刚查过:merge_state 已是
clean——full 矩阵跑绿后分支保护的全部必需检查齐备,合并只剩你的批准。两个建议(各给一个方向,不甩选项)
Merge pull request #3737 from ranxianglei/2026-10-19_dsh-authored-com…
dsh authored client compaction: answer the ranxianglei#1729 guard loc…
storage wrap-up: GC/archive + reap journal + media CAS + incremental …
docs: backfill LIFECYCLE.md — register 22 unledgered BILI_* env vars …
fix: re-anchor on the authored checkpoint's conv declaration when ful…
fix(#5596): correct stale #3733 changelog claim — refusal bytes no lo…
fix(conflict): name bili's own authored checkpoint in the dsh landing…
fix: exempt the dsh plugin lane and compaction calls from the 32 MiB …
fix(#5596): correct stale #3733 changelog claim — refusal bytes no lo…