Skip to content

Subagent requests share the parent session id and trip fold-reconcile #4352

Closed

Description

@BangDoll98

Summary

In Claude Code native mode, requests from subagents (the Agent tool) reach
the proxy under the parent session's id. fold-reconcile treats each subagent
request as the parent session resending its history. It then concludes that
the folded messages were dropped by the host. After that, the model's
compress calls are rejected as substrate-destruction and the folded blocks
show coverage-lost. The parent conversation in Claude Code is intact. No
compact_boundary exists in its transcript.

Environment

Item Value
billion-context 0.1.204 (c87185a), bili plugin install claude (native mode, /bili/ path)
Client Claude Code VS Code extension 2.1.307 (entrypoint: claude-vscode)
OS Windows 11 Pro, Node.js 24.13.1
Model claude-opus-5-5, window declared as 1000000 in billion-context.json
Settings DISABLE_AUTO_COMPACT=1 (set by the installer)

What happened

One long session (about 1,270 messages) launched 14 subagents over two days.
One was foreground and 13 were background (run_in_background: true). Each
subagent's system prompt is 3,044 chars and it sends 27 to 59 messages. The
parent's system prompt is 11,170 chars.

In bili.log, the parent session id logs these lines once a subagent is
running:

[fold-reconcile] system prompt changed (11170 → 3044 chars); fold state
  unaffected (#1921)
processTurn: 27 msgs, renderTags=text-only, ...
[fold-reconcile] 98 covered id(s) no longer on the wire with no replacement
  evidence and remaining substrate present — host-side truncation/dropped
  history, fold snapshot retained (#2695/#3641)
[fold-reconcile] resent history drifted: 102 covered id(s) missing with no
  anchor match — mutation ...
[cache-ledger] fold seq 154 (block b154) coverage-lost: covered id(s) no
  longer on the resent wire ...
[fold-reconcile] fold epoch confirmation required: 104 covered id(s) missing
  with NO anchor match and NO word evidence for 73 consecutive passes, 61 min
  so far — the resent history shares nothing with the fold substrate ...

Of the 14 drop / epoch events for this session, 12 fall inside a subagent
run. The other two came right after the first answer and at a preflight fail-fast 502. The system prompt changed (11170 → 3044) line appears one
second after each launch we checked, for example:

Subagent launched (transcript) First system prompt changed (11170 → 3044) Next drop / epoch event
2026-10-22T00:06:21Z 00:06:22Z —
2026-10-22T03:49:02Z 03:49:03Z 03:49:50Z (fold epoch confirmation required)

After this, the model's compress calls fail:

[Compression FAILED: Requested range(s) cannot be anchored (e.g. m01434..m01640):
refs ... are known to this session but no longer back any visible or folded
message — the client rewrote or dropped those messages ... These refs are now
recorded as DEAD ... [cause: substrate-destruction — host-native compaction or
bulk client-side history rewrite landed outside bili's knowledge
(#1729/#2193); structural, report it]

The same session also logs about 40 [storage] unified shadow DIGEST DRIFT ... unified replay != legacy load view (repeat: consecutive sampled drift — the views are not converging) errors. We suspect the same cause but have not
confirmed it.

Expected

Subagent traffic is kept apart from the parent session's fold state. It could
use a separate session key, or it could be detected through the different
system prompt and the short, unrelated history. The parent's folds and refs
would then survive a subagent run.

Notes

  • The parent transcript has no compaction: 0 compact_boundary lines, and
    DISABLE_AUTO_COMPACT=1 is set
  • The context_management field the client sends is only
    {"edits":[{"type":"clear_thinking_20251015","keep":"all"}]}
  • Possibly related and seen only while the window was still capped at 200k
    ([bug] window resolution: registry 1M advertisement outranks built-in 200k standard window for claude native without context-1m beta header #1321), before the 1M declaration took effect: twice in the same second
    as preflight fail-fast 502, the client showed API Error: 400 messages.<N>: The final block in an assistant message cannot be thinking,
    after thinking-pair-violated warnings. Not seen after the restart that
    applied the 1M window

Activity

  1. ranxianglei commented on Oct 23, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

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

    查重:不重复 —— 同家族但不同症状/不同机制:

    版本核对:v0.1.204(c87185a0)。已按该 tag 的代码核验;master 与 v0.1.204 在这些路径上无实质差异(仅一处无关注释变更),结论两边通用。

    机制核验(v0.1.204 代码):

    1. fix: split Claude Code subagent sessions so they stop queueing on the main session lock (#970) #975 的拆分门(claudeSubagentAgentId,src/session-id.ts:409)是双信号 AND:① 请求带 x-claude-code-agent-id 或 x-claude-code-parent-agent-id;② system 不含主 agent 前缀("You are Claude Code…" / "You are an interactive agent…")。任一信号不命中,请求就留在原始父 id 上。
    2. 你的日志显示 3044 字符 system 的请求是在父会话里被处理的([fold-reconcile] 日志用的是 session.id,拆分后的会话会显示成 <id>|sub:...)——即你的 subagent 请求没通过这道门。最可能的原因:VS Code 扩展(entrypoint claude-vscode)不发这两个头。fix: split Claude Code subagent sessions so they stop queueing on the main session lock (#970) #975 的验证流量是 CLI -p 模式 + 自定义 agent;它设计的「安全降级方向」正是「信号不命中就不拆」——于是落进了你现在踩的坑。
    3. 落到父会话之后的损害链与你逐条吻合:subagent 短历史(27–59 条)与父会话折叠基底零重叠 → drop 事件逐 pass 累积 → epoch 确认(73 passes / 61 min)→ substrate-destruction 判决 → 模型 compress 被拒、refs 记为 DEAD。代码自己的日志文本其实已经承认了另一假说("or a brand-new conversation on the same session id",src/fold-reconcile.ts:2004),但没有对它采取任何保护动作。

    想请你补一个证据(不阻塞修复):你的 subagent 模型请求是否带 x-claude-code-agent-id / x-claude-code-parent-agent-id 头?能复现的话开 bili debug 日志后在 bili.log 里 grep 这两个头名即可。若确实没有,即可坐实 VS Code 扩展不发头。

    修复方向(进行中):dsh 对这类问题已有成熟基建——顺序优先的会话解析(src/session-resolve.ts,#2944:顺序+id 认领同一会话、内容 hash 只作防错护栏、历史不连续的分叉到 |sub: 车道)。计划:Anthropic 线的 claude 流量在 #975 头门未命中时改走同一 resolver(白名单限定 x-claude-code-session-id,evidence-per-client 纪律,与 Responses 线已对 claude 的处理一致,#1107)。主 turn 即使 system 漂移也留在原 key(历史连续即认);subagent 借道(历史零重叠)分叉到独立车道,父会话折叠状态不受触碰。最坏角落下「分叉」也不劣于现状的「毁掉折叠状态 + refs 永久 DEAD」。回归测试按双向断言纪律补齐。PR 稍后给出。

    另:~40 条 DIGEST DRIFT 疑似同源(subagent 消息以父会话 id 写入统一存储),应随修复消失,会在测试里验证。

    标签:bug / claude-code / scope/wiring / p1 —— 凡用 subagent 的会话核心承诺(压缩)被永久破坏,refs 一旦记 DEAD 无法恢复。

  2. BangDoll98 commented on Oct 23, 2026

    @BangDoll98
    Author

    Thanks. Two data points from the same session:

    1. Signal (2) cannot pass for VS Code extension subagents. In the transcripts
      (api-request-shape), the parent and all 14 subagents send the same first
      system block, verbatim: "You are Claude Code, Anthropic's official CLI for
      Claude, running within the Claude Agent SDK." (94 chars). Only the second
      block differs (parent 10,719 chars; subagent 2,669 chars starting "You are
      an agent for Claude Code, ..."). So the main-agent-prefix check fails for
      these subagents whether or not the headers are present.
      Client: Claude Code VS Code extension 2.1.307 (entrypoint claude-vscode).

    2. Headers: I could not confirm them from logs. bili.log already has ~14.5k
      debug lines but never prints x-claude-code-* header names, so grepping it
      does not answer this. The extension binary (2.1.309) does contain the
      strings x-claude-code-agent-id and x-claude-code-parent-agent-id.
      Whether they are attached to subagent requests I can't tell without a
      switch that logs inbound header names. If there is one, I can re-run a
      small subagent.

    Given (1), the #975 gate misses these subagents even with the headers, so
    forking on zero history overlap looks like the right fix.

  3. added 2 commits that reference this issue on Oct 23, 2026
  4. ranxianglei commented on Oct 23, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

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

    修复已完成,PR:**https://github.com/ranxianglei/billion-context/pull/4409**(Closes 本 issue)。你给的第二个数据点(父与全部 14 个 subagent 逐字共享第一个 system block)正是关键证据——它证明 #975 的头门即使头都在也永远过不了,所以修复完全不依赖前缀启发式。

    八问

    1. 是什么问题:Claude Code(VS Code 构建)的 subagent 请求以父会话 id 进入代理,其 27–59 条的短历史被 fold-reconcile 误判为「宿主丢掉了折叠消息」,累积成 substrate-destruction 判决;此后模型对父会话的 compress 调用全部被拒、refs 永久记 DEAD——该会话的压缩从此不可用(对话本身完好)。
    2. 什么原因导致的:fix: split Claude Code subagent sessions so they stop queueing on the main session lock (#970) #975 拆分门是双信号 AND:①带 agent-id 头;②system 不以主 agent 前缀开头。你的构建里 subagent 第一个 system block 与父逐字相同("You are Claude Code…"),信号②必失败 → subagent 流量留在父 id 上;短历史与折叠基底零重叠 → drop 事件逐 pass 累积 → epoch 确认(73 passes / 61 min)→ substrate-destruction。根因是会话身份判定依赖前缀启发式且无兜底:启发式失手时流量直接落进父会话并摧毁其折叠状态。
    3. 影响范围与严重程度:p1。所有用 subagent(Agent 工具)的 Claude Code native 模式会话;触发条件 = claude native + subagent 运行 + 拆分门不命中(VS Code 扩展已坐实;任何 system 首块带主前缀的自定义 agent 同理)。后果是持久性的:refs 记 DEAD 后不可恢复,会话压缩实质报废。
    4. 怎么修复的:fix: split Claude Code subagent sessions so they stop queueing on the main session lock (#970) #975 头门未命中时,claude anthropic 线流量改走既有的「顺序优先」会话解析器(会话身份:顺序+自铸id 为认领主判,hash 降级为防漂移护栏(通用规则,取代 persona-fp 阶梯) #2944/[[bug] dsh 0.1.185: main lane forks itself on a mid-session model switch, orphaning the persona anchor — every native compress is refused (9/9, not covered by #2157) #2241,dsh/codex 车道已在用的同一基建):主会话按顺序+内容证据留在原 id;历史零重叠的 subagent ride 分叉到独立 |sub:<fp> 车道(独立锁链、独立压缩状态,同一 persona 后续 pass 稳定同车道)。白名单限定「获胜会话源为 x-claude-code-session-id」的请求(证据纪律),其他 anthropic 客户端行为不变。你提供的共享首块形状已作为回归测试行精确钉住。
    5. 是否有回归问题:diff 触碰路径的既有行为逐项审过(详见 PR 描述):fix: split Claude Code subagent sessions so they stop queueing on the main session lock (#970) #975 CLI 拆分路径原样保留(第一分支未动);非 claude anthropic 客户端保持 verbatim(负向 e2e 钉住);dsh persona 路径不变;顺序解析器本身零改动(只加一个调用点);side call / 空 system 豁免保持;全程无任何 wire 改写。本地定向套件 121/121 + 新套件 8/8 绿,typecheck 干净,全量 CI 在推送的 head 上跑。
    6. 是否破坏缓存:否——父会话出站字节逐字不变;分叉出去的 subagent 车道自建缓存谱系(此前它们正是在污染父缓存基底)。
    7. 是否改了设计方向:否——把既有机制(顺序解析器)接到新车道,无架构/边界/数据流转向。
    8. 是否引入新配置:无新字段。既有 subagentSplit(BILI_SUBAGENT_SPLIT)语义扩展:false 现在同时禁用这条无头兜底(原先只禁双信号头拆分),默认仍开;CONFIGURATION.md 中英已更新。

    回答你上一条的两个点

    • 头名日志开关:有——bili --debug 会在 bili.log 里记录每个请求的入站客户端头,grep x-claude-code- 即可确认扩展到底发不发这两个头。不过现在这只是锦上添花:修复不再依赖任何头信号,发不发都不影响。
    • ~40 条 DIGEST DRIFT:判断同源——subagent 消息以父 id 写进统一存储导致 replay 视图漂移。修复后 subagent 流量落在自己的会话键下,应随之消失;无法在本地复现你的数据,请升级后跑一次 subagent 确认(若仍出现请单独反馈,那会是另一个问题)。

    修复随下个版本发布(PR 待人工 review 合并,涉及身份/会话绑定逻辑按规约必须人审);自更新会自动带到。标签维持:bug / claude-code / scope/wiring / p1。

  5. ranxianglei commented on Oct 23, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    (ai: vllm-qwen/qwen3.8-27b) 补充:期间 master 前进了 10+ 个合并(含 #4372 zcode MCP 方言、#4344 相关),PR #4409 已 rebase 到最新 master(head 现为 117c331)。唯一文本冲突在 src/host-profiles.ts(master 新增的 zcode profile 条目 vs 本 PR 给所有条目加的 personaOrderKeyed 字段),按双方意图并集解决;master 在本 PR 触碰文件上的其余改动(zcode MCP dialect、probe conversation 参数)与本修复无语义交互。rebase 后本地复验:typecheck 干净,定向套件 141/141 绿。全量 CI 在推送的 head 上跑。

  6. ranxianglei commented on Oct 23, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

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

    修复完成 → PR #4409: https://github.com/ranxianglei/billion-context/pull/4409(Closes #4352)

    你给的两个数据点都已纳入修复与测试:

    1. 首块 system 逐字相同 —— 坐实了这个形状让 fix: split Claude Code subagent sessions so they stop queueing on the main session lock (#970) #975 的前缀检查必败(门要求「没有任何 system 块以主 agent 前缀开头」,而你的 subagent 第一块正是父会话的第一块,带不带头都过不了)。新路径不依赖这个检查:头门未命中时 claude 流量改走顺序优先会话解析器——subagent 借父 id 但历史零重叠 → 分叉到独立 |sub:<fp> 车道,之后父请求回到原 key。我已把恰好这个字段形状(首块逐字相同、次块不同)钉成回归测试行。
    2. 头日志开关 —— 有:bili --debug(或 env ACP_DEBUG=1 / 配置 "debug": true)会对每个转发请求打一行 client headers: <全部入站头名>(只打名字、不打值;src/server/relay.ts:458,已核代码路径)。你之前那份日志里没有这行,说明当时 debug 实际未开——重跑一个小 subagent 后 grep x-claude-code- 即可。两种结果都被修复覆盖:带头则 fix: split Claude Code subagent sessions so they stop queueing on the main session lock (#970) #975 门优先(行为不变),不带头走新的顺序解析路径。

    ~40 条 DIGEST DRIFT 疑似同源(subagent 消息以父 id 写入统一存储),应随修复消失——升级后请再确认一次。

    结构化八问

    1. 是什么问题:Claude Code native 模式下 subagent 请求以父会话 id 到达代理,fold-reconcile 把它当「父会话重发历史」,判折叠基底被毁(substrate-destruction),此后模型 compress 调用被永久拒绝、refs 记 DEAD。
    2. 什么原因导致的:bili 按客户端提供的 conversation 值逐字定压缩状态键。fix: split Claude Code subagent sessions so they stop queueing on the main session lock (#970) #975 拆分门是双信号 AND(agent-id 头 + system 无主前缀);VS Code 扩展的 subagent 与父共享同一首块 system,信号②结构性过不了(且头可能根本没发)→ subagent 流量全落父 id,其 27–59 条无关短史与父折叠基底零重叠 → drop 事件累积 → epoch 确认 → substrate-destruction 判决。
    3. 影响范围与严重程度:p1 —— 凡用 subagent 的 Claude Code native 会话,核心承诺(压缩)被永久破坏:refs 记 DEAD 不可恢复,compress 持续失败直到换会话。触发条件:任何没通过 fix: split Claude Code subagent sessions so they stop queueing on the main session lock (#970) #975 门的 subagent 请求(VS Code 扩展已证实;CLI 自定义 agent 若头缺失同样中招)。
    4. 怎么修复的:fix: split Claude Code subagent sessions so they stop queueing on the main session lock (#970) #975 头门未命中时,Anthropic 线的 claude 流量(白名单限定 x-claude-code-session-id,evidence-per-client 纪律,与 Responses 线对 claude 的既有处理一致 fix: invert the Responses instructions fingerprint into a codex/claude-only allowlist #1107)改走 dsh 同款的顺序优先会话解析器(会话身份:顺序+自铸id 为认领主判,hash 降级为防漂移护栏(通用规则,取代 persona-fp 阶梯) #2944):历史连续才留原 key(顺序+内容证据),借道者(历史零重叠)分叉独立车道,父会话折叠状态/refs 全程不被触碰。最坏角落下「分叉」也不劣于现状的「毁折叠状态 + refs 永久 DEAD」。
    5. 是否有回归问题:逐项审过既有行为——主 turn system 漂移仍留原 key(历史连续即认,解析器语义未动);title-gen sidecar(sideRequestLike)与空 system 请求照旧不认领锚点、verbatim 通行;非 claude 客户端(无该头)照旧 verbatim;fix: split Claude Code subagent sessions so they stop queueing on the main session lock (#970) #975 双信号拆分保持优先、行为不变;dsh persona 车道不受影响。回归测试双向断言(该分叉时分叉 + 不该分叉时留原 key,含你给的字段形状行)。
    6. 是否破坏缓存:不影响——分叉车道是独立会话键、独立缓存状态;父会话出站字节不变(subagent 请求本就不该进父会话,之前的损害源正是混进来的消息)。
    7. 是否改了设计方向:不转向架构——复用既有 会话身份:顺序+自铸id 为认领主判,hash 降级为防漂移护栏(通用规则,取代 persona-fp 阶梯) #2944 解析器基建,claude 车道对齐 dsh 车道的既有模式。
    8. 是否引入新配置:无新字段。既有 subagentSplit(env BILI_SUBAGENT_SPLIT)语义扩展到覆盖这条回退路径:设 false 会同时禁用无头回退(默认 ON;CONFIGURATION.md en+zh 已更新)。

    状态

    判定:修复完成,PR 待人工合并;升级后若 DIGEST DRIFT 仍在,回来报一声那就要另查机制了。

  7. ranxianglei commented on Oct 23, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

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

    两个数据点都很有用,谢谢。

    1. 这个数据点是决定性的。 父会话和所有子代理共享同一个首块("You are Claude Code, …running within the Claude Agent SDK.")——它以 "You are Claude Code" 开头,正好命中主代理前缀表。所以 #975 的门即使两个 header 都在也永远过不了信号(2):VS Code 扩展的子代理走 header 通道是死路。这确认了正确的修法不是补 header 探测,而是按你说的"零历史重叠"来分流——我实现的正是这个:claude-anthropic 车道的流量在 header 门未命中时改走会话顺序解析器(与 dsh persona 分裂同一机制)——历史不相交且 system 不同 → 分到独立的 |sub:<fp> 车道;父会话的后续回合(包括 system 漂移、native /compact 后的重放)仍留在原 key。header 在不在都不影响这条路径生效。

    2. 没有这样的开关——bili 在任何 debug 级别都不打印入站 header 名(查过代码,不存在该日志面)。不过按第 1 点,这个问题已经不重要了:修复恰好覆盖"header 缺失"和"header 存在但信号(2)失败"两种情形。

    进度:新测试套件本地全绿(含负例:非 claude 客户端保持逐字身份、opt-out 开关、side call/空 system 豁免),相邻身份/车道测试套件正在跑完,PR 马上提。

  8. qiangu2020 commented on Oct 24, 2026

    @qiangu2020
    Contributor

    Note on the closure of #4409: the stale-ticket bot closed #4409 on 2026-10-24, saying this issue was fixed by the merged #4337. #4337 changes pi's incremental ack and the storage drift fallback (#4323); it does not touch the Claude subagent split. The routing from #4409 is not on master (code search finds no personaOrderKeyed, which #4409 added to src/host-profiles.ts). So the VS Code subagent case in this issue still looks open.

    A related MCP-side problem (Task subagents' bili tool calls bound to the root session id, including one subagent fold applied to the parent) is filed as #4580.

  9. ranxianglei commented on Oct 24, 2026

    @ranxianglei
    Owner

    (ai: zhipuai-lb/glm-5.3)

    孤儿 issue 清理:修复已由已合并 PR #4337, #4414 落地(含今日五列合并列车),但本 issue 未随之关闭。现补关;若该修复仍有残留问题请 reopen 并描述复现。

  10. added a commit that references this issue on Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions