Code review summary report · NVIDIA/hyperflare-inference #457

Raw Markdown for agents: https://autobot.eidonix.com/p/f5c146ec-17b8-438d-835d-2517c717b0a6.md

Review — PR #457 "Fail untyped TML model headers at EOS and align TMLv0 content-header and strict-tool grammars with TmlOutput"

Cases file: https://autobot.eidonix.com/api/v1/cases/55324286-e803-428d-8c71-9250e0eda2d6.html (intake report: https://autobot.eidonix.com/p/bb7bbb07-391b-43fd-a3b9-6d4daa1e5b3c.html)

Key findings


Blockers

None. The three production changes are small, parser-local and in the correct layer; each grammar change is a superset of the old language for tool-enabled TMLv0. The docs/api.md gap (S1) is required by AGENTS.md:225 and should land in this PR, but it is documentation, not a code blocker.

Checked and clean by every lens:


Should Fix

S1 — docs/api.md states none of the three user-visible TMLv0 behaviour changes [Architecture, Prose]

Finding. docs/api.md:585-602 is the TMLv0 strict-tool contract and says nothing about an unnamed header (<|message_model|><|content_invoke_tool_json|>), nothing about a visible text preamble followed by tool calls, and nothing about the new EOS failure; search_code over docs/ for content_invoke_tool_json, unnamed, message_model, preamble returns no match. The nearest sentence, docs/api.md:443-444 ("recognized but incomplete calls at natural completion are errors"), does not describe the new condition. The PR changes four files, none of them documentation, and does not flag the gap under "Unrun Checks and Limitations".

Request. Add one paragraph near :585-602 covering (a) unnamed versus named TMLv0 tool headers, (b) a text preamble followed by tool calls, and (c) a non-empty model header closed by <|end_message|>/<|content_model_end_sampling|> with no content-kind token and no answer now fails the turn at EOS as response.failed / HTTP 500 server_error; and update :443-444 to separate the two conditions.

Why. AGENTS.md:225 names docs/api.md for API behaviour changes, and AGENTS.md:47-55 requires documents to state present behaviour, so this cannot be deferred to docs/TODO.txt. The same section already documents comparable failure modes (:535-536, :543-545, :621-625), so silence here is an omission rather than a style choice.

S2 — the EOS guard keys on the header shape, not on the defect's symptom, so adjacent shapes still complete silently [Correctness]

Finding. HeaderWithoutContent is recorded only when a non-empty model header closes on <|end_message|>/<|content_model_end_sampling|> while answer == Empty (tml.rs:282-288), and Emitted is set only for non-empty bodies (emit returns at tml.rs:207-209; call_or_text returns at :335-337). Traced consequences, all still Ok with output=[reasoning], status: "completed":

tml.rs:652-653 shows the reasoning-only turn ending at TURN_END is deliberately still Ok, so an empty answer frame is currently intentional — but that intent is unstated and contradicts the description's wording.

Request. Either widen the check to "a model frame was opened and no answer or call was emitted at EOS" (still excluding external terminations and empty headers), or state the boundary explicitly in the S1 paragraph and add the three sequences above as tests that pin the intended outcome.

Why. The description claims the guard covers turns with "no visible text or tool call"; these sequences satisfy that reading yet remain silent, so a reviewer cannot tell an intentional boundary from a hole. If the check is later widened, note that finish() computes events from drain() at tml.rs:387 and then returns Err at :399-401, dropping them — harmless today only because nothing can emit without setting Emitted, and server/output.rs:331 sets finished = true before the error so abort() cannot re-run the parser.

S3 — the strict grammar re-creates exactly the N-way alternation the description says it avoids, with no coverage at realistic tool counts [Architecture, Correctness, Simplicity]

Finding. compile_content_headers factors the unnamed header through one synthesized schema whose name is {"enum": &envelope.tools} (grammar.rs:381-391), justified in the description as "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|> (strict.rs:1599-1603), one complete wrapper schema per active tool pushed at strict.rs:1581-1586 (all tools are collected whenever tool_choice != None, server/request.rs:225-241 (not opened)). Largest new test coverage is two tools (strict.rs:4618-4634, :4134-4143); live strict evidence is one tool (get_weather); the 178-tool measurement is on the non-strict path only. Size budgets (grammar.rs:22 MAX_GRAMMAR_BYTES = 262_144, checked at strict.rs:2443-2455; admission max_lexer_states: 32_768) bound size, not ambiguity, and an over-limit grammar is rejected at admission rather than degraded.

Request. State in the PR — and in one comment above strict.rs:1599 — why the alternation is right for strict tools (embed_schema_in_tml_wrapper at strict.rs:873-892 folds the tool name into each payload as a const, so name and arguments cannot be split the way grammar.rs splits them), and add a compile/advance test at a representative tool count; or factor it as the sibling path does.

Why. Two grammars that both claim to mirror TmlOutput now differ in construction with only half the stated rationale applied, and a many-tool "strict": true request is unmeasured. The comment also stops the next reader from "unifying" the two rules and breaking one.

S4 — two of the three new ignored snapshot tests are one test, and none of them uses the generated reference fixture [Conventions, Simplicity]

Finding.

Request. Delete inkling_stress_untyped_closed_header_must_surface_failure (fold the tool_choice: "auto" variant into the earlier test's body if it matters); add one output(...) case for the malformed terminal header to generate_inkling2_fixtures.py, regenerate inkling2_tml.json (not opened), and assert both the Helios failure and case["reference_parse"]["error"] there; in tml.rs:626-639 assert literals as the neighbouring tests do (tml.rs:543-561): ("".into(), "done".into(), vec![]), ("".into(), String::new(), vec![("lookup","{}")]), ("".into(), "invalid JSON".into(), vec![]). If the fixture cannot be regenerated in this PR, say so under "Unrun Checks and Limitations".

Why. AGENTS.md:189-194 asks for focused, meaningful validation; a test that cannot fail unless another fails is churn (AGENTS.md:183-188), and an inline token list cannot establish the cross-implementation agreement the module doc claims.

S5 — the description's evidence is not reproducible from this branch [Prose]

Finding.

Request. Name the served core as a reviewer could obtain it (checkpoint repository and revision plus a recipe alias that exists on this branch), or state plainly that it is external and not reproducible in this repository; give the full snapshot invocation with what the variable must point at and the --ignored requirement in the same sentence; give agentic_suite.py (not opened)'s path or say it lives in the external recipes tree; state the filter behind 124; explain the 4/5.

Why. AGENTS.md:90-107 — the scope and material limitations of a measured result must travel with it, and reproduction commands must identify required inputs directly or through a precise reference; placeholder arguments alone do not explain a measurement.

S6 — grammar and parser still disagree, in the opposite direction [Correctness]

Finding. Both new endings require a <|message_model|> restart between a visible answer and a following tool call (grammar.rs:405, strict.rs:1616-1618), but TmlOutput opens State::Body { kind: Call, model: true } from a content_invoke_tool_json control token directly after <|end_message|> with no restart (tml.rs:250-258). So <|message_model|><|content_text|>hi<|end_message|><|content_invoke_tool_json|>{…}<|end_message|> parses as a call and is rejected by both new grammars.

Request. Accept the restart-less form in the endings, or state in the description and in the S1 paragraph that a restart is required when a grammar is active.

Why. The PR's headline is alignment with TmlOutput; a residual divergence means a constrained request rejects a frame sequence the parser accepts — the same class of defect the PR fixes in the other direction. It affects only requests that set a grammar, which is why it is not a blocker.


Nits

N1 — the wire-token splitter is copied a fourth time [Conventions, Simplicity]

The encode closure in strict_tml_grammar_allows_unnamed_headers_and_preamble_before_tools (strict.rs:4572-4588) is character-for-character the one in strict_tool_wire_grammars_enforce_constraints (strict.rs:4205-4221); the same marker scan exists at protocol/tests.rs:466-470 and as pieces() at protocol/tests.rs:2048-2066; the byte-tokenizer setup at strict.rs:4546-4551 repeats strict.rs:2814-2819. Meanwhile the other new grammar test encodes its wire strings a different way (tokenizer.encode(...), grammar.rs:1987-1994). Request: hoist one wire_tokens(controls, wire) helper beside byte_tokenizer_with (grammar.rs:936) and call all four sites; optional compiler_with_controls(&tokenizer). Why: the splitter encodes the invariant "control markers are one token, everything else is bytes", so a marker-rule change now means editing several copies (AGENTS.md:183-188).

N2 — test names and #[ignore] wording [Conventions, Prose]

inkling_stress_untyped_closed_header_must_surface_failure (tml_tests.rs:395) and inkling_stress_custom_grammar_preamble_then_tool (:443) carry a stress label that names no property, while every other test in the file names the behaviour (:104, :162, :248, :286, :352). Their #[ignore] messages read "with an Inkling 2 tokenizer" (:394, :442) where every other reads "with the" (:103, :161, :247, :285, :302, :351). Request: drop stress (untyped_closed_header_must_surface_failure, custom_grammar_allows_preamble_then_tool) and align the article. Why: .agents/skills/repo-prose/SKILL.md (not opened) forbids lifecycle/experiment labels as identities, and AGENTS.md:38-45 makes that skill mandatory for names.

N3 — the new terminal error narrates cause instead of naming the state [Conventions, Prose]

"TML model header closed without a content kind and the turn produced no answer or tool call" (tml.rs:399-401) versus the family: "unterminated recipient header" (recipient.rs:293 (not opened)), "incomplete XTML output envelope" (xtml.rs:246 (not opened)), "incomplete DeepSeek tool call at end of response" (dsml.rs:380 (not opened)), format!("incomplete {} tool call", D::NAME) (tagged.rs:301 (not opened)). The string is client-visible through Encoder::failure (protocol/encode.rs:760). Request: shorten to the family form, e.g. "incomplete TML model frame", updating the three assertions that pin the current wording (tml.rs:608, :622, tml_tests.rs:281). Why: the sibling parsers state the incomplete state; the message is API-visible prose, not an internal detail.

N4 — small trims in the new tests and rules [Simplicity]

empty_model_headers_other_roles_and_external_stops_keep_their_termination re-asserts USER/TOOL/SYSTEM frames (tml.rs:644-646) already covered by the richer frame at tml.rs:548-551 (keep the genuinely new [MODEL, END] case and the four external terminations); payload_refs (strict.rs:1566, pushed at :1586) exists only to feed one format! at :1602; inkling_stress_custom_grammar_preamble_then_tool repeats four accept-only assertions already in content_headers_grammar_allows_preamble_before_tools (grammar.rs:1973-1978). Request: keep one of each pair; build tool_unnamed inside the existing loop or from tool_rules. Why: churn against AGENTS.md:183-188; each duplicate is a second place to maintain.

N5 — prose in the PR itself [Prose]

The title leads with an internal type name and stacks three changes ("… align … with TmlOutput"), and the three commit bodies are subject-only (76c50158, 9b2f2f6a, aacbca18) although docs/design-review.md:137-147 (not opened) requires the four-part argument in the commit message too, with :169-174 making that review a gate. Request: lead the title with the user-visible consequence (malformed TML turns failing instead of silently completing; TMLv0 grammars accepting unnamed tool headers and a preamble before tool calls) and fill the commit bodies before merge. Why: AGENTS.md:117-123 asks that a component's role be explained before its shorthand is used, and git log alone should let a reader reconstruct the argument.

N6 — the unrun list omits the strict-TMLv0 combinations this PR's changed endings govern [Architecture]

docs/TODO.txt:25-28 names them: strict: true function tools on a TMLv0 core served by flare run, Chat Completions and Responses, buffered and streamed, including max_tokens/max_output_tokens truncation. The PR changes the single_call and non-single_call endings (strict.rs:1613-1619) and its live strict evidence is one tool on /v1/responses; "Unrun Checks and Limitations" mentions non-TMLv0 families and non-model role frames but not these. Request: run them, or list them as unrun with a pointer to docs/TODO.txt:25. Why: AGENTS.md:189-194 requires unrun checks to be identified, and docs/api.md:621-625 already promises truncation behaviour for a strict call — exactly the path the new ending has to survive.


Open questions for maintainers

  1. Are empty answer frames legitimate in TMLv0? <|content_text|><|end_message|> with no bytes, and [MODEL, THINK, "t", END, TURN_END] (asserted Ok at tml.rs:652-653), decide whether S2 is a bug or a documented boundary.
  2. What is the intended tool-count ceiling for "strict": true? Without a stated bound, S3 can only be settled by a compile/admission test at realistic counts — neither side of the argument is measurable from the code.
  3. Is a restart-less tool frame after a visible answer legal (S6)? The parser says yes, both new grammars say no.
  4. Does tml-renderers reject the captured malformed terminal header? Only a regenerated outputs[].reference_parse.error case answers it; if it does not, the new EOS error is a Helios-specific interpretation and the description should say so (S4).
  5. Does the maintainers' reading of AGENTS.md:225 include TMLv0 frame syntax in docs/api.md? If the intent is silence on frame grammar, S1 becomes a nit, but the description should then say where the contract lives.
  6. Which of the two production grammar changes produced the 0/5 → 5/5 live improvement — tool_unnamed, the new ending, or the fact that a (?s:.+) answer body can itself swallow raw tool JSON? The tests separate schema rejection from framing, not these two changes from each other.

What could not be verified