[PR #966] [CLOSED] serve: recover tool calls the model writes next to the template's form, and return the rest as content #2941

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

📋 Pull Request Information

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

Base: main ← Head: serve-tool-call-drift


📝 Commits (10+)

  • 749d957 setup (--backend hip): a system ROCm without the HIP development files falls back to the wheels (#446)
  • 5a30024 calibrate: the engine's arguments come from the server's engine_args; a failed tuning says why (#447)
  • 9f60d13 serve, setup: name the small split card that caps the prompt chunk; setup recommends the big card alone (#448)
  • eb8da1d /metrics: each request's speculative draft counts, and their sums in the totals (#457)
  • 6a09387 setup (--gguf-dir): GGUFs Strata cannot run are named as such, with the --family/--model to use (#444)
  • d6a91e2 docs: the Coder is weaker outside code, Chinese/CJK text included; the unpruned sizes for that (#438)
  • 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)

📊 Changes

3 files changed (+295 additions, -25 deletions)

View changed files

📝 docs/DETAILS.md (+6 -0)
📝 serve/frontend.py (+204 -25)
📝 serve/test_server.py (+85 -0)

📄 Description

On a corpus of 1,462 real agent turns, main ends 73 of them (5%) with a server_error. With this PR it parses 98.3% of the turns as intended, up from 92.3%, and ends none.

This builds on #700. Its commit is the first one here, cherry-picked onto current main; if #700 merges first, this rebases to one commit. #700 makes a <tool_call> open a call only when a call follows it. This PR widens what counts as a call, for a tool the request declared:

the model wrote before now
<tool_call><parameter=NAME>... (the tool's name as a parameter tag) ValueError, request ends the call
<tool_call>{"name": NAME, "arguments": {...}}</tool_call> (also "parameters", or arguments as a JSON string) ValueError, request ends the call
<function=NAME>...</function> at the start of a line, no <tool_call> (a stray </tool_call> after it is dropped) text to the client, agent stops the call
two calls inside one <tool_call> (the second may open as <parameter=NAME>) ONE call with the second's parameters merged into the first two calls

Anything else in those forms comes back as content, verbatim: an undeclared name, broken JSON, a JSON object that never closes, <function= inside a ``` code block or mid-line. A body that still fails to parse becomes content instead of raising. Every recovery needs a declared tool, so requests without tools behave exactly as before.

Streamed output equals the whole output at any chunk size, with and without stream_tools, and an announced call's streamed arguments equal its final ones.

How I found it

I replayed a corpus of real model output through OutputParser: 1,462 agent turns in 176 distinct shapes, captured from Qwen3.8-27B under Claude Code (redacted, from signalnine/q27's drift corpus), each labelled with the calls the model meant. server.py handles the parser's ValueError("malformed tool call") as an engine error, so the client gets server_error and the agent's session ends.

turns read as intended shapes turns that end the request
main 92.3% 113/176 73
#700 + this PR 98.3% 154/176 0

The 25 turns still missed are mostly invalid JSON and redaction artifacts. Qwen3.8-Flash-Next drifted less in a live check: 12 SWE-bench Verified instances under Claude Code had 0 malformed calls on main and on this branch (117 tool calls on this branch, all parsed; 11 of 12 runs edited the gold patch's file).

Tests

  • New ToolCallDrift in serve/test_server.py, every case at steps 1 / 7 / whole with stream_tools on and off: each recovered form (with corpus shape ids), each form that must stay text, broken and unclosed JSON. The recovery cases fail on main + #700 (54 subtest failures) and all pass with the change.
  • #210 / #211 / #700 tests pass unchanged.
  • python -m unittest discover -s serve -p 'test_*.py' -t .: 279 tests, plus one error that main has too (test_responses.OverHttp.test_json_schema_text_format).
  • docs/DETAILS.md: a paragraph under Streaming.

One judgement call worth a look: a declared tool's <function=NAME> block at the start of a line, outside a code block, counts as a call without the wrapper. A model explaining the format in prose with a real tool's name at the start of a line would run that call. The corpus had 27 turns of the bare form and zero of that prose case.


🔄 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/966 **Author:** [@signalnine](https://github.com/signalnine) **Created:** 10/5/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `serve-tool-call-drift` --- ### 📝 Commits (10+) - [`749d957`](https://github.com/Niko1221/Strata/commit/749d957a1790b1a171dd4a01ab3e31b3882c9892) setup (--backend hip): a system ROCm without the HIP development files falls back to the wheels (#446) - [`5a30024`](https://github.com/Niko1221/Strata/commit/5a3002446dbb9dfcabb7d0bd9f113da90cc2f3c0) calibrate: the engine's arguments come from the server's engine_args; a failed tuning says why (#447) - [`9f60d13`](https://github.com/Niko1221/Strata/commit/9f60d13246e46b02b1dd0841980b4d18b0faaea7) serve, setup: name the small split card that caps the prompt chunk; setup recommends the big card alone (#448) - [`eb8da1d`](https://github.com/Niko1221/Strata/commit/eb8da1d8c26ec41e6ffb084fdf579dba7cad10bd) /metrics: each request's speculative draft counts, and their sums in the totals (#457) - [`6a09387`](https://github.com/Niko1221/Strata/commit/6a093874fe037020f49bd5cf053879ff6a133c21) setup (--gguf-dir): GGUFs Strata cannot run are named as such, with the --family/--model to use (#444) - [`d6a91e2`](https://github.com/Niko1221/Strata/commit/d6a91e2d1770d0f469d6ec15890acc7ee93e764c) docs: the Coder is weaker outside code, Chinese/CJK text included; the unpruned sizes for that (#438) - [`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) ### 📊 Changes **3 files changed** (+295 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+6 -0) 📝 `serve/frontend.py` (+204 -25) 📝 `serve/test_server.py` (+85 -0) </details> ### 📄 Description On a corpus of 1,462 real agent turns, `main` ends 73 of them (5%) with a `server_error`. With this PR it parses 98.3% of the turns as intended, up from 92.3%, and ends none. This builds on #700. Its commit is the first one here, cherry-picked onto current `main`; if #700 merges first, this rebases to one commit. #700 makes a `<tool_call>` open a call only when a call follows it. This PR widens what counts as a call, for a tool the request declared: | the model wrote | before | now | | --- | --- | --- | | `<tool_call><parameter=NAME>...` (the tool's name as a parameter tag) | `ValueError`, request ends | the call | | `<tool_call>{"name": NAME, "arguments": {...}}</tool_call>` (also `"parameters"`, or arguments as a JSON string) | `ValueError`, request ends | the call | | `<function=NAME>...</function>` at the start of a line, no `<tool_call>` (a stray `</tool_call>` after it is dropped) | text to the client, agent stops | the call | | two calls inside one `<tool_call>` (the second may open as `<parameter=NAME>`) | ONE call with the second's parameters merged into the first | two calls | Anything else in those forms comes back as content, verbatim: an undeclared name, broken JSON, a JSON object that never closes, `<function=` inside a ``` code block or mid-line. A body that still fails to parse becomes content instead of raising. Every recovery needs a declared tool, so requests without tools behave exactly as before. Streamed output equals the whole output at any chunk size, with and without `stream_tools`, and an announced call's streamed arguments equal its final ones. ## How I found it I replayed a corpus of real model output through `OutputParser`: 1,462 agent turns in 176 distinct shapes, captured from Qwen3.8-27B under Claude Code (redacted, from [signalnine/q27](https://github.com/signalnine/q27)'s drift corpus), each labelled with the calls the model meant. `server.py` handles the parser's `ValueError("malformed tool call")` as an engine error, so the client gets `server_error` and the agent's session ends. | | turns read as intended | shapes | turns that end the request | | --- | ---: | ---: | ---: | | main | 92.3% | 113/176 | 73 | | #700 + this PR | 98.3% | 154/176 | 0 | The 25 turns still missed are mostly invalid JSON and redaction artifacts. Qwen3.8-Flash-Next drifted less in a live check: 12 SWE-bench Verified instances under Claude Code had 0 malformed calls on `main` and on this branch (117 tool calls on this branch, all parsed; 11 of 12 runs edited the gold patch's file). ## Tests - New `ToolCallDrift` in `serve/test_server.py`, every case at steps 1 / 7 / whole with `stream_tools` on and off: each recovered form (with corpus shape ids), each form that must stay text, broken and unclosed JSON. The recovery cases fail on `main` + #700 (54 subtest failures) and all pass with the change. - #210 / #211 / #700 tests pass unchanged. - `python -m unittest discover -s serve -p 'test_*.py' -t .`: 279 tests, plus one error that `main` has too (`test_responses.OverHttp.test_json_schema_text_format`). - `docs/DETAILS.md`: a paragraph under Streaming. One judgement call worth a look: a declared tool's `<function=NAME>` block at the start of a line, outside a code block, counts as a call without the wrapper. A model explaining the format in prose with a real tool's name at the start of a line would run that call. The corpus had 27 turns of the bare form and zero of that prose case. --- <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:20 +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#2941
No description provided.