Lens D (simplicity) review of PR #573 — helios: tolerate omitted closing tags on complete tagged tool calls at EOS
Key findings
Two should-fix items, both duplication rather than design: three of the five new ToolDialect::parse_eos implementations are byte-equivalent to a path that already exists in the same file, and the "non-EOS causes always omit" assertion is copy-pasted into four dialect test modules although it exercises one shared early-return branch that already has coverage at the protocol layer. Everything else is nits (dead resets, one garbled error string, a rule stated twice in docs/api.md, one duplicated character-class predicate, one test block that re-asserts unchanged behaviour).
The core of the change is correctly small and I found nothing to complain about there — see "Correctly small, no finding" at the end. In particular confirmed/outer_closed are single pieces of per-call state, not per-model flags, and emit_calls is a genuine dedupe.
Should fix
D1. parse_eos re-implements parse_candidate in three of five dialects — helios/src/output/chatml.rs:30-32, helios/src/output/minimax_xml.rs:203-205, helios/src/output/pipeline.rs:49-51
What is wrong. Each of these three parse_eos bodies is the same call its dialect's parse_candidate already makes, with the same arguments, so the acceptance rule for "closing wrapper omitted at EOS" is now spelled in two places per dialect and can drift.
helios/src/output/chatml.rs:27-32:
andfn parse_candidate(body: &str, tools: &[Value]) -> Result<Option<Vec<(String, String)>>> { Ok(parse_tool_candidate(body, tools, WRAPPING_NEWLINES, true)?.map(|call| vec![call])) } fn parse_eos(body: &str, tools: &[Value]) -> Result<Vec<(String, String)>> { Ok(vec![parse_tool(body, tools, WRAPPING_NEWLINES, true)?]) }parse_tool(chatml.rs:85-93) is onlyparse_tool_candidate(body, tools, wrapped_parameters, allow_unclosed_function)?.ok_or_else(|| "incomplete JSON parameter".into()). The two compositions are therefore identical, including the error string.helios/src/output/minimax_xml.rs:200-205:parse_candidateisSelf::parse_body(body, tools, true).map(Some)andparse_eosisSelf::parse_body(body, tools, true)— literally the same expression with the same flag.helios/src/output/pipeline.rs:46-51:PlainText::parse_eosrepeatsPlainText::parse's body verbatim (Err("tool parsing is not configured".into())).
Why it matters. Two spellings of one rule is where dialect behaviour silently diverges later; AGENTS.md requires focused, meaningful validation, and repository prose/design guidance asks for one statement of an invariant, not two. It is also free to remove.
Fix — the smaller version.
// chatml.rs
fn parse_eos(body: &str, tools: &[Value]) -> Result<Vec<(String, String)>> {
Self::parse_candidate(body, tools)?.ok_or_else(|| "incomplete JSON parameter".into())
}
// minimax_xml.rs
fn parse_eos(body: &str, tools: &[Value]) -> Result<Vec<(String, String)>> {
Self::parse_candidate(body, tools)?.ok_or_else(|| "XML tool call requires an invoke tag".into())
}
// pipeline.rs
fn parse_eos(body: &str, tools: &[serde_json::Value]) -> Result<Vec<(String, String)>> {
Self::parse(body, tools)
}
Secondary, optional: after the chatml.rs rewrite, parse_tool's 4th parameter allow_unclosed_function (chatml.rs:89, threaded into parse_tool_candidate at chatml.rs:99 and tested at chatml.rs:127) has only true call sites through parse_candidate/parse_eos, and false only from parse (chatml.rs:25) and two test calls (chatml.rs:407-415). Whether the parameter itself can go depends on whether D::parse must stay strict for its other callers — that should be checked before deleting it; the duplicated body above can go regardless.
Keep parse_eos a required trait method with no default: the explicit per-dialect opt-in is exactly what prevents fabrication from undecided openers, and a default implementation would silently make every dialect lenient. Note that argument_tags.rs:25-110 is the counter-example that gets this right — its eos flag carries checks that do not exist on the streaming path (name character set at :36, non-strict requirement at :45, non-empty body at :48), so it is not duplication.
D2. The "non-EOS causes always omit" loop is copy-pasted into four dialect test modules and proves one shared branch — argument_tags.rs:598-612, chatml.rs:1069-1086, gemma_call.rs:308-324, minimax_xml.rs:401-419
What is wrong. Four identical 13-line blocks, differing only in dialect and payload:
// Non-EOS termination causes always omit unclosed calls.
for cause in [Termination::OutputLimit, Termination::UserStop,
Termination::Cancelled, Termination::ExecutionError] {
let mut parser = /* dialect */::new(/* config */);
parser.push(Input::Text(/* one complete unclosed call */)).unwrap();
assert!(parser.finish(cause).unwrap().is_empty(), "{cause:?}");
}
All four exercise the same code: TaggedTools::finish's single early return, tagged.rs:302-312, which is dialect-independent (it matches on the cause before any dialect function is reached).
Why it matters. They add no coverage that a single test cannot give, they are already redundant with existing tests, and they will have to be edited four times if that branch ever changes.
Coverage that already exists and overlaps:
chatml.rs:867-900(terminal_cause_preserves_incomplete_call_errors_and_never_fabricates_calls) assertsCancelled,ExecutionError,UserStopandOutputLimitomission for the function-tag dialect.helios/src/server/protocol/tests.rs:2606-2631(step 5) assertsOutputLimitomission of a structurally complete unclosed call, including the finish reason, for all five dialects across Chat, Messages and Responses; steps 6 (tests.rs:2633-2660) do the same forUserStop.
Fix — the smaller version. Delete the four loops. If parser-level Cancelled/ExecutionError coverage is wanted for every dialect, replace them with one test in tagged.rs that drives TaggedTools with a single dialect (the branch is dialect-generic), or one shared helper invoked once per dialect with a one-line payload table — not four hand-written copies. Keep the strict-tool and partial-value assertions in those tests (chatml.rs:1024-1068, gemma_call.rs:294-306), which do prove new behaviour.
Nits
D3. Dead state resets in TaggedTools::finish — helios/src/output/tagged.rs:313-316
let body = std::mem::take(&mut self.buffer);
self.search_from = 0;
let in_json_string = std::mem::replace(&mut self.in_json_string, false);
self.escaped = false;
search_from is only ever read as an index into self.buffer (tagged.rs:258-259, 274, 287-288, 291) and escaped only feeds the in-string scan that runs under in_json_string (tagged.rs:261-267); with the buffer taken and in_json_string consumed into a local that is read on the next line, neither reset has a reader. The in_json_string replace must stay — it is read at tagged.rs:317. Delete lines 314 and 316, or, if the intent is to leave the parser usable after finish (a contract ToolCallParser does not state), say so in one comment; per repo-prose (.agents/skills/repo-prose/SKILL.md:38-39 (not opened)) a comment must name the invariant, not leave the reader guessing.
D4. Garbled error string — helios/src/output/gemma_call.rs:127-129
Err("incomplete strict Gemma call tool call".into()) reads as the generic format at tagged.rs:318 ("incomplete {} tool call", D::NAME = "Gemma call") with "strict " spliced in, doubling "call", and it does not say what is missing. Fix: name the missing condition, e.g. "strict Gemma call requires <tool_call|>". Align with argument_tags.rs:46, which is at least grammatical ("incomplete strict GLM tool call") but could likewise say "strict GLM call requires </tool_call>". Citation: repo-prose SKILL.md:13-14 ("state behavior, invariants, interfaces … directly") and AGENTS.md:43-50 (required prose review).
D5. The recovery rule is stated twice in docs/api.md — docs/api.md:447-451 and docs/api.md:514-525
The general statement ("At natural completion, tagged tool parsers accept a non-strict call whose inner arguments are structurally complete and self-delimited when only its closing wrapper tag is omitted; undecided openers, bare headers without a closing argument delimiter, unclosed arguments, trailing text, and unclosed strict calls remain errors.") is restated per dialect at 514-525, whose closing sentence ("Bare headers without a closing argument delimiter, undecided openers, unclosed arguments, strict calls missing their wire closer, and calls cut off by output limits or stop sequences are never recovered.") repeats 449-451 almost word for word. Fix: keep the specific per-dialect paragraph (it names the wire closers, which is the information the reader needs) and reduce 447-451 to the truncation/omission fact it already carries plus a pointer, or drop the restatement at 522-525. Citation: SKILL.md:26-29 — "Documentation is a present-state specification, not a changelog. Replace stale claims instead of layering history on top."
D6. The tool-name character rule is spelled twice — helios/src/output/argument_tags.rs:36 and :119
name.chars().any(|c| c == '<' || c == '>' || c.is_whitespace()) repeats the terminator predicate starts_call uses at argument_tags.rs:119 (text.find(|c: char| c == '<' || c == '>' || c.is_whitespace())). Fix: one fn name_char(c: char) -> bool used by both, so the definition of a legal GLM function name exists once.
D7. One new test block asserts unchanged behaviour — helios/src/output/pipeline.rs:1418-1435
The plain-text </think> block checks that <tool_call>run<arg_key>… stays reasoning and yields no tool call when the close delimiter was not the control token. That is the pre-existing rule (see the paragraph at docs/api.md:488-499), and unconfirmed-opener rejection is covered by the undecided-prefix cases the PR adds elsewhere. Either drop it, or keep it and say in the comment that it guards against EOS recovery firing on an unconfirmed opener — as written, the comment describes the dialect rule, not what the new code could break. Low value either way; the token-gated block above it (pipeline.rs:1381-1416) and the Gemma block (pipeline.rs:1437-1450) do prove new behaviour.
Correctly small — checked, no finding
Stated so the findings above are not read as "the design is over-built":
helios/src/output/tagged.rs:225-245:emit_callsis a real removal — the same enumerate/flat_map block lived insidepushand is now shared withfinish(tagged.rs:298,:321).tagged.rs:219(confirmed): not a second decision path. It records the verdictD::starts_callalready produced (decision == Some(true)) and is set true attagged.rs:431forOutputStart::ToolBodybecause that mode begins inside a confirmed body. No new predicate and no per-model flag, consistent with the charter's "keep the runtime small and model-agnostic … shouldn't accumulate per-model branches".tagged.rs:220(outer_closed): fixes a real defect (outer pending set even afterD::CLOSEwas consumed) with one bool mirroring the tuple element already computed attagged.rs:275-283. It cannot be derived fromD::FUNCTION.is_some(); the information is genuinely per-call.tagged.rs:520-529: advancingself.callsforToolBeginevents emitted duringfinishmakes the index consistent with the push path (tagged.rs:579-583) rather than adding a second counting scheme.- Each new
parse_eosis 1–5 lines apart from the duplication above; none adds a parsing engine. Rejecting the "just callparseat EOS" alternative is correct, and the reason is visible in code:TaggedOutput::finishpromotes undecided openers toMode::Tool. - New tests drive the production entry points (
OutputPipeline, decoder/logprobs, protocol encoders) rather than source text, which is what AGENTS.md asks for.
Open questions / not verified here
- Whether
D::parsestill needs its strict (non-lenient) behaviour for callers other thanparse_eos— this decides whetherchatml.rs'sallow_unclosed_functionparameter can be deleted outright after D1, or must stay. A grep of::parse(overhelios/src(outside tests) settles it; I did not resolve it conclusively. - D2's claim that the four loops are fully redundant rests on
tests.rs:2606-2660running for every dialect; the dialect table there is parameterised (glm,qwen,mimo,gemma,minimax), and the test was reported passing, so the coverage claim holds at the protocol layer. Parser-levelCancelled/ExecutionErrorfor the non-function-tag dialects would be lost — that is one shared branch (tagged.rs:302-312), so one dedicated test replaces four.