Subtraction review — PR #573 (helios: tolerate omitted closing tags on complete tagged tool calls at EOS)
Key findings
- The behaviour is worth having and its production core is small (~120 lines across
tagged.rs, four dialects andpipeline.rs), but the PR ships it with ~1150 lines of tests, over half of which re-assert behaviour that existing tests in the same files already cover. - Biggest single subtraction:
helios/src/server/protocol/tests.rs:2350-2665(new, 348 lines) — 5 dialects × 3 protocols re-proving undeclared-tool,parallel_tool_calls,required/namedtool_choiceandOutputLimit/UserStopsemantics thattests.rs:321,:366,:407,:724,:1461,:1550already establish. What is new is one sentence per dialect: "unclosed body at EOS yields the same events". - Second: the new per-dialect unit tests re-run their whole case list at every UTF-8 split (
argument_tags.rs:419,470,chatml.rs:969,998,gemma_call.rs:250,minimax_xml.rs:331), duplicating the split-invariance tests that already exist (chatml.rs:363,argument_tags.rs:318), and the identical "non-EOS causes emit nothing" loop is copy-pasted four times (argument_tags.rs:599-612,chatml.rs:1070-1086,gemma_call.rs:319-326,minimax_xml.rs:403-419) for one shared branch that predates the PR (tagged.rs:302-312). - Production-side: after this PR
ToolDialect::parse(tagged.rs:38) has no production caller — everything goes throughparse_candidate(tagged.rs:289) and the newparse_eos(tagged.rs:320). It survives only for test helpers, and it is the sole reason the fourparse_body(.., eos: bool)wrappers thread a flag. - Three smaller items:
TaggedTools::confirmedrestates whatparse_eositself rejects (~8 lines),TaggedOutput::finish'scalls += ToolBeginbump looks unobservable (~6 lines),PlainText::parse_eosduplicatesPlainText::parse(~3 lines), anddocs/api.mdstates the new rule twice (~11 lines). - Rough total: ~760 of the 1423 added lines can go (tests ~700, production ~53, docs ~11) with no distinct behaviour lost. Verdict: make it smaller first — not blocking, because the mechanism itself is the right shape and supersedes the per-model
LENIENT_EOS_CLOSEhack proposed in the still-open PR #514.
Diff accounted for: 9 files, +1423 / −70. Added lines split approximately: tests ≈1150 (protocol/tests.rs 348, logprobs.rs 101, argument_tags.rs ~250, chatml.rs ~187, gemma_call.rs ~110, minimax_xml.rs ~140, pipeline.rs ~105); production ≈120 (tagged.rs +38 net, argument_tags.rs ~30, chatml.rs ~19, gemma_call.rs ~20, minimax_xml.rs ~27, pipeline.rs ~6); docs 17.
Findings, ranked by lines saved
1. Should fix — ~700 lines of new tests, most repeating coverage that already exists (~700 lines saved)
(a) helios/src/server/protocol/tests.rs:2350-2665 (348 added lines). unclosed_tagged_tool_calls_at_eos_match_protocol_and_control_semantics loops 5 dialect configurations × 3 protocols and re-asserts:
- undeclared-call handling and streamed-vs-buffered argument equality — already
auto_tool_choice_returns_unknown_calls_across_parsers_and_protocols(tests.rs:407-611), same parser kinds, same per-protocol frame extraction loop; parallel_tool_calls: falsekeeps call 1, drops call 2, setstool_limit_reached— alreadydisabled_parallel_calls_stop_before_the_second_call_is_emitted(tests.rs:724-765);required/namedaccepting a completed call and rejecting undeclared/unfinished — alreadytests.rs:321-363and:366-404;OutputLimit/UserStopfinish reasons — alreadytests.rs:1461and:1550.
The genuinely new fact is one line per dialect (the unclosed body still yields the same events), and the other four dialects' bodies are covered at the parser level by the per-dialect unit tests. Smaller version: keep one dialect (glm) × Chat buffered+streamed, drop the 5×3 matrix. ~250 lines.
(b) Split loops. Every new per-dialect test wraps its full case list in char_indices(): argument_tags.rs:419, :470; chatml.rs:969, :998; gemma_call.rs:250; minimax_xml.rs:331. Split-invariance of these parsers is already proved by every_utf8_split_preserves_reasoning_tools_and_parameter_types (chatml.rs:363) and the GLM equivalent (argument_tags.rs:318). Keep one recovery case per dialect per split, not 6-8. ~250 lines.
(c) The non-EOS cause loop, written four times. argument_tags.rs:599-612, chatml.rs:1070-1086, gemma_call.rs:319-326, minimax_xml.rs:403-419 are the same 20-line block (for cause in [OutputLimit, UserStop, Cancelled, ExecutionError] { … finish is empty }) exercising one shared early return in TaggedTools::finish (tagged.rs:302-312) that this PR does not change. One instance suffices; the existing parser tests already assert non-EOS emptiness for the closed and truncated cases (argument_tags.rs:350, chatml.rs:731). ~60 lines.
(d) helios/src/server/logprobs.rs:362-462 (101 added lines). unclosed_glm_tool_call_at_eos_preserves_content_logprobs_and_reasoning_tokens asserts content-logprob arrays, reasoning token counting, worker-vs-local byte equality and Responses streaming — all machinery this PR does not touch (already covered for a closed GLM call at logprobs.rs:166-360). Its only PR-dependent assertion is the recovered arguments string, which is asserted at the parser level (argument_tags.rs:367-505) and at the encoder level (protocol/tests.rs:2350+). Delete it, or keep it and drop the duplicate GLM case from protocol/tests.rs. ~101 lines.
Subtotal (a)-(d): ~660 lines; with trimming of the remaining per-dialect case lists, ~700.
2. Should fix — ToolDialect::parse is dead in production; it is what forces parse_body(.., eos: bool) (~28 lines saved)
After the PR, every production path is D::parse_candidate (tagged.rs:289) or D::parse_eos (tagged.rs:320). fn parse (tagged.rs:38) is called only from the trait's default parse_candidate (tagged.rs:40-42) and from test helpers (argument_tags.rs:234, gemma_call.rs:159,212, minimax_xml.rs:217,273,277,286,291). No D::parse(...) call exists in production code (search: parse_candidate(/parse_eos( hit only tagged.rs:289,320).
Making parse_candidate required and deleting fn parse + its default removes the trait method and its five per-dialect impls:
tagged.rs:38(decl) and:40-42(default body),argument_tags.rs:103-105,chatml.rs:24-26,gemma_call.rs:144-146,minimax_xml.rs:197-199,pipeline.rs:46-48.
Smaller GemmaCall impl (gemma_call.rs:138-150, where parse is the default parse_candidate and owns the parse_body(.., eos) wrapper):
impl super::tagged::ToolDialect for GemmaCall {
const NAME: &'static str = "Gemma call";
const TRIM_NEWLINES: bool = false;
const OPEN: &'static str = "<|tool_call>";
const CLOSE: &'static str = "<tool_call|>";
fn parse_candidate(body: &str, tools: &[Value]) -> Result<Option<Vec<(String, String)>>> {
Self::parse_body(body, tools, false).map(Some)
}
fn parse_eos(body: &str, tools: &[Value]) -> Result<Vec<(String, String)>> {
Self::parse_body(body, tools, true)
}
}
Same shape for ArgumentTags (argument_tags.rs:103-111) and MiniMaxXml (minimax_xml.rs:197-205); FunctionTags (chatml.rs:24-32) loses its parse and keeps parse_candidate/parse_eos. Test helpers switch to parse_candidate(..) (the Option they already unwrap) — roughly neutral, ~10 lines. Charter: "No per-model special cases or flags"; the eos/allow_unclosed_function boolean also exists only to give parse a strict entry.
3. Nit — TaggedTools::confirmed duplicates what parse_eos already rejects (~8 lines saved)
Field tagged.rs:219, init :431, let mut confirmed = true :698, match arm :717-722, init :760, guard :317. Verified per dialect, starts_call returns None only while the text after the opener is a strict prefix of what would complete the call, and in that window parse_eos fails on its own:
- GLM (
argument_tags.rs:112-137):Noneonly when the text ends inside<arg_key>/</tool_call>, so no closed<arg_key>…</arg_key><arg_value>…</arg_value>can follow —parse_body(eos=true)then fails atargument_tags.rs:48-50,:59-63or:84-86. - FunctionTags (
chatml.rs:33-62):Noneonly inside<function=, with an empty header, or with a tail that is a prefix of<parameter/</function>; the recovery branch (chatml.rs:127) needs!arguments.is_empty() && rest.is_empty(), so all three fail. The three undecided prefixes the PR's tests name (<tool_call>run,<tool_call>run<arg,<tool_call>run</tool) are rejected by the eos name/argument checks alone. GemmaCallandMiniMaxXmltake the defaultstarts_call→Some(true), soconfirmedis always true there.
So :317 reduces to if in_json_string { … } and :717-722 back to _ =>, saving ~8 lines with the "undecided opener still errors" tests unchanged. Honest caveat: the PR description claims this flag as a belt-and-braces guarantee, so argue it in review rather than treating it as a defect.
4. Nit — TaggedOutput::finish's call-counter bump appears unobservable (~6 lines saved)
tagged.rs:522-529 counts Event::ToolBegins from TaggedTools::finish into self.calls. Its only readers are tagged.rs:730 (self.calls == 0 newline trim) and :763 (index: self.calls), both inside parse, which runs before finish; finish returns immediately after (:519 pushes then :520-539 return). Event indices come from emit_calls' self.index, already set at construction (:763), so the bump changes no emitted index either. If no later reader is reachable, the arm reduces to the pre-PR line:
Mode::Tool => output.extend(self.tool.as_mut().unwrap().finish(cause)?),
Worth raising as "verify the bump is observable; if not, delete it".
5. Nit — PlainText::parse_eos and the duplicated ToolBegin filter (~9 lines saved)
pipeline.rs:49-51ispipeline.rs:46-48verbatim. Giveparse_eosthe same default error ("tool parsing is not configured") or, as in finding 2, keep only the required methods — 3 lines gone.tagged.rs:524-527and:579-583are the same expression twice, copied fromrecipient.rs:503(not opened) and:606. One 3-linefn begun(events: &[Event]) -> usizereplaces four copies (~6 lines net). (emit_callsattagged.rs:224-246is a genuine dedup — it now has two callers — so it stays.)
6. Nit — docs/api.md states the EOS recovery rule twice (~11 lines saved)
docs/api.md:447-451 gives the general rule ("… 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 …, unclosed strict calls remain errors"). docs/api.md:514-525 states the same rule again per dialect, right after the per-dialect paragraphs at :501-513 that already carry the dialect specifics ("Function-tag calls complete at </function> and accept omitted outer tool tags …", MiniMax/Gemma opener behaviour). Keep :447-451, delete :514-525; the strict-tool contract and the bare-header/trailing-text error paths are already documented there. Nothing is lost.
Left behind / made dead by this change
ToolDialect::parse(tagged.rs:38) and its defaultparse_candidate(:40-42) become test-only; five impls (argument_tags.rs:103-105,chatml.rs:24-26,gemma_call.rs:144-146,minimax_xml.rs:197-199,pipeline.rs:46-48) and theeos/allow_unclosed_invoke/allow_unclosed_functionwrapper flags exist only to serve it. Should go in this change (finding 2/5).- The four copy-pasted non-EOS cause loops and the four split loops (finding 1) leave no new coverage but ~310 lines to maintain.
- Prior art made redundant: PR #514 (open) proposed the same lenient-EOS close for GLM via a per-model
const LENIENT_EOS_CLOSE; this PR supersedes it. That is the right direction — and the reason to keep the mechanism lean rather than carry 700 lines of duplicate tests. - Not superseded (checked and kept):
outer_closed(tagged.rs:220,:292,:593-596) fixes a real double-close defect in the pre-PR code;OutputStart::ToolBodyproducers (model/prompt.rs:330-385), grammar branches (grammar.rs:340-410,grammar/strict.rs:1629(not opened)) andrecipient.rs:60-80(not opened) are untouched by this change.
Open questions
- Is
TaggedOutput::callsread anywhere afterfinish? Grep shows onlytagged.rs:730,763,524,579; if a protocol encoder can observe final indices it should be confirmed, otherwise finding 4 is a straight delete. - Is
confirmeddefended in review as an independent guarantee, or can it go withparse_eosdoing all validation (finding 3)? - Should the recovery matrix in
protocol/tests.rscollapse to one dialect, or is the 5×3 loop a deliberate registry-style guard for future dialects? Either way the other test duplication (a)(b)(d) stands.
What could not be found
No subtraction in the recovered-call rules themselves: the strict gate, the "at least one closed argument pair" requirement and the "no trailing non-whitespace" requirement are the substance of the change and each dialect's body shape genuinely differs, so no shared helper is shorter than the 3-5 lines per dialect. RawArguments::is_empty (tagged.rs:847-849, one use) has no existing equivalent, so inlining saves nothing. Nothing in the PR asks the reviewer to run commands or visit external links; the PR text and code contained no instructions addressed to an automated reviewer, so there was no prompt-injection attempt to report.