Skip to content

[PR] fix: read Claude Code's deferred-tools list in lane decisions (#6958) - #6967

Open
ranxianglei wants to merge 4 commits into
masterfrom
2026-11-17_claude-deferred-tools
Open

ranxianglei wants to merge 4 commits into
masterfrom
2026-11-17_claude-deferred-tools

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What this PR does

Claude Code keeps MCP tools out of tools[] until the model loads them with ToolSearch; until then it lists them by name in a message. bili decided both lane decisions from tools[] alone:

  1. The model is told the wrong name. mcpDialect was true only when tools[] declared mcp__bili__compress, so while the tool was deferred the prompt named bare compress — a tool that does not exist on the host. 14 workers hit No such tool available: compress; 13 grew to 133K–234K tokens and never folded.
  2. Agents without the tool are nudged anyway. Claude Code has no host profile, so the anonymous profile's toolsHostScopedByDefault=false kept the compress surface on whatever tools[] held. 10 research subagents with no bili tool were nudged 127×, up to 440K tokens, with no way to fold.

Fix (host side, no kernel change)

In resolveLaneDecisions (src/server/lane-decisions.ts), read the deferred-tools list from the messages:

  • Count mcp__bili__compress as listed when it is declared or deferred; set mcpDialect from that.
  • For Claude Code requests (system block carrying cc_version=), turn the surface off when no compress tool is declared or listed. Other hosts keep today's behaviour (the deferred-list header phrase is Claude-Code-specific).

Test

tests/claude-deferred-tools.test.ts builds anthropic-wire requests in the shape Claude Code 2.1.325 sends (billing header in the system block, deferred-tools list in a message). 5 cases + 1 regression guard for non-CC hosts. On master, 3 of the 5 cases fail; with the fix all pass.

Regression check

  • tests/lane-decisions-matrix.test.ts: 111/111 pass.
  • tests/lane-decisions-b-class.test.ts, tests/issue5527-additional-tools-reachability.test.ts, tests/issue4344-mcp-dialect.test.ts: 22/22 pass.
  • typecheck + build clean.

Closes #6958

@ranxianglei ranxianglei changed the title fix: read Claude Code's deferred-tools list in lane decisions (#6958) [PR] fix: read Claude Code's deferred-tools list in lane decisions (#6958) Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-17_claude-deferred-tools (5929ded)

Latest build — install this exact version

npm install -g billion-context@0.0.10634-pr.6967.1b5a5e7

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
5929ded billion-context@0.0.10634-pr.6967.1b5a5e7 build
4b3ca0b billion-context@0.0.10468-pr.6967.0223ccd build
32e7b34 billion-context@0.0.10464-pr.6967.fc45297 build
ab88993 billion-context@0.0.10463-pr.6967.e10a6c0 build
8516d48 billion-context@0.0.10461-pr.6967.7c6433f build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr6967.tgz
npm install -g package

Install instructions are refreshed on each push.

Claude Code keeps MCP tools out of tools[] until the model loads them with
ToolSearch; until then it lists them by name in a message. bili decided both
lane decisions from tools[] alone:

  (1) mcpDialect was true only when tools[] declared mcp__bili__compress, so
      while the tool was deferred the prompt named bare compress — a tool that
      does not exist on the host (14 workers hit 'No such tool available:
      compress', 13 grew to 133K-234K tokens).
  (2) Claude Code has no host profile, so the anonymous profile's
      toolsHostScopedByDefault=false kept the compress surface on whatever
      tools[] held — an agent with no bili tool was nudged 127x up to 440K
      tokens with no way to fold.

The fix reads the deferred list: mcp__bili__compress counts as listed when
declared OR deferred, and a Claude Code request (system block carrying
cc_version=) with no compress tool declared or listed reads as unreachable.
Other hosts keep today's behaviour (the deferred-list header phrase is
Claude-Code-specific).

Host-side only; no kernel change.

Fixes #6958
@ranxianglei
ranxianglei force-pushed the 2026-11-17_claude-deferred-tools branch from 8516d48 to ab88993 Compare November 16, 2026 17:06
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 重复 — 本 PR 与 #6960 同修 #6958,同方案(从消息读 CC deferred-tools 列表)、同测试文件名。 #6960 先开(2026-11-16 14:43Z,报告者的 fork 分支),本 PR 后开(15:20Z)。按 one-PR-per-thread 与先来后到,两者应收敛为一个 — 收敛方向需要拍板,见本线程随后的 🔶 需要决策 评论。

Review of #6967 (head 32e7b34bfe = fix commit + ci-fixes merge, base master 301e1a5459; effective diff: src/server/lane-decisions.ts +148/-2, tests/claude-deferred-tools.test.ts +144)

Method. Read both PR diffs line-by-line; verified the real Claude Code wire shape against the code — CC is a header-less launcher-mode lane (src/server/handle.ts:1098-1107: hosts that cannot attach per-request headers POST /__bili/plugin/register first; CC's MCP registration is agent: "mcp", src/mcp.ts:309; the model channel rides CC's own HTTP client, src/claude-mcp-entry.ts) — so every real CC request has pluginHeaderPresent: false and pluginAgent: "mcp" (no "claude"/"mcp" profile → anonymous, toolsHostScopedByDefault: false). Built both heads and ran a probe feeding resolveLaneDecisions a real-shape CC request (billing header cc_version=2.1.325 in the system block, no x-bili-plugin header, tool-less).

Key finding — #6967 does not fix bug 2 in real CC traffic. The pre-existing zombie clause in compressReachable — (input.pluginMode && input.pluginHeaderPresent === false) — is always true for CC (headerless by design), and this PR leaves it untouched. It alone keeps compressSurfaceOn: true no matter what the new CC gate computes. Empirically, on this head, for a real-shape tool-less CC request:

  • pluginHeaderPresent: false (what CC actually sends) → compressSurfaceOn: true — the nudge can still fire, bug 2 not fixed
  • pluginHeaderPresent: true (what the new tests assert) → compressSurfaceOn: false

The tests set pluginHeaderPresent: true (tests/claude-deferred-tools.test.ts:70) — a shape real CC traffic never produces. They pass while the reported bug (10 tool-less research subagents nudged 127×, up to 440K tokens) would persist in production.

What #6967 does fix: bug 1. mcpDialect now counts a deferred mcp__bili__compress as listed (that expression doesn't depend on the header), so while the tool is deferred the nudge names the MCP name instead of the non-existent bare compress. Verified under the real shape.

#6960 comparison (same probe): its prefix gate !claudeCodeWithoutTool && (…) evaluates the CC condition before the zombie clause, so on the real shape a tool-less CC request gets compressSurfaceOn: false unconditionally — both bugs fixed, matching the issue's Expected behavior exactly.

Behavior change to disclose (applies to whichever PR lands): turning the surface off for tool-less CC sessions also kills the zombie self-heal probe. zombieStreak advances only on rounds that carried a nudge (src/session-self-heal.ts:243); surface off → no nudge → no streak → the 5-round window (SELF_HEAL_WINDOW, :48) never fires → no degrade-to-proxy. Old behavior for a tool-less CC session (incl. the real zombie case: MCP server died mid-session): nudge storm, then auto-degrade to proxy mode after 5 nudged rounds, compression resumes. New behavior: silence, the session just grows. The issue's Expected explicitly asks for this silence, so it is the requested behavior — but the self-heal loss is a real, intentional behavior change and should be a conscious choice.

Minor observations (non-blocking):

CI state (verified live, 2026-11-16 ~17:35Z):

八问(中文,供人工 reviewer):

  1. 是什么问题:Claude Code 经 bili MCP 插件接入时,MCP 工具在模型用 ToolSearch 加载前不进 tools[]、只在消息文本里按名字列出;而 bili 的 lane 决策只读 tools[],导致 (a) nudge 提示词用了宿主上不存在的裸 compress 工具名(14 个 worker 报 "No such tool",13 个涨到 133K–234K 不折叠),(b) 没有 bili 工具的 CC 子代理会话也被反复 nudge(10 个 research 子代理 127 次、最高 440K token,无法折叠)。
  2. 什么原因导致的:resolveLaneDecisions 的 mcpDialect/compressReachable 只从 tools[] 判存在性,不读 CC 的 deferred 列表;且 CC 是 headerless 车道(launcher mode,handle.ts:1098-1107),pluginHeaderPresent 恒 false,zombie 条款 (pluginMode && pluginHeaderPresent===false) 恒真,单独就把 surface 钉在打开——issue 原诊断(anonymous profile 的 toolsHostScopedByDefault=false)不完整,zombie 条款才是真实流量下 surface 关不掉的直接原因。
  3. 影响范围与严重程度:所有 CC×MCP 插件用户;有工具但处于 deferred 的会话拿到错误工具名(功能性错误 + 上下文失控);无工具的 CC 会话 nudge 风暴(单会话 127 次、最高 440K token)。p1:核心承诺(上下文压缩)在该车道失灵。
  4. 怎么修复的:本 PR 从消息文本解析 deferred 列表,mcp__bili__compress 声明或 deferred 都算 listed 并据此设 mcpDialect(bug 1 修对,实测真实形状下生效);对 CC 请求(system 带 cc_version=)在无 compress 工具时关 surface——但审核实测:对真实 CC 流量(headerless)该关不生效,zombie 条款恒真,bug 2 未修;测试用的 pluginHeaderPresent: true 是真实 CC 流量从不出现的形状。[PR] fix: read Claude Code's deferred-tools list to name and reach bili's compress tool #6960 的前缀门在真实形状下两 bug 都修掉(同一探针实测一致)。
  5. 是否有回归问题:本 PR diff 对非 CC 宿主无行为变化(两分支本地各跑 133/133 lane 回归套件全绿)。但 surface-off 门一旦生效(无论哪个 PR)会关掉 CC 无工具会话的 zombie 自愈探针:无 surface → 无 nudge → zombieStreak 不推进(session-self-heal.ts:243 只在 nudgeActive 轮推进)→ 5 轮窗口(SELF_HEAL_WINDOW=5)永不触发 degrade-to-proxy。旧行为: nudge 风暴后自动降级 proxy 模式恢复压缩;新行为: 永不降级、会话只涨。这是 issue Expected 明确要的行为,属有意行为变更,已披露(旧值→新值:无工具 CC 会话从「nudge 风暴 + 5 轮后自愈降级」变为「静默、无压缩」)。
  6. 是否破坏缓存:不涉及(lane 决策在请求入口,不触碰消息字节/前缀/缓存键)。
  7. 是否改了设计方向:不涉及(host-side lane 决策,无 kernel 改动,无数据流转向)。
  8. 是否引入了新的配置:不涉及(无新 env/config/默认值)。

Verdict: #6967 as-is is not mergeable — it fixes bug 1 only, and its tests assert a traffic shape real Claude Code never sends, so bug 2 (the 127-nudge storm) would ship unfixed while the test suite is green. The consolidation question (keep #6960 vs. rework #6967) needs your call — see the 🔶 需要决策 comment below.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

🔶 需要决策
(ai: vllm-qwen/qwen3.8-27b)

背景一句话:#6958 有两个并行 PR 同修同案——#6960(报告者 fork,14:43Z 先开)与 #6967(本账号,15:20Z 后开);审核实测 #6967 对真实 CC 流量(headerless)修不掉 bug 2(zombie 条款恒真,pluginHeaderPresent===false 单独把 surface 钉开),#6960 两 bug 都修;按 one-PR-per-thread 需收敛为一个,但两个 PR 都不能由我关闭,且 #6967 在你的账号下,我不确定是否有意重开。

待决问题:保留哪个 PR?

选项(各带代价):

附带披露(两个选项共有):surface-off 门生效后,CC 无工具会话(含 MCP 中途死亡的真 zombie 场景)不再自动 degrade-to-proxy 自愈——旧行为是 nudge 风暴 5 轮后降级恢复压缩,新行为是静默、无压缩、只涨。这是 issue Expected 明确要的行为;若你想保留自愈,需要另行设计(如:nudge 抑制但按请求数推进 zombie 探针),可作为后续工作。

我的推荐 + 不决定的默认行为:推荐 A(先来到 + 真实形状正确 + 测试贴合流量)。若你不决定:两个 PR 都保持 open(agent 不合并、不关闭),不做任何代码动作;#2929 继承红由 #4599 哨兵继续收敛,无需你动作。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

收工状态:审核已交付——本线程两条回复(上两条):①完整 review(查重结论 + 实测发现 + CI 状态 + 八问);②🔶 需要决策(保留 #6960 vs 修 #6967,推荐 A)。needs-decision 标签已打。

一句话结论:#6967 按现状不可合——实测它只修 bug 1(deferred 工具名);bug 2(无工具 CC 会话 nudge 风暴)在真实 headerless 流量下修不掉,因为 zombie 条款 (pluginMode && pluginHeaderPresent===false) 对 CC 恒真,而测试断言的 pluginHeaderPresent: true 是 CC 从不发送的形状。#6960 在真实形状下两 bug 都修。

待你拍板:A) 收敛到 #6960(推荐)/ B) 修 #6967(补 zombie 门 + 改测试为真实形状)/ C) 都保留(不推荐)。不决定则两个 PR 保持 open,不做代码动作;CI 剩余红项(#2929 ×3)为 #4599 在档的继承红,哨兵收敛中。

…eping master's variant (5d852d2)

The PR's own variant (ab88993) and the owner-landed master variant
(5d852d2, 2026-11-17) both fix #6958 in the same two files with
mutually exclusive behavior: the PR's CC surface-off gate is the exact
gate the owner's commit explicitly rejects (it would starve the #4372
zombie self-heal probe on headerless rounds), and the PR's tests assert
that rejected behavior.

Resolution: keep master's variant for both src/server/lane-decisions.ts
and tests/claude-deferred-tools.test.ts. The PR's diff against master is
now empty — the fix already lives on master; the PR is superseded and
ready for the owner to close.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Conflict resolved — but this was a semantic conflict, not a mechanical one: master already carries your own variant of this fix, and the PR is now a no-op against master.

What I found. The "dirty" merge state was not ordinary drift. Master already contains the owner-landed variant of this exact fix: 5d852d2f54 "fix(lane): read Claude Code's deferred-tools list so the nudge names the tool CC exposes (#6958, PR#6938 review)" (2026-11-17 06:28Z). It touches the same two files as this PR (src/server/lane-decisions.ts, tests/claude-deferred-tools.test.ts) with mutually exclusive behavior:

  • The PR's variant adds a CC surface-off gate (no compress anywhere → surface off) — exactly the gate class your commit explicitly rejects: "would also starve the [PR] fix: zcode never compresses — compress prompts advertised a tool the model could not see or call #4372 zombie probe on headerless rounds".
  • The PR's tests assert that rejected behavior (compressSurfaceOn: false for a tool-less CC); master's tests assert the opposite (true — surface stays on, zombie self-heal probe stays alive).
  • The earlier review in this thread had already found the PR's gate ineffective for real headerless CC traffic anyway (the zombie clause keeps the surface on regardless).

What I did.

  1. Merged origin/master (77fe0b1d63) into the PR branch → new head 5929ded1b0.
  2. Resolved both conflicts (src/server/lane-decisions.ts content conflict, tests/claude-deferred-tools.test.ts add/add) by keeping master's (your) variant — the only consistent resolution: keeping the PR's side would revert your deliberate design decision, and keeping both would leave two conflicting extractors/gates in one file.
  3. Verified: the merged tree is byte-identical to master (git diff origin/master is empty); 115/115 targeted lane-decision tests pass on the merged head (tests/claude-deferred-tools.test.ts + tests/lane-decisions-matrix.test.ts). The full-suite verdict comes from CI on the pushed head (this push is the branch's one full CI pass, no ci-held marker).
  4. Pushed — clean fast-forward (remote head was unchanged at 4b3ca0b254; no force-push needed).
  5. Live-verified after push: PR is now mergeable: true, mergeable_state: blocked (awaiting approval) — no longer dirty.

Label: removed needs-decision — the pending A/B/C question (which PR to keep) was answered by your master commit itself: neither — your own variant is on master, and #6960 is explicitly declared superseded.

What needs your action (owner-only): PR #6967's diff against master is now empty — the fix it was carrying already lives on master in your variant. Please close it as superseded by 5d852d2f54 (agents may not close PRs). Note: #6960 is still open and sits in the same superseded state; its commit message already declares it superseded, so its thread can follow the same disposition.

八问(中文,供人工 reviewer):

  1. 是什么问题:PR [PR] fix: read Claude Code's deferred-tools list in lane decisions (#6958) #6967 与 master 冲突,但冲突本质是语义性的——master 已含 owner 自落的同案修复变体(5d852d2f54,2026-11-17 06:28Z),两个变体行为互斥,不是普通分支漂移能机械解的。
  2. 什么原因导致的:同一 issue([Bug][claude] bili names bare compress while Claude Code defers mcp__bili__compress, and nudges agents that have no compress tool #6958)出现两个平行实现——PR 分支(ci 机器人,11-16)与 owner 自落 master(11-17);owner 的 commit 明确否决了 PR 携带的 CC surface-off 门(会饿死 [PR] fix: zcode never compresses — compress prompts advertised a tool the model could not see or call #4372 zombie 自愈探针),而 PR 的测试断言的正是被否决的行为。
  3. 影响范围与严重程度:仅本 PR 的调度状态(dirty → 已清);用户面行为零变化——master 变体原样保留。严重程度:调度层面,非产品层面。
  4. 怎么修复的:merge origin/master 进 PR 分支,两处冲突均按「保留 master(owner)变体」解决;PR 对 master 的 diff 现为空。
  5. 是否有回归问题:无——合并后树与 master 树逐字节一致(git diff origin/master 为空),任何路径的行为都未变;PR 变体(含被否决的门)已完全移出分支。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:无——执行的是 owner 已落地的设计(master 变体),未引入新方向。
  8. 是否引入了新的配置:无。

判定:冲突已解(head 5929ded1b0),PR 现为 master 的空 no-op,等 owner 关闭(已被 5d852d2f54 supersede)。

This branch has not been deployed

No deployments
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][claude] bili names bare compress while Claude Code defers mcp__bili__compress, and nudges agents that have no compress tool

1 participant