[PR #525] [CLOSED] serve: rescue a tool call stranded in an unclosed thinking span #2676

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

📋 Pull Request Information

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

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


📝 Commits (10+)

  • d8d4ad3 Merge branch 'f-135-eng' into rel-0.1.35
  • 7b600d5 Merge branch 'f-135-small' into rel-0.1.35
  • d9ab843 Engine 0.1.35: Windows AMD uses its bundled HIP runtime (#468 #461), the low-RAM resident mode on Windows 32 GB PCs (#467), fixes #460 #459 #446 #447 #457 #448 #444; setup requires it
  • 57bd713 sycl: pipeline the expert cache's profile fill (model load 3-4x faster)
  • e3bdd74 A prompt cancelled mid-read is logged and recorded with the tokens it read (#471)
  • f2aaba1 "The draft head does not fit" says what to change (#474)
  • 64987c8 UPDATE.bat / update.sh: update Strata without starting the model (#475)
  • 6d0e648 Opt-in: keep what the expert cache learned across restarts (--expert-profile-save, #477)
  • 5ccf3a7 Engine 0.1.36: a cancelled prompt logged as read so far (#471), the draft-head hint (#474), UPDATE.bat (#475), --expert-profile-save (#477); setup requires it
  • b750bbc #136: fused int8 tensor-core experts for the Q2_0 pack's prompt path, grouped on the GPU (opt-in STRATA_PF_FUSED=1)

📊 Changes

6 files changed (+334 additions, -294 deletions)

View changed files

📝 docs/DETAILS.md (+4 -1)
📝 serve/fixtures/format_fix_specimens.json (+246 -163)
➖ serve/fixtures/stranded_tool_call_failures.json (+0 -33)
📝 serve/frontend.py (+38 -23)
📝 serve/server.py (+3 -0)
📝 serve/test_server.py (+43 -74)

📄 Description

Some chat templates render a tool call right after the reasoning block without ever emitting </think> before it. The whole call then streams out as reasoning_content, and a client that runs tools from the content channel ends its turn with nothing to execute — seen live as agents stopping silently mid-task (transcript: thinking-only message, end_turn, thinking text ends with a complete <tool_call> block).

The rescue is deliberately conservative: during generation the parser behaves exactly as before (no divert, nothing withheld). It keeps the reasoning text from the first <tool_call> opener aside; a </think> after the opener clears it — a valid quoted call example inside a closed thinking span is a mention, not an act, and is never fired as a call. Only at end of generation, in a span that never closed, is the kept tail delivered as tool_call events, and only when every complete block parses against the request's tool schemas. Malformed or unfinished bodies stay reasoning; a reply cut by max tokens mid-call is untouched (#530 already names that case).

Deferred rather than opt-in: a rescued call is by construction at the very end of the reply (the span never closed and generation ended), so nothing is delayed in practice — the only thing given up is stream_tools progressive args for rescued calls, which arrive whole at end of stream.

Tests: the live stranded shape (chunked at 1/7/10k × stream_tools on/off), a valid quoted example in a closed span (the review's false positive — the first version of this fix fired it as a real call), a stranded call with trailing thought, two stranded calls, a malformed mention in an unclosed span, </think>-before-opener, an unfinished call, and the content-channel path.

🤖 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/525 **Author:** [@chimpera](https://github.com/chimpera) **Created:** 10/2/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/tool-call-opens-inside-thinking` --- ### 📝 Commits (10+) - [`d8d4ad3`](https://github.com/Niko1221/Strata/commit/d8d4ad337d3c98ba21d3bd0af1a16e9177e112b6) Merge branch 'f-135-eng' into rel-0.1.35 - [`7b600d5`](https://github.com/Niko1221/Strata/commit/7b600d55ff801caaaa11542af1523050992e049b) Merge branch 'f-135-small' into rel-0.1.35 - [`d9ab843`](https://github.com/Niko1221/Strata/commit/d9ab8435f654c368c586340d490915f6addf56a3) Engine 0.1.35: Windows AMD uses its bundled HIP runtime (#468 #461), the low-RAM resident mode on Windows 32 GB PCs (#467), fixes #460 #459 #446 #447 #457 #448 #444; setup requires it - [`57bd713`](https://github.com/Niko1221/Strata/commit/57bd713454ddb4b965f994e95d95cacd68c93fb1) sycl: pipeline the expert cache's profile fill (model load 3-4x faster) - [`e3bdd74`](https://github.com/Niko1221/Strata/commit/e3bdd7449223c4305ef53e331538346765855a2c) A prompt cancelled mid-read is logged and recorded with the tokens it read (#471) - [`f2aaba1`](https://github.com/Niko1221/Strata/commit/f2aaba1e3d219a6ff165fca367d92b6a1dad7080) "The draft head does not fit" says what to change (#474) - [`64987c8`](https://github.com/Niko1221/Strata/commit/64987c891dc7cf3edb954f5b5f6b8cde233594db) UPDATE.bat / update.sh: update Strata without starting the model (#475) - [`6d0e648`](https://github.com/Niko1221/Strata/commit/6d0e648f65795a510d41be9ecbaaf24f54854001) Opt-in: keep what the expert cache learned across restarts (--expert-profile-save, #477) - [`5ccf3a7`](https://github.com/Niko1221/Strata/commit/5ccf3a72cd30159ecaa60d7324a4b79ea9b7b1b5) Engine 0.1.36: a cancelled prompt logged as read so far (#471), the draft-head hint (#474), UPDATE.bat (#475), --expert-profile-save (#477); setup requires it - [`b750bbc`](https://github.com/Niko1221/Strata/commit/b750bbcc142b5a7e398bb53ac89e03d0d0f69016) #136: fused int8 tensor-core experts for the Q2_0 pack's prompt path, grouped on the GPU (opt-in STRATA_PF_FUSED=1) ### 📊 Changes **6 files changed** (+334 additions, -294 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+4 -1) 📝 `serve/fixtures/format_fix_specimens.json` (+246 -163) ➖ `serve/fixtures/stranded_tool_call_failures.json` (+0 -33) 📝 `serve/frontend.py` (+38 -23) 📝 `serve/server.py` (+3 -0) 📝 `serve/test_server.py` (+43 -74) </details> ### 📄 Description Some chat templates render a tool call right after the reasoning block without ever emitting `</think>` before it. The whole call then streams out as `reasoning_content`, and a client that runs tools from the content channel ends its turn with nothing to execute — seen live as agents stopping silently mid-task (transcript: thinking-only message, `end_turn`, thinking text ends with a complete `<tool_call>` block). The rescue is deliberately conservative: during generation the parser behaves exactly as before (no divert, nothing withheld). It keeps the reasoning text from the first `<tool_call>` opener aside; a `</think>` after the opener clears it — a valid quoted call example inside a *closed* thinking span is a mention, not an act, and is never fired as a call. Only at end of generation, in a span that never closed, is the kept tail delivered as `tool_call` events, and only when every complete block parses against the request's tool schemas. Malformed or unfinished bodies stay reasoning; a reply cut by max tokens mid-call is untouched (#530 already names that case). Deferred rather than opt-in: a rescued call is by construction at the very end of the reply (the span never closed and generation ended), so nothing is delayed in practice — the only thing given up is `stream_tools` progressive args for rescued calls, which arrive whole at end of stream. Tests: the live stranded shape (chunked at 1/7/10k × `stream_tools` on/off), a valid quoted example in a closed span (the review's false positive — the first version of this fix fired it as a real call), a stranded call with trailing thought, two stranded calls, a malformed mention in an unclosed span, `</think>`-before-opener, an unfinished call, and the content-channel path. 🤖 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:18 +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#2676
No description provided.