Repository navigation
[PR] fix(#4168): self-rebind stale claude MCP binding on witness conflict — management tools recover after host-native compaction - #4219
Conversation
…e session A claude MCP shim captures CLAUDE_CODE_SESSION_ID once at spawn. When the host later moves the conversation to a new session id (native-compaction continuation / resume), the stale id still RESOLVES, so every management call fails closed on the outbound-witness 409 forever - #656's adoption only ever saw 404s and never fired, leaving the session lost for good. - proxy: the TOOL_CONVERSATION_CONFLICT 409 keeps its fail-closed code and error prefix but now names the unique witnessing conversation (so the model can re-route via the #760 per-call channel) and carries additive recency facts (conversationId/namedSessionId/witnessSessions/ namedSessionLastSeen/witnessLastSeen) for machine consumers. - shim: forwardTool adopts the UNIQUE witnessing session on that 409, one retry, under the same ORPHAN_ADOPT gate (BILI_MCP_NO_ORPHAN_ADOPT=1 opt-out) as #656 - only when the recency facts prove traffic moved after the bound session's last activity; multi-witness, fresh-binding, missing-facts and per-call-override all stay on the loud 409. - shim: effectiveConversationId is recomputed per attempt so an in-loop adoption retry actually carries the NEW id (previously the #656 404 adoption's immediate retry silently re-POSTed the stale id). Regression tests: tests/issue4168-claude-compaction-rebind.test.ts (proxy payload shape incl. both gate directions; shim adoption positive + five negative cases).
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.5010-pr.4219.9e59a3aThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr4219.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复——检索 open/closed PR 中引用 #4168 的条目,仅本 PR;#2849(线级拒绝 CC 原生 compaction)是触发器侧预防、方向不同,正文已声明 out-of-scope、与本 PR 互补而非并列。 标签:bug, claude, scope/wiring, p1(宿主侧会话 id 轮换后压缩管理面整场停摆、会话内无恢复路径、用户反馈多次复发——核心能力可用性缺陷) 收到。本 PR 带 |
(ai: vllm-qwen/qwen3.8-27b) 审核完成:方向正确、实现扎实、证据链闭合——可合(需人工合并);独立审出 1 个边界缺陷需要你拍板(见第 5 问发现 A)。 独立核验证据(未照抄 PR 正文结论,全部自己重做):
结构化八问:
判定:主机制端到端验证通过、CI 在本 head 全绿、测试有牙——可合。session-binding 属人工审核层,请手动合并:#4219 (mergeable_state=blocked 系人工审批要求,checks 本身全绿)。发现 A 请你拍板(并入 vs follow-up);发现 B 仅记录。线②决策(D1 合并 #2849 / D2 继任者跟随)仍待你拍板,见 #4168 floor 4。 |
Closes #4168
Problem
After Claude Code's host-native compaction (or any host-side session-id rotation — resume/fork), all bili management tools (
compress/acp_status/ …) fail permanently for the rest of that session:compress/acp_status→bili tool error: outbound tool witness does not match conversationId(409);Root cause (verified at reporter's v0.1.197): the MCP shim captures
CLAUDE_CODE_SESSION_IDexactly once at spawn (src/mcp.ts:83). When the host later moves the conversation to a new session id, the stale id still resolves — so every call fails closed at the outbound-witness conflict (routing ladder's!nativeCallerbranch). #656's orphan adoption only fires on 404 ("no model request has arrived"), so it never sees this failure mode and the binding stays stale forever. A latent second defect: even when adoption DID fire (#656's 404 path), the immediate retry re-POSTed the stale id becauseeffectiveConversationIdwas captured above the retry loop.Changes
src/plugin.ts): theTOOL_CONVERSATION_CONFLICT409 keeps its fail-closed semantics, machine-readablecode, and the original error prefix, but now alsoconversation_idchannel);conversationId,namedSessionId,witnessSessions[],namedSessionLastSeen,witnessLastSeen.With multiple witnesses it names none ("refuse to guess").
src/mcp.ts):forwardTooladopts the UNIQUE witnessing session on that 409 — one retry only — under the same gate as MCP tools fail with 'unknown plugin conversation' after Claude Code --resume (shim holds a stale session id) #656 (ORPHAN_ADOPT: identity-bound claude shims; opt out withBILI_MCP_NO_ORPHAN_ADOPT=1). Adoption requires the proxy's recency facts to prove traffic moved to the witness AFTER the bound session's last activity. Multi-witness, still-fresh binding, missing facts (older proxy), per-call-override ids, and a second consecutive conflict all stay on the loud 409 — fail closed, never guess.effectiveConversationIdis recomputed per attempt, so an in-loop adoption (both the new [Bug] Claude Code native compaction: compress/acp_status permanently broken after resumption — outbound tool witness doe | [Bug] Claude Code 原生 compaction 续接后 compress/acp_status 永久失效:outbound tool witness does not match conversationId,ref 空间为空 #4168 path and the pre-existing MCP tools fail with 'unknown plugin conversation' after Claude Code --resume (shim holds a stale session id) #656 path) retries with the NEW id instead of silently re-POSTing the stale one.Net effect for the reported incident: the first conflicting call after the host moves the session transparently re-binds the shim to the live conversation and succeeds —
compress/acp_statuskeep working without user action. Callers that don't run this shim get an actionable error naming the live conversation instead of an opaque string.Behavior changes (old → new)
errortextoutbound tool witness does not match conversationIdcodeunchanged, prefix preserved for existing consumers{ok, code, error}conversationId,namedSessionId,witnessSessions,namedSessionLastSeen,witnessLastSeenNo config surface added (reuses existing
BILI_MCP_NO_ORPHAN_ADOPT), no kernel change, no wire/model-traffic change, no cache/retry/cursor impact.Tests
New:
tests/issue4168-claude-compaction-rebind.test.ts(10 tests, both gate directions per #3617 discipline):Targeted local runs (green): the new suite +
tool-ring,host-native-caller,issue2072-native-caller-stamping,issue2601-persona-fork-lineage,plugin-fork,claude-mcp-entry,mcp-native-thread(real server + real shim over stdio). Typecheck + build green on the rebased head (c87185a). Full-suite verdict: remote CI on this head.Note: master is currently in a CI red storm unrelated to this PR (#4196 — node-22 lanes fail 15 window/preflight tests identically on master).
Out of scope (tracked elsewhere)