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
-
The strict path does the N-way alternation the PR says it avoids.
compile_content_headersbuilds a single factoredpayload_anysubgrammar whosenameis{"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_tmlinstead emitstool_unnamed: <|content_invoke_tool_json|> (@payload_0 | … | @payload_k) <|end_message|>(helios/src/grammar/strict.rs:1599-1603), where each@payload_iis a complete wrapper schema pushed atstrict.rs:1581-1586for every active tool (server/request.rs:225-241collects all tools whentool_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 capMAX_GRAMMAR_BYTES = 262_144,grammar.rs:22, checked atstrict.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-4605instrict_tml_grammar_allows_unnamed_headers_and_preamble_before_tools, and theTML_unnamedcase atstrict.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 whosenameis anenumof active tool names) or document and enforce a strict-tool bound, plus a test at the counts the non-strict path was measured at. -
The EOS guard is stated over the header, but the defect users hit is "no answer was produced".
AnswerState::HeaderWithoutContentis recorded only when a non-empty model header closes on<|end_message|>/<|content_model_end_sampling|>whileanswer == Empty(helios/src/output/tml.rs:282-288), and the error is raised only for that state (tml.rs:399-401).Emittedis set inemit(tml.rs:219, which returns early attml.rs:207-209whenvisible == 0) and incall_or_text(tml.rs:338, which returns early attml.rs:335-337when the call body is empty). So these still complete silently withoutput=[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|>→OkThe 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-653asserts[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).
-
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.TmlOutputaccepts a tool frame directly after<|end_message|>: inState::FrameaJSON_CALLcontrol token opensState::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 withTmlOutput, so it is worth either fixing or stating as intentional.
Callers and reach
TmlOutput::finishis called throughOutputPipeline::finish(output/pipeline.rs:267-268) fromOutputPresentation::finish(server/output.rs:301-348), which is the only serving path. The newErrpropagates fromserver/output.rs:333, soEncoder::failure/response.failedis produced for/v1/responsesexactly as the new test asserts (server/request/tml_tests.rs:276-283). Verified, no other caller depends onfinish()being infallible on EOS:finishis called inabortwith the result discarded (server/output.rs:358,*_Termination::Cancelled|ExecutionError, which the new check excludes), and all other call sites are tests.- Grammar changes are reached only for TMLv0 (
grammar.rs:241-246dispatchesToolParserKind::TmlJsontocompile_content_headers) and strict tools go throughcompile_presented_strict_tools→compile_strict_tml(strict.rs:1533, dispatched fromstrict.rs:1440-1478). The non-TML recipient pathcompile_recipientstill uses(answer | tools)(grammar.rs:354), which matches the PR's stated TMLv0-only scope. call_or_textreordering (tml.rs:334-344) moves the empty-body check beforeself.call; behaviour is unchanged there (call("")previously fell through the JSON parse and returnedNone, thenvec![]), andEmittedis now set before the call so both a tool event batch and a rejected-payload-as-text answer count. No caller ofcall_or_textoutsidedrain/finishexists.
Configurations (models, cache, parallel layout, hardware)
- Model families: the failing-EOS check lives in the TMLv0 parser only; ChatML (
output/chatml.rs(not opened)), DSML (output/dsml.rs(not opened)), XTML (output/xtml.rs(not opened)), recipient (output/recipient.rs(not opened)) and tagged (output/tagged.rs(not opened)) have their ownfinishand are untouched. The grammar edits are TMLv0-only, exceptstrict.rs:1613-1619, which is insidecompile_strict_tml. So non-TML families are unaffected structurally; the PR's own limitation note ("verified through unit tests only, not live GPU") stands and is honest. - Cache schemes / parallel layout / multi-host / hardware: no change touches scheduling, prefix cache, TP/PP or device paths; the
answerstate is per-TmlOutputinstance, i.e. per served turn, and is not serialized, so cached prefix reuse cannot resurrect a staleHeaderWithoutContent. I found no cross-request or cross-turn state. OutputStartcontinuations: the check applies to all starts includingRecipientHeader/Content/ToolBody, since the condition is evaluated in the shared header/body states, andContent/ToolBodystarts go straight into a body, so the guard cannot fire spuriously for them.prompt_startis unchanged (tml.rs:86-100).
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
- CI on head
aacbca1reports no checks, so nothing in the PR is machine-verified on merge. - The three new Inkling 2 regressions (
server/request/tml_tests.rs:246-283,393-431,434-523) are all#[ignore]d and needFLARE_INKLING2_TEST_SNAPSHOT; the only unnamed-header behaviour exercised on the default path is the unit tests inoutput/tml.rsand the grammar tests. - The strict per-tool alternation (finding 1) has no test above two tools and no measurement at the tool counts the non-strict fix was measured at (178).
- Live verification is single-model (Inkling 2 on SM120) and single strict tool; the description says so.
Open questions
- 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. - 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. - 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
- Per-token parse cost of the strict N-way
tool_unnamed— that needs a benchmark or an admission test at scale, not code reading. - Any live serving behaviour on non-TML families, non-SM120 hardware, or multi-host layouts: the PR runs none and the code paths are untouched, so the risk is low but unproven.