fix(ai): fold gateway-namespaced Anthropic tool references onto the request's tools - #1480
Merged
Merged
Conversation
…equest's tools A native tool search can hand back tool_reference names under a wire-path namespace (mcp__<id>__<tool>) that the request never defined and that does not survive across requests; replaying that tool_search_tool_result block then fails the whole request with "Tool reference '<name>' not found in available tools" (observed live on 2026-09-08 with claude-fable-5-1, which hard-errored and fell back to another model). demoteUnavailableToolReferences now decides availability from the final tools array alone: namespaced references and history tool_use blocks are folded onto the request's own tool names, references that still do not resolve are dropped, a search pair left with no references is demoted to text together with its server_tool_use, and a dangling discovery no longer keeps a later tool_use alive.
…ai and the release changelog
This was referenced Sep 8, 2026
…red-ref-400 # Conflicts: # packages/coding-agent/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A native Anthropic tool search can hand back
tool_referencenames under a wire-path namespace (mcp__<id>__<tool>) that the request never defined and that does not survive across requests. Thetool_search_tool_resultblock replays verbatim on the next same-model request, and Anthropic rejects the whole request:Observed live on 2026-09-08 (senpi 4adba7a, omo desktop, claude-fable-5-1): the turn hard-errored and fell back to another model. The same session's later native results carried a different namespace id (
mcp__5153__), and other sessions carried8e8c/7439/cdd2, so the namespace is not something senpi can predict or replay.Root cause
demoteUnavailableToolReferencesinpackages/ai/src/api/anthropic-messages.tscollected the namespaced names as dangling but only rewrote references insidetool_resultcontent; nativetool_search_tool_resultblocks fell through untouched (:974), and a dangling discovery still exempted a latertool_usefrom demotion (:900-901).Fix
Availability is decided by the request's final
toolsarray alone, and every reference site is repaired:tool_reference(clienttool_resultcontent or nativetool_search_tool_result) under a gateway namespace is folded onto the request's own tool name when that tool is defined; one that still does not resolve is dropped;server_tool_use;tool_useunder a gateway namespace is renamed to the request's tool name; atool_usewhose only justification was a dangling discovery is demoted like any other unavailable call.Evidence
eab8c4b30):packages/aibunx vitest --run test/anthropic-tool-reference-integrity.test.ts-> 5 failed | 5 passed (e.g.expected ['mcp__925c__memory'] to deeply equal ['memory']). GREEN with the fix: 10 passed. Run on a remote node (mengmotaMac, bun 1.4.0).packages/aisuite with the fix: 266 files / 2591 tests passed; the single failing file (test/codex-apply-patch-wire-schema.test.ts,Failed to resolve entry for package "@earendil-works/pi-tui") fails identically on unpatchedeab8c4b30in the same fresh worktree.test/mcp/native-anthropic.test.ts,test/tool-search/native-anthropic.test.ts,test/suite/regressions/0000-anthropic-native-tool-search-contract.test.ts): 3 files / 37 tests passed.server_tool_use+tool_search_tool_resultblocks throughstreamAnthropicwith a capturing fake client): baseline emits five dangling referencesmcp__925c__{memory,task_send,todo,eval,web_search}; fixed emitsmemory, task_send, todo, eval, web_searchwith zero dangling references.bun run checkgreen; changelog gate PASS (packages/ai/src/changes.mdentry +[Unreleased]Fixed entry).Out of scope (filed separately)
after_provider_response, so the native-search adapter's permanent-400 fallback is unreachable on the live error path.Summary by cubic
Fixes a 400 error on Anthropic requests after a native tool search: tool references that come back under a gateway namespace (
mcp__<id>__<tool>) are now folded onto the request's own tool names, and unresolvable references are dropped instead of replaying verbatim.Bug Fixes
demoteUnavailableToolReferencesnow decides availability solely from the request'stoolsarray.tool_referenceitems in bothtool_resultand nativetool_search_tool_resultblocks are rewritten to the request's tool names.server_tool_use.tool_useblocks with namespaced names are renamed, and a dangling discovery no longer exempts a call from demotion.Written for commit e9d914c. Summary will update on new commits.