Correctness report · NVIDIA/hyperflare-inference #457

Raw Markdown for agents: https://autobot.eidonix.com/p/7005cddc-c25c-47e7-8278-8034fec707ac.md

Review of PR #457 — Fail untyped TML model headers at EOS and align TMLv0 grammars with TmlOutput

Lens A: correctness and consequences — every caller, every configuration the project documents, lifetimes, inactive and edge paths, state transitions, and whether existing artifacts still load.

Key findings

  1. The strict path does the N-way alternation the PR says it avoids. compile_content_headers builds a single factored payload_any subgrammar whose name is {"enum": &envelope.tools} (helios/src/grammar.rs:381-391), and the PR description justifies exactly that shape ("avoiding N-way Earley ambiguity across large tool sets"). compile_strict_tml instead emits tool_unnamed: <|content_invoke_tool_json|> (@payload_0 | … | @payload_k) <|end_message|> (helios/src/grammar/strict.rs:1599-1603), where each @payload_i is a complete wrapper schema pushed at strict.rs:1581-1586 for every active tool (server/request.rs:225-241 collects all tools when tool_choice != None). Per-token parse state therefore grows with tool count, bounded only by fixed admission limits (grammar.rs:176-181: max_grammar_size: 131_072, max_lexer_states: 32_768; composed-grammar byte cap MAX_GRAMMAR_BYTES = 262_144, grammar.rs:22, checked at strict.rs:2443-2455) — and an over-limit grammar is rejected at admission, not degraded. The only multi-tool unnamed coverage added is two tools (strict.rs:4590-4605 in strict_tml_grammar_allows_unnamed_headers_and_preamble_before_tools, and the TML_unnamed case at strict.rs:4131-4140); live verification used a single strict tool (get_weather). The 178-tool condition that motivated the non-strict fix is unmeasured with "strict": true. Fix: mirror the non-strict factorization (one wrapper whose name is an enum of active tool names) or document and enforce a strict-tool bound, plus a test at the counts the non-strict path was measured at.

  2. The EOS guard is stated over the header, but the defect users hit is "no answer was produced". AnswerState::HeaderWithoutContent is recorded only when a non-empty model header closes on <|end_message|>/<|content_model_end_sampling|> while answer == Empty (helios/src/output/tml.rs:282-288), and the error is raised only for that state (tml.rs:399-401). Emitted is set in emit (tml.rs:219, which returns early at tml.rs:207-209 when visible == 0) and in call_or_text (tml.rs:338, which returns early at tml.rs:335-337 when the call body is empty). So these still complete silently with output=[reasoning], status: "completed":

    • <|message_model|><|content_thinking|>plan<|end_message|><|message_model|>bash<|content_text|><|end_message|> → Ok
    • <|message_model|><|content_thinking|>plan<|end_message|><|message_model|><|content_invoke_tool_json|><|end_message|> → Ok The claim "malformed TMLv0 turns whose non-empty model header closes without a content-kind token and without any visible text or tool call fail at EOS" is therefore met only for the header-dropped variant. Note the PR deliberately keeps a reasoning-only turn that ends after <|content_thinking|>…<|end_message|> (tml.rs:652-653 asserts [MODEL, THINK, "t", END, TURN_END] → Ok), so an "empty answer frame" is currently intentional; that intent contradicts the stated condition and should be made explicit, or the check should key on "no answer emitted at EOS" while distinguishing the two cases (e.g. record that a frame was opened and closed empty).
  3. Residual grammar/parser mismatch, smaller than the two above but in the same direction. The new ending (answer ({restart} thinking* tool)* | tools) (grammar.rs:405; strict.rs:1616-1618) requires a <|message_model|> restart between a visible answer and a following tool call. TmlOutput accepts a tool frame directly after <|end_message|>: in State::Frame a JSON_CALL control token opens State::Body { kind: Call, model: true } with no restart (tml.rs:250-258). So <|message_model|><|content_text|>hi<|end_message|><|content_invoke_tool_json|>{"name":"bash","args":{}}<|end_message|> parses as a call but is rejected by both new grammars. It only bites requests that set a grammar, and it is the opposite direction (grammar stricter than parser) from the mismatch being fixed, but the PR title claims alignment with TmlOutput, so it is worth either fixing or stating as intentional.

Callers and reach

Configurations (models, cache, parallel layout, hardware)

Lifetimes, and the events dropped on the error path

finish() computes events from drain() at tml.rs:387 and then returns Err at tml.rs:399-401, dropping them; server/output.rs:331 sets self.finished = true before calling parser.finish(cause)? at line 333, so abort() will not re-run the parser and those events never reach the encoder. Harmless today — no event can be emitted from that path without setting Emitted, which would clear the state — but the invariant is implicit and fragile if the guard is later widened (as finding 2 asks). Worth a comment or moving the state check before drain.

Inactive and edge-case paths

Covered by the new tests and confirmed re-reading the code: empty model header ([MODEL, END]) stays Ok; non-model role frames (USER|SYSTEM|TOOL) are exempt (tml.rs:282-286 gates on model); external terminations (OutputLimit, UserStop, Cancelled, ExecutionError) are exempt via cause == Termination::Eos (tml.rs:399); a valid answer or tool call after an untyped header clears the state because emit/call_or_text set Emitted unconditionally (tml.rs:219, 338). Body::Visible kinds (text-call, tool-error, XML, image) also route through emit and clear it. The one remaining hole is finding 2 (empty body). Non-empty answer bodies and completed calls are covered by a_closed_untyped_header_allows_visible_content_and_completed_calls (tml.rs:626-639).

State and graph transitions

The new AnswerState is monotone (Empty → HeaderWithoutContent → Emitted) except that HeaderWithoutContent can be overwritten by a later Emitted, which is the intended "answer after an untyped header" behaviour and is exactly what the new test asserts for both orders. The grammar changes are a superset of the old language for tool-enabled TMLv0 ((answer | tools) ⊂ (answer ({restart} thinking* tool)* | tools)), so no previously accepted generation becomes inadmissible; I checked that direction against each ending in grammar.rs:403-406 and strict.rs:1613-1619, including require_call (unchanged, still tools) and single_call (a cap of one tool, asserted at strict.rs:4640). The added tool_unnamed rule cannot reject a tool that was accepted before, because every tool name already had its own tool_{index} rule.

Existing data and artifacts

No checkpoint, recipe, exported core, grammar cache or on-disk format is touched: the diff is four Rust files (grammar.rs, grammar/strict.rs, output/tml.rs, server/request/tml_tests.rs), with no serialization, no wire change and no tokenizer contract change. Preserved OpenAI-compatible output shapes; response.failed with server_error is the documented error path for a failed turn, so clients that already handle failures keep working (agent clients that previously saw status: "completed" will now see a failure, which is the point of the change).

Evidence gaps

Open questions

  1. Is an answer frame that opens and closes with no bytes (<|content_text|><|end_message|>) considered legitimate by the TMLv0 renderers? If yes, the PR description should say so, because it contradicts "without any visible text or tool call"; if no, finding 2 should be fixed in this PR.
  2. What is the intended tool-count ceiling for "strict": true? Without a stated bound, finding 1 can only be settled by a compile-admission test at realistic tool counts.
  3. Should a tool frame with no <|message_model|> restart after a visible answer be legal (finding 3)? The parser accepts it and the new grammars do not.

What I could not verify