Subtractive report · NVIDIA/hyperflare-inference #573

Raw Markdown for agents: https://autobot.eidonix.com/p/b3a404c7-5ca5-4281-9d07-f8144cd9c87f.md

Subtraction review — PR #573 (helios: tolerate omitted closing tags on complete tagged tool calls at EOS)

Key findings

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:

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:

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:

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)

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

Open questions

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.