Skip to content

feat: inherit refs/blocks/lineage across resume forks (#1486) - #1519

Merged
ranxianglei merged 3 commits into
masterfrom
2026-09-27_resume-ref-inheritance
Sep 27, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-09-27_resume-ref-inheritance

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #1486

What changed

When an identified client (sends its own session id — e.g. Claude Code's x-claude-code-session-id) resumes a conversation under a NEW session id while replaying the full transcript (cc --resume forks a fresh UUID), the resumed session previously restarted numbering at m00001. Stale model citations (refs from the old generation) then mis-hit renumbered messages — guardrails catch it (no data damage) but long sessions hit it repeatedly (#1486).

Now bili detects the resume and inherits state (copy-on-resume; parent untouched):

config surface

New optional fields, both defaulting to the new behavior:

  • env BILI_RESUME_INHERITANCE=0 turns the feature OFF;
  • config file "resumeInheritance": false does the same; env wins.

No existing field is renamed or re-semantics'd. Why not reuse forkAdoption: that gate only controls BLOCK adoption for anonymous forks (#629, default OFF); resume inheritance also covers ref assignments and lineage, and is ON by default because the old fresh-start behavior IS the bug being fixed. Docs mirrored in CONFIGURATION.md / CONFIGURATION.zh-CN.md.

Behavior change (old → new)

  • OLD: a cc --resume-style fork started a zero-state session numbering from m00001; stale-generation citations could mis-hit renumbered messages (guardrailed, but noisy in long sessions).
  • NEW: detected resumes inherit refs/blocks/lineage from the byte-exact parent, so stale citations resolve to their ORIGINAL messages. Opt-out: BILI_RESUME_INHERITANCE=0.
  • Also new: identified sessions now persist affinity chains (≤256 entries, 7-day TTL) so resume detection survives proxy restarts. Anonymous-session behavior is unchanged.

Verification

  • typecheck ✓ · full suite ✓ (2997 pass / 0 fail / 12 gated-skip, rebased onto current master ce53d3b incl. acp-kernel 0.0.97) · build ✓
  • New e2e tests/resume-ref-inheritance.test.ts: grow → fold → resume-under-new-id asserts every parent ref survives (incl. non-block-covered ones), blocks adopted, lineage recorded, parent untouched, fresh refs above the parent space; disabled-mode test pins the old behavior; unrelated-history negative test.
  • New resolver units in tests/prefix-affinity.test.ts: detection matrix (threshold, edited head, shorter candidate, self-exclusion, deepest-wins, >128-item cap, snapshot roundtrip, equal-depth duplicate rejection, anonymous-vs-identified boundary).
  • Local codex E2E: preflight (E2E_CHECK=1) ✓; full ACP_TEST_E2E=1 run blocked in this sandbox (codex warmup exit=1 — identical on clean master, environmental). The CI e2e job runs it on this hot-file diff.

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-27_resume-ref-inheritance (b9d3d97)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1463-pr.1519.ec7c65e

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-pr1519.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

收到,开始审查 PR #1519(resume-fork 继承,Closes #1486)。这是之前会话按 owner 拍板的方案三实现的工作,我不重做,走完整 review:拉分支核对代码、回归清点(#309/#629/#1333/#499/#1075 边界)、本地跑 typecheck+全量测试+build 验证声明、核对 CI 状态。结论稍后回这里。

ework-agent added 2 commits September 27, 2026 23:29
Identified clients (cc --resume style) fork a fresh session id while replaying the full transcript; the resumed session previously restarted at m00001 so stale model citations mis-hit renumbered messages. Track identified sessions' chains (append-only, #1075 discipline), detect a resume when an incoming history strictly extends a tracked chain byte-exactly (>= 8 msgs, progressive hash valid beyond the item cap), and on the session's first request seed the parent's ref assignments (all overlapping ids, not just block-covered), adopt fully-present blocks behind the existing forkAdoption gate, and record derivedFrom lineage. BILI_RESUME_INHERITANCE=0 / config resumeInheritance:false restores old behavior. Anonymous resolution never adopts identified chains (#309 kept intact); equal-depth replays under another id are duplicates, not resumes.
@ranxianglei

Copy link
Copy Markdown
Owner Author

Rebased onto current master (59d6f16d, includes v0.1.163 release + #1478/#1514) — no conflicts. Re-ran the full gate on the rebased head: typecheck ✓ · test suite ✓ (3011 tests, 2999 pass / 0 fail / 12 gated-skip) · build ✓. Codex E2E preflight ✓ (full local run remains blocked by sandbox env, identical on clean master; CI e2e job covers it).

@ranxianglei
ranxianglei force-pushed the 2026-09-27_resume-ref-inheritance branch from f9445ff to d4fba62 Compare September 27, 2026 15:34
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

收到,rebase 到 59d6f16d 的新 head 正在重新核对:① rebase 前后逐文件 diff 一致性(确认没夹带改动)② 新 head 上本地重跑 typecheck+全量测试+build ③ 新 head 的 CI 状态。代码审查(fork-adoption/server/测试有效性)继续,最终结论一次回这里。

The e2e resume scenario resends the parent transcript in order, so fresh
numbering coincides with the parent's and a seedAllRefs regression survives
it. These unit cases craft the hazard directly: a pruned middle message
leaves a numbering hole between block coverage and the resent tail. With
seedAllRefs the tail keeps its parent numbers and the cursor holds at the
parent max (the hole's number is never re-issued); without it the seeded
prefix ends at the block edge and the child would renumber the tail —
exactly the stale-citation misattribution #1486 reports.
@ranxianglei

Copy link
Copy Markdown
Owner Author

Deep review complete — mergeable. Verification and one addition:

Verified myself (not paraphrasing the author's self-review):

  • 22/22 across the five fork/resume suites + neighborhood 11/11 green on this head; typecheck clean.
  • Mutation A (disable the maybeAdoptResume call): resume-inheritance test goes red — the gate is pinned.
  • Containment: adoption fires once per session (stats.requests === 0 && derivedFromSessionId undefined), wrapped in try/catch → failure degrades to fresh state, request continues; lineage is recorded before adoption so even a failed adoption keeps the audit trail. Parent sessions are never mutated (plan → apply on child only).
  • Cursor guarantee: applyForkAdoption seeds child messageRefs from the plan so the kernel cursor (highestUsedIndex+1) starts above the parent max — the id-never-reused contract survives the fork; freshAboveParent is asserted e2e.
  • Kill switch: resumeInheritance: false / BILI_RESUME_INHERITANCE=0 pinned by test; blocks ride only when forkAdoption is on (conservative rollout, documented).
  • CCR store adoption reuses bug(ccr): fork adoption carries covered refs without adopting their content-store entries #1341's cloneStoreForRefs — cited/inherited refs get their originals, parent store untouched.

Coverage gap found and fixed (my commit b9d3d97): mutation B — flipping the wiring to seedAllRefs: false — survived the e2e suite. Cause: the e2e resumes resend the parent transcript in the same order, so fresh numbering coincidentally reproduces the parent's numbers. The hazard seedAllRefs exists for needs a numbering hole (a parent message the client never resends — pruned tool noise, folded originals). Added tests/fork-adoption-plan.test.ts (2 unit pins): with seedAllRefs the resent tail keeps its parent numbers and maxRef holds at the parent max (the hole's number is never re-issued); the second test documents the default block-edge-stop behavior — i.e. exactly why maybeAdoptResume must pass seedAllRefs: true.

Non-blocking observation: the stale-citation scenario in the wild (cc --resume under a fresh session id) is exactly the identified path; report #1486's repro should re-verify after this ships in a release.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

收到自审结论与新增 commit b9d3d97(fork-adoption-plan 单测)。我这边独立 review 继续收尾:拉新 head 核对 b9d3d97 是否纯测试、新 head 上重跑本地门禁、核对新 head CI、补完测试有效性审查(三个测试文件的断言是否有牙)+ 回归清点,最终结论一次给出。

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Claude 上 resume 导致消息错乱

1 participant