[PR #523] [CLOSED] serve: a tool call that opens inside thinking is an implicit think end #2673

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/523
Author: @chimpera
Created: 10/2/2026
Status: ❌ Closed

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


📝 Commits (1)

  • f321b94 serve: a tool call that opens inside thinking is an implicit think end

📊 Changes

2 files changed (+96 additions, -7 deletions)

View changed files

📝 serve/frontend.py (+35 -7)
📝 serve/test_server.py (+61 -0)

📄 Description

The problem

The chat template opens <think> in the prompt, but only the model can close it. When the model goes from its reasoning straight to a tool call, it sometimes never emits </think> — so the entire tool call stays inside the thinking span, and OutputParser channels it all as reasoning.

Through the OpenAI API surface that means the call arrives as reasoning_content: a client that runs tools from the content channel sees a thinking-only message with finish_reason: stop and nothing to execute. Observed live on a Qwen3.8-Flash-Next deployment: agents stopping silently mid-task; the transcript shows end_turn messages whose reasoning tail contains a complete, well-formed <tool_call> block (2 occurrences in one overnight session).

The fix

An OutputParser in the reasoning state that finds <tool_call> treats it as an implicit think end:

  • reasoning is emitted up to the opener (the hold-back now watches CALL_START too, so an opener split across deltas is not leaked as thinking),
  • the rest parses as a normal call — for both streamed deltas and whole completions,
  • a </think> still wins when it comes first; nothing changes for well-formed output.

Two guards keep false positives harmless:

  • a reasoning-span mention of the call format that closes like a call but has no call body falls back to visible reasoning verbatim (call_from_reasoning) instead of raising — the historical content-span behavior of failing the stream is untouched,
  • an unfinished call at finish() is still never reported as a whole call.

Tests

ReasoningToolCall in serve/test_server.py: the opener-inside-thinking case (across chunk steps 1/7/10000 and both stream_tools settings), </think>-before-opener precedence, the malformed-mention fallback, and the unfinished-call case. Full suite: 104 tests OK (python -m unittest serve.test_server).

🤖 Generated with Claude Code


🔄 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/523 **Author:** [@chimpera](https://github.com/chimpera) **Created:** 10/2/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/tool-call-opens-inside-thinking` --- ### 📝 Commits (1) - [`f321b94`](https://github.com/Niko1221/Strata/commit/f321b949b5674b00d88e41c5e67c10a03880c1f2) serve: a tool call that opens inside thinking is an implicit think end ### 📊 Changes **2 files changed** (+96 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+35 -7) 📝 `serve/test_server.py` (+61 -0) </details> ### 📄 Description ## The problem The chat template opens `<think>` in the prompt, but only the model can close it. When the model goes from its reasoning straight to a tool call, it sometimes never emits `</think>` — so the entire tool call stays inside the thinking span, and `OutputParser` channels it all as `reasoning`. Through the OpenAI API surface that means the call arrives as `reasoning_content`: a client that runs tools from the content channel sees a thinking-only message with `finish_reason: stop` and nothing to execute. Observed live on a Qwen3.8-Flash-Next deployment: agents stopping silently mid-task; the transcript shows `end_turn` messages whose reasoning tail contains a complete, well-formed `<tool_call>` block (2 occurrences in one overnight session). ## The fix An `OutputParser` in the `reasoning` state that finds `<tool_call>` treats it as an implicit think end: - reasoning is emitted up to the opener (the hold-back now watches `CALL_START` too, so an opener split across deltas is not leaked as thinking), - the rest parses as a normal call — for both streamed deltas and whole completions, - a `</think>` still wins when it comes first; nothing changes for well-formed output. Two guards keep false positives harmless: - a reasoning-span *mention* of the call format that closes like a call but has no call body falls back to visible reasoning verbatim (`call_from_reasoning`) instead of raising — the historical content-span behavior of failing the stream is untouched, - an unfinished call at `finish()` is still never reported as a whole call. ## Tests `ReasoningToolCall` in `serve/test_server.py`: the opener-inside-thinking case (across chunk steps 1/7/10000 and both `stream_tools` settings), `</think>`-before-opener precedence, the malformed-mention fallback, and the unfinished-call case. Full suite: 104 tests OK (`python -m unittest serve.test_server`). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:02:16 +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#2673
No description provided.