Skip to content

Contain nested calls within legacy DSML envelopes - #684

Merged
ashhart merged 1 commit into
ashhart:mainfrom
akol1:fix/dsml-envelope-containment
Oct 12, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
akol1:fix/dsml-envelope-containment

Conversation

@akol1

@akol1 akol1 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

What this changes

Fixes legacy <|DSML|tool_calls> containment in whole parsing, final completion and streaming. Nested XML/JSON call-looking payloads remain arguments or unfinished text, never independent executable calls.

  • Complete outer calls emit once, only after validation; incomplete/malformed outer envelopes cannot promote nested calls.
  • Preserves adjacent existing XML, wrapped JSON, GLM, Gemma and namespaced legacy envelopes, ordered indices and one-call quotas. Rejected closed envelopes and literal < prose cannot swallow later valid calls.
  • Valid bare JSON calls still treat literal DSML marker strings as argument data.
  • Existing streaming tests are extracted into tool_stream_test.zig to keep production modules below 600 lines; their assertions are retained.
  • No new V4.1 tag format, model types, family/backend registration, templates or model-support claims. No dependency on another open PR.

Before / after

Clean upstream whole and SSE HTTP replies incorrectly promoted a complete nested <tool_call> inside an unfinished DSML envelope into lookup({}). A valid outer envelope produced its literal q argument in whole replies but streamed the nested empty call instead.

Freshly built scripted HTTP server now agrees in whole/SSE replies: incomplete outer produces zero calls; valid outer produces exactly one call with literal nested text. Mixed formats, malformed/unoffered middle envelopes, literal less-than prose and quota cases retain the exact expected calls and arguments. Review-discovered regressions were reproduced over HTTP, corrected and kept as consumer regression cases before publication.

Receipt

  • Base e7c523eb; candidate 6c82f740. Apple M3 Ultra, macOS 26.6.2, Zig 0.17.0. Model-free scripted engine uses the real HTTP server; no checkpoint, MLX or PyTorch.
  • zig build test test-golden -Dcpu=apple_m1 --summary all: 143/143 steps succeeded. Final run executed 272 checks, 0 failures, 0 new skips: 136 server checks each through Metal and CUDA-host roots. Unchanged targets were cached. The unchanged clean-base host run separately passed 1290 checks with 2 dependency skips; those are inherited, not claimed newly executed.
  • Whole parser target: 20 passed, then cached unchanged in the final run.
  • Frozen HTTP corpus: 309/319 equal, 10 inherited known differences, 0 unexpected differences, unchanged from the clean base.
  • Actual final HTTP smoke: 46 scenarios passed — 19 whole/SSE pairs plus 8 parallel_tool_calls:false cases, asserting call counts, order and exact argument values. Includes unfinished/valid/malformed outers, unfinished inner literals, adjacent formats in both orders, unoffered JSON/XML, empty/malformed closed XML and literal < prose.
  • Permanent tests cover exhaustive byte split points, byte-by-byte and repeated feeds, closeCall, whole/SSE consumers with incremental/batched delivery, release of preparing state and quota precedence.
  • zig fmt --check passed. Lean checker: 534 inherited findings, exactly pinned baseline; zero added findings. Exit 1 is explicitly not a clean checker result. Source/test file limits are respected.
  • Specialist review: all concrete findings corrected; final review reports no remaining blockers. Complete public tree, outgoing authorship/history and this receipt scrubbed; existing notices retained.
  • Not run: a live checkpoint/model gate, CUDA GPU execution, other Metal hardware. This shared text-parser change does not alter model arithmetic or lane rounds; served decode/prompt/model exactness claims are intentionally absent.
  • Residual existing protocol limit: literal outer-close-tag ambiguity remains governed by the legacy parser, not a new escaping protocol. Completed envelopes use request-arena parsing allocations; no GPU work or model loader is added.

Checklist

  • Existing lane rounds, drafts, arithmetic and backend callers unchanged.
  • Failure demonstrated before; whole/SSE consumer behavior demonstrated after.
  • Tests cover containment, transitions, malformed input, ordering and quotas, not source-text wiring.
  • Unrun platforms and cached test counts stated explicitly.
  • Single-line comments and source-file limits; zero added lean findings.
  • No private identities, hosts, paths, credentials, family fixtures or attribution trailers in the public contribution.

@ashhart
ashhart merged commit 2eafa4c into ashhart:main Oct 12, 2026
2 checks passed
@ashhart

ashhart commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Thank you, @akol1. This is careful work, and the tests pin every edge you listed. Your commit 6c82f7405 landed in 1.0.8 under your name, so GitHub shows this PR as merged.

What we checked:

  • With tool_parse.zig and tool_stream.zig as they were before your change, six server tests (three in the consumer suite, three in tool_stream_test.zig) and three parse tests fail. With it, test-server-cpu passes 148/148 and the parse tests 20/20.
  • zig build test passes 599/599 on Linux, and the Mac host suites pass apart from the Neural Engine test our sandbox always blocks.
  • On Nemotron, served on an M5 Max and on a GB10, six tool prompts gave the same calls, arguments, prose and token SHAs before and after your change, whole and streamed, with the same number of streamed argument pieces. That covers parallel and single calls, a search call, prose with no call, a code-first reply and a streamed /v1/messages tool_use.

Two changes on our side, in commits after yours:

  • stream_preflight_test.zig went past our 600-line limit once your tests met the thinking-budget tests from Reject unsupported thinking budgets before submission #649, so your five consumer tests moved unchanged to stream_dsml_test.zig, and the helpers they share became pub.
  • The CHANGELOG line names two behaviour changes that reach every model with tools: a streamed reply that starts with {, [ or a code fence gets its calls whole at the end instead of as argument deltas, and a whole reply that is one bare JSON call keeps any tag text in its arguments. The 1.0.8 notes list the streamed one under behaviour changes.

One idea for a follow-up, if you are interested. When the streamer meets a < with no later < or >, it records that position and rescans the rest of the reply from there on every feed, so a long reply with one stray < rescans its tail each round. It is small today, but a cursor past that < would keep the scan linear.

BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
… move)

stream_preflight_test.zig passed 600 lines once ashhart#684's tests met the candidate's thinking-budget tests; the five DSML tests and their three constants move unchanged, and the helpers they share (TestText, CallEngine, Seen.content, sendWith) become pub.
BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
@ashhart ashhart mentioned this pull request Oct 14, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
… move)

stream_preflight_test.zig passed 600 lines once ashhart#684's tests met the candidate's thinking-budget tests; the five DSML tests and their three constants move unchanged, and the helpers they share (TestText, CallEngine, Seen.content, sendWith) become pub.
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
ashhart#684 landed above as 7684087fe (the author's commit, rebased onto this candidate). This keeps the PR's own head commit in the history, with no change to the tree.
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