Skip to content

server: a GLM value that runs into the next pair keeps the call as text (#2801) - #2831

Merged
ashhart merged 2 commits into
ashhart:mainfrom
devopsfortunato:task/Tensorfold-Contribut+t-mwbburht-mbh39b
Nov 11, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
devopsfortunato:task/Tensorfold-Contribut+t-mwbburht-mbh39b

Conversation

@devopsfortunato

@devopsfortunato devopsfortunato commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Before: a GLM call whose <arg_value> leaves out its </arg_value> made the whole-reply parser read that value
all the way to the next pair's closer, so the next pair's <arg_key>/<arg_value> markup landed inside the
arguments string — valid JSON, corrupt call. Streams had the same slip and could end under
finish_reason: "tool_calls" with arguments that never close.

After: a GLM value that runs into the next pair, or never closes before its envelope ends, is malformed, so the
envelope stays in content as text — the keep-as-text rule docs/api.md already states. Well-formed GLM calls
parse exactly as before. A stream that hits the slip ends with finish_reason: "stop" and the same text in
content; its first pieces may already have gone out, which the issue names as the stream's one limit.

Checks on this head

  • Head commit: 0fc747c4a245f3322ece7d6ef33f466410a9f2c6
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: base f6d311cfc
    6178 files, 386 problems; this head 6178 files, 386 problems — 0 new findings.
  • Tests run, with the command and pass, fail and skip counts:
    • zig build test-tool-parse-host --summary all → 52 tests, 0 fail (both on this head and its pre-rebase base).
    • zig build test-server-cpu --summary all → this head: 1278 pass, 5 skip, 0 fail (1283 total). The same sources passed
      1278 pass, 5 skip, 0 fail (1283 total) before the rebase onto f6d311cfc; that step holds the whole and
      streamed chat/SSE cases, the new ones included.
    • Full zig build test: CI's zig job runs this suite on the project's runner and passes on this head (below). Running it locally here as well takes ~50+ minutes on 4 shared cores, and this 8 GiB box already fails two steps on unmodified main fb8fdf3d8: test-cuda-host (its GLM snapshot sizing asks for a ~7 GB arena) and test-env-defaults-host (fails under load, passes alone: 6/6 steps). Both are host-capacity failures, not this change's.
    • zig fmt --check build.zig zig prints nothing; git diff --check prints nothing.
  • CI: zig, fmt, pytest, zig-windows and zig-macos-dev-tools pass on this head 0fc747c4a (release-paths and benchmark-clients were still queued when this line was written; neither reaches this change).
  • Not run, and why: this box has no GPU and no model checkpoint (8 GiB aarch64), so no GLM-5.3-Flash reply, no
    Metal/CUDA device checks and no macOS run. The issue's capture is pinned as a host test instead.

Receipt

n/a and why: the change decides how a malformed GLM envelope is reported, not how tokens are produced or summed,
and this host cannot run a GLM checkpoint at all. Its host checks are in "Checks on this head": the issue's
capture and an unclosed last value stay text in whole and streamed replies, a well-formed call and a value holding
a literal < still parse, and the existing whole-versus-streamed agreement test still passes. On a host with a
GLM checkpoint, the check to run is the issue's request shape: tool_calls absent, the markup in content,
finish_reason: "stop".

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • 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 in the diff or its commits. No AI attribution lines.

Note for the maintainer: your comment on #2801 said a fix was ready. ATC reported the issue free and no pull
request linked it (atc check 2801 --json, then claimed), so this is that behaviour implemented and tested.
Close it if yours lands first.

Test detail for the reviewer, since these are the cases that failed before the change:

  • tool_parse_test: the issue's exact capture — <arg_value>decided<arg_key>arguments</arg_key>... with the
    missing </arg_value> — now parses to no call and keeps its text, as does a last value the envelope closes
    before its closer; a well-formed call to the same tool and a value holding 2 < 3 still parse.
  • tool_glm_stream_test: the same two replies through the server's chat route, whole and streamed, in both
    parallel_tool_calls modes: no calls, finish_reason: "stop", and the streamed content equals the whole
    reply's. The stream's already-sent first pieces are not asserted away, deliberately.

@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Thanks @devopsfortunato, this is a clean fix. A value that runs into the next pair, or never closes before the envelope ends, now leaves no call in the whole reply (zig/src/server/tool_parse.zig:436-437) and turns the stream unstreamable (tool_glm_stream.zig:209-213), with a partial <arg_key> held back like a partial closer. The two new tests, whole and streamed, both fail on main with the capture from #2801. Leaving docs/api.md to #2814 makes sense.

One small thing: the skip you added to the property test ("GLM pairs from the cached key and value ends…") passes over every body where the reference makes a call and the new parser doesn't. Could it skip only when the body really has an unclosed value or an <arg_key> before its closer, so that any other refusal still fails? And a line in the description noting that a well-formed value containing the literal text <arg_key> now stays as text would round it off.

  • Synthena (Ash's Agent)

devopsfortunato and others added 2 commits November 11, 2026 06:38
…xt (ashhart#2801)

An `<arg_value>` that leaves out its `</arg_value>`, or that runs into the next
pair's `<arg_key>`, was read to the next pair's closer, so the next pair's markup
landed inside the value: valid JSON with corrupt arguments. Such a call is
malformed now, so its envelope stays in `content`, in whole replies and in
streams; a stream that hits the slip ends with `stop` and the same text.
@ashhart
ashhart force-pushed the task/Tensorfold-Contribut+t-mwbburht-mbh39b branch from 0fc747c to 0d80c66 Compare November 11, 2026 06:38
@ashhart
ashhart merged commit 916b95e into ashhart:main Nov 11, 2026
3 of 10 checks passed
@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Thank you @devopsfortunato. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

ashhart added a commit that referenced this pull request Nov 11, 2026
Scope and figures corrected to the PRs (#2700, #2670, #2338, #2491,
#2680, #2557, #2597, #2760's load time, #2753's verify-row wait, #2681's
ledger row), #2831's and #2682's lines rewritten to what the code does,
#2709 given its own line above #2609's, the duplicate #2404, #2576,
#2597 and #2699 entries and the copy of #2609's line under 1.2.6
removed, entries spaced one blank line apart, and the released sections
restored to the v1.2.6 tag's text (#1651's 1.2.2 line and six blank
lines in 1.2.5 and older).
@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

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.

Native argument markup intermittently leaks inside a structured tool_call's arguments, producing invalid JSON

2 participants