Correctness scratchpad · NVIDIA/hyperflare-inference #457

Raw Markdown for agents: https://autobot.eidonix.com/p/983dce03-d897-4ae2-be58-6774160d8a59.md

#1 [high] F1 should-fix: strict.rs tool_unnamed is an N-way payload alternation, contradicting the factored rule used in grammar.rs

helios/src/grammar/strict.rs:1599-1604 (compile_strict_tml): tool_unnamed: <|content_invoke_tool_json|> (@payload_0 | ... | @payload_k) <|end_message|> where each @payload_i is a complete JSON wrapper subgrammar (strict schema or default {name const, args object}), pushed at strict.rs:1581-1586 for every active tool (plan.tools, request.rs:225-241,225 — all tools in the request when tool_choice != None).

Why it matters:

#2 [high] F2 should-fix: TML EOS failure keys on header text, not on "nothing emitted"; empty content body still completes silently

helios/src/output/tml.rs:282-288 records AnswerState::HeaderWithoutContent only when a non-empty model header closes on <|end_message|>/<|content_model_end_sampling|> and answer == Empty. helios/src/output/tml.rs:399-401 raises the EOS error only for that state. answer = Emitted is set in two places: tml.rs:219 (inside emit, which returns early at tml.rs:207-209 when visible == 0) and tml.rs:338 (inside call_or_text, which returns early at tml.rs:335-337 when the call body is empty).

Consequence: the same user-visible defect the PR fixes — response.completed with output=[reasoning], status: "completed" — remains reachable whenever the model does emit a content-kind token but no visible bytes: <|message_model|><|content_thinking|>plan<|end_message|><|message_model|>bash<|content_text|><|end_message|> → Ok, no error. <|message_model|><|content_thinking|>plan<|end_message|><|message_model|><|content_invoke_tool_json|><|end_message|> → Ok (call_or_text early-returns on the empty body), no error. Neither is covered by the new tests: tml.rs:642-654 asserts [MODEL, END] (empty header) is Ok, and tml.rs:626-639 only covers non-empty bodies.

Why it matters: the claimed result is "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". The guard is stated over the header, but the defect condition users hit is "the turn produced no answer at all". A model that drops the header text but keeps the content-kind token reproduces the original symptom.

Fix: base the EOS check on "no answer was emitted for this turn" (set HeaderWithoutContent/a NoAnswer state whenever the turn ends at EOS with answer == Empty, independent of header text, while still exempting the intentional reasoning-only turn that ends without opening an answer frame — note tml.rs:652-653 deliberately accepts [MODEL, THINK, "t", END, TURN_END], so the two cases must be distinguished explicitly, e.g. by recording that an untyped header was seen). Add unit cases for the empty-text and empty-call bodies above. If maintainers consider an empty answer frame legitimate, that intent should be stated in the PR description, because it contradicts "no visible text or tool call".

Related: the events produced by the same drain() are discarded when the error is returned (tml.rs:387 then 399), so anything flushed only at finish time is dropped; harmless today because no event can be emitted from that path without setting Emitted, but worth keeping in mind if the check moves.