Skip to content

Per-wire continuity proofs + reasoning-drop tolerance (model-switch / fork-adoption / mode-upgrade) - #2732

Merged
ranxianglei merged 6 commits into
masterfrom
2026-10-11_continuity-proof-wires
Oct 11, 2026
Merged

ranxianglei merged 6 commits into
masterfrom
2026-10-11_continuity-proof-wires

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

Continuation of the m02811 proof-gap census, driven by the #2636 model-switch incident class. Three proof families go per-wire, and one real misdiagnosis found on the way gets fixed.

1. fix: tolerate a pure reasoning drop as sanctioned model-switch churn (#2193 follow-up, #2636)

Cross-model replay on the anthropic/responses/google wires is DROP-KEEP: structured thinking (thinking blocks / reasoning items / thought parts) is discarded wholesale while every text/tool core keeps its kernel id (ids are seeded blind to thinking siblings). With >=10 dead reasoning ids and zero reanchoring claims, the destroy-escalation logged compression substrate appears destroyed on a sanctioned host behavior — the fold itself stayed healthy.

  • FoldAnchor gains c (contentType) so the drift check can classify the unmatched set.
  • A reasoning-only unmatched set is tolerated (no streak accrual), and only non-reasoning missing ids count toward the destroy threshold — so "model switch + one honest user edit" (10 dead reasoning + 1 dead user) can never cry destruction either.

2. identity-proof: per-wire model-switch phases (#2636)

3. fork-adoption: per-wire anonymous-fork adoption (#629)

tests/fork-adoption-wires.test.ts generalizes the chat e2e scenario (grow -> fold -> mid-list edit -> fork -> seeded refs identical -> follow-up reconciles -> parent untouched) over anthropic (native mock), responses (chat relay bridge), google (native mock), plus a responses OFF control. Tooth: removing anthropic from the adoption SUPPORTED set fails exactly the anthropic test.

4. mode-upgrade boundary proof (#1426)

tests/mode-upgrade-proof.test.ts pins the proxy->plugin upgrade contract on one rig: same session across the flip (no fork), proxy-era fold keeps its acp_summary carrier in plugin mode, tool injection stops exactly at the flip, a plugin-era fold via /__bili/plugin/tool coexists with the proxy-era block (coverage ledger spans both eras), the binding is sticky when the header disappears, a different agent header overrides the recorded value, and no sanctioned flip latches escalation or conflict events. Tooth: deleting the sticky-restore line in src/server/handle.ts fails the sticky phase.

Also included: the two-scenario continuity proof (already merged via #2729 for chat) now runs on anthropic + responses wires (commit 2d529c1).

Evidence

  • identity-proof 11/11, mode-upgrade 1/1, fork-adoption-wires 4/4, session-continuity-proof 9/9, cache-friendly-plugin 11/11, fold-reconcile x2 + issue2202 + fork/resume-adoption family: 126/126 combined run green on this branch.
  • npm run typecheck clean, npm run build OK.

Config surface

No config changes (no new fields, env vars, or flags).

Kernel boundary

No changes under kernel/ — the reasoning-drop tolerance lives in src/fold-reconcile.ts (host reconcile layer).

5. Reap-side reasoning-awareness (4efdb30, follow-up to §4)

The §4 classification tolerates pure reasoning drops at the session escalation level, but the per-block #2695 zombie streak still counted dead reasoning ids in its majority test: a fold span whose covered ids are reasoning-majority (thinking-only turns, multi-thought turns, dense reasoning stretches) would reap a healthy block 3 passes after a sanctioned drop-keep model switch — summary lost, surviving text re-billed, silently replaced by a re-fold over the decimated history.

Fix: the majority test ("gone") now runs on the non-reasoning covered ids only (anchors carry contentType via the "c" field); a span with no non-reasoning ids never reads as gone. Genuine decimations (text/tool substrate gone) still reap — #2695 semantics unchanged for real loss.

Teeth (A/B, worktree at 28bf4e6):

Note: builds on the review supplement 70b212d (c backfill on anchor reuse) — that closes the pre-upgrade-anchor gap for the escalation side; the same backfill serves the reap side whenever the id rides the wire at least once post-upgrade.

…ponses wires (#2601/#2676)

The #2729 proof pinned scenario A (model switch = one session) and
scenario B (fork copies state) on the chat wire only, but the persona
wiring is per-call-site in src/server/handle.ts (anthropic :811 /
openai :821 / responses :843,:880) with a different system-text
extractor per lane — correct-in-one-lane is not correct-in-all (#377).

Parameterize the harness over chat/anthropic/responses: per-wire
request builders (system message vs top-level system vs instructions),
per-wire mock upstream responses, identical session-state assertions.
google is deliberately absent (no persona call site, issue #2730).

Teeth (A/B @ 4ecd82f pre-#2719): scenario A mints the |sub: fork on
all three wires; scenario B 409s (#2676); controls still fork on all
three — the persona path is engaged per wire, not vacuous.
…le (#629)

fork-adoption.test.ts proves the anonymous fork lane (grow → proxy fold
→ mid-list edit → fork mint → seeded refs + adopted blocks + untouched
parent) on the openai chat wire only. The mint is protocol-neutral, but
identity extraction and the tool protocol are per-wire call sites —
correct-in-one-lane is not correct-in-all (#377, the #2658 lesson).
resume-adoption-wires.test.ts covers the IDENTIFIED resume twin on
responses/google; this file covers the ANONYMOUS fork twin on all three
remaining wires (anthropic native tool_use mock, responses via the
chat bridge, google native functionCall mock) plus a forkAdoption=off
control on responses.

Teeth: dropping "anthropic" from fork-adoption.ts SUPPORTED makes
exactly the anthropic test fail; adoption assertions, seeded-ref
identity and the copy-on-fork parent check are shared verbatim with
the chat proof.
…2193 follow-up, #2636)

Cross-model replay on the anthropic/responses/google wires discards
structured thinking wholesale while every text/tool core keeps its kernel
id. With >=10 dead reasoning ids and zero reanchoring claims, the
destroy-escalation diagnosed this sanctioned host behavior as 'compression
substrate appears destroyed'. Classify a reasoning-only unmatched set as
tolerated (fold substrate healthy) and count only non-reasoning missing
ids toward the destroy threshold, so 'model switch + one honest user
edit' can never cry destruction either.

Identity proof grows per-wire model-switch companions (drop-keep churn
with two thinking carriers per turn) asserting coverage retention, no
thinking re-billing, honest edit re-entry, and no escalation latch; on
master they fail with 'destroy-escalation latched on a sanctioned model
switch'.
…ion, one carrier, sticky binding (#1426)

Single-rig proof of the mode-upgrade contract the two compression modes
rely on: a session that grew and folded in proxy mode upgrades to plugin
mode via x-bili-plugin without forking, keeps the proxy-era fold alive
(preflight blocks carry acp_summary in any mode), stops tool injection
exactly at the flip, executes a plugin-era fold through /__bili/plugin/
tool coexisting with the proxy-era block, refuses downgrade when the
header disappears (sticky pluginAgent), lets a different agent header
override the recorded value, and never latches destroy-escalation or
conflict events on any sanctioned flip. Tooth verified: deleting the
sticky-restore line in server/handle.ts fails the sticky phase.
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-11_continuity-proof-wires (4efdb30)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2981-pr.2732.416b838

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

Install instructions are refreshed on each push.

…easoning-drop tolerance (#2732 review supplement)

Review finding: FoldAnchor.c is only set at anchor creation, but the anchor REUSE path copies pre-existing anchors verbatim — anchors persisted before this change never gain c (session state outlives the process), stay classified as non-reasoning forever, and the reasoning-only-drop tolerance never reaches pre-upgrade sessions. Add the established #2396/#2636 backfill branch (recompute from live bytes once while the id is on the wire; same-id implies same identity fields incl. contentType, so exact) plus three unit tests in the #2636 suite: pure reasoning drop above the 10-id floor never escalates, mixed drop (dead reasoning + one honest user edit) accrues the ordinary streak but can only warn, and stripped pre-upgrade anchors regain c verbatim-shape on the next live pass.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成 — 可合并(CI 绿后)(PR: #2732)

结构化八问

  1. 是什么问题:两部分。① 一个真实误诊:[dsh] 原生压缩拦截门的 SHAPE 信号(≤4 条消息)在 dsh-compaction-basic 0.2.0-rc.2 上恒假 → 压缩静默落地 → 1510 条 fold 锚点永久失配,连刷 166 条 no-anchor-match 且面板仍报 netSaved 355.9M #2193 的 destroy-escalation 把「跨模型重放丢弃结构化思考」(anthropic/responses/google 线的 DROP-KEEP churn)当成「压缩基底被销毁」——text/tool core 全部原样在场、fold 完全健康,却因 ≥10 个死掉的 reasoning id 而记 compression substrate appears destroyed 错误并锁 escalation。② 证明缺口:m02811 census 的三类证明(model-switch identity、anonymous fork adoption、proxy→plugin mode-upgrade)此前只有 chat 线有,其余 wire 靠假设协议中立([Bug] ACP: ≥2 compressed blocks render as multiple system messages → SGLang (vLLM-compatible) upstreams return 400 #377/[bug] dsh 原生压缩单轮 rebase 兜底缺失于 anthropic 线路(#2432 修复未覆盖):checkpoint 落地后 ACP 状态永久失效 #2658 的教训)。

  2. 什么原因导致的:FoldAnchor 没有内容类型分类,drift 检查把所有 unmatched id 一视同仁——死的 reasoning id 既计入 total-loss streak 又计入 ≥10 的 destroy 门槛,尽管它们对应的 fold 覆盖内容(text/tool core)逐字节都在线上。

  3. 影响范围与严重程度:proxy 模式下 (a) fold 覆盖过结构化思考、(b) 之后切换模型或宿主剪掉 thinking、(c) 覆盖跨度内 ≥10 个 reasoning id 的会话 → 虚假 error 日志 + escalation 锁 + (dsh witnessed 时) native-compaction-inferred conflict 记录。无数据丢失,fold 本身健康——属误诊级(日志/告警面),非功能损坏。本地 A/B 已证实 master 上三条 drop-wire 恰好按此失败。

  4. 怎么修复的:锚点时刻记下 contentType(FoldAnchor.c,来自 message.contentType);unmatched 集合纯 reasoning 且零 reanchoring ⇒ 判定为受认可的宿主行为,不累积 streak、不锁 escalation;destroy 门槛只数非 reasoning 的缺失 id(所以「模型切换 + 一次诚实用户编辑」= 10 死 reasoning + 1 死 user 也永远不会 cry destruction)。未知/缺 c 一律保守按非 reasoning 处理。

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

  6. 是否破坏缓存:不涉及。prefix cache/计费路径未触碰;测试反向钉住 thinking 永不重计费(drop wire 上 scratch- 标记不得出现在线上 body)。

  7. 是否改了设计方向:不涉及。全部在 host reconcile 层(src/fold-reconcile.ts)+ 测试;kernel/ 零改动(Kernel Boundary 合规,无需 kernel-change 声明);wire 形状、配置面、持久化格式均未动。

  8. 是否引入新配置:无(与 PR 声明一致,config-surface-guard 亦绿)。

验证证据(本人实测,非转述)

  • 定向运行(branch head):fold-reconcile 62/62、identity-proof 11/11、mode-upgrade 1/1、fork-adoption-wires 4/4、session-continuity 9/9 —— 87/87 绿;typecheck 干净、build OK。
  • Tooth A/B:把 src/fold-reconcile.ts 回退到 master 后重跑 identity-proof → 恰好 anthropic/responses/google 三条 model-switch 以 destroy-escalation latched on a sanctioned model switch 失败,chat 线保持绿(其 churn 由 Pass 3 认领,本无误诊)——与 PR 声明逐字吻合。
  • mode-upgrade sticky tooth 代码核实:src/server/handle.ts:1178(if (!pluginAgent && typeof session.metadata.pluginAgent === "string") pluginAgent = session.metadata.pluginAgent;)即 sticky-restore 行,删掉后 headerless turn 恢复工具注入,phase 4 断言必挂。fork-adoption tooth 锚点:src/fork-adoption.ts:76 的 SUPPORTED 集合含四线。
  • diff 整洁度:每一行都服务于本 PR 目的;无 lockfile/生成物/version 漂移;base 即当前 master tip(82acfc464),无 stale-base 风险。测试有效性:断言有牙(A/B 失败模式实证),且单元层从此也有分类牙齿(原先仅 e2e 兜底)。

Review 中发现的小问题 — 已直接修掉(小问题直接修政策)
FoldAnchor.c 只在锚点创建时写入,而锚点复用路径(src/fold-reconcile.ts:1053 起)对既有锚点是原样拷贝(除 #2396/#2636 两个回填分支外)。会话状态跨进程存活 → 升级前积累的锚点永远拿不到 c,永远按非 reasoning 处理,误诊在这批老会话上持续存在——而这恰是长时会话这一核心用户面。已按既有的 #2396/#2636 回填模式补第三个分支(id 在线时一次性从活字节重算,same-id ⇒ same identity fields 含 contentType,精确;之后恢复稳态复用)+ 三个单测钉住(纯 drop 不升级 / 混合 drop 只 warn 不升级 / 剥离后的旧锚点回填后与 fresh 形状逐字段相等)。commit 70b212df1 已推到 PR 分支,补充后 87/87 复跑仍绿。

观察(不阻塞,供知悉,不立项):#2695 zombie-reap 路径未变——若某 fold block 的覆盖集以 reasoning core 为多数,模型切换后该块会在 3 个 pass 后被 reap(摘要丢失)。这是 #2695 机制的既有行为、触发条件苛刻(fold 范围须 reasoning 占多数)、与本 PR 机制域不同,且我无真实流量证据证明其发生,故只在此记录边界,不动它。

CI:guard 全线绿(docs-sync/config-surface/lane/kernel/pi-subagents/version/lock/build-artifact 等);test 作业在我推入 70b212df1 后重新排队运行中,结果出来我再跟一条。

判定:可合并(待 CI test 作业绿;merge 由人执行)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI 跟进:head 70b212df1(含我的 backfill 补充 commit)上全部 15/15 check runs 完成且 success——11 条 guard(docs-sync / config-surface-guard / lane-guard / kernel-guard / pi-subagents-guard / version-guard / lock-sync / build-artifact / dsh-plugin-lane / unused-exports / docs-coverage)+ 4 条全量 test(ubuntu/windows × 22/24)。PR 状态 open、mergeable、无冲突。

判定维持:可合并,merge 请人工执行:#2732

@ranxianglei ranxianglei added the p1 label Oct 11, 2026
…ng drop must not eat fold blocks (#2695, #2636)

The GAP-1 classification tolerates pure reasoning drops at the session
escalation level, but the per-block zombie streak still counted dead
reasoning ids in its majority test. A fold span whose covered ids are
reasoning-majority (thinking-only turns, multi-thought turns, dense
reasoning stretches) would reap a HEALTHY block 3 passes after a
sanctioned drop-keep model switch — summary lost, surviving text
re-billed, then silently replaced by a re-fold over the decimated
history.

The majority test now runs on the non-reasoning covered ids only
(anchors carry contentType); a span with no non-reasoning ids never
reads as gone. Genuine decimations (text/tool substrate gone) still
reap — #2695 semantics unchanged for real loss.

Teeth: unit majority-reasoning span survives 4 drop passes then still
reaps on real decimation; identity-proof anthropic drop lane rebuilt
pair-free (75% reasoning span) asserts the settled block survives the
switch — red on master-lineage tip without the fix (b1 reaped,
replaced by text-only re-fold), green with it.
@ranxianglei
ranxianglei merged commit 251cb96 into master Oct 11, 2026
15 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.261-master.251cb96 (rolling master tag).

npm install -g billion-context@0.0.261-master.251cb96  # 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.

antclt pushed a commit to antclt/billion-context that referenced this pull request Oct 11, 2026
@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
ranxianglei added a commit that referenced this pull request Oct 12, 2026
…e as substrate destruction

External analysis of #2815 (user relayed): stripRawStage runs BEFORE ids are
minted in every prepare (e.g. prepare-openai.ts strip -> openaiToCore), so
sessions folded before the marker engine carry covered ids minted from
marker-laden bytes. A stateless client resends that history forever; post-
upgrade every marker-bearing covered message arrives under a fresh clean-byte
id on every pass. Probe-verified shape: fold state survives (user ids
verbatim, positional anchors hold, z=0 nothing reaped), churned assistant
content re-covers on the next re-fold — but with >=10 marker-covered turns
the #2193 gate latched foldDriftEscalated and logged 'compression substrate
appears destroyed / host-native compaction' while compression was healthy.
Exactly the #2789 victim population; same misread class as the reasoning-
drop sanction (#2732).

Fix (suggestion 3 of the analysis): prepares keep the strip counts and pass
markerStripped: markerArtifactCount(counts) into reconcileFoldCoverage. A
pass that stripped raw artifacts proves the resend carried bili echoes, so
its total-loss drift accrues no streak. One acceptance info line per
session (foldMarkerChurnNoted latch, never reset — stateless churn has no
episode end) replaces the misleading per-pass 'mutation or client-side
deletion' warn. Marker-free passes still escalate on their own streak:
real destruction is never masked (pinned by test).

Tests (tests/fold-reconcile.test.ts): marker-explained churn x5 passes ->
zero errors, no latch, single note, no warn; 2 marker passes + 5 clean
destructive passes -> still escalates on its own streak.

Goldens: metadata-section-only drift, verified to be exactly the new
foldMarkerChurnNoted latch (state/blockContents/stats digests identical).

Also notes the load-bearing unpinned order: anonymous prefix affinity
resolves on the RAW body (handle.ts, before the prepares) while the strip
mutates parsed inside the prepare — session identity stays stable across
the upgrade. To be pinned/argued with the owner in the PR thread.
@ranxianglei
ranxianglei deleted the 2026-10-11_continuity-proof-wires branch October 15, 2026 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant