Skip to content

fix(gateway): refuse a hop that would drop the tool a request requires - #233

Merged
fylorn merged 1 commit into
mainfrom
fix/refuse-unsendable-required-tool
Sep 29, 2026
Merged

fylorn merged 1 commit into
mainfrom
fix/refuse-unsendable-required-tool

Conversation

@fylorn

@fylorn fylorn commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Why

Claude Code runs every web search as a separate request. It carries only the server-side web_search_20250305 tool, forces it with tool_choice: {type: "tool", name: "web_search"}, and reads the answer's server_tool_use and web_search_tool_result blocks. Any text in the answer also becomes part of the "results".

When that request is converted for an upstream of another format (Bedrock Converse, OpenAI Chat or Responses, Gemini), the server tool is dropped, since only the provider it belongs to can run it. The forced tool_choice then has nothing to point at and is dropped too. The model answered the search prompt from memory, and Claude Code handed that text back as search results. No error was raised; the only trace was a "dropped" entry in the request details.

What changes

hop.rs gets unsendable_tool, called in prepare right after the request is encoded for the upstream's format. It refuses the hop when either of these holds:

  • tool_choice names a tool that is no longer among the tools sent (gw.convert.tool_unsendable, args tool, upstream), or
  • tool_choice requires a tool call, no tool is left, and tools were dropped (gw.convert.tools_unsendable, arg upstream).

A refused hop behaves like a conversion failure. It goes on the attempt chain, and the next upstream of the route is tried, since an upstream of the same format may come later. If none can take the request, the client gets a 400 invalid_request_error that names the tool and the upstream. Claude Code then shows the search as failed instead of passing on made-up results.

Server tools offered with tool_choice: auto alongside other tools are still dropped and reported. Some clients attach them to every request, and the conversation works without them.

Tests

tests/dialect.rs:

  • Claude Code's web-search request to an OpenAI-format upstream returns 400 naming web_search and the upstream. The upstream receives nothing, and RequestFailed carries gw.convert.tool_unsendable.
  • A required tool call whose only tools are server tools is not sent either.
  • The existing test with web_search offered alongside other tools under auto still passes: the request is sent, and the drop is reported.

cargo fmt --check, cargo clippy --workspace --all-targets -D warnings and cargo test --workspace pass locally. msg-codes.txt is updated.

🤖 Generated with Claude Code

Claude Code runs each web search as its own request that carries only the
server-side web_search tool and forces the model to use it. Converted for
an upstream of another format (Bedrock, OpenAI, Gemini, ...), the server
tool is dropped, so the model answered without searching and Claude Code
passed that answer on as the search results, with no error anywhere.

When the tool a request forces (tool_choice naming a tool, or requiring a
tool call when every tool was dropped) cannot be sent in the upstream's
format, that hop is not sent: the next upstream of the route is tried, and
if none can take it the client gets a 400 saying which tool and which
upstream (gw.convert.tool_unsendable, gw.convert.tools_unsendable).
Server tools offered alongside others with tool_choice auto are still
dropped and reported, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fylorn
fylorn merged commit 6abb562 into main Sep 29, 2026
4 checks passed
@fylorn
fylorn deleted the fix/refuse-unsendable-required-tool branch September 29, 2026 04:53
@fylorn fylorn mentioned this pull request Sep 29, 2026
fylorn added a commit that referenced this pull request Sep 29, 2026
Patch release for #233.

- Bump the workspace version to 0.55.1
- release-notes/0.55.1.md

The control-plane protocol (28) and the request store schema (22) are
unchanged.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant