Repository navigation
fix: Claude Code fork 按 transcript 解析父会话,保留父会话编号空间,大量追加不再误报改写 (#2426) - #2427
Conversation
… CI gate) isClaudeSessionUuid / claudeConfigDirs / TranscriptParentLookup are only referenced inside their declaring file (the test imports claudeTranscriptParent and resolveClaudeTranscriptLineage), so they are INTERNAL_ONLY per the ranxianglei#1440 gate and must not be exported.
startRig pointed XDG_STATE_HOME at a fresh mkdtemp without restoring it; restore the previous value in closeAll, mirroring the CLAUDE_CONFIG_DIR handling already used by the e2e cases in this file.
[bot] 🏷 Review 结论(结构化八问) — 全量读完 7 个文件 diff(+593/-16),原 issue #2426 已做方向审核,kernel/宿主编号消费面逐项审计,定向测试本地实跑,一处 CI 失败已复现并直接在分支上修复。 审查动作(结论前的验证)
八问
未验证(作者已披露,接受):无真实 Claude Code A/B(需现场触发额度错误 fork,e2e 用按真实 transcript 结构构造的夹具);Windows/macOS 的 判定:可合 —— 等重跑的 CI 全绿后由人工合并(系统规则禁止我合并;当前 |
|
Reviewed against master Verdict: direction correct, all three defects confirmed at code level, implementation sound. Local verification green. Details below, plus the interaction checks with the recently-merged fork-adoption work. Defect 1 — transcript lineage. Confirmed the failure mode in
Defect 2 — ref floor. The Defect 3 — dual ratio. Checked the shape that must KEEP firing: a codex-style local-compaction replay (2 of 14 ids retained) → Interactions with the recently-merged fork work (my review focus):
Local verification on Merge notes: touches message-ref numbering + session identity binding → stays human-review per §7.4 (correctly self-declared in the PR body). Base is behind master ( One question for the record, not a blocker: when the transcript chain resolves to a KNOWN ancestor that is NOT the direct parent (fork-of-fork whose middle session never hit this proxy), the child adopts the nearest known ancestor's refs/blocks for shared ids only. That's the intended "nearest tracked ancestor" semantics and content-addressing keeps it safe — just confirming it's deliberate (the |
[bot] 🏷 确认:「最近已知祖先」语义是有意的,理由如下(供存档):
其余无异议:merge notes 收到(rebase 或原样合并都干净,交给你定); |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.161-master.64ca1ef # this exact build
npm install -g billion-context@master # always the newest merged build
|
Fixes #2426
问题
Claude Code 会话经 SDK
forkSession后以普通 resume 继续(opencode-claude 在额度错误后重试回合就是这样),没有--fork-session的 SessionStart 声明;且首个请求的尾部与父会话最后一个请求不同(resume 时的<system-reminder>、技能差量)。字节级的findResumeParent因此拒绝了真正的父会话(等长且最后一条不同),采纳了一个更老的祖先:18 个块未继承、约 1871 条消息重新折叠、触发unannounced-rewrite。详见 #2426。改动(三处独立修复,均无新增配置项/环境变量)
src/claude-transcript-lineage.ts,读取 Claude Code 写在 fork transcript 每一行的forkedFrom,沿链找到 bili 已知的最近祖先。src/server/handle.ts的 Claude 上 resume 导致消息错乱 #1486 resume-inheritance 块对以x-claude-code-session-id标识的请求(anthropic、主 lane、仅回环地址)先走它,查不到 transcript / 标记 / 已知祖先时回退到原有前缀匹配。安全限制:只读<CLAUDE_CONFIG_DIR 或 ~/.claude>/projects/*/<id>.jsonl头部(≤256 KB)、realpath 必须在 projects 根目录内、防环、深度上限 8。reserveRefsThrough在继承时以及applyCompactionArchive裁剪之后,在messageRefs.byRaw写入bili:ref-floor哨兵保留父会话的编号空间(不计入改写统计),避免父会话里表示消息 X 的编号在子会话里表示另一条消息。detectUnannouncedHistoryRewrite增加knownIncoming / knownBefore < 0.5判据,正常追加不再被报为改写,真实改写仍会报。需要人工审阅的点(按 AGENTS.md §7.4)
claude --resume <id> --fork-session的 SessionStartsource:"fork";SDKforkSession后的 plain resume 没有这个声明,本 PR 用 transcript 里的forkedFrom补上这个缺口,并且不要求字节前缀一致。kernel/。测试
tests/claude-transcript-lineage.test.ts(12 个用例):transcript 查找各分支、symlink 越界、血缘链/环/深度上限、追加不误报与真实改写仍报、ref floor、anthropic e2e(等长尾改后按 transcript 继承且无编号复用;无 transcript 时找不到父;x-acp-session不读 transcript)。ref m00015 must denote the same message in parent and child失败。tests/fork-ccr-adoption.test.ts:原用例写死子会话复用父会话编号(m00006–m00009),现断言子会话分支编号从父会话最高 ref 之上开始。d189be53后的分支头上:npm run typecheck通过;npm test5097 项,5069 通过,0 失败,28 跳过(XDG_STATE_HOME指向空目录,避免claude-native用例读取本机端口偏好);npm run build通过。未验证
~/.claude路径解析没有实测。