Repository navigation
Conversation
…rses whole; a missing <arg_key> is put back
GLM-5.3-Flash sometimes writes its end token before </tool_call>. The CUDA server then sent no call: the
reply finished "stop" with the call's markup as its text, and agent clients stalled. When the model's end
token (not a stop string, not the token limit) ends the reply inside a GLM call, the call is now closed
(</arg_value> too when a value is open) and sent if it then parses strictly: one whole call to an offered
tool, nothing but its markup, arguments a JSON object (close_glm_call). Otherwise its markup stays the text,
as before. A call the token limit or a stop string cut is unchanged. Only models whose tokenizer has GLM's
call marks as tokens take this path.
GLM calls whose <arg_key> the model wrote as whitespace ("read path</arg_key><arg_value>..", or
"</arg_value>\npath</arg_key>") get it back in the shared GLM parser (repair_glm_keys), so both servers'
end parsers read them; before, the first form came back as text and the second lost the argument. Blocks
with no unopened </arg_key> are unchanged.
Reported on the GLM-5.3-Flash DGX Spark recipe, issue ashhart#22.
Tests: tests/test_glm_tool_call_end.py.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This carries the server half of PR #285 by MiaAI-Lab. When the model's end token ends a reply inside a tool call, before </tool_call>, the server now closes the call and sends it if it then parses whole. Until now such a reply finished "stop" with no call. A streamed client kept the call's opening delta and arguments that never closed, and a non-streamed client got the markup as text. tool_parse.closeCall takes the opener the end parser would leave unclosed and adds what the call's arguments lack: </function> for an XML call, or the open arrays and objects that tool_params.closedJson closes for a JSON call. It never closes a value, and it returns the closers only when the closed block parses strictly as one call to an offered tool with nothing but its markup. Generation.finish appends them to the reply's text before the think split, so a call that ends an unclosed think block becomes the answer, as in the PR. In a streamed reply the streamer reads the closers like markup the model wrote, so the call completes with the same deltas. A call that does not parse whole is left as it is. A non-streamed reply keeps its markup as text, and a streamed reply whose opening delta already went out finishes as before. Nothing closes a reply that ends on a stop string or the length limit, or one that sets ignore_eos. The PR's other half, which puts back a GLM <arg_key> the model wrote as whitespace, waits for the GLM family in Zig and is not in this change. The new unit tests close whole XML, JSON and GLM calls and check that the end parser then returns them. Calls cut inside a value, a key without its value, a tool that was not offered, an empty block and an earlier unclosed opener stay text. A streamed call left open ends with the deltas of one closed by its markup, and one cut inside a value gets nothing more. The two completion tests fail with closeCall stubbed to close nothing, and the two guard tests fail when it skips the whole-call check. The server's unit tests now run in zig build test through a root.zig test module, the one zig/tests/server/zig_test.sh runs, which takes the step from 37 to 60 tests. On the scripted fake server, the open-call scripts now finish "tool_calls" streamed and not, all 240 replies of the existing corpus are unchanged against the base, and the parity harness still matches the Python server in 315 of 319 cases with no unexpected difference. Co-authored-by: MiaAI-Lab <[email protected]>
|
Thank you, @MiaAI-Lab. The server half of this landed in the Zig engine as 1c3487c, with your credit. A tool call that the model's end token leaves open is now completed when its arguments parse whole, and a non-streamed call that doesn't parse stays the reply's text, as in your fix. There is one difference. The Zig server streams a call as it parses, so when a streamed call's arguments don't parse whole, the client has already seen the call start, and it stays unfinished rather than turning back into text. The missing |
… it back GLM-5.3-Flash sometimes writes the key of an argument without its <arg_key>, leaving whitespace where that token belongs: "read_file path</arg_key><arg_value>..", or "</arg_value>\nlimit</arg_key><arg_value>..". glmCall then read the first as text and lost the second argument. repairGlmKeys() puts <arg_key> back before the word ahead of each unopened </arg_key> (one after the name, or after a </arg_value>), and glmCall reads the repaired block; a block missing none, a key with no name before it, or no word at all comes back as written. The parsers that end a reply and close a call the end token left open both go through glmCall, so both read the repaired call. The second half of TensorFold ashhart#285 by MiaAI-Lab (closed unmerged), carried by the 2.x line since 2.5.0 (repair_glm_keys); the test cases are that commit's.
…e closes it
When the model's end token comes before </tool_call>, closeCall closes the call if it then
parses strictly. A GLM call ended inside its value ("run<arg_key>command</arg_key>
<arg_value>ls -la") stayed the reply's text here; the 2.x line (TensorFold ashhart#285 by
MiaAI-Lab, since 2.5.0) closes the value too, with </arg_value> ahead of </tool_call>, and
sends the call when that parses. argumentsClose now does the same, so tool-eval reads the
3.x line as it read 2.x. The strict parse still decides: a key with no value, a tool not
offered, text after an argument or a think block past the call stay open.
The test that kept an open GLM value as text now closes it, and the 2.x cases of
close_glm_call (tests/test_glm_tool_call_end.py) are added.
…hen parses
When the model's end token comes before </tool_call>, closeCall closes the call if it then
parses strictly. A GLM call ended inside its value ("run<arg_key>command</arg_key>
<arg_value>ls -la") stayed the reply's text here; ashhart#285 (by MiaAI-Lab, closed unmerged)
closed the value too, with </arg_value> ahead of </tool_call>, and sent the call when that
parsed. argumentsClose now does the same. The strict parse still decides: a key with no
value, a tool not offered, text after an argument or a think block past the call stay open.
The test that kept an open GLM value as text now closes it, and ashhart#285's cases of
close_glm_call (tests/test_glm_tool_call_end.py) are added.
… it back GLM-5.3-Flash sometimes writes the key of an argument without its <arg_key>, leaving whitespace where that token belongs: "read_file path</arg_key><arg_value>..", or "</arg_value>\nlimit</arg_key><arg_value>..". glmCall then read the first as text and lost the second argument. repairGlmKeys() puts <arg_key> back before the word ahead of each unopened </arg_key> (one after the name, or after a </arg_value>), and glmCall reads the repaired block; a block missing none, a key with no name before it, or no word at all comes back as written. The parsers that end a reply and close a call the end token left open both go through glmCall, so both read the repaired call. The second half of ashhart#285 by MiaAI-Lab (closed unmerged); the test cases are that PR's. Co-authored-by: MiaAI-Lab <[email protected]>
…hen parses
When the model's end token comes before </tool_call>, closeCall closes the call if it then
parses strictly. A GLM call ended inside its value ("run<arg_key>command</arg_key>
<arg_value>ls -la") stayed the reply's text here; ashhart#285 (by MiaAI-Lab, closed unmerged)
closed the value too, with </arg_value> ahead of </tool_call>, and sent the call when that
parsed. argumentsClose now does the same. The strict parse still decides: a key with no
value, a tool not offered, text after an argument or a think block past the call stay open.
The test that kept an open GLM value as text now closes it, and ashhart#285's cases of
close_glm_call (tests/test_glm_tool_call_end.py) are added.
Co-authored-by: MiaAI-Lab <[email protected]>
… it back GLM-5.3-Flash sometimes writes the key of an argument without its <arg_key>, leaving whitespace where that token belongs: "read_file path</arg_key><arg_value>..", or "</arg_value>\nlimit</arg_key><arg_value>..". glmCall then read the first as text and lost the second argument. repairGlmKeys() puts <arg_key> back before the word ahead of each unopened </arg_key> (one after the name, or after a </arg_value>), and glmCall reads the repaired block; a block missing none, a key with no name before it, or no word at all comes back as written. The parsers that end a reply and close a call the end token left open both go through glmCall, so both read the repaired call. The second half of ashhart#285 by MiaAI-Lab (closed unmerged); the test cases are that PR's.
…hen parses
When the model's end token comes before </tool_call>, closeCall closes the call if it then
parses strictly. A GLM call ended inside its value ("run<arg_key>command</arg_key>
<arg_value>ls -la") stayed the reply's text here; ashhart#285 (by MiaAI-Lab, closed unmerged)
closed the value too, with </arg_value> ahead of </tool_call>, and sent the call when that
parsed. argumentsClose now does the same. The strict parse still decides: a key with no
value, a tool not offered, text after an argument or a think block past the call stay open.
The test that kept an open GLM value as text now closes it, and ashhart#285's cases of
close_glm_call (tests/test_glm_tool_call_end.py) are added.
…al by name, as ashhart#759's and ashhart#761's heads now say Comment and test-name wording only, from the PRs' current heads. Co-authored-by: Bizuayeu <[email protected]>
This carries the server half of PR ashhart#285 by MiaAI-Lab. When the model's end token ends a reply inside a tool call, before </tool_call>, the server now closes the call and sends it if it then parses whole. Until now such a reply finished "stop" with no call. A streamed client kept the call's opening delta and arguments that never closed, and a non-streamed client got the markup as text. tool_parse.closeCall takes the opener the end parser would leave unclosed and adds what the call's arguments lack: </function> for an XML call, or the open arrays and objects that tool_params.closedJson closes for a JSON call. It never closes a value, and it returns the closers only when the closed block parses strictly as one call to an offered tool with nothing but its markup. Generation.finish appends them to the reply's text before the think split, so a call that ends an unclosed think block becomes the answer, as in the PR. In a streamed reply the streamer reads the closers like markup the model wrote, so the call completes with the same deltas. A call that does not parse whole is left as it is. A non-streamed reply keeps its markup as text, and a streamed reply whose opening delta already went out finishes as before. Nothing closes a reply that ends on a stop string or the length limit, or one that sets ignore_eos. The PR's other half, which puts back a GLM <arg_key> the model wrote as whitespace, waits for the GLM family in Zig and is not in this change. The new unit tests close whole XML, JSON and GLM calls and check that the end parser then returns them. Calls cut inside a value, a key without its value, a tool that was not offered, an empty block and an earlier unclosed opener stay text. A streamed call left open ends with the deltas of one closed by its markup, and one cut inside a value gets nothing more. The two completion tests fail with closeCall stubbed to close nothing, and the two guard tests fail when it skips the whole-call check. The server's unit tests now run in zig build test through a root.zig test module, the one zig/tests/server/zig_test.sh runs, which takes the step from 37 to 60 tests. On the scripted fake server, the open-call scripts now finish "tool_calls" streamed and not, all 240 replies of the existing corpus are unchanged against the base, and the parity harness still matches the Python server in 315 of 319 cases with no unexpected difference. Co-authored-by: MiaAI-Lab <[email protected]>
… it back GLM-5.3-Flash sometimes writes the key of an argument without its <arg_key>, leaving whitespace where that token belongs: "read_file path</arg_key><arg_value>..", or "</arg_value>\nlimit</arg_key><arg_value>..". glmCall then read the first as text and lost the second argument. repairGlmKeys() puts <arg_key> back before the word ahead of each unopened </arg_key> (one after the name, or after a </arg_value>), and glmCall reads the repaired block; a block missing none, a key with no name before it, or no word at all comes back as written. The parsers that end a reply and close a call the end token left open both go through glmCall, so both read the repaired call. The second half of ashhart#285 by MiaAI-Lab (closed unmerged); the test cases are that PR's. Co-authored-by: MiaAI-Lab <[email protected]>
…hen parses
When the model's end token comes before </tool_call>, closeCall closes the call if it then
parses strictly. A GLM call ended inside its value ("run<arg_key>command</arg_key>
<arg_value>ls -la") stayed the reply's text here; ashhart#285 (by MiaAI-Lab, closed unmerged)
closed the value too, with </arg_value> ahead of </tool_call>, and sent the call when that
parsed. argumentsClose now does the same. The strict parse still decides: a key with no
value, a tool not offered, text after an argument or a think block past the call stay open.
The test that kept an open GLM value as text now closes it, and ashhart#285's cases of
close_glm_call (tests/test_glm_tool_call_end.py) are added.
Co-authored-by: MiaAI-Lab <[email protected]>
… it back GLM-5.3-Flash sometimes writes the key of an argument without its <arg_key>, leaving whitespace where that token belongs: "read_file path</arg_key><arg_value>..", or "</arg_value>\nlimit</arg_key><arg_value>..". glmCall then read the first as text and lost the second argument. repairGlmKeys() puts <arg_key> back before the word ahead of each unopened </arg_key> (one after the name, or after a </arg_value>), and glmCall reads the repaired block; a block missing none, a key with no name before it, or no word at all comes back as written. The parsers that end a reply and close a call the end token left open both go through glmCall, so both read the repaired call. The second half of ashhart#285 by MiaAI-Lab (closed unmerged); the test cases are that PR's.
…hen parses
When the model's end token comes before </tool_call>, closeCall closes the call if it then
parses strictly. A GLM call ended inside its value ("run<arg_key>command</arg_key>
<arg_value>ls -la") stayed the reply's text here; ashhart#285 (by MiaAI-Lab, closed unmerged)
closed the value too, with </arg_value> ahead of </tool_call>, and sent the call when that
parsed. argumentsClose now does the same. The strict parse still decides: a key with no
value, a tool not offered, text after an argument or a think block past the call stay open.
The test that kept an open GLM value as text now closes it, and ashhart#285's cases of
close_glm_call (tests/test_glm_tool_call_end.py) are added.
…al by name, as ashhart#759's and ashhart#761's heads now say Comment and test-name wording only, from the PRs' current heads. Co-authored-by: Bizuayeu <[email protected]>
…hen parses
When the model's end token comes before </tool_call>, closeCall closes the call if it then
parses strictly. A GLM call ended inside its value ("run<arg_key>command</arg_key>
<arg_value>ls -la") stayed the reply's text here; ashhart#285 (by MiaAI-Lab, closed unmerged)
closed the value too, with </arg_value> ahead of </tool_call>, and sent the call when that
parsed. argumentsClose now does the same. The strict parse still decides: a key with no
value, a tool not offered, text after an argument or a think block past the call stay open.
The test that kept an open GLM value as text now closes it, and ashhart#285's cases of
close_glm_call (tests/test_glm_tool_call_end.py) are added.
TL;DR: on CUDA, a GLM tool call that the model ends with its end token before
</tool_call>is now closed and sent as a call when it parses as a whole call. If it doesn't parse, its markup stays the reply's text, as before. Separately, a GLM call where the model wrote whitespace instead of an<arg_key>token gets that token back in the shared GLM parser, so both servers read the call.Problem
Reported on the GLM-5.3-Flash DGX Spark recipe (issue #22). Agent clients (opencode among them) sometimes got a reply with
finish_reason: "stop"and no tool call, although the model had written one:</tool_call>, for example<tool_call>read_file<arg_key>path</arg_key><arg_value>notes.txt</arg_value>and then the end token.parse_tool_callsonly reads closed blocks, so no call goes out. The client receives the call's markup as plain text.<arg_key>. The model writes whitespace where the<arg_key>token belongs:read_file path</arg_key><arg_value>.., or</arg_value>\nlimit</arg_key><arg_value>3</arg_value>for a later argument. In the first form the whole call comes back as text. In the second form the argument is silently lost, and a single-call request (parallel_tool_calls: false) refuses the call.Fix
cuda/server.py: the fix applies only when all of these hold:ignore_eos)<tool_call>blockIn that case
close_glm_call(cuda/reply_text.py) appends</tool_call>, plus</arg_value>when a value is still open. The suffix is kept only if the closed block then parses strictly: one whole call to an offered tool, nothing but its markup, arguments a JSON object. Streamed and non-streamed replies take the same path. This includes a call at the end of an unclosed think block, whichsplit_thinkingalready treats as the answer once it is closed.server/tools.py:repair_glm_keysputs a missing<arg_key>back before_parse_glm_payloadreads a block: the word before an unopened</arg_key>becomes the key. Both servers' end parsers use this, so the Mac server reads these calls too. A block with no unopened</arg_key>is returned as it was.Unchanged: these replies stay exactly as they are today:
Token ids and
token_shanever change. Only the parsing of the finished text does.Tests
tests/test_glm_tool_call_end.py(new):repair_glm_keyscases, and both parsers (parse_tool_calls,parse_tool_calls_from_content) reading repaired callsclose_glm_callcases: what gets closed, and what stays open (a tool that wasn't offered, a key with no value,</think>after the call, text after an argument)GlmAppthrough HTTP, streamed and not, on a byte-level tokenizer with GLM's marks. It covers calls the end token left open (with and without text before them, after a closed call, inside an unclosed think block), open calls that stay text, the token-limit and stop-string cuts (unchanged), and a closed call with a missing key.mlx):pytest tests --ignore=tests/cuda -k 'tool or glm or cuda_server or stop or reply or thinking or policy'.main: 934 passed (the difference is the 49 new tests).mlx.