Correctness scratchpad · NVIDIA/hyperflare-inference #573

Raw Markdown for agents: https://autobot.eidonix.com/p/669341a1-11ee-4651-b2d9-5e235c3970b6.md

#3 [high] Research summary

I reviewed PR 573 (helios: tolerate omitted closing tags on complete tagged tool calls at EOS) through the correctness lens: I read the charter, AGENTS.md, and every changed file in context — helios/src/output/tagged.rs (the shared TaggedTools/TaggedOutput state machine, both before and after), argument_tags.rs, chatml.rs, gemma_call.rs, minimax_xml.rs, pipeline.rs, docs/api.md, plus the test-only additions in helios/src/server/logprobs.rs and helios/src/server/protocol/tests.rs — and followed the callers in model/prompt.rs:226 (prepare_output), server/request.rs:230-284/500-518, server/http.rs:471-567, grammar/strict.rs:1392-1486 and server/protocol/encode.rs (not opened).

I found no blocking defect. The core design checks out: the new ToolDialect::parse_eos is implemented by all five dialects (no per-model boolean flags in shared code, consistent with the charter's "no per-model special cases" rule); confirmed is false exactly for openers that starts_call could not confirm and true for OutputStart::ToolBody, so undecided prefixes such as <tool_call>run, <tool_call>run<arg and <tool_call>run</tool still error and cannot fabricate calls; finish clears and omits for OutputLimit/UserStop/Cancelled/ExecutionError exactly as before; the in-JSON-string rejection preserves the anti-fabrication guard; and TaggedOutput::finish now counts ToolBegin events in self.calls, which is needed for correct indexes and newline trimming when a call is only emitted at finish. outer_closed correctly stops outer_tool_pending from waiting for a </tool_call> the model already wrote. Strict tools are guarded in all four dialects at the point where the strict flag is read.

Two things worth a reviewer's attention, recorded in the scratchpad: (1) the relaxation is broader than EOS for the function-tag and MiniMax dialects — parse_candidate also passes the lenient flag, so a non-strict call closed by </tool_call> without </function>/</invoke> is now accepted during ordinary streaming too (intended and documented in docs/api.md:511-524, tested, and previously an error); (2) I could not confirm from the request path that a strict: true tool always carries strict in the presented config.tools that the dialects inspect — server/request.rs:503-518 builds the presented function object without strict, and it is added only in grammar/strict.rs:1441-1448 when a strict grammar is compiled — so the "strict calls still fail" guarantee should be confirmed with a request-path test rather than hand-built configs. Details and line references are in scratchpad notes 1 and 2.

#4 [high] Correctness review conclusions for PR 573 (no blocking findings)

PR 573 review, correctness lens. Verdict: no blocking defect found; two observations to record (see note 2 for the MiniMax/function-tag broadening and the strict-flag-from-request-path caveat).

Checks performed and their outcomes:

  1. ToolDialect::parse_eos is required by the trait (tagged.rs:43-45) and implemented by all five dialects (argument_tags.rs:109, chatml.rs:30, gemma_call.rs:147, minimax_xml.rs:203, pipeline.rs:49). No per-model boolean flags added to shared code; matches charter "no per-model special cases" and AGENTS.md "No per-model special cases or flags".
  2. Anti-fabrication preserved: TaggedTools.confirmed is set from the starts_call decision (decision == Some(true)) at tagged.rs:698,721-722, and true for OutputStart::ToolBody (tagged.rs:431). finish rejects !confirmed || in_json_string (tagged.rs:317-319), so undecided openers (<tool_call>run, <tool_call>run<arg, <tool_call>run</tool) and an unterminated JSON string still error. ArgumentTags also rejects names containing <, > or whitespace (argument_tags.rs:36-38) and empty arg bodies (48-50); chatml requires at least one closed parameter plus empty rest (chatml.rs:127-129); MiniMax requires at least one closed element and no leftover text (minimax_xml.rs:178-180, 184-186); Gemma uses the brace-balanced parser and rejects trailing non-whitespace (gemma_call.rs:131-134).
  3. Non-EOS causes unchanged: finish clears and returns empty for OutputLimit/UserStop/Cancelled/ExecutionError (tagged.rs:303-312), identical to main (main tagged.rs:290-302).
  4. TaggedOutput::finish now advances self.calls by the number of emitted ToolBegin events (tagged.rs:522-529). This matters because the call index and the self.calls == 0 newline-trim branch (tagged.rs:730,763) would otherwise mis-number calls emitted only at finish. In http.rs:471-567 a request with parallel_tool_calls:false finishes the decoder with Termination::Cancelled once the tool limit is reached, so the second (unclosed) call is still dropped — semantics preserved.
  5. outer_closed (tagged.rs:275-283,292,593-596) only suppresses outer_tool_pending when the inner </function>/</invoke> closer ended the call; combined with the </tool_call> drain path in Mode::Content (tagged.rs:615-635) this avoids waiting for a closer the model already emitted. Multi-call cases are covered by the new protocol and dialect tests.
  6. docs/api.md:444-451 and 511-524 state the recovery rules and the cases that remain errors; they match the implemented guards.
  7. Tests: new unit tests cover every UTF-8 split boundary; protocol tests cover all five tagged dialects × Chat/Messages/Responses, tool_choice auto/required/named, undeclared tools, parallel_tool_calls:false, OutputLimit, UserStop and strict rejection; logprobs test covers worker/local decode and buffered/streamed Responses. PR description answers why/what/result/evidence as AGENTS.md requires and lists unrun checks honestly. Unrun: checkpoint-gated tokenizer/grammar integration tests and live GPU serving, so end-to-end tokenizer/grammar behaviour of the omitted-closer path is not evidenced — consistent with the PR's own stated limitations.

#1 [medium] Overview: PR 573 tagged EOS recovery — files and shape

PR 573 "helios: tolerate omitted closing tags on complete tagged tool calls at EOS" (open, ready for review, base main, head 09cc524, CI passed, no reviews). Files: docs/api.md (+17/-1), helios/src/output/{argument_tags,chatml,gemma_call,minimax_xml,pipeline,tagged}.rs, helios/src/server/logprobs.rs (test only), helios/src/server/protocol/tests.rs (test only). Size 9 files +1423/-70.

Core mechanism (helios/src/output/tagged.rs):

#2 [medium] Verified: MiniMax parse_candidate relaxation also applies mid-stream, not only at EOS

helios/src/output/minimax_xml.rs:200-202 parse_candidate now calls parse_body(body, tools, /*allow_unclosed_invoke*/ true), and helios/src/output/chatml.rs:127-129 gates on allow_unclosed_function, which parse_candidate (line 28) also passes as true. TaggedTools::push (tagged.rs:274-296) calls parse_candidate on the buffer up to the outer D::CLOSE; therefore a non-strict call closed by the outer </tool_call> without </invoke> / </function> is now accepted during ordinary streaming/buffered generation, not only at Termination::Eos. Before this PR that path returned Err ("tool function requires parameter or closing tag" / "unterminated XML invocation"), because parse_candidate fell through to the strict parse. This is intended per docs/api.md:511-524 and covered by tests (chatml tests case "<tool_call><function=lookup><parameter=city>Paris</parameter></tool_call>Done.", minimax test case with {close}Done.). strict tools are still rejected (chatml.rs:127 !strict, minimax.rs:170 !strict). Verification note: the strict flag consulted by these guards is the strict field of the matching entry in the presented config.tools (built in helios/src/server/request.rs:503-518 — note it does not copy tool.strict into the presented function object), so I could not confirm from the request path that a strict: true tool always carries strict in the presented definitions; TaggedTools::finish would then not see the flag. In the same crate grammar/strict.rs:1441-1448 sets function["strict"] = true on the presentation only when a strict grammar is compiled, which suggests the guard normally holds. Worth confirming with a protocol-level test (the PR's own tests construct config.tools by hand with "strict": true, and server::protocol::tests::strict_tool_wires_reach_encoder_only_after_parser_completion does exercise the real request path).