Skip to content

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

Closed

Description

@ranxianglei

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:

  1. Intercept the host's compaction call — the existing marker-decisive detectors (nudge 死锁无检测:同一 session 交替收到两种结构互斥的请求流(巨型单消息 ↔ 多轮)时不告警 #1729 family) stay, their purpose inverts from "refuse" to "answer".
  2. 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)
  3. 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 refs map straight to our server-side blocks; no word-bag guessing.
  4. 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).
  5. 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.
  6. Single-author discipline — a host compaction that does NOT carry our tag still gets 422. Nobody else's checkpoint ever lands.
  7. 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

  1. after an authored compaction, the host's file shrinks (dsh: renderer recovers)
  2. the resent checkpoint is recognized declaratively (no fuzzy path); blocks stay claimed
  3. CCR retrieval by header refs works; export/fork unaffected
  4. un-tagged host compaction still 422s
  5. 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

Activity

  1. ranxianglei commented on Oct 18, 2026

    @ranxianglei
    OwnerAuthor

    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:

    • wire lanes (proxy/native): we see the wire, full capability set;
    • no-wire lane ([PR] feat(contrib): billion_context_native #1790's shape): host hooks push the transcript up, pull restore content down — storage / recall / compression all live in bili, the plugin shrinks to hooks + an MCP shim;
    • identity is isomorphic on both sides: snapshot bound to sessionid, restore blocks carry our tags. A user upgrading from no-wire to a wire lane keeps the same recognized conversation.

    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.

  2. ranxianglei commented on Oct 18, 2026

    @ranxianglei
    OwnerAuthor

    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, explicit allowDshCompaction still wins, originals recoverable via CCR/export/fork. 15 dedicated tests + all affected families green.

  3. ranxianglei commented on Oct 18, 2026

    @ranxianglei
    OwnerAuthor

    🤖 Powered by ework · qwen3.8-27b

    [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 门禁修复):

    • 代码评审已过:核心机制与 issue 设计逐点对齐——guard 命中时本地零出口应答(autoModeForge 纪律)、身份头 <bili-snapshot v1 conv=… seq=… blocks=… /> + 内核渲染格式的活跃块摘要、重放经 [bug] DSH 桌面端 0.1.188:宿主原生压缩落地摧毁折叠基底 → 同一区间永久不可锚定、compress 连片失败并熔断(compaction-basic auto:false 仍无效) #2432 rebase 声明式识别(无 fuzzy 路径)、未标记/判不出的宿主压缩仍 422、显式 allowDshCompaction 优先于 authored。
    • 测试评审已过:新增 416 行测试,单测钉住三种 wire 的 forge 体形状(含事件序)与 carrier+novelty 双方向门禁,e2e 六条 lane 走真代理+mock 上游(零出口、计数器、knob-off 422 钉死、无块回落 422、allow 优先、落点识别)。
    • CI:head 上各静态门禁全绿(含 config-surface-guard),docs-coverage 在第二提交已修复;全量 test shards 仍在跑。
    • 顺手发现一个文档缺陷:master 上 CONFIGURATION.md 本来就有两行相邻重复的 BILI_ALLOW_DSH_COMPACTION(一新一旧 scope note,合并残留),PR 的新行正好插在中间。我会按「小问题直接修」在 PR 分支补一个标注 commit 把重复行合并。
    • 本地定向测试进行中,完成后按八问体例给最终结论。
  4. ranxianglei commented on Oct 18, 2026

    @ranxianglei
    OwnerAuthor

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

    #3737 审核收尾——全部验证完成,结论:可合(等人工合并)。以下是完整判定。

    结构化八问

    1. 是什么问题:dsh 发起的 compaction 请求被 nudge 死锁无检测:同一 session 交替收到两种结构互斥的请求流(巨型单消息 ↔ 多轮)时不告警 #1729 守卫一律 422 拒绝,bili 既不代理也不写 checkpoint,dsh 会话文件因此只增不减([Bug][dsh] Unbounded growth of raw history → 39.7MB session file overwhelms dsh desktop renderer process, entire UI beco | [Bug][dsh] 原始历史无上限增长 → 39.7MB 会话文件压死 dsh 桌面端渲染进程,UI 全部无响应 #3723:39.7MB / 9001 条消息,渲染器开始熔化)。
    2. 什么原因导致的:[PR] fold anchoring doctrine: order over hash — shape churn, image offload, host truncation stop reading as destruction (#3641) #3644 之前,外来 checkpoint 会遮蔽原始历史 = 基底被毁,拒绝是正确防御;[PR] fold anchoring doctrine: order over hash — shape churn, image offload, host truncation stop reading as destruction (#3641) #3644 之后基底已迁到服务端快照,客户端侧删除只是 snooze(原文留在 CCR),但守卫仍按旧威胁模型拒绝,且拒绝方式不产出任何 checkpoint → 文件无限增长。
    3. 影响范围与严重程度:长周期 dsh 会话(p2,能用但体验持续恶化);有绕行(显式 allowDshCompaction=true 或重启),所以不是 p1。
    4. 怎么修复的:守卫从「拒绝」翻转为「本地作答」——拦截器不变(nudge 死锁无检测:同一 session 交替收到两种结构互斥的请求流(巨型单消息 ↔ 多轮)时不告警 #1729 marker-decisive 检测族),响应由 bili 自己撰写:autoModeForge 纪律零出站,内容 = 身份头 <bili-snapshot v1 conv=… seq=… blocks=…> + 内核渲染格式的活跃块摘要。重放识别是声明式的(tag 随消息内容走,refs 直映服务端块),不走 words-bag 模糊匹配;无 tag 的外来 compaction 仍 422。显式 allowDshCompaction 优先级保留(checked-first)。
    5. 是否有回归问题:逐项审过既有行为——默认关时 422 拒绝路径字节级不变(sticky refusal latch、passthrough lane、错误码 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→吞错、无阈值/时序/输出格式漂移。
    6. 是否破坏缓存:不涉及——未触碰缓存/重试/游标/去重键;checkpoint 落地复用既有 [bug] DSH 桌面端 0.1.188:宿主原生压缩落地摧毁折叠基底 → 同一区间永久不可锚定、compress 连片失败并熔断(compaction-basic auto:false 仍无效) #2432 native-compaction rebase 通道。
    7. 是否改了设计方向:不涉及——这是 nudge 死锁无检测:同一 session 交替收到两种结构互斥的请求流(巨型单消息 ↔ 多轮)时不告警 #1729 守卫族在同一 lane 内的语义翻转,不是新架构。issue 覆盖表里的 codex/CC/opencode/pi 扩展不在本 PR 范围(后续按表跟进)。
    8. 是否引入了新的配置:BILI_DSH_AUTHORED_COMPACTION(env-only,默认 OFF,逐请求读取无需重启;file/web toggle 有意推迟,CONFIGURATION.md 已注明)。默认值下行为零变化。

    验收标准对照(issue 五条)

    # 标准 结果
    1 authored compaction 后宿主文件缩小 ✅ e2e 证明伪造 checkpoint 作为 dsh 记录的摘要落盘,原始消息不再驻留
    2 重放声明式识别,块保持 claimed ✅ tag 前缀匹配 + novelty 门(#2621 纪律),无模糊路径;dshAuthoredCheckpointLanded 记录并走 #2432 rebase
    3 CCR 按头 refs 取回,export/fork 不受影响 ⚠️ 部分:原文经既有 CCR/export/fork 通道可取回(会话键寻址,不受影响),但尚无解析 conv/seq/blocks 的客户端「展开此摘要」端点——这正是 issue 正文点名的缺失件,留作后续小工
    4 无 tag 宿主 compaction 仍 422 ✅ 双向钉死(knob 关 / 无活跃块 / undecidable 三条 422 路径各有测试)
    5 整个循环上游 wire 保持小 ✅ 零出站(e2e 断言 mock upstream 收到的请求数不变)

    证据链

    备注

    判定:#3737 可合。 设计逐条符合 issue 规格,验收 4/5 满足(第 3 条的部分性为 issue 自身点名的后续件),回归面审毕无破坏,CI 核心矩阵在真实 head 上全绿。

  5. ranxianglei commented on Oct 18, 2026

    @ranxianglei
    OwnerAuthor

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

    增量复审:分支在我上一轮结论后又落了 3 个 review follow-up commit(e726bcb0c → 5e0ba2a53 → 4ce219647),已逐个过完并重新验证,结论维持可合,另发现并处理了一个合并机械阻塞。

    新提交复审(3 个,均通过)

    1. e726bcb0c docs: 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 长格式条目。内容与英文版一致,无漂移。
    2. 5e0ba2a53 docs: 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 确认仅一行注释)。
    3. 4ce219647 test: 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)

    • 本地定向:tests/dsh-authored-compaction.test.ts 16/16(原 15 + 新 responses lane)。
    • 远程 CI:核心矩阵全绿(run 39149698384,PR 事件触发:6 条 test leg + 双 static-gates + 全部门禁含 kernel/lane/pi-subagents/version-guard);各 e2e workflow(dsh-native / fake-codex / real-codex / pi / windows-codex overlay)同 head 全绿。中间两个 head 的矩阵被后到的 push 按并发组取消,属预期。

    合并阻塞(机械,已处理)

    查 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 矩阵跑绿 + 你批准后即可合;我会在矩阵完成后回一条确认。

  6. ranxianglei commented on Oct 18, 2026

    @ranxianglei
    OwnerAuthor

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

    full 矩阵确认:run 39152048757 @ 4ce219647 completed / 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 两轮矩阵全绿、合并机械阻塞已清除。

  7. ranxianglei commented on Oct 18, 2026

    @ranxianglei
    OwnerAuthor

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

    No-wire lane 设计注记已消化。判定与两个明确建议如下。

    与 #3737 已交付设计的兼容性:无需改动,同构性成立

    范围与状态

    #3737 保持 wire-lane 范围不变(已交付、已全验)。刚查过:merge_state 已是 clean——full 矩阵跑绿后分支保护的全部必需检查齐备,合并只剩你的批准。

    两个建议(各给一个方向,不甩选项)

    1. [PR] feat(contrib): billion_context_native #1790 现在按 contrib 合入(维持你此前的立场)。理由:受众需求是当下的;它已过两轮 review;而同构性让后续迁移代价极低——它唯一会「锁住」的东西是 transcript 存储,而那本就要搬进 unified store,迁移时识别会话直接延续。为一个尚未排期的项目 hold 一个已就绪的贡献,风险是把真实受众的需求无限期推迟。
    2. no-wire 统一 lane 作为下一个排期项,以这条注记为规格底稿。我不擅自立项——它是功能方向,形状(尤其两块新面的设计)该由你定;你点头我就把 issue 立起来(带来源标记指向本条注记),或直接按你给的形状开工。
  8. added 2 commits that reference this issue on Oct 19, 2026
  9. added 4 commits that reference this issue on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions