Repository navigation
feat: inherit refs/blocks/lineage across resume forks (#1486) - #1519
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1463-pr.1519.ec7c65eThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1519.tgz
npm install -g packageInstall instructions are refreshed on each push. |
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.
|
Rebased onto current master ( |
f9445ff to
d4fba62
Compare
收到,rebase 到 |
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.
|
Deep review complete — mergeable. Verification and one addition: Verified myself (not paraphrasing the author's self-review):
Coverage gap found and fixed (my commit Non-blocking observation: the stale-citation scenario in the wild (cc |
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 --resumeforks 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):
src/prefix-affinity.ts,src/server.ts): identified sessions' chains are tracked with the same progressive-hash scheme as anonymous ones (append-only discipline per detectUnannouncedHistoryRewrite 误判 1 条消息的侧边辅助请求(如 WebSearch),导致 Ref 映射表被洗空、编号雪崩耗尽(m99999)及 363 万 Token 溢出 #1075: side requests never shrink a chain; longer-or-equal payloads extend/rewrite). Entries are flaggedidentifiedand persist with the existing 重启/会话分裂后上游 prompt cache 命中掉到 0% —— 每请求全量付费(成本回归) #499 snapshot (new optional field, backward compatible).findResumeParent()— the incoming history must be STRICTLY deeper than a tracked chain and byte-exact head-anchored over the whole parent (progressive hash at depth-1 == stored tailHash; stays valid beyond the 128-item per-item cap). Floor ≥ 8 messages. Deepest match wins. Equal-depth byte-exact replays under another id are duplicates, NOT resumes — linking them would adopt foreign blocks and trip the derived-parent restrictions (regression-pinned by unit tests).planForkAdoptionextended with an opt-inseedAllRefs; default call sites unchanged) — adopt fully-present blocks behind the EXISTINGforkAdoptiongate, recordderivedFrom/derivedFromSessionIdlineage. Fresh messages number above the parent's ref space (kernel cursor = highest used + 1).config surface
New optional fields, both defaulting to the new behavior:
BILI_RESUME_INHERITANCE=0turns the feature OFF;"resumeInheritance": falsedoes 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)
BILI_RESUME_INHERITANCE=0.Verification
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.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).E2E_CHECK=1) ✓; fullACP_TEST_E2E=1run blocked in this sandbox (codex warmup exit=1 — identical on clean master, environmental). The CI e2e job runs it on this hot-file diff.