mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #211] A tool call cut off by the end of the turn is returned as complete (closed JSON, finish_reason "tool_calls") #109
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#109
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?
Originally created by @alphastorm on GitHub (Sep 30, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/211
When the model ends its turn in the middle of a tool call (the call's name has already streamed, but
</parameter>/</function>never come), the server returns the call as if it were complete:OutputParser.finish()(serve/frontend.py#L473-L482) handles "the output ended inside a call that was already announced" by calling_close_scan()(#L389-L402), which closes the partial JSON so that "clients can still parse it", and then emits atool_callevent;tool_calls(serve/server.py#L1087).The arguments are valid JSON and the finish reason says the call is complete, so a client cannot tell that it was cut and runs the tool with truncated arguments. We hit this with an agent client: it ran a
writecall whosecontentended mid-word and saved the partial file.A cut at the token limit is reported correctly (
finish_reason: "length").Reproduce (v0.1.27,
a790805, mock engine, no GPU)choices[0]of the answer:With
"stream": truethe streamed arguments add up to the same JSON, and the stream ends withfinish_reason: "tool_calls".Expected
A call the model did not finish should not be reported as a finished one, so that clients can drop it instead of running it: for example, leave its arguments unclosed and end with a finish reason other than
tool_calls, as a token-limit cut does. (finish()'s docstring says "an unterminated tool call is returned as content"; today that happens only when the cut comes before the call's name was streamed.)@Interpause commented on GitHub (Sep 30, 2026):
dupe of #210, in fact #210 is likely the root cause. what youre suggesting is to report when it happens better
@alphastorm commented on GitHub (Sep 30, 2026):
Thanks, you're right: #210 covers this. Its second trigger is this case (the turn ends inside a call and
_close_scancloses it), and its fail-loud fix is what this issue asks for. #210 went up a minute before this one, so our duplicate search missed it. Closing as a duplicate of #210.One detail for that fix: the OpenAI stream counts a call as soon as its name is streamed (server.py#L1072-L1074), and L1087 turns
stopplus any counted call intofinish_reason: "tool_calls"; the non-streamed answer takes its finish reason from the same stream. So a fix infinish()/_close_scan()alone would still reporttool_calls; the finish reason also has to follow whether the call was completed.@alphastorm commented on GitHub (Sep 30, 2026):
Reopening: 0.1.28 fixed #210's first trigger (
</parameter>/</tool_call>inside a value), not this one. When the output ends inside a call,finish()(frontend.py#L532-L535) still closes it and emitstool_call, and the answer still ends withfinish_reason: "tool_calls".At
bbaaabb(0.1.28), no model:Through
python -m serve.server --engine mock --script "</think>\n\n<the text above>", a streamed and a non-streamed OpenAI request with awritetool both end withfinish_reason: "tool_calls"and the arguments{"path":"a.txt","content":"partial content"}. In the web app's MCP loop, the unfinished call runs with empty arguments.#231 proposes a fix.
@Niko1221 commented on GitHub (Sep 30, 2026):
Confirmed. #231 goes into 0.1.31, plus one more change: a non-streamed OpenAI answer also drops tool calls whose arguments don't parse when the answer was cut, since many SDKs run any tool calls present.
@Niko1221 commented on GitHub (Oct 1, 2026):
Fixed in 0.1.31 (#231 plus the non-streamed follow-up). Thanks!