[PR #939] [CLOSED] serve: a tool call written inside an unclosed thinking span is an implicit think end (#804) #2924

Closed
opened 2026-11-04 02:04:13 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/939
Author: @brxperience
Created: 10/5/2026
Status: ❌ Closed

Base: main ← Head: fix/tool-call-inside-thinking


📝 Commits (1)

  • 469bed9 serve: a tool call written inside an unclosed thinking span is an implicit think end (#804)

📊 Changes

3 files changed (+163 additions, -1 deletions)

View changed files

📝 serve/frontend.py (+64 -1)
📝 serve/server.py (+3 -0)
📝 serve/test_server.py (+96 -0)

📄 Description

Problem

Qwen3-family models sometimes go straight from their reasoning to a tool call without ever emitting </think>. OutputParser only leaves the reasoning state on </think>, so the whole call is channeled out as reasoning_content: the client sees no tool_calls, finish_reason: "stop", and its agent loop stops silently with nothing to run. Reported live in #804 (Qwen3.8-Flash-Next, GSQ-RCO IQ3_S; ~4 of 1050 responses in agent use).

Fix

A <tool_call> that ends an unclosed thinking span is an implicit end of thinking, with a strict trigger so quoted markup stays reasoning. In the reasoning state, it must be:

  1. at the start of a line (right after a newline, or the very first text of the thinking),
  2. outside a ``` / ~~~ fenced code block,
  3. followed - after only whitespace - by the <function= that opens a real call body.

The text before it stays reasoning_content, and the call goes through the normal call state, so it is extracted in streaming (stream_tools) and non-streaming paths alike. A candidate whose follower has not arrived is held, so streamed and whole outputs are identical. This follows the proposal in #804 (and vLLM PR #35687's idea, with the stricter trigger).

self.buf keeps its original trimming - the reasoning budget in server.py relies on not parser.buf - and the reasoning span is tracked separately in self.rseen.

Each implicit end is logged: [strata] implicit end of thinking: N tool call(s) ....

Tests

New ToolCallInsideThinking in serve/test_server.py:

  • the live shape, fed 1 char at a time, in chunks of 7, and whole, with stream_tools on and off: exactly 1 call, the reasoning kept;
  • </think> before the opener is unchanged;
  • 10 mention-only controls that must stay reasoning (backticked, mid-sentence, indented, markdown quote, ``` and ~~~ fences, no function body, tag after tag, bare tag before </think>);
  • a call the output ends inside is not reported;
  • server-level: finish_reason: "tool_calls" and the arguments.

python -m unittest serve.test_server: 144 tests OK (Python 3.13; jsonschema and the pack tokenizer absent).

Note

The chat template also renders a stranded call from the history in the #804 proposal, but the server loads the template from the pack (<pack>/tokenizer/chat_template.jinja), not serve/, so that half needs the pack side and is left out here.

Fixes #804.


🔄 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/939 **Author:** [@brxperience](https://github.com/brxperience) **Created:** 10/5/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/tool-call-inside-thinking` --- ### 📝 Commits (1) - [`469bed9`](https://github.com/Niko1221/Strata/commit/469bed9c1abe2d7e88abd8488436a1b9973405a9) serve: a tool call written inside an unclosed thinking span is an implicit think end (#804) ### 📊 Changes **3 files changed** (+163 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+64 -1) 📝 `serve/server.py` (+3 -0) 📝 `serve/test_server.py` (+96 -0) </details> ### 📄 Description ## Problem Qwen3-family models sometimes go straight from their reasoning to a tool call without ever emitting `</think>`. `OutputParser` only leaves the `reasoning` state on `</think>`, so the whole call is channeled out as `reasoning_content`: the client sees no `tool_calls`, `finish_reason: "stop"`, and its agent loop stops silently with nothing to run. Reported live in #804 (Qwen3.8-Flash-Next, GSQ-RCO IQ3_S; ~4 of 1050 responses in agent use). ## Fix A `<tool_call>` that ends an unclosed thinking span is an implicit end of thinking, with a strict trigger so quoted markup stays reasoning. In the `reasoning` state, it must be: 1. at the start of a line (right after a newline, or the very first text of the thinking), 2. outside a ``` / ~~~ fenced code block, 3. followed - after only whitespace - by the `<function=` that opens a real call body. The text before it stays `reasoning_content`, and the call goes through the normal `call` state, so it is extracted in streaming (`stream_tools`) and non-streaming paths alike. A candidate whose follower has not arrived is held, so streamed and whole outputs are identical. This follows the proposal in #804 (and vLLM PR #35687's idea, with the stricter trigger). `self.buf` keeps its original trimming - the reasoning budget in `server.py` relies on `not parser.buf` - and the reasoning span is tracked separately in `self.rseen`. Each implicit end is logged: `[strata] implicit end of thinking: N tool call(s) ...`. ## Tests New `ToolCallInsideThinking` in `serve/test_server.py`: - the live shape, fed 1 char at a time, in chunks of 7, and whole, with `stream_tools` on and off: exactly 1 call, the reasoning kept; - `</think>` before the opener is unchanged; - 10 mention-only controls that must stay reasoning (backticked, mid-sentence, indented, markdown quote, ``` and ~~~ fences, no function body, tag after tag, bare tag before `</think>`); - a call the output ends inside is not reported; - server-level: `finish_reason: "tool_calls"` and the arguments. `python -m unittest serve.test_server`: 144 tests OK (Python 3.13; `jsonschema` and the pack tokenizer absent). ## Note The chat template also renders a stranded call from the history in the #804 proposal, but the server loads the template from the pack (`<pack>/tokenizer/chat_template.jinja`), not `serve/`, so that half needs the pack side and is left out here. Fixes #804. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:04:13 +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#2924
No description provided.