Skip to content

[PR] fix: read Claude Code's deferred-tools list to name and reach bili's compress tool - #6960

Open
MohammadErfan-Jabbari wants to merge 3 commits into
ranxianglei:masterfrom
MohammadErfan-Jabbari:2026-11-16_claude-deferred-tools
Open

MohammadErfan-Jabbari wants to merge 3 commits into
ranxianglei:masterfrom
MohammadErfan-Jabbari:2026-11-16_claude-deferred-tools

Conversation

@MohammadErfan-Jabbari

Copy link
Copy Markdown
Contributor

Fixes #6958

Problem

Claude Code keeps mcp__bili__compress out of tools[] until the model loads it with ToolSearch, and lists it by name in a message instead. bili reads tools[] only, so while the tool is deferred it tells the model to call bare compress, which fails with No such tool available: compress. Claude Code agents whose allow-list holds no bili tool are still nudged, because the anonymous profile keeps the compress surface on.

Fix (host side, no kernel change)

In src/server/lane-decisions.ts:

  • observeDeferredTools(parsed) reads the names after Claude Code's deferred-tools announcement in the messages.
  • mcpCompressListed is true when mcp__bili__compress is declared in tools[] or listed as deferred. mcpDialect now follows it, so the prompt names mcp__bili__compress while the tool is deferred.
  • A Claude Code request (system block with cc_version=) with no compress tool declared or listed is not compress-reachable, so it gets no surface and no nudge. Other hosts keep today's behaviour.

Both compression modes

The change reads only the request body. In plugin mode it decides the prompt's tool name and whether the surface is on. Proxy mode never sets mcpDialect and is not a Claude Code plugin lane, so its path is unchanged.

Tests

  • tests/claude-deferred-tools.test.ts (new) builds requests in the shape Claude Code 2.1.325 sends: deferred tool → MCP name; loaded tool → MCP name; no bili tool anywhere → surface off; a non-Claude-Code lane and a bare compress declaration → unchanged; an announcement in a string message body → read. On master 3 of 5 fail; with the fix 5 pass.
  • tests/lane-decisions*.test.ts and tests/*mcp*.test.ts: 205 pass. tsc --noEmit is clean.
  • Live, Claude Code 2.1.325 with Haiku through a test proxy: on master the model was told compress and its call failed; with the fix it was told mcp__bili__compress and its fold succeeded. A subagent limited to Read,Bash logged surface=off(top-level=[Read,Bash]) and got no nudge.

Review tier

This changes when the compress surface is on for one host's lane (a lane decision), so per §7.4 it stays with a human reviewer. No config, persistence-format, wire-shape or kernel change.

🤖 Generated with Claude Code

…compress tool

Claude Code keeps MCP tools out of `tools` until the model loads them with
ToolSearch and lists them by name in a message instead. bili read only
`tools`, so it told Orca workers to call bare `compress` ("No such tool
available"; 13 of 81 workers never folded) and nudged research subagents
whose allow-list holds no bili tool 127 times. bili now takes the deferred
list into account for the MCP dialect, and drops the compress surface for a
Claude Code agent that has bili's tool in neither list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ranxianglei ranxianglei changed the title fix: read Claude Code's deferred-tools list to name and reach bili's compress tool [PR] fix: read Claude Code's deferred-tools list to name and reach bili's compress tool Nov 16, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷

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

Reviewed the diff, traced all 5 new tests against the new code, and pulled the CI failure logs. Assessment below.

Direction & correctness — solid, root cause not symptom. The fix reads Claude Code's actual deferred-tools announcement (deferred tools are now available via ToolSearch in the messages) instead of guessing from tools[]. The claudeCodeWithoutTool gate is correctly scoped to CC (requires the cc_version= billing-block signal), so every other host keeps today's behavior. I traced all 5 tests in tests/claude-deferred-tools.test.ts against the new code: all pass with the fix; on master, tests 1/3/5 fail — matching the issue's "3 of 5 fail".

CI — all 4 failures are inherited master-red, none are this PR's.

The PR's own new test passed (it sits in a passing shard). Path to green per the CI policy: git merge origin/ci-fixes into the branch (or wait for the master-red fixes to land).

Minor, non-blocking:

  • All 5 tests use pluginHeaderPresent = false (the helper default), so the real header-present CC lane isn't directly pinned. The fix works for both (the ANONYMOUS profile's toolsHostScopedByDefault = false carries reachability), but a header-present row would lock it in.
  • compressReachable doesn't take mcpCompressListed (deferred) directly — a deferred tool's reachability rides on the ANONYMOUS profile default. Fine for CC today; worth a comment in case a future CC profile ever sets toolsHostScopedByDefault = true.

8问(供人审):

  1. 是什么问题:CC 把 mcp__bili__compress 从 tools[] 延迟(ToolSearch 加载前只在消息里按名列出),bili 只读 tools[],于是让模型调裸 compress → No such tool available: compress;完全没有 bili 工具的 CC 子代理还会被反复 nudge 却没有折叠出口。
  2. 什么原因导致的:工具可达性判定只认 tools[] 声明、不认 CC 的 deferred-tools 公告;且对「CC 但没有任何 compress 工具」的请求缺一个关 surface/nudge 的闸门。
  3. 影响范围与严重程度:仅 Claude Code 插件车道;触发 = CC 请求且 compress 工具被延迟或完全缺失。特定条件下有问题(模型调不到工具 / 无效 nudge 推高上下文),非全局不可用。
  4. 怎么修复的:新增 observeDeferredTools 解析 CC deferred-tools 公告里的工具名;mcpCompressListed = 声明或延迟;mcpDialect 跟随它(延迟时也报 MCP 名);新增 claudeCodeWithoutTool 闸门(仅 CC、无 compress 工具)关 surface 与 nudge。只读请求体,不动 wire/内核/配置。
  5. 是否有回归问题:无。claudeCodeWithoutTool 要求 cc_version= 账单块,只对 CC 生效,其他宿主 compressReachable 表达式不变;mcpDialect 仅在延迟场景由 false 变 true;proxy 模式不设 mcpDialect,路径不变。
  6. 是否破坏缓存:不涉及(未改缓存/重试/游标/去重键)。
  7. 是否改了设计方向:不涉及(在既有 lane-decision 框架内加一个 CC 专属闸门,未动架构/边界/数据流)。
  8. 是否引入了新的配置:不涉及(无新 env/config/默认值)。

Verdict: Correct, well-scoped, root-cause fix; clean code (clear names, no as any/@ts-ignore/console.error, why-comments present). All 4 CI reds are inherited master-red, not the PR's. Suggest merging ci-fixes to clear the inherited reds and (optionally) adding a header-present test row; after that it's ready for a human reviewer per §7.4 — the author is right to route it there, since it changes when the compress surface is on for one host's lane.

…cture-docs fixes

Inherited master failures (not PR-introduced), per owner policy 2026-10-24:
- test (ubuntu 24/3, windows 22/4, ubuntu 22/3): ranxianglei#2929 nudge-fold probe
  anchor drift — recalibrated on ci-fixes (245ecb1, 7247410)
- architecture-docs: src/responses-system-sections.ts missing from module
  map — added on ci-fixes (8ed56be)
Zero file overlap with this PR's diff (lane-decisions.ts, claude-deferred-tools.test.ts).
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

The red CI on this PR is fixed. Both failures are master-level (inherited) failures, not introduced by this PR's diff — I verified that before touching anything.

What was red

Why it's not the PR's fault
The PR only touches src/server/lane-decisions.ts and adds tests/claude-deferred-tools.test.ts, and every one of its changes is gated on input.pluginMode. The failing #2929 test runs in proxy mode (pluginMode=false), so the PR's diff cannot affect it; and the PR doesn't touch reference/architecture.md or src/responses-system-sections.ts.

Fix (owner policy 2026-10-24, CI-failure coordination)
Merged origin/ci-fixes (the sentinel-converged branch) into the PR branch. ci-fixes already carried both fixes:

  • 245ecb1a9e + 7247410976 — recalibrated the #2929 probe anchor and made it schedule-independent.
  • 8ed56be997 — added src/responses-system-sections.ts to the module map.

The merge was clean (zero file overlap with the PR's diff).

Verified locally on the merged head 79451cf032

  • architecture-docs guard: all green.
  • tests/issue2929-codex-fold-double-miss.test.ts: pass.
  • tests/claude-deferred-tools.test.ts (the PR's own test): pass (5/5).

Pushed the final head 79451cf032 to the PR branch (no CI-hold marker → this is the branch's one full CI pass). The mirror check cache is stale (~14h) and hasn't captured the new head's run yet, so I confirmed the two red checks locally rather than asserting a live green I couldn't see.

七问(中文结构化结论)

  1. 是什么问题:PR 分支 CI 红——3 个 test 分片(ubuntu 24/3、windows 22/4、ubuntu 22/3)全挂在同一个 #2929 nudge-fold 探针测试上,外加 architecture-docs 守卫红。
  2. 什么原因导致的:两处都是 master 级继承性失败,非本 PR 引入。① #2929 是对 nudge 调度敏感的探针,锚点随调度漂移而失效;② architecture-docs 是 reference/architecture.md 缺了 master 早已存在的 src/responses-system-sections.ts([Bug] Inconsistent system prompt separator in Responses internal re-request breaks cache prefix | [Bug] Responses 内部重请求的系统提示分隔符不一致,破坏缓存前缀 #6922 加的)。本 PR 改动全部 gated on pluginMode,而 #2929 跑在 proxy mode(pluginMode=false),且 PR 不碰 architecture.md,故与本 PR 无关。
  3. 影响范围与严重程度:只影响本 PR 的 CI 能否转绿(3 个 test 分片 + 1 个守卫);不波及任何运行时行为、wire、配置。严重度:仅 CI 红,非产品缺陷。
  4. 怎么修复的:按 owner 2026-10-24 CI 协调政策,把 origin/ci-fixes(哨兵已收敛全部 master 修复)merge 进 PR 分支——ci-fixes 上已有这两处修复(245ecb1a9e/7247410976 重校 #2929 探针 + 8ed56be997 补 architecture 模块图),零文件重叠,合并干净。
  5. 是否有回归问题:无。merge 只带进一个测试文件 + 一个文档,不碰 src/ 任何代码;本 PR 自身的 claude-deferred-tools 测试在合并后仍 5/5 通过。
  6. 是否破坏缓存:不涉及——没碰任何缓存/重试/游标/去重逻辑。
  7. 是否改了设计方向 / 是否引入新配置:都不涉及。纯 CI 收敛,无架构转向、无新 env/config/默认值。

收工判定:修复已推送(final head 79451cf032,无 ci-held 标记,触发本分支唯一一次全量 CI);两处红均为继承性失败且已在本地验证转绿,等 CI 跑完即绿。

ranxianglei added a commit that referenced this pull request Nov 17, 2026
…the tool CC exposes (#6958, PR#6938 review)

CC 2.1.x keeps MCP tools out of tools[] until ToolSearch loads them and
announces them in the request messages instead ("deferred tools are now
available via ToolSearch … mcp__bili__compress"). observeDeclaredTools
reads tools[] only, so the #4344 dialect was always false for CC and the
nudge advertised the bare `compress` — which CC answers "No such tool
available" — so workers WITH the tool never folded (field sample: 14 hard
fails, 13 never folded, sessions pinned at 133K–244K tokens).

resolveLaneDecisions now treats "declared in tools[] OR announced
deferred" as "the host has this tool" for both the dialect and compress
reachability; the announcement is observed from this request's messages
(single site, no caller changes — extractDeferredBiliToolNames).
Deliberately NOT the #6960 variant: its claudeCodeWithoutTool gate (no
compress anywhere → surface off) would also starve the #4372 zombie probe
on headerless rounds. PR #6960 stays unmerged; this supersedes it on the
release branch.

Tests: tests/claude-deferred-tools.test.ts (CC field repro — dialect flips
on the announcement; deferred-only reachability on a host-scoped profile
with control; bare compress still wins; extractor over both content
shapes). 153 regression tests across the six lane-decision/self-heal
files pass unchanged.
…erred-tools already on master)

Resolving the merge conflict against master (6a641f3):
- master 5d852d2 (ranxianglei#6958, PR#6938 review) already ships the deferred-tools
  observation — refined (exported extractDeferredBiliToolNames, mcp__bili__-only
  filter) — in src/server/lane-decisions.ts + tests/claude-deferred-tools.test.ts.
- This PR's unique claudeCodeWithoutTool gate was DELIBERATELY excluded in
  ranxianglei#6958 (master test comment: it would starve the ranxianglei#4372 zombie probe on
  headerless rounds; 'that trade needs its own discussion').
- Taking master's version for both conflicting files makes this branch
  byte-identical to master (empty diff). The PR has no unique changes left.
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

The merge conflict is resolved. Key finding: this PR is fully superseded by #6938/#6958, which are already on master.

What happened
Master moved 301e1a5459 → 6a641f3785, and among the new commits is 5d852d2f54 fix(lane): read Claude Code's deferred-tools list so the nudge names the tool CC exposes (#6958, PR#6938 review) — the same feature as this PR, touching the same two files (src/server/lane-decisions.ts, tests/claude-deferred-tools.test.ts). That's what caused the conflict.

The two implementations differ, and master's is the reviewed one

The PR's unique gate was deliberately excluded in #6958
Master's test file states it explicitly:

// Deliberately NOT the #6960 variant: its claudeCodeWithoutTool gate (no
// compress anywhere → surface off) would also starve the #4372 zombie probe
// on headerless rounds (the pluginHeaderPresent === false clause). That
// trade needs its own discussion and is left out here.

So the owner/reviewers already decided: merge the observation (master's refined version), leave out this PR's gate. That's a documented decision, not one for me to re-make.

Resolution
Took master's version for both conflicting files. The result is byte-identical to master (verified: empty diff). The PR now has changed_files: 0 — no unique changes left. Pushed the merge (e0409b1fb6); the PR is now mergeable (no conflict) but empty.

Recommendation
This PR is superseded by #6938/#6958. It has nothing left to contribute — please close it as superseded (I can't close PRs; that's owner-only). If the claudeCodeWithoutTool gate is still wanted despite the #4372 zombie-probe trade-off, that's a separate discussion (as master's comment notes) and should be its own PR.

七问(中文结构化结论)

  1. 是什么问题:PR 与 master 冲突(merge state: dirty)——master 前进后(301e1a5459 → 6a641f3785)合入了与本 PR 同一功能的 5d852d2f54([Bug][claude] bili names bare compress while Claude Code defers mcp__bili__compress, and nudges agents that have no compress tool #6958/PR#6938),两个文件撞车。
  2. 什么原因导致的:本 PR 的 deferred-tools 功能已被 [PR] release v0.1.216 #6938/[Bug][claude] bili names bare compress while Claude Code defers mcp__bili__compress, and nudges agents that have no compress tool #6958 独立实现并合入 master(更精炼的版本:导出的 extractDeferredBiliToolNames、只匹配 mcp__bili__)。本 PR 是同一功能的并行/早期版本,二者改了同样的行。
  3. 影响范围与严重程度:仅影响本 PR 能否合并;不涉及任何运行时行为——master 上已是该功能的正式实现。严重度:PR 冗余,非产品缺陷。
  4. 怎么修复的:冲突的两个文件都取 master 版本(尊重 [Bug][claude] bili names bare compress while Claude Code defers mcp__bili__compress, and nudges agents that have no compress tool #6958 已做的决策),结果与 master 逐字节一致(diff 为空),推送合并提交 e0409b1fb6。
  5. 是否有回归问题:无。取的是 master 已评审、已合入的版本;本 PR 无独有改动,不引入任何行为变化。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向 / 是否引入新配置:都不涉及。本 PR 独有的 claudeCodeWithoutTool 门在 [Bug][claude] bili names bare compress while Claude Code defers mcp__bili__compress, and nudges agents that have no compress tool #6958 被有意排除(会饿死 [PR] fix: zcode never compresses — compress prompts advertised a tool the model could not see or call #4372 的 zombie probe,master 测试注释明说"需另议"),我未重新引入。

收工判定:冲突已解(PR 现 mergeable,但 diff 为空、changed_files: 0);本 PR 已被 #6938/#6958 完全取代,建议 owner 以 superseded 关闭。若仍想要 claudeCodeWithoutTool 门(连同 #4372 的取舍),那是另开的讨论/PR,不在本次范围内。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

2 similar comments
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

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

2 participants