You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[bug] Claude Code Task subagents: bili MCP tools run against the root session (process-wide CLAUDE_CODE_SESSION_ID) → 409 witness conflicts, phantom range errors, and a subagent fold applied to the parent | Claude Code 子代理的 MCP 压缩落到父会话 #4580
Claude Code CLI 2.1.306 / 2.1.308 (terminal), launched through bili … claude. bili 0.1.20x at the time (2026-10-20 → 10-23). On master, src/mcp.ts still binds once per process: CONVERSATION_FROM_ENV = process.env.CLAUDE_CODE_SESSION_ID?.trim() || ….
Task tool subagents (general-purpose, background), depth 1 and 2. The proxy-side split works for them: their tags restart at m00001, as on a |sub: lane.
Data
All mcp__bili__compress results in ~/.claude/projects/** transcripts, 2026-10-20 → 10-23 (deduplicated by tool_use_id):
caller
calls
applied
409 witness conflict
"covered by active blocks"
dead refs
no net shrink
too small
malformed
main sessions (14 files)
63
56
0
1
0
4
0
2
Task subagents (14 files)
50
4
10
23
4
7
2
0
Two cases that show the binding
Case 1 (depth-1 subagent, Claude Code 2.1.306). At 2026-10-21 08:41:03Z the subagent had 145 transcript messages and no successful compression (its first call at 08:37:54 got bili tool error: outbound tool witness does not match conversationId). It asked for ranges from its own context and got:
Range contains no compressible messages — all are already covered by active blocks or protected. [cause: covered-by-block …] [Current context: 85 visible message(s), refs m00001–m00372, 6 active block(s). …]
At that moment the root session had 361 transcript messages and 6 applied blocks. The status describes the root session.
Case 2 (depth-2 subagent, Claude Code 2.1.308). At 2026-10-22 15:34:28Z the subagent had 40 transcript messages and no blocks. Its compress error said:
[Current context: 249 visible message(s), refs m00001–m00545, 6 active block(s). …] Current compressible ranges (use these refs exactly as listed): Compressible ranges (11, oldest first): m00356–m00388 33 msgs 12.2K [tool 66% | text 34%] · 6 user msgs …
The root session had 536 transcript messages and 6 applied blocks; no sibling subagent was larger than 234 messages. The subagent then did what the error told it to do: it called compress for m00356..m00388 with a summary of its own work and got {"outcome":"applied","blocksCreated":1}. Those refs never existed in the subagent's context. A subagent replaced 33 messages of another conversation with an unrelated summary.
Cause
Claude Code runs one bili MCP server process per session and Task subagents share it. The shim reads CLAUDE_CODE_SESSION_ID once, so every subagent call is posted with the root conversation id.
The proxy's outbound witness (sha256 of tool name + args, 10-min ring) catches only some of these calls (409 TOOL_CONVERSATION_CONFLICT). When the lookup misses, the call runs against the root session.
The Claude Code 2.1.308 CLI bundle attaches a per-call id to MCP tools/call: _meta: {"claudecode/toolUseId": <tool_use id>} (I found this in the bundle; I have not captured it on the wire). The proxy already sees that tool_use block in the response stream of the session that emitted it (settleWitnesses / recordJsonToolWitnesses). Suggested:
When settling witnesses, also record tool_use.id → session.id (including |sub: lanes).
Activity
ranxianglei commentedon Oct 24, 2026
(ai: vllm-qwen/qwen3.8-27b)
查重: 不重复。相关但不同:#4352/#4409(子代理模型请求的
|sub:车道拆分——本 issue 的前提,已合入)、#4168/#4219(resume/native-compaction 导致的进程级绑定过期 + 一次性 self-rebind——同一 shim 家族、不同触发机制)、#2728(/compact 后 ACP 状态失配——不同症状)。无在途 PR 做 per-call tool_use id 路由。标签:
bugclaude-codescope/wiringp1(缺陷;Claude Code CLI 车道;MCP shim/插件工具路由接线;p1——Task 子代理压缩实质整体不可用(50 次调用仅 4 次落地且其中一次落错会话),并伴随父会话被无关 fold 污染的跨会话状态破坏)。已按 master 代码逐条核实,你的因果链成立:
src/mcp.ts:83CONVERSATION_FROM_ENV = CLAUDE_CODE_SESSION_ID || BILI_CONVERSATION_ID,整个 shim 生命周期一个值;每个 tools/call 都把它作为 bodyconversationId发出。claudeSubagentSplit(src/session-id.ts:427,Subagent first token stalls 1-2min: withSessionLock covers full forward + slow flash upstream first byte #970/Subagent requests share the parent session id and trip fold-reconcile #4352/[PR] fix: split header-less claude code subagents onto their own session lane (#4352) #4409)落到<id>|sub:<agent>会话,witness 记录(settleWitnesses, src/plugin.ts:2466)记在拆分后的 session id 下。TOOL_CONVERSATION_CONFLICT,错误文案与你贴的完全一致。方案评估:你提的 per-call
_meta["claudecode/toolUseId"]通道打在根因上——per-call 宿主盖戳身份替代进程级猜测,409 类和 miss 类都被确定性消除(不再依赖 (name,args) hash 命中),同时覆盖 #4168 的 resume 场景且无需 rebind。我按此实现,两处加固:接下来:tool-ring 扩展 + shim 转发 + 路由阶梯第 0 步,三层测试(shim 契约 / 代理路由策略 / 真实 server+shim 事故形态 e2e),PR 引用本 issue。
fix: #4580 id-ring eviction orders by recorded time, not map position
Merge pull request #4978 from ranxianglei/2026-10-27_claude-subagent-…
Task 子代理的 bili 调用不再压缩错会话 (ranxianglei#4580)