Skip to content

[PR] fix(#5122): degrade fork adoption when zero fold state inherited - #5126

Open
ranxianglei wants to merge 13 commits into
masterfrom
2026-10-29_fork-adopt-empty-inheritance-degrade
Open

ranxianglei wants to merge 13 commits into
masterfrom
2026-10-29_fork-adopt-empty-inheritance-degrade

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

What

Phase 1 (stop-the-bleed) for #5122 — makes the false-success honest and opens the recovery path that was previously hard-skipped. It does not restore the parent's compression by itself, and it does not fix the root cause (tracked in #5122).

Symptom

DSH GUI clone -> POST /__bili/plugin/fork returns 201 with inheritedBlocks: [], but the client only reads replayed and reports outcome:"adopted". That sets publicForkReceipt, which skips the #1486 resume-inheritance fallback entirely (skipReason="publicForkReceipt"). The child ends up with 0 collapsed blocks -> replays the whole parent raw (~1.4M tok) -> preflight runs ~300s -> client disconnects.

Root cause (confirmed against code)

handlePluginFork (src/plugin.ts) builds the child from the client-declared branch-point prefix: prefix = snapshot.orderedMessages.slice(0, request.branchPoint.messageCount); blocks are filtered by full containment in that prefix's rawIds. When the client's matchForkPrefix collapses to a tiny branch point (compressed + reasoning sessions where reasoning->text rewrites and tool-call JSON re-serialization diverge the identity hash), the prefix holds only ~4 rawIds -> no parent block is fully contained -> 0 blocks by construction. The child's later rows come from the client's lossy replay, not a server-side clone.

What this PR changes

Server (src/plugin.ts): computes degraded = (inherited 0 blocks while the parent held some) from its own ledger; logs it (was silent); adds an additive degraded boolean (+ parentBlocks count for diagnostics) to the fork response. Old clients ignore both.

Client (src/agent/fork-adopt.ts): honors the server's degraded flag directly (server-authoritative — no client-side recomputation, robust across mixed-version peers). On degrade it returns {outcome:"degraded"}, leaving publicForkReceipt unset so the #1486 resume-inheritance path is not hard-skipped on the next turn.

What this does NOT do (honest scope)

Degrading opens the resume-inheritance recovery path, but that path is itself best-effort against the client's re-projection: block adoption (src/fork-adoption.ts:175) requires every cell of a block to be present in the client's resent content-hash set, and that set is built from the same lossy projection (reasoning dropped, tool-call JSON re-serialized) that collapsed matchForkPrefix. So deep fold blocks are very likely NOT recovered by Phase 1 alone — it restores visibility + an honest status + a best-effort ref-seeding door, not guaranteed compression. Full recovery is the root-fix work below.

Behavioral change (flagged)

A degenerate fork can now return degraded (not adopted) when the server inherits zero blocks while the parent had some. Old behavior silently claimed adopted. Fires only in the pathological case; a healthy fork (blocks inherited, or a never-compressed parent) still returns adopted. No effect on old clients (the gate keys off the additive degraded flag they ignore).

Root fix (NOT in this PR — pending decision in #5122)

The definitive fix makes the child's state independent of the client's lossy verified prefix (verbatim row-clone of the parent at fork time). Options A/B/C plus a decisive open question — does the DSH client send the inherited state verbatim on the next turn, or its own re-render (which decides whether a bili-only fix can hold, since syncBlocks deactivates blocks whose source messages are absent from the wire)? — are being decided in #5122. Stays ONE issue/PR per the coherence policy.

Tests

tests/dsh-fork-adopt.test.ts: 5 client-side tests (degrade-on-flag / trust-flag-even-on-full-match / adopt-healthy / adopt-zero-block-parent / legacy-no-flag backward-compat) + 1 server-side test asserting degraded:false + parentBlocks for a never-compressed parent. Targeted file green (26/26); full suite = remote CI.

Config surface

None. No new config fields / env vars / CLI flags.

Refs #5122

A DSH GUI clone returns 201 with inheritedBlocks=[] when the client's
matchForkPrefix collapses to a tiny branch point (compressed + reasoning
sessions), yet the client only reads `replayed` and claims "adopted" —
setting publicForkReceipt and skipping the #1486 resume-inheritance
recovery. The child then replays the whole parent raw (~1.4M tok) and
preflight runs for minutes before the client gives up.

Server: log the degenerate case (was silent) and expose `parentBlocks`
in the fork response (additive field; old clients ignore it).

Client: when parentBlocks>0 && inheritedBlocks===0 && the child carries
more history than the verified prefix (branchPoint < core.length), return
"degraded" instead of "adopted" so publicForkReceipt stays unset and the
#1486 resume-inheritance recovery path can run on the next turn.

Stop-the-bleed / detectability only. The root cause — fork rebuilds the
child from the client-chosen branch-point prefix, so a collapsed branch
point inherits nothing — is tracked in #5123 and needs the verbatim
row-clone redesign (human review: load-bearing identity/contentStore).
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-29_fork-adopt-empty-inheritance-degrade (a00bd0e)

Latest build — install this exact version

npm install -g billion-context@0.0.9225-pr.5126.00bf797

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

Recent builds (commit → version)

commit version build
a00bd0e billion-context@0.0.9225-pr.5126.00bf797 build
d186533 billion-context@0.0.9143-pr.5126.d5691d5 build
9444aa6 billion-context@0.0.7386-pr.5126.d961c8c build
5828821 billion-context@0.0.7297-pr.5126.7cb2913 build
77230c9 billion-context@0.0.7111-pr.5126.32a11a9 build
3a5a9aa billion-context@0.0.6963-pr.5126.9407a4a build
d0bc86c billion-context@0.0.6946-pr.5126.320f43a build
f896178 billion-context@0.0.6770-pr.5126.9a2a646 build
880e44b billion-context@0.0.6763-pr.5126.630e607 build
ef00412 billion-context@0.0.6756-pr.5126.9cd7abe build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr5126.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

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

查重: 不重复。 本票是根因票 #5123(平台号;GitHub #5122)的 Phase 1 修复 PR;检索 open issues/PRs 无其他在途项触碰 fork adoption 路径。
标签: bug, dsh, scope/wiring, p1(fork 继承被永久放弃 → 零折叠子会话,按 owner 修订的「会话无法恢复/数据丢失类」p1 口径)。

已审 PR #5126(head 435b5dd,base 即当前 master,3 文件 +96/-2)。CI 全绿:12 个 test shard + static-gates + mysql-contract + gate/plan 全部 success;e2e 各 lane 为门禁正常 skip。

核心结论:「诚实化」一半成立,「解锁恢复」一半不成立——PR 描述过度承诺。

查证事实链:

  1. publicForkReceipt 是服务端在 fork 时无条件写入的(src/plugin.ts:1560,返回 201 之前),不是由客户端报 adopted 才写。
  2. Claude 上 resume 导致消息错乱 #1486 resume-inheritance 兜底的入口条件是 publicForkReceipt === undefined(src/server/handle.ts:1635);不满足时打 [resume-inheritance] skipped: publicForkReceipt(:1710-1712)——正是原票现场证据里的日志行 37089。
  3. 本 PR 的客户端 gate 在收到 201 之后才触发——此时 receipt 已写入;degraded 判定只在本地消费(createForkAdopter 只多打一行日志、不重试、不通知服务端)。
  4. 因此合并后,degenerate fork 的子会话下一请求仍会打 skipped: publicForkReceipt,resume-inheritance 仍不会跑,用户可见病理(原文重放 ~1.4M tok → preflight ~300s → 断连)不变。本 PR 实际交付的是:两端诚实日志 + additive parentBlocks 字段 + 客户端分类。

原票「期望修法」第 1 条(「不匹配 → degraded,让 resume-inheritance 兜底能跑」)存在同一因果误读——把客户端判定与服务端 receipt 混为一谈了。

回归审查(diff 触碰的既有行为):

  • parentBlocks 为 additive 字段,旧客户端忽略 → 无影响;
  • 客户端 gate 三条件(parentBlocks>0 ∧ inheritedBlocks=0 ∧ branchPoint<core.length)对健康全匹配克隆(branchPoint==core.length)、零块父会话、无该字段的旧服务器均不误触发(backward-compat 有测试钉住);
  • 唯一理论上的过降级场景(部分匹配 + 零包含块):fork POST 已成功时两种判定的服务端状态完全相同,差别仅在日志措辞——无行为回归;
  • 新的 degraded reason 不命中 transient 重试正则 → 终态,不会重试风暴;
  • 缓存/重试/增量游标无影响;配置面零变更(已核对,与 PR 声明一致)。

测试有效性: 4 个 client gate 测试(degrade / adopt-with-blocks / adopt-parent-empty / legacy-no-field)+ 1 个 server field 测试,双向断言齐备、断言有牙;但没有测试钉住「恢复路径」——因为它并没有被打开,与上述发现一致。

八问:

  1. 是什么问题:DSH 克隆会话时 fork 返回 201 但子会话继承 0 个折叠块,客户端谎报 adopted,全文重放,preflight 跑 300s 后被断连。
  2. 什么原因:fork 按「客户端声明的 branch-point 前缀」克隆,只有完全落在前缀内的块才被继承;identity hash 失配(reasoning→text 改写)时前缀塌缩到几条消息 → 构造性地零块;客户端把 HTTP 201 等同成功。
  3. 影响范围与严重程度:dsh 插件车道 + 压缩过的 reasoning 会话 + GUI 克隆 → 模型静默数分钟、会话实质不可用;p1(fork 继承被永久放弃)。
  4. 怎么修复的:服务端对零继承打 warn + 暴露 parentBlocks;客户端在「父有块 ∧ 子得零 ∧ 匹配未到尾部」时降级为 degraded。
  5. 是否有回归:既有行为无回归(逐项见上);但承诺的「解锁 resume-inheritance」未兑现——属未兑现的承诺,非旧行为破坏。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不转向;根因(verbatim row clone)继续在 [PR] fix: corrupted index.db now auto-quarantines and recovers instead of degrading forever (quick_check throw shapes) #5123 跟踪。
  8. 是否引入新配置:无。

处置建议(需拍板):

收工判定:代码质量可合(无回归、CI 绿、diff 干净),但描述承诺与实际行为不符,建议先定 A/B 再合。合并由你执行。

Phase 1 keyed the client's degrade decision off the additive parentBlocks
count plus a local branchPoint<core.length check. That re-derives server
state on the client and silently no-ops when a mixed-version peer lacks the
new field. Per review, move the judgment to the server: it computes
degraded = (inherited 0 blocks while the parent held some) from its own
ledger and sends an additive boolean; the client honors it directly and no
longer second-guesses with a truncation gate. Old clients ignore the flag.

Adds a test pinning that the client degrades on the flag even for a full
local match (no residual truncation gate), and pins degraded:false for a
healthy never-compressed parent clone.
@ranxianglei ranxianglei changed the title [PR] fix(#5123): degrade fork adoption when zero fold state inherited [PR] fix(#5122): degrade fork adoption when zero fold state inherited Oct 29, 2026
ci-check added 2 commits October 29, 2026 18:37
…e + honest blockStatus

Fork adoption builds the child from the client-declared branch-point prefix and
matchForkPrefix caps that prefix at the first identity mismatch. On compressed
sessions re-projected by hosts (reasoning dropped to text, tool-call args
re-stringified) every such cell broke the hash, so branchPoint collapsed to ~4-5
and the full-containment block filter inherited ZERO parent blocks — voiding all
prior compaction (the #5122 1.4M-tok replay).

- forkIdentityHashOf/forkMessageIdentityHash (client+server, kept byte-identical):
  drop contentType (a reasoning cell and a text cell with the same text are the
  same history cell) and JSON-canonicalize tool-call text (re-stringified args
  differ only in whitespace). role/text/toolName/toolCallId/thinkingTokens/
  summaryOfBlockId/toolIsError remain hard gates. sameSnapshotView stays
  byte-exact on purpose so CoW never retains a stale snapshot.
- fork response: add tri-state blockStatus (inherited/none-inherited/
  nothing-to-inherit) alongside status + degraded, resolving the
  "status:exact + inheritedBlocks:[]" contradiction for receipt readers.
- scripts/align-check.mjs: read-only index.db oracle measuring strictPrefix /
  ordered-align depth per identity mode + which parent blocks are fully
  inheritable (owner-provided acceptance harness for this fix).

Behavior change (intended): fork prefix verification is now tolerant of
serialization/projection noise, so affected forks match deeper and inherit more
blocks via the existing filter. Content-level divergences still truncate the
match (hard gates unchanged). Stabilizes the common case; the residual deep-block
case (prefix capped low by genuine reorderings) needs the verbatim clone (Option
A), tracked in this PR.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI 红已修复并推送:merge ci-fixes 进 PR 分支,新 head f89617850,全量矩阵重跑中(约 30–40 分钟),结果出来跟进。

结构化八问

  1. 是什么问题:本 PR 的 CI 有 4 个 test 分片红(windows-22 s1/s2、ubuntu-22 s2、ubuntu-24 s2),但不是这个 PR 代码的问题——是 master 带下来的继承红。
  2. 什么原因导致的:[PR] fix: keep test suite off the production sessions dir (#5107) #5120 合入 master 后,tests/preload-test-env.mjs 新增了一个 BILI_CONFIG_FILE=<不存在的文件> 的环境钉死;配置路径解析(src/paths.ts 的 configFile())优先读这个 env、而不是从 XDG_CONFIG_HOME 推导默认路径,于是把所有「把自己临时目录指到 XDG_CONFIG_HOME + 在默认位置写配置」的测试 fixture 整体遮蔽了——claude-native 的 4 个文件层断言读不到自己的 fixture 配置,native lanes suspected of not reusing instances: one proxy per process, instances only grow (v0.1.197 / opencode v2) | [Bug?] native 车道疑似不复用实例:一进程一代理,实例只增不减(v0.1.197 / opencode v2) #3436 的兼容检查把 mitm.domains 解析成空、改走 spawn 路径后 60s 超时。时间线证据:本 PR 首个 head 435b5ddbc([PR] fix: keep test suite off the production sessions dir (#5107) #5120 合入前跑)全绿;之后两个 head 的 merge ref 含新 preload → 确定性红;master@1fad21de8 自身也是同样 4 shard 红。本地按 CI 同款环境复现:pass 1 / fail 4,错误文案与 CI 逐字一致。
  3. 影响范围与严重程度:影响所有 merge ref 包含 [PR] fix: keep test suite off the production sessions dir (#5107) #5120 的 PR(包括 master 自身);纯 CI/测试 harness 问题,对生产用户零影响。严重度 = CI 假红阻塞合并。
  4. 怎么修复的:没动本 PR 的代码(已验证其 diff 与失败套件零交集:fork-adopt.ts/plugin.ts 只在 plugin-fork handler 内加 degraded 标志 + 新增 dsh-fork-adopt 单测)。按 CI 协调流程把 origin/ci-fixes merge 进 PR 分支——哨兵已把修复收敛在 ci-fixes cf99d935f(BILI_CONFIG_FILE 由钉死改为删除,解除 fixture 遮蔽;另修 Windows 会话树相对路径键归一)——新 head f89617850。
  5. 是否有回归问题:无。merge 带入的只有测试基建 + 文档变更(12 个文件,零产品代码);typecheck 干净;受影响套件按 CI 完全相同的 preload 链本地验证 96/96 绿(claude-native 57 / test-suite-lock 31 / native lanes suspected of not reusing instances: one proxy per process, instances only grow (v0.1.197 / opencode v2) | [Bug?] native 车道疑似不复用实例:一进程一代理,实例只增不减(v0.1.197 / opencode v2) #3436 8),与哨兵验证口径一致。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:无。
  8. 是否引入了新的配置:无。

注:作者车道自己的提交 880e44b6a("stabilize fork prefix identity…")原样保留在分支中,本次修复未触碰。

判定:继承红已按收敛流程(ci-fixes)修复并推送,待矩阵重跑终态确认。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

✅ 重跑终态:新 head f89617850 全矩阵绿——11/11 test 分片 success(ubuntu 22×3、ubuntu 24×3、windows 22×5)+ static-gates 两腿 / mysql-contract / pi-subagents-guard / gate 全 success,E2E 车道按门控 skip。此前 4 个红分片全部转绿,结案。PR 可正常走合并流程(合并由人工执行)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Re-synced to latest master (e5e210865) and pushed — new head 9444aa644. Merge clean, zero conflicts (master still churning in small increments through the consolidation window). State after push: base == master tip e5e210865 (no longer behind), mergeable=true, ms=blocked (fresh CI running). No design conflict; no decision-request filed. Merge stays human-only.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Status confirmed (continuing the churn-sync loop): branch synced to master e5e210865, head 9444aa644, base == master tip (not behind), mergeable=true, CI running (ms=blocked). Nothing further needed from this branch until master settles; merge stays human-only.

ci-check added 2 commits November 11, 2026 20:22
Resolve the fork-identity hash field-set conflict as the union of #5123 serialization-tolerance (drop contentType, JSON-canonicalize tool-call text) and #4266 signed-content carriers (drop thinkingTokens value; add thinkingSignature/googleThoughtSignature/redactedPayloadDigest). Pinned by tests/dsh-fork-adopt.test.ts parity + tests/issue4266-fork-thinking-gate.test.ts drift pins.
master moved past the previous sync (dc041dd) by the web handoff-render
(#6260) + anthropic trailing-system (#5432/#5441) + snapshot-write-lifecycle
(#6186) landings. None of those commits modify src/plugin.ts or
src/agent/fork-adopt.ts (master's version of both == merge-base), so this
merge is clean and preserves the #5123/#4266 union resolution untouched.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

Conflict re-resolved and pushed (auto-fix lane). Master moved past the previous sync while this branch was open, so the PR went dirty again — this run re-synced it.

Live state at start: master had advanced dc041dd → c26c31a (~13 commits: web handoff-render #6260, anthropic trailing-system #5432/#5441, snapshot-write-lifecycle #6186). The PR head (my previous merge d186533) did not contain it → dirty.

Key finding: none of those new master commits touch src/plugin.ts or src/agent/fork-adopt.ts — master's version of both files is byte-identical to the merge-base. So the re-sync is a clean merge that preserves the #5123/#4266 union resolution from the prior run untouched (no re-resolution needed).

What I did:

  • Merged c26c31a into the branch → clean, zero conflicts → merge commit a00bd0ea05 (parents d186533 + c26c31a).
  • Verified: master is now an ancestor of the head (PR no longer dirty); the union tuple is intact in both files; no conflict markers.
  • npm run typecheck clean; the three fork-identity suites pass 58/58 (dsh-fork-adopt 28, issue4266-fork-thinking-gate 8, pi-omp-fork-adopt 22).
  • Pushed fast-forward (no force) → branch now at a00bd0ea05.

(One transient hiccup: tsup was missing from node_modules on the shared worktree — restored with npm ci before typechecking. Not a code issue.)

CI status (live): the mirror check snapshot still reflects the previous head d186533 (16 success / 14 skipped / 0 failing); the fresh run on a00bd0ea05 will land as the poller refreshes. Not asserting the new head's CI state until it is verifiable.

八问

  1. 是什么问题:PR 与 master 再次合并冲突(dirty)——master 在上次同步后继续前进,分支落后。
  2. 什么原因导致的:长开分支期间 master 高频落地(web 交接渲染 [PR] Web Panel: Handoff Documentation and Collapsed Tree Diagram Rendering Upgrade (eWork-Level Rendering, Appendix Sectionin | Web 面板:交接文档与压缩树图渲染升级(eWork 级渲染、附录分节、冻结快照水合) #6260、anthropic 尾随 system Anthropic 400: mid-conversation system must FOLLOW a user message — heal only checks the follower, and trailing nudge/notes land after a trailing system #5432/[PR] fix: insert Anthropic ephemeral tails before trailing client systems (#5432) #5441、快照写生命周期 [PR] fix: await unified snapshot writes and reset each debounce batch #6186),分支未含最新 master 故再次变 dirty;非代码缺陷。
  3. 影响范围与严重程度:仅阻塞本 PR 合入;对生产用户零影响。严重度 = 合并阻塞。
  4. 怎么修复的:把最新 master(c26c31a)merge 进分支。因这批 master 提交不触碰 src/plugin.ts / src/agent/fork-adopt.ts(两文件 master 版 == merge-base),合并零冲突,上一轮的 [PR] fix: corrupted index.db now auto-quarantines and recovers instead of degrading forever (quick_check throw shapes) #5123/Zero-Inheritance Session Cloning: Unified Fix for Eight Independent Defects in the Fork Adoption Chain (Next Release Tar | 会话克隆零继承:fork 收养链上八类独立缺陷统一修复(下版目标) #4266 并集解法原样保留,无需重新裁决。
  5. 是否有回归问题:无。typecheck 干净;三个消费 fork 身份哈希的测试套件 58/58 全绿;合并未改动本 PR 的任何产品代码(只带入 master 的 web/anthropic/snapshot 变更)。高危模式逐项过:无语义漂移、无吞错、无阈值/时序/输出格式漂移。
  6. 是否破坏缓存:不涉及(未触碰缓存/重试/游标逻辑)。
  7. 是否改了设计方向:否,纯同步。
  8. 是否引入新配置:不涉及。

判定:合并冲突阻塞已清除(分支现含 master,mergeable 将转 clean),待新 head a00bd0ea05 的 CI 终态;合并仍由人工执行。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

Stale trigger — no action taken. Verified live this run: master is unchanged at c26c31a and is fully contained in the PR head a00bd0ea05 (my previous push), so there is no merge conflict to resolve — git log PR..master is empty.

The "dirty" in the trigger came from a pre-push snapshot. The live mirror state is mergeable_state: blocked, which here means CI is still running on the new head, not a conflict (a real conflict reads as dirty).

CI on a00bd0ea05 (live): 30 checks — 6 success, 13 skipped, 11 test shards still running, 0 failing so far. I'll report the final state once the matrix completes; if any shard goes red it's this lane's to fix.

No re-sync or push performed (local == remote == contains master). Merge stays human-only.

This branch has not been deployed

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

Labels

bug Something isn't working dsh p1 scope/wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant