Skip to content

Hardening: tool-call parsing, streaming and grammar compiles - #4378

Merged
ashhart merged 6 commits into
mainfrom
lead/harden-protocol
Nov 22, 2026
Merged

ashhart merged 6 commits into
mainfrom
lead/harden-protocol

Conversation

@ashhart

@ashhart ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Hardening of streamed protocol parsing, tool calls and grammar compilation, from an internal review:

  • Tool-call parsing bounds every slice, keeps markup inside JSON strings as data, and validates arguments (non-finite numbers, nested $ref schemas, required properties) before emitting them.
  • Streaming parsers stop rescanning text they have already consumed.
  • MiniMax tool grammars use matching constants and a free-form body only for non-strict calls; strict schemas stay constrained.
  • Abandoned grammar compiles release their worker slot, and budget work is cancelled.
  • Responses and Anthropic requests reject out-of-range or wrong-type fields instead of accepting them.

Two follow-up commits move protocol helpers and a metrics test into their own files (600-line cap) and remove a shadowed name. Covered by host tests for tool parsing, grammar and the Responses routes.

- Harden streaming protocol parsing, schema checks, and model-family tool handling.
- Cancel abandoned grammar budget work and release worker slots without moving cleanup onto callers.
- Verify grammar ownership regressions and the real xgrammar v0.2.8 budget gate.
- Avoid a Zig local-name shadow in Responses reasoning translation.
- Keep strict MiniMax schemas constrained while using a free-form body for non-strict calls.
- Exercise real MiniMax element syntax, arbitrary properties, and parallel calls through xgrammar.
…ayed thought's own bytes

The streamed envelope closer (tool_json_close.Closer) stepped past a '<' at the
end of a feed whose '</tool_call>' had not fully arrived, and never looked at
it again; it also decided JSON or not before the payload's first byte arrived
and scanned a non-JSON payload's later feeds as JSON. A <tool_call> envelope
the stream buffered (after a DSML block, or a rejected call) then never closed
and its calls were lost, while the whole reply kept them. It now decides on
the first non-blank byte, searches a non-JSON payload for the closer as text,
and stops at a partial closer until the next feed.

A replayed reasoning item's text went into an assistant message as a slice of
the buffer the next reasoning item reused, so later items overwrote it; the
message now takes a copy.
@ashhart
ashhart force-pushed the lead/harden-protocol branch from 69acdcb to db6d552 Compare November 22, 2026 10:31
@ashhart
ashhart merged commit 86ae2a5 into main Nov 22, 2026
10 of 11 checks passed
@ashhart
ashhart deleted the lead/harden-protocol branch November 22, 2026 10:31
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.

1 participant