Skip to content

server: GLM tool calls the model wrote with a key or an end missing still parse - #761

Merged
ashhart merged 2 commits into
ashhart:mainfrom
Bizuayeu:pr/glm-tool-parse
Oct 13, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
Bizuayeu:pr/glm-tool-parse

Conversation

@Bizuayeu

Copy link
Copy Markdown
Contributor

What this changes

Two repairs to GLM's tool-call parser, both from #285 (by @MiaAI-Lab, closed unmerged), with its test cases:

  • GLM-5.3-Flash sometimes writes an argument's key without its <arg_key>, leaving whitespace where that token
    belongs (read_file path</arg_key><arg_value>…). repairGlmKeys() puts <arg_key> back before the word ahead of
    each unopened </arg_key>; a block missing none comes back as written.
  • When the end token comes inside an argument's value, the call stayed the reply's text. argumentsClose now closes
    the value too (</arg_value> before </tool_call>) and sends the call when that parses. 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.

Both paths go through glmCall, so a reply's end and a closed call read the same repaired block.

Receipt

  • Environment: TensorFold 0efbd447 plus this change; one GB10 (DGX Spark, sm_121, CUDA 13.3).
  • Exactness: tokens are unchanged; only how a reply's text is read as a call.
  • Decode and prompt speed: not applicable.
  • Tests run:
    • zig build test: 547 passed, 5 skipped, 0 failed; the three new tests (repaired keys, repaired calls in both
      modes, a call the end token left open) need this change, and the test that kept an open GLM value as text now
      expects it closed.
    • zig build test-cuda-host: 359 passed, 0 failed. zig fmt --check: clean. lean_check: 539, as main.
  • Not run, and why: Metal's GLM family serves through the same parser; no Mac here.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Prompt processing is no slower than the last release.
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

… 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.
@ashhart
ashhart merged commit f2ee72a into ashhart:main Oct 13, 2026
2 checks passed
jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 13, 2026
jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 13, 2026
jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 13, 2026
…e repaired before they parse

docs/api.md still said include is refused and that a partial value stays content; ashhart#759 and ashhart#761 changed both.
jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 13, 2026
…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]>
@ashhart

ashhart commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Thank you, @Bizuayeu, and thank you @MiaAI-Lab, whose #285 these repairs and cases come from: both commits, as we landed them (bc530f455, 4d093cd5d), carry a Co-authored-by line for you. A key written without its <arg_key>, and a value the end token cut off, now parse when the repaired call parses strictly. A key with no value, a tool not offered, or text after an argument still stays reply text. The parser tests pass on macOS and Linux.

Your head moved after we landed it, with comments that now name #285. We took that wording as 3af60a449, with you as co-author, and both heads are merged into the history with no change to the tree (b07997563, then f2ee72a0f for the current one), so GitHub shows this PR as merged in 1.0.9.

outcastofmusic added a commit to outcastofmusic/TensorFold that referenced this pull request Oct 16, 2026
…t off, is a call

Two GLM writings left a reply's call as text, so the agent's turn carried no call. A key the model wrote as
whitespace ("read_file path</arg_key>...") gets its <arg_key> back before the word ahead of each lone </arg_key>
(server/tools.repair_glm_keys, both servers). A call the model's end token ended before </tool_call> closes with
what it lacks (</arg_value>, </function> or JSON's brackets) when the closed call then parses strictly as one call
to an offered tool (cuda/reply_text.close_call); a stop string, the length limit or ignore_eos closes nothing.
Upstream TensorFold 1.0.9 (ashhart#761) does the same, and the tests are its cases.

Tests: tests/test_glm_call_repair.py, with the server path through the CUDA app.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…e repaired before they parse

docs/api.md still said include is refused and that a partial value stays content; ashhart#759 and ashhart#761 changed both.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…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]>
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
@Bizuayeu
Bizuayeu deleted the pr/glm-tool-parse branch October 25, 2026 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants