Skip to content

fix(sessions): reconcile forked-session fold lineage from disk at boot (#2807) - #2887

Merged
ranxianglei merged 5 commits into
ranxianglei:masterfrom
asuan-dev:fix/2807-fork-lineage-block-inheritance
Oct 13, 2026
Merged

ranxianglei merged 5 commits into
ranxianglei:masterfrom
asuan-dev:fix/2807-fork-lineage-block-inheritance

Conversation

@asuan-dev

@asuan-dev asuan-dev commented Oct 12, 2026 •

Copy link
Copy Markdown

Issues

Closes #2985 — fork child sessions orphaned across a bili restart: metadata.derivedFromSessionId is persisted but no code path ever reads it back to trigger block adoption, so the child serves with zero blocks and re-sends the full shared prefix until the upstream rejects the over-window payload. (Family origin #2807 is already closed; this PR covers the cross-restart facet it left behind.)

Summary

boot
  initSessions()
  loadConversations()
+ reconcileDerivedLineage(listSessions())
    for each session with derivedFromSessionId, no blocks, not yet adopted
      peekSession(parent) ?? getStore().loadSync(parent)     # try/catch: a bad parent file skips one session
      planForkAdoption(parent, byRaw keys, { seedAllRefs })
      applyForkAdoption(s, plan, parent)                     # copy-on-fork
+     cloneStoreForRefs(contentStoreOf(parent), plan.refs.byRef)
+       └─ adoptContentStore(s, storeSlice)                  # CCR originals for the inherited refs
      metadata.derivedBlocksAdopted = true

Three breaks of the same root cause — "lineage and ledger live only in process
memory" — are now closed from the disk side:

# break why it orphaned the child
① strong resume-inheritance needs a byte-exact prefix chain a mid-session model switch rewrites the first system message, so the chain breaks at index 0
② plugin register's parent declaration is in-process (pendingRegisters) after a restart derivedParent is undefined and the weak gate never opens
③ metadata.derivedFromSessionId was written but never read back lineage known, parent ledger on disk, no inheritance triggered

reconcileDerivedLineage addresses ③ (and with it ②: no register table needed);
the weak path gains real block adoption for ①'s fork variant.

Second fix in the same change: the weak derived path read opts.forkAdoption
(default OFF) while the boot reconcile read opts.resumeInheritance
(default ON) — two inheritance paths answering to two different switches,
so the weak path never adopted at all. It is now gated on resumeInheritance
like the strong resume path (#1834/#629 reserve forkAdoption for anonymous
forks), and the derivedBlocksAdopted marker moves to after the adoption
call so a partial id overlap cannot close the gate permanently.

Evidence

Real session 01a12de8 (fork child, 34 compressible ranges fully exposed,
state.blocks: [], derivedFromSessionId intact on disk):

Before — first request after restart:

503: {"type":"server_error","code":"preflight_compress_failed",
 "message":"context ~1360470 tokens exceeds the model window 1032176
  (model=oc/step-5-preview-free), with 34 compressible range(s) still
  visible and preflight compression could not bring it under: the
  summarization call was rate-limited by the upstream (HTTP 429).
  The over-window payload was NOT forwarded.","retryable":true}

After — same session, one boot later:

[info] [lineage-reconcile] 01a12de8… adopted 3 block(s) (~91873 tokens, 4 straddled)
                            from parent 01a12bbd…
[info] [lineage-reconcile] restored fold state for 1 forked session(s)

Disk: state.blocks 0 → 3, blockContents 0 → 3, messageRefs.byRaw 1580,
stats.lastInputTokens 0 → 35908. This file was never hand-edited — the
recovery is code-only.

Tests (node --import tsx --test):

tests/lineage-reconcile-boot.test.ts            tests=3 pass=3 fail=0
  AC9  boot reconcile adopts the parent's blocks into a restarted fork child
  AC10 reconcile is idempotent across repeated boots
  AC11 resumeInheritance:false disables boot reconcile
tests/derived-fork-block-inheritance.test.ts    tests=2 pass=2 fail=0
  a derived child whose messages differ from the parent at index 0 still inherits
  a derived child whose ids do not overlap the parent inherits nothing (AC4)
tests/issue1333-derived-inheritance.test.ts     tests=8 pass=8 fail=0
tests/fork-adoption-wires.test.ts               tests=4 pass=4 fail=0

npx tsc --noEmit clean. Full suite: 1788 pass, and the failures
(installer lane, cache-friendly*, cache proof, e2e chat relay) reproduce
on unmodified master — verified by stashing the diff and re-running.

Not covered: R5 from the originating PRD (estimateCoreMessagesUpper counts
characters as tokens on the unknownBaseline path) is deliberately out of
scope here — fixing ③ means lastInputTokens is no longer 0, so that path
stops firing. Flagging it as a separate issue.

Agent verification (2026-10-13, platform daemon)

Verified on head 7831c9013 trial-merged onto current master c60c2d109 (40 commits ahead of the branch base): clean auto-merge, zero conflicts; tsc --noEmit clean.

  • New suites green: tests/lineage-reconcile-boot.test.ts 4/4 (AC9–AC12), tests/derived-fork-block-inheritance.test.ts 2/2. (The counts/names in the block above predate commit 7831c9013, which added AC12 and reworked the second test.)
  • Regression teeth proven: restoring master's versions of src/fork-adoption.ts / src/server.ts / src/server/handle.ts makes 4 of the 6 tests fail (AC9, AC10, AC12, id-intersection adoption); AC4 and AC11 pass on master by design (correct no-overlap behaviour / gate-off trivially holds).
  • No regressions in related lanes: 18 existing fork/lineage/resume suites (fork-adoption*, fork-ccr-adoption, issue1333-derived-inheritance, dsh-fork-adopt, opencode-fork-adopt, pi-omp-fork-adopt, plugin-fork, resume-adoption-wires, resume-ref-inheritance, truncation-fork, claude-fork-lineage, claude-transcript-lineage, issue2601-persona-fork-lineage, fork-nudge-trigger, fork-side-request-lane, preflight-fork-estimate) — 163/163 pass.

Behavior Changes (old → new)

Intentional semantics shifts introduced by this PR (disclosure per repo policy):

  1. Identified derived forks inherit fold state by default (was: never across a restart). Old: a fork child whose parent was identified (plugin register / identity lane) received a lineage link plus the read-only decompress fallback only; after a bili restart it served with zero blocks and re-sent the entire shared prefix — the ~1.36M-token over-window 503 in [Bug] 重启后 fork 子会话账本孤儿化:derivedFromSessionId 已持久化但无代码读回 #2985. New: blocks/refs are adopted at link time (weak path, first request) AND at boot (reconcileDerivedLineage) for children that already had requests before the restart. Why: the ledger was persisted but no code path ever read derivedFromSessionId back to trigger adoption.
  2. resumeInheritance scope widens (default ON, value unchanged). Old: gated only the strong resume path (Claude 上 resume 导致消息错乱 #1486); the weak derived path answered to forkAdoption (default OFF) and therefore never adopted. New: gates both the weak-path adoption and the boot reconcile. The existing opt-out (resumeInheritance: false) keeps working and now also disables the boot sweep.
  3. New persisted field metadata.derivedBlocksAdopted (boolean). Set only after a successful adoption; deliberately NOT set on any non-success case, so multi-hop chains (P→C→G where the intermediate parent is still empty at sweep time) keep retrying on later boots. Purely additive: older readers ignore the unknown key.

Merge Danger

Door: two-way — all three files are additive; reverting the commit restores
master behaviour. No schema migration: exactly one new purely-additive metadata key (derivedBlocksAdopted, boolean) is introduced — older readers ignore unknown keys — and nothing migrates or deletes state.

Blast Radius: session boot path. reconcileDerivedLineage runs once per
boot over every session on disk, so the cost scales with session-file count
(it is gated to sessions that record a parent, hold no blocks, and have not
adopted). Default behaviour is unchanged when resumeInheritance: false.

ranxianglei#2807)

A forked child session starts with an empty fold ledger while carrying the
parent's full raw history, so preflight re-estimates and re-folds everything
and the payload overruns the model window. The lineage is written to
metadata.derivedFromSessionId but never read back, so a restart (or a fork
that missed the byte-exact prefix match) left the child orphaned.

Add reconcileDerivedLineage(), run after initSessions()/loadConversations():
for every session that records a parent, holds no blocks, and has not yet
adopted, load the parent from disk and re-run planForkAdoption +
applyForkAdoption by message-id intersection — copy-on-fork, parent
untouched, and the CCR content store is cloned for the inherited refs.

Also fix the weak derived path: it read opts.forkAdoption (default OFF), so it
never adopted blocks while the boot reconcile still did — two inheritance
paths answering to two different switches. Gate it on resumeInheritance, the
same switch as the strong resume path, and move the derivedBlocksAdopted
marker to after the adoption call so a partial overlap does not close the
gate permanently.

Tests: tests/lineage-reconcile-boot.test.ts (adoption, idempotency across
boots, resumeInheritance:false) and
tests/derived-fork-block-inheritance.test.ts (byte-differing fork inherits,
non-overlapping ids inherit nothing).
@asuan-dev
asuan-dev force-pushed the fix/2807-fork-lineage-block-inheritance branch from 2074cbc to ac29ecd Compare October 12, 2026 07:39
ranxianglei pushed a commit to asuan-dev/billion-context that referenced this pull request Oct 12, 2026
… review)

reconcileDerivedLineage resolves parents via peekSession/getStore().loadSync
(session id), never through the plugin conversation routing table — the real
ordering constraint is initSessions(), not loadConversations().
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成 — 暂缓合并(缺回归测试),方向与机制认可。 已拉取分支、rebase 到当前 master(干净)、本地 typecheck + 定向测试全绿、逐行审完 3 个文件(+148/-1)。结论按八问如下。

结构化八问

  1. 是什么问题:fork 子会话的折叠血缘(metadata.derivedFromSessionId)只写不读——bili 重启后子会话零 blocks,而父会话的折叠账本在磁盘上;子会话把共享前缀整段原始重发,被上游以超窗拒绝(实测 ~1.4M tokens vs 窗口 ~1M → 503 preflight_compress_failed)。
  2. 什么原因导致的:两条既有继承路径都依赖进程内状态——强路径(Claude 上 resume 导致消息错乱 #1486)扫 prefixAffinity.trackedChains(内存),弱路径([pi plugin] Prime RLM inline 派生子会话在代理模式下零继承:搜不到也解压不了父会话压缩块(billion-context-pi#531 同场景) #1333)依赖 plugin register 表 pendingRegisters(内存)——重启后两者全丢,且持久化的 derivedFromSessionId 没有任何代码读回。根因是「血缘持久化了,但恢复逻辑不存在」,不是某条路径的 bug。
  3. 影响范围与严重程度:所有跨重启存活的 fork 子会话(dsh/pi/omp/opencode subagent 系)。严重度:特定条件下完全不可用(父已折叠 ∧ 子零 blocks ∧ 发生过重启 → 超窗拒绝);未触发时仅为体验损失(重复重发前缀)。读路径(decompress/search_context 沿父链只读回退)一直可用,所以是「折叠收益丢失 + 可能超窗」,不是数据丢失。
  4. 怎么修复的:反向对账——boot 时在 loadConversations() 之后、listen 之前跑一次 reconcileDerivedLineage:对每个「记录了父 ∧ 自身零 blocks ∧ 未采纳过」的会话,从内存/磁盘取父,按 raw-id 交集复用既有的 copy-on-fork 原语(planForkAdoption/applyForkAdoption/CCR store slice)种入 blocks+refs+原文。同时让弱链接路径在链接时刻就做同样的采纳(不再只记血缘)。疏而非堵:补的是缺失的恢复机制本身,没有在任何传输层做过滤/掩盖。
  5. 是否有回归问题:审过的既有行为逐项——boot 序列(sweep 在 listen 之前、try/catch 包裹、失败仅 warn 继续)✔;强路径 Claude 上 resume 导致消息错乱 #1486 未触碰 ✔;匿名 fork Design: tree-shaped prefix affinity — forked branches inherit the shared prefix's compression state #629//bili/url/重启agent、重启bili、开新会话分支啥的都有概率丢失压缩 #1834 与 forkAdoption 门未触碰 ✔;[pi plugin] Prime RLM inline 派生子会话在代理模式下零继承:搜不到也解压不了父会话压缩块(billion-context-pi#531 同场景) #1333 链接幂等性、末行日志、decompress 父链回退未触碰 ✔;ref 编号安全:applyForkAdoption 只补缺不覆盖既有 byRaw/byRef,reserveRefsThrough(父最高位) 保住 kernel「id 永不复用」不变量 ✔;双采纳互锁:强路径置 derivedFromSessionId 使弱门跳过;弱路径在采纳 try 之前先置 derivedFromSessionId,抛错后也不会二次进入(不会重复 push blocks);boot 侧以 blocks.length===0 ∧ !marker 兜底 ✔。一个残留限制(非回归,见下「发现 2」):若子会话历史相对父发生截断/重排/装饰差异导致编号漂移,被采纳 block 摘要里引用的父编号可能在子会话解析到别的消息——目标宿主均为追加式重放,风险有界;可选加固是先抽样比对重叠 raw 的编号一致性再采纳 blocks。
  6. 是否破坏缓存:不影响缓存/重试/去重策略。上游 prefix cache 反而受益(修复目的就是让折叠视图生效);无游标/去重键变化。
  7. 是否改了设计方向:没有架构转向。新增的是「持久化血缘 → boot 对账」这一恢复面,与既有 copy-on-fork 原语同构;两条继承路径统一到同一个开关(见第 8 问)。
  8. 是否引入了新的配置:无新 env/config/CLI。但有两处语义扩展必须披露:

拦点(阻塞合并)

PR 描述的测试证据在分支里不存在。 描述声称 green 的 tests/lineage-reconcile-boot.test.ts(AC9 boot 采纳 / AC10 跨 boot 幂等 / AC11 resumeInheritance:false 禁用)与 tests/derived-fork-block-inheritance.test.ts(字节差异 fork 可继承 / AC4 无交集不继承)——两个文件在 PR 分支和 master 上都不存在;整个 tests/ 目录对 reconcileDerivedLineage / derivedBlocksAdopted / lineage-reconcile 零引用。现有通过的测试并没有钉住任何新行为。请把这两个测试文件推上来(或说明它们在哪);这是 §7.4 门禁第 2 条(回归测试复现原 bug)的硬要求,也是本 PR 唯一硬拦点。

顺手修掉(已在分支上补 commit c972b2d)

src/server.ts boot 处注释称 sweep「Must run after loadConversations(): the parent may live in the plugin conversation map」——事实不符:reconcileDerivedLineage 全程用 session id 走 peekSession/getStore().loadSync,从不查 plugin 路由表;真实约束是 initSessions()。已改为准确表述(纯注释,无语义变化)。

发现 2(建议处理,不单独拦)

多跳血缘的过早关门。设链 P→C→G(P 已折叠,C/G 均零 blocks):boot sweep 按 lastSeen 降序处理,G 通常最先被处理,看到 C 空 → 置 derivedBlocksAdopted=true 永久关门;同一次 sweep 随后 C 才从 P 采纳。G 此后再无重试机会(marker 已置 + 重启前已链接的会话其弱路径链接块因 derivedFromSessionId 已持久化而整体跳过),G 只能靠自身 preflight 压缩自救。同理,adoptedActive===0(straddle)与 incomingIds.size===0 两个分支也提前关门,但子会话后续增长本来会让 straddle block 变 fully-present。建议:除「成功采纳」外一律不置 marker(留待下次 boot 重试,与「父不在盘上」分支的既有哲学一致),代价只是每次 boot 多几次廉价 plan。深度 ≥2 的 fork 树(dsh persona / pi RLM 链)正是自然形态,值得修;若 owner 认为可接受,请在回复里明确拍板。

验证记录

  • 本地(rebase 到当前 master 后的头):npm run typecheck 干净;定向套件 fork-adoption* / issue1333-derived-inheritance / dsh-fork-adopt / fork-ccr-adoption 共 43 例全过(未本地跑全量,交给 CI)。
  • CI:前一 head 的 ubuntu test(22/24)+ e2e + 各 guard 全绿;windows 两例当时仍在跑。作者中途 rebase 到最新 master 并 force-push(内容树与我本地验证的完全一致),我补的注释 commit 之上 CI 正在重跑,合并前请确认全绿。
  • diff 整洁度:3 文件 +148/-1,每行都与本 PR 目的相关,无空行/生成物噪声 ✔。

判定:方向正确、机制成立、证据可信;补齐声称的两个测试文件(并 ideally 处理发现 2)后即可合。本 PR 触及 session 身份/持久化逻辑,属人审合并范围。

…s adoption gates (ranxianglei#2807)

The PR described tests/lineage-reconcile-boot.test.ts and
tests/derived-fork-block-inheritance.test.ts as green, but only the src
files had been staged — the tests were untracked, so the branch carried
no regression coverage for reconcileDerivedLineage at all.

Both files are added now:
- lineage-reconcile-boot: AC9 boot adoption, AC10 cross-boot idempotence
  plus an unreachable-parent orphan check, AC11 resumeInheritance:false,
  AC12 multi-hop lineage gate deferral.
- derived-fork-block-inheritance: byte-prefix fork inheritance and the
  no-intersection case.

AC12 is the regression test for review finding 2: reconcileDerivedLineage
walks sessions by lastSeen descending, so in a P->C->G chain the
grandchild is reached before the child has adopted from its own parent.
Three branches (parent has no blocks, child has no refs, nothing fully
present yet) previously set derivedBlocksAdopted, closing the gate
permanently; the grandchild could then only rely on preflight
compression. They now leave the marker unset so the next boot retries,
matching the existing 'parent not on disk' philosophy. AC12 fails without
this change and passes with it.

Also corrects the boot comment: the sweep resolves parents by session id
(peekSession, then the store), so the real ordering constraint is
initSessions(), not loadConversations() — the plugin routing table is
never consulted.
@ranxianglei

Copy link
Copy Markdown
Owner

[bot] 🏷 Verified against current master (2026-10-13):

  • Head 7831c9013 trial-merged onto master c60c2d109 (40 commits ahead of the branch base): clean auto-merge, zero conflicts; tsc --noEmit clean.
  • New suites green: tests/lineage-reconcile-boot.test.ts 4/4 (AC9–AC12), tests/derived-fork-block-inheritance.test.ts 2/2. Regression teeth proven: restoring master's versions of the three touched source files makes 4 of the 6 tests fail (AC9/AC10/AC12/id-intersection adoption); AC4 + AC11 pass on master by design.
  • 18 existing fork/lineage/resume suites: 163/163 pass. CI on the head commit: all checks green.
  • No code changes were needed on your branch — your rebase already addressed the earlier review findings (regression tests added, non-success gate deferral, boot-comment accuracy).
  • PR body updated: added Closes #2985 (the cross-restart fork orphaning tracked there), added a Behavior Changes (old → new) section, and corrected one inaccurate sentence in Merge Danger (the change does introduce one new purely-additive metadata key, derivedBlocksAdopted).

Ready for owner review/merge.

@ranxianglei

Copy link
Copy Markdown
Owner

Review 收尾:拦点清零 + update-branch + 维护者重构(行为不变)

① 原 review 硬拦点已清(核实过分支现状)
7831c901 已把两个测试文件推上来,已核实存在且与描述一致:

  • tests/lineage-reconcile-boot.test.ts — 4 用例:AC9 boot 采纳 / AC10 跨 boot 幂等 / AC11 resumeInheritance:false 禁用 / AC12 多跳孙会话在中间父未长全时保持可采纳
  • tests/derived-fork-block-inheritance.test.ts — 2 用例:字节差异 fork 按消息 ID 交集继承 / 无交集不继承(AC4)

② Finding 2(多跳过早关门)已按 review 建议实现
非成功分支(父无块 / adoptedActive===0 straddle / incomingIds 空)一律不置 derivedBlocksAdopted,留待下次 boot 重试;incomingIds 空 defer 到首请求。残余限制(进程内不主动重试、非成功要等下次 boot)已知并接受——plan 便宜,正确性优先。

③ update-branch:已并入最新 master(3241e000)
原绿 CI 是对 merge-base 3269d71c(10-12)跑的;master 之后进了统一存储 R2 系列(#2960 ③/⑤、#2992 identity index),恰好动了本 PR 依赖的 session 存储读路径。文本无冲突,已 merge 并触发 CI 复跑(本条评论时的 head 即复跑头)。

④ 维护者重构提交 c33e1f9c(无行为变化)
handle.ts 弱路径里 30 行内联采纳块提取为 fork-adoption.ts 的 maybeAdoptDerivedFork()——与 maybeAdoptForkBlocks / maybeAdoptResume 同款 hook 模式,门控/marker/try-catch/日志逐字保留。本地验证:typecheck 干净、fork/adoption/resume/derived 相关 10 套件 107/107 通过、build 成功;全量套件交本轮 CI。

⑤ owner 结论

描述勘误:原文 "metadata keys pre-exist, nothing new" 不准确——derivedBlocksAdopted 是本 PR 新增的 metadata 键(见上 ⑤),已修正。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 复核完成:五条全部核实属实,拦点清零。 本轮拉取当前 head(952c799bb,已含 refactor 后的第二次 master merge,#3010/#3014 均已并入,rev-list --count head..origin/master = 0)逐项验证:

① 测试文件 — 存在且断言有牙

  • tests/lineage-reconcile-boot.test.ts:AC9 / AC10 / AC11 / AC12 四个用例齐。不是纸面测试——真起 proxy + mock upstream 走完整生命周期:AC9 把弱路径已种下的块剥掉、模拟重启后断言 boot reconcile 独立种回 blocks+blockContents+lineage,并逐块验证 copy-on-fork(父的块与 refs 一个不少);AC10 双 boot 幂等(deepEqual 块序 + contents 不翻倍)+ 不可达父不消费 marker 且有日志;AC11 门控关闭不消费 marker。
  • tests/derived-fork-block-inheritance.test.ts:字节差异 fork 按 id 交集继承(精确断言恰好缺 1 个被装饰消息的 ref)+ 无交集不继承(AC4,直接单元级钉住空交集路径)。

② Finding 2(多跳过早关门)— 按建议实现且更完整
reconcileDerivedLineage(src/fork-adoption.ts:415)现在只有成功分支置 derivedBlocksAdopted(L481);父不在盘上(L442)、父无块(L449)、incomingIds 空(L459)、adoptedActive===0(L470)、catch(L488)一律留待重试。其中 incomingIds 空 defer 到首请求比我建议的"下次 boot"更准——首请求本来就是弱路径的真实对账点,提前关门会废掉它。AC12 专门复现 P→C→G 孙会话先于中间父被访问的场景,把这个回归钉死了。

③ update-branch — 确认
head 对 master 落后 0;merge 干净,文本无冲突痕迹。

④ 重构 c33e1f9c — 纯提取,语义零漂移
逐行比对:旧内联块的 gate(resumeInheritance !== false && marker !== true)、maybeAdoptResume 参数(sharedDepth:0/blocksEnabled:true)、marker 时序、catch 日志文案全部原样搬入 maybeAdoptDerivedFork(src/fork-adoption.ts:374-391);调用点仍在原外层 link 块内(src/server/handle.ts:1397),位置未变。注释也随函数迁移,没有丢。

本地定向验证(本轮):npm run typecheck 干净;fork/adoption/resume/derived 相关 12 个套件(含两个新文件)80/80 pass。
CI:check-runs 除 test (windows-latest, 22) 和 test (windows-latest, 24) 两个 job 还在跑外,其余全绿(ubuntu 22/24 test、static-gates、e2e、registry e2e、kernel/pi-subagents/config-surface/version/doc guards)。PR mergeable: true,blocked 仅为等待这两个 check 完成,非冲突。


结构化八问(收口轮)

  1. 是什么问题:fork 出的子会话重启后丢失折叠谱系(lineage 只写不读、两条采纳路径都依赖进程内存态),整段原始历史重发,超窗即被拒(实测 ~480K 会话被按 ~1.4M 拒掉)。
  2. 什么原因导致的:谱系持久化了但没有任何代码读回;强路径靠 prefixAffinity.trackedChains、弱路径靠 pendingRegisters,两者都是进程本地状态,重启即失忆。
  3. 影响范围与严重程度:所有经 plugin register 声明过父会话、且经历过 bili 重启的 fork 子会话;特定条件下严重(超窗会话完全无法继续压缩,只能裸奔重发或 503)。
  4. 怎么修复的:boot 时从盘上读回 lineage 反向对账(reconcileDerivedLineage,按 raw-id 集成交付父的折叠账本,copy-on-fork);弱路径 link 时就地采纳;三条继承路径统一归 resumeInheritance 管;marker 只在成功后落,失败留待重试。
  5. 是否有回归问题:无。强路径(Claude 上 resume 导致消息错乱 #1486 字节前缀)与匿名 fork(Design: tree-shaped prefix affinity — forked branches inherit the shared prefix's compression state #629//bili/url/重启agent、重启bili、开新会话分支啥的都有概率丢失压缩 #1834 + forkAdoption 门控)逐行未动;refill-missing-only 的 ref 合并保住 kernel "id 永不复用"不变量;重构提交为纯提取(已逐行比对);本地 80/80 + CI 近全绿。
  6. 是否破坏缓存:不涉及。新增 metadata 键是加法、不动消息字节;前缀缓存不受影响。
  7. 是否改了设计方向:不涉及架构转向;三处默认行为变化(owner 已拍板进 release notes):identified derived fork 从不继承→默认继承;resumeInheritance:false 从关一条路变关三条;新增永久 metadata 键 derivedBlocksAdopted。
  8. 是否引入了新的配置:不涉及。无新 env/config 字段;derivedBlocksAdopted 是内部 metadata,非配置面。

判定:可合并。 等最后两个 windows test job 转绿即可;合并按仓库规矩由人工执行。残余限制(进程内不主动重试、非成功分支要等下次 boot)与 ref-number drift 边界风险维持我第一轮评估:已知、有界、接受。

@ranxianglei

Copy link
Copy Markdown
Owner

CI note: the earlier red on test (windows-latest, 24) was a flake, not a regression from this PR:

  • Failing entry was file-level only (tests/issue1881-reasoning-tag-leak.test.ts ✖ 262ms, zero subtests executed, error swallowed as 'test failed') while windows-22 + both ubuntu lanes were green on the same head.
  • Re-run of the failed job only → green (all 35 checks pass on 952c799b).
  • Repro attempt on a real Windows box (Win10, node v24.21.0, this exact head): 12/12 pass, twice.

No code change needed; head 952c799b is fully green and ready for review-merge.

@ranxianglei
ranxianglei merged commit 48c281b into ranxianglei:master Oct 13, 2026
52 of 53 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.368-master.48c281b (rolling master tag).

npm install -g billion-context@0.0.368-master.48c281b  # 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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 重启后 fork 子会话账本孤儿化:derivedFromSessionId 已持久化但无代码读回

2 participants