mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #966] [CLOSED] serve: recover tool calls the model writes next to the template's form, and return the rest as content #2941
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2941
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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+)
749d957setup (--backend hip): a system ROCm without the HIP development files falls back to the wheels (#446)5a30024calibrate: the engine's arguments come from the server's engine_args; a failed tuning says why (#447)9f60d13serve, 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)6a09387setup (--gguf-dir): GGUFs Strata cannot run are named as such, with the --family/--model to use (#444)d6a91e2docs: the Coder is weaker outside code, Chinese/CJK text included; the unpruned sizes for that (#438)d8d4ad3Merge branch 'f-135-eng' into rel-0.1.357b600d5Merge branch 'f-135-small' into rel-0.1.35d9ab843Engine 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 it57bd713sycl: 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,
mainends 73 of them (5%) with aserver_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:<tool_call><parameter=NAME>...(the tool's name as a parameter tag)ValueError, request ends<tool_call>{"name": NAME, "arguments": {...}}</tool_call>(also"parameters", or arguments as a JSON string)ValueError, request ends<function=NAME>...</function>at the start of a line, no<tool_call>(a stray</tool_call>after it is dropped)<tool_call>(the second may open as<parameter=NAME>)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.pyhandles the parser'sValueError("malformed tool call")as an engine error, so the client getsserver_errorand the agent's session ends.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
mainand on this branch (117 tool calls on this branch, all parsed; 11 of 12 runs edited the gold patch's file).Tests
ToolCallDriftinserve/test_server.py, every case at steps 1 / 7 / whole withstream_toolson and off: each recovered form (with corpus shape ids), each form that must stay text, broken and unclosed JSON. The recovery cases fail onmain+ #700 (54 subtest failures) and all pass with the change.python -m unittest discover -s serve -p 'test_*.py' -t .: 279 tests, plus one error thatmainhas 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.