[PR #4700] [CLOSED] [Engine] Claude Code stops when a tool call comes back as text #5141

Closed
opened 2026-11-07 16:33:00 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4700
Author: @xrip
Created: 10/30/2026
Status: ❌ Closed

Base: main ← Head: pr/anthropic-tool-search


📝 Commits (1)

  • 03310de serve: Anthropic's tool search on /v1/messages (defer_loading, tool_reference) (#4663)

📊 Changes

4 files changed (+196 additions, -16 deletions)

View changed files

📝 docs/DETAILS.md (+6 -0)
📝 serve/frontend.py (+39 -7)
📝 serve/server.py (+12 -9)
➕ serve/test_tool_search.py (+139 -0)

📄 Description

Problem and result

What you see: Claude Code stops in the middle of a job. Its last message is not a step. It is text like this, and the turn ends (end_turn):

<tool_call>
<function=mcp__openaiDeveloperDocs__search_openai_docs>
<parameter=query>
Responses API background mode
</parameter>
</function>
</tool_call>

Nothing runs, and Claude Code waits for the user.

Why: the model made a good tool call, but Strata sent it back as answer text, not as a tool call. Strata does this for every tool that is not in the request's tools list.

Claude Code has tool search on by default when ANTHROPIC_BASE_URL is set. Then its MCP tools are not in tools until the model loads them with ToolSearch. Claude Code only gives their names in the chat. So when the model calls an MCP tool straight away, Claude Code gets only text. It has nothing to run, so it stops. Qwen does this, for example, when a hook names the tool.

This is the case Tsury reproduced in #4663 on 0.2.8. We had it 8 times in two days of Claude Code work with Qwen3.8-Flash-Next.

After this PR: the call comes to Claude Code as a tool call. Claude Code runs it, and the job goes on.

Two small fixes on the same path:

  • When the model loads a tool with ToolSearch, it now sees the tool's description in the answer. Before, the answer was empty.
  • Loading a tool no longer changes the tool list at the start of the prompt, so the chat's cached prompt stays good. I did not time this.

Only requests with tool search change (a tool marked defer_loading in the request). All other requests work as before.

Refs #4663. This fixes the Claude Code case from Tsury's comment.

It does not change the first report in #4663: Chat Completions, with tools that change between turns. There the client gives no sign that it holds tools back, so a call for a tool that is not in the list stays text, as decided in #3075 and #3796.

Approach

Claude Code expects the server behind ANTHROPIC_BASE_URL to handle defer_loading and tool_reference, as Anthropic's API does. This PR follows Anthropic's rules.

I ran Claude Code 2.1.314 against a small fake API (no model) and saved what it sends:

  1. The tool list has the built-in tools, ToolSearch and an empty DeferredToolPlaceholder marked defer_loading: true. MCP tools are only named in the chat.
  2. After ToolSearch, the answer is a tool_reference to the tool. From then on the tool is in tools, marked defer_loading: true.
  3. Claude Code runs a call to an MCP tool even when the model never loaded it.

What changed, only on /v1/messages:

  • When the request has a defer_loading tool, a call for a tool that is not in the list is a tool call. This is so in the answer and in the thinking.
  • A defer_loading tool can be called, but it is not in the tool list at the start of the prompt.
  • A tool_reference becomes the tool's description, in the tool list's form, in the same place. Other references are left out, as before.

llama.cpp keeps this from happening: after <tool_call> it lets the model write only names from the list. Strata does not limit the model's output that way, so that is not part of this PR.

Validation

Passed:

  • python -m unittest serve.test_tool_search -v on 03310de7 (upstream main 870aedd9 + this commit), Windows 11, Python 3.14.2, jinja2 3.1.6: 12 tests OK. They test:
    • the change of the request;
    • a call for a tool not in the list, in the answer and in the thinking;
    • a loaded tool keeping its argument types;
    • the /v1/messages route with MockEngine, and that requests without tool search work as before.
  • The parser and route tests on 03310de7, 174 tests OK: serve.test_tool_search serve.test_frontend serve.test_tool_name_alias serve.test_tool_corpus serve.test_tool_routes serve.test_quoted_call_values serve.test_stop_holdback serve.test_parser_call_scan serve.test_parser_hold serve.test_parser_track serve.test_reasoning_loop_recovery serve.test_reasoning_rescue serve.test_reasoning_tools serve.test_tool_call_envelope serve.test_tool_call_unclosed serve.test_tool_name_space serve.test_anthropic_base_url
  • The whole serve/ suite on 03310de7, same Windows machine: python -m unittest discover -s serve -p 'test_*.py' -t ., 1268 tests OK (19 skipped).
  • The same change on Ubuntu 24.04.4 with the server's venv: serve.test_tool_search and serve.test_frontend, 38 tests OK.
  • Claude Code 2.1.314 against the fake API: the three points under Approach.

Failed:

  • None seen. A first version gave an error (400) for a tool_reference to an unknown tool. That broke test_frontend's test_messages_tool_reference_in_a_tool_result_is_left_out, so I took it out.

Not run:

  • A real Claude Code session with a real model on this commit. It is next on our 2x CMP 50HX machine (Swift 1.5 IQ3_XXS). I will add the result here.
  • GPU, HIP, SYCL and Metal builds: not needed (only Python under serve/ changed).

Limits

  • Only /v1/messages. The first report in #4663 (Chat Completions) stays as it is.
  • With tool search on, a call for any name that is not in the list becomes a tool call. Claude Code answers names it does not know itself; I did not test a made-up name.
  • A tool_choice that names a held-back tool works like auto, as it does today for any name not in the list.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4700 **Author:** [@xrip](https://github.com/xrip) **Created:** 10/30/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/anthropic-tool-search` --- ### 📝 Commits (1) - [`03310de`](https://github.com/Niko1221/Strata/commit/03310de7bc96dcb37e6bf7531b23eacb36aeff43) serve: Anthropic's tool search on /v1/messages (defer_loading, tool_reference) (#4663) ### 📊 Changes **4 files changed** (+196 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+6 -0) 📝 `serve/frontend.py` (+39 -7) 📝 `serve/server.py` (+12 -9) ➕ `serve/test_tool_search.py` (+139 -0) </details> ### 📄 Description ## Problem and result **What you see:** Claude Code stops in the middle of a job. Its last message is not a step. It is text like this, and the turn ends (`end_turn`): ``` <tool_call> <function=mcp__openaiDeveloperDocs__search_openai_docs> <parameter=query> Responses API background mode </parameter> </function> </tool_call> ``` Nothing runs, and Claude Code waits for the user. **Why:** the model made a good tool call, but Strata sent it back as answer text, not as a tool call. Strata does this for every tool that is not in the request's `tools` list. Claude Code has tool search on by default when `ANTHROPIC_BASE_URL` is set. Then its MCP tools are not in `tools` until the model loads them with `ToolSearch`. Claude Code only gives their names in the chat. So when the model calls an MCP tool straight away, Claude Code gets only text. It has nothing to run, so it stops. Qwen does this, for example, when a hook names the tool. This is the case Tsury reproduced in #4663 on 0.2.8. We had it 8 times in two days of Claude Code work with Qwen3.8-Flash-Next. **After this PR:** the call comes to Claude Code as a tool call. Claude Code runs it, and the job goes on. Two small fixes on the same path: - When the model loads a tool with `ToolSearch`, it now sees the tool's description in the answer. Before, the answer was empty. - Loading a tool no longer changes the tool list at the start of the prompt, so the chat's cached prompt stays good. I did not time this. Only requests with tool search change (a tool marked `defer_loading` in the request). All other requests work as before. ## Related discussion Refs #4663. This fixes the Claude Code case from Tsury's comment. It does not change the first report in #4663: Chat Completions, with tools that change between turns. There the client gives no sign that it holds tools back, so a call for a tool that is not in the list stays text, as decided in #3075 and #3796. ## Approach Claude Code expects the server behind `ANTHROPIC_BASE_URL` to handle `defer_loading` and `tool_reference`, as Anthropic's API does. This PR follows Anthropic's rules. I ran Claude Code 2.1.314 against a small fake API (no model) and saved what it sends: 1. The tool list has the built-in tools, `ToolSearch` and an empty `DeferredToolPlaceholder` marked `defer_loading: true`. MCP tools are only named in the chat. 2. After `ToolSearch`, the answer is a `tool_reference` to the tool. From then on the tool is in `tools`, marked `defer_loading: true`. 3. Claude Code runs a call to an MCP tool even when the model never loaded it. What changed, only on `/v1/messages`: - When the request has a `defer_loading` tool, a call for a tool that is not in the list is a tool call. This is so in the answer and in the thinking. - A `defer_loading` tool can be called, but it is not in the tool list at the start of the prompt. - A `tool_reference` becomes the tool's description, in the tool list's form, in the same place. Other references are left out, as before. llama.cpp keeps this from happening: after `<tool_call>` it lets the model write only names from the list. Strata does not limit the model's output that way, so that is not part of this PR. ## Validation **Passed:** - `python -m unittest serve.test_tool_search -v` on 03310de7 (upstream main 870aedd9 + this commit), Windows 11, Python 3.14.2, jinja2 3.1.6: 12 tests OK. They test: - the change of the request; - a call for a tool not in the list, in the answer and in the thinking; - a loaded tool keeping its argument types; - the `/v1/messages` route with `MockEngine`, and that requests without tool search work as before. - The parser and route tests on 03310de7, 174 tests OK: `serve.test_tool_search serve.test_frontend serve.test_tool_name_alias serve.test_tool_corpus serve.test_tool_routes serve.test_quoted_call_values serve.test_stop_holdback serve.test_parser_call_scan serve.test_parser_hold serve.test_parser_track serve.test_reasoning_loop_recovery serve.test_reasoning_rescue serve.test_reasoning_tools serve.test_tool_call_envelope serve.test_tool_call_unclosed serve.test_tool_name_space serve.test_anthropic_base_url` - The whole `serve/` suite on 03310de7, same Windows machine: `python -m unittest discover -s serve -p 'test_*.py' -t .`, 1268 tests OK (19 skipped). - The same change on Ubuntu 24.04.4 with the server's venv: `serve.test_tool_search` and `serve.test_frontend`, 38 tests OK. - Claude Code 2.1.314 against the fake API: the three points under Approach. **Failed:** - None seen. A first version gave an error (400) for a `tool_reference` to an unknown tool. That broke `test_frontend`'s `test_messages_tool_reference_in_a_tool_result_is_left_out`, so I took it out. **Not run:** - A real Claude Code session with a real model on this commit. It is next on our 2x CMP 50HX machine (Swift 1.5 IQ3_XXS). I will add the result here. - GPU, HIP, SYCL and Metal builds: not needed (only Python under `serve/` changed). ## Limits - Only `/v1/messages`. The first report in #4663 (Chat Completions) stays as it is. - With tool search on, a call for any name that is not in the list becomes a tool call. Claude Code answers names it does not know itself; I did not test a made-up name. - A `tool_choice` that names a held-back tool works like `auto`, as it does today for any name not in the list. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:33:00 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5141
No description provided.