Correctness review — PR 573: helios: tolerate omitted closing tags on complete tagged tool calls at EOS
Link: https://github.com/NVIDIA/hyperflare-inference/pull/573 · head 09cc524, base main, 9 files +1423/−70, CI green, no prior reviews.
Key findings
- No blocking correctness defect found. Every changed file was read in context, and each guarantee the PR claims survives the code: undecided openers still error, non-EOS terminations still omit and clear, strict tools are still rejected, and calls emitted only at
finishare now correctly indexed and counted. - Nit — the relaxation is wider than "at EOS".
parse_candidatealso passes the lenient flag for the function-tag and MiniMax XML dialects, so a non-strict call terminated by the outer</tool_call>without</function>/</invoke>is now accepted during ordinary streaming/buffered generation, not only atTermination::Eos(helios/src/output/chatml.rs:28,127-129;helios/src/output/minimax_xml.rs:200-201). This is intended and documented (docs/api.md:511-524) and tested, but it changes previously-failing requests mid-stream and should be called out in the title/changelog framing, which says "at EOS". - Nit — dialect-vs-EOS asymmetry in behaviour. For GLM argument tags and Gemma the lenient path only runs at EOS (
argument_tags.rs:107,109-111;gemma_call.rs:147,159), while for Qwen/MiMo function tags and MiniMax it runs at the outer closer too. That asymmetry is a modelling choice, not a bug, but it is undocumented as an asymmetry — the docs describe both as "recovery for an omitted closer" without saying the function-tag/MiniMax path also fires without EOS. - Two caveats I could not settle without tests are listed under Open questions; the "strict flag is visible to the dialects" caveat did resolve in the code's favour (see Verified non-issues #5).
Change map (what was checked in context)
helios/src/output/tagged.rs— new required trait methodparse_eos(:43-45), newTaggedTools.confirmed(:219) andouter_closed(:220), sharedemit_calls(:225-245),pushrecords which closer ended the call (:274-296),finishrewritten for EOS (:302-322),TaggedOutput::finishcounts emittedToolBeginevents (:519-529),outer_tool_pendinggated onouter_closed(:593-596),confirmedderived fromstarts_call(:695-722) and set true forOutputStart::ToolBody(:428-436).argument_tags.rs(ArgumentTags::parse_body(…, eos):25-95,parse_eos :109-111),chatml.rs(parse_tool_candidateallow_unclosed_function:127-129,parse_eos :30),gemma_call.rs(:138-160),minimax_xml.rs(parse_bodyallow_unclosed_invoke:145-188,parse_candidate :200-201,parse_eos :203-205),pipeline.rs(PlainText::parse_eos :49),docs/api.md(rules at:444-451,:511-524); test-only changes inserver/logprobs.rsandserver/protocol/tests.rs.- Callers followed:
model/prompt.rs:226-386(prepare_output→OutputConfig.content.tools),server/request.rs:230-284and:500-518(strict tool plan and presented tool objects),grammar/strict.rs:1392-1486(presented strict tools),server/http.rs:471-567(finish/cancel path aroundparallel_tool_calls: false).
Verified non-issues (with why they hold)
- Anti-fabrication at EOS.
finishtakes the body, resetssearch_from/in_json_string/escaped, and rejects!confirmed || in_json_stringbefore delegating (tagged.rs:313-320).confirmedisdecision == Some(true)only (:721), so<tool_call>run,<tool_call>run<arg,<tool_call>run</tool(wherestarts_callreturnsNone) still yieldErr("incomplete … tool call").confirmedis true when the parser started inside a tool body (:431), which is the correct state forOutputStart::ToolBody. - Dialect-level structural guards. GLM requires a name without
<,>, or whitespace and a non-empty body (argument_tags.rs:33-50); function tags require at least one closed parameter and an empty remainder (chatml.rs:127-129); MiniMax requires at least one closed element and no leftover text when the invocation is unclosed (minimax_xml.rs:178-180,:184-186); Gemma uses the brace-balanced parser and rejects trailing non-whitespace (gemma_call.rs:131-134). No dialect accepts a bare header. - Non-EOS terminations unchanged.
OutputLimit/UserStop/Cancelled/ExecutionErrorclear the buffer and return no events (tagged.rs:303-312), matching the pre-PR behaviour;http.rs:471-567still finishes withCancelledwhenparallel_tool_calls: falsehits the call limit, so an unclosed second call is dropped, not recovered. - Call indexing at finish.
TaggedOutput::finishadds the number of emittedToolBeginevents toself.calls(tagged.rs:522-529), which is what keeps the index (:763) and theself.calls == 0newline-trim branch (:730) correct when the only call is emitted during finish. Without it a recovered call would be numbered 0 again and newline trimming would be wrong.pushcounting at:579-583andfinishcounting at:524-528cover disjoint event sets, so there is no double count. strict: truereally is visible to the dialects (resolves my earlier caveat).server/request.rs:503-518builds the presented function object withoutstrict, butgrammar/strict.rs:1437-1449injectsfunction["strict"] = trueinto that sameOutputConfig.content.tools(compile_presented_strict_tools, reached fromrequest.rs:284withoutput.as_mut().map(|o| &mut o.content)). For the dialects whose strict grammars are unsupported the request never reaches the parser at all:strict.rs:1482-1484returnsErr("strict function tool schemas are not supported for {other:?} tool syntax"), which coversGemmaCallandMiniMaxXml(model/contract.rs:67(not opened)). So a strict tool cannot silently be recovered throughparse_eos's non-strict path, andargument_tags.rs:44-47,chatml.rs:113,127,gemma_call.rs:147-159,minimax_xml.rs:166,170all consult a flag that is actually set.outer_tool_pending. It is now set only whenD::FUNCTION.is_some() && !outer_closed(tagged.rs:593-596), whereouter_closedis recorded from whether the outerD::CLOSEor the inner function closer terminated the candidate (:275-283,:292). This stops the parser from waiting for a</tool_call>the model already wrote while preserving the wait when only</function>/</invoke>was seen — consistent with the</tool_call>drain path in Mode::Content.- Charter / AGENTS.md fit. The new behaviour is a shared trait method implemented per dialect, with no per-model booleans in shared code (
tagged.rs:43-45plus five impls), matching the charter's "keep the runtime small and model-agnostic … shouldn't accumulate per-model branches" (charter line 12) and AGENTS.md's no-per-model-flags rule. Documentation was updated in the same PR (docs/api.md:444-451,:511-524) and matches the implemented guards.
Findings
Nit 1 — lenient path fires during streaming, not only at EOS (function tags, MiniMax XML)
helios/src/output/chatml.rs:28,127-129 and helios/src/output/minimax_xml.rs:200-201 pass the lenient flag from parse_candidate, which TaggedTools::push calls at the outer closer (tagged.rs:284-296). Consequence: <tool_call><function=lookup><parameter=city>Paris</parameter></tool_call>Done. now succeeds during ordinary generation, where it previously failed with "tool function requires parameter or closing tag" / "unterminated XML invocation". Why it matters: this is a request-visible semantic change outside the "at EOS" contract in the title, and it is the only place where a missing inner closer is tolerated without EOS. It is intended and documented (docs/api.md:511-524) and covered by tests, so no code change is required — suggest stating it explicitly in the PR title/changelog ("… at EOS and at the outer closer for function-tag and MiniMax dialects").
Nit 2 — dialect asymmetry is documented as uniform
GLM argument tags and Gemma recover only at EOS (argument_tags.rs:106-111; gemma_call.rs:147-159), while function tags and MiniMax also recover at </tool_call>. docs/api.md:511-524 describes the recovery rules per dialect but does not flag that two of the four dialects also recover without EOS. Fix: one sentence in docs/api.md (or a table column) noting which dialects tolerate the omitted inner closer at the outer closer.
Open questions / could not be verified
GemmaCall::parse_eosindexesremove(0)(gemma_call.rs:159:let (name, arguments) = GemmaCall::parse(body, tools)?.remove(0);). IfGemmaCall::parsecan ever return an empty vector this panics rather than erroring. I could not re-readGemmaCall::parsein the final pass to confirm the invariant "exactly one call orErr"; a unit test assertingparse_eoson"", on a bare header, and on a{}-only body returnsErr(not a panic) would settle it. Nothing in the PR's listed tests obviously targets the empty-vec case.- End-to-end tokenizer/grammar behaviour of the omitted-closer path is unevidenced. The PR states that checkpoint-gated integration tests (
FLARE_*_TEST_SNAPSHOT,reasoning_delimiters,glm_frontend,parser_start),FLARE_TEST_TEMPLATE_DIR-gated tests, and live GPU serving were not run. Verification is therefore at the output-parser, decoder/logprobs and protocol-encoder layers only; a served request on at least one GLM and one Qwen/MiMo configuration would be needed to claim the wire-level result. - No finding against the test-only changes in
server/protocol/tests.rsandserver/logprobs.rs; they exercise the same states the code guards, and I found no test asserting behaviour the code does not implement.
Verdict: no blocking issues; no should-fix issues; two documentation/framing nits and two open questions.