Subtractive scratchpad · NVIDIA/hyperflare-inference #573

Raw Markdown for agents: https://autobot.eidonix.com/p/e9d469d2-6949-42a2-9308-5c9b9d1ac5f4.md

#1 [high] Blocking: ~700 lines of new tests re-prove behaviour existing tests already cover

Change size: 9 files, +1423/−70. Production code is ~120 lines (tagged.rs +66/−28, argument_tags +280 incl. tests, chatml +206, gemma +130, minimax +167, pipeline +108 — of these only ~25/25/12/25/6 lines are non-test). ~1150 added lines are tests, ~365 of them in one new test.

Duplication with tests already on main:

#2 [high] Should fix: ToolDialect::parse is now dead in production; parse_eos adds a required method on top of it

After the PR every production path goes through parse_candidate (tagged.rs:289) or the new parse_eos (tagged.rs:320). ToolDialect::parse (tagged.rs:38) is referenced only by the trait's default parse_candidate (tagged.rs:40-42) and by tests:

#8 [high] Should fix: logprobs test (+101) asserts machinery the PR never touches; totals

The claim in the PR description — "across buffered and streaming Chat Completions, Messages, and Responses APIs" — adds a 101-line test in helios/src/server/logprobs.rs:362-462 unclosed_glm_tool_call_at_eos_preserves_content_logprobs_and_reasoning_tokens.

Every assertion in it is about machinery the PR does not touch: content logprob arrays, reasoning-token counting, worker-vs-local decoding, Responses streaming. The only PR-dependent part is assert_eq!(response["output"][2]["arguments"], r#"{"text":"ok"}"#) (logprobs.rs:440-442) — the same GLM EOS recovery already asserted per-split in argument_tags.rs:367-505, at the encoder level in protocol/tests.rs:2350+, and with logprobs already covered for the closed GLM call by the existing decoder tests (logprobs.rs:188-360). The test's four-way (worker, streaming) loop multiplies one fact by 4.

Smaller version: nothing; delete the test, or keep it and delete the equivalent GLM case from protocol/tests.rs. Save ~101 lines.

Overall totals for the report:

Not a finding (checked, keep): the outer_closed field at tagged.rs:220/292/593-596 is 3 lines and fixes a real double-close bug in the pre-PR code — necessary.

#9 [high] Research summary

Reviewed PR #573 (helios: tolerate omitted closing tags on complete tagged tool calls at EOS; 9 files, +1423/−70) through a subtraction lens, reading each changed function in context plus the tests and docs it supersedes.

The behaviour itself is justified and small (~120 production lines across tagged.rs, argument_tags.rs, chatml.rs, gemma_call.rs, minimax_xml.rs, pipeline.rs, plus 17 doc lines), but the change carries ~1150 lines of tests, most of which repeat coverage that already exists in the same files. My headline finding is that roughly half the diff — about 700 lines of tests, 53 lines of production plumbing and 11 lines of docs, ~760 total — can go with no loss of a distinct behaviour: the one new test in server/protocol/tests.rs re-asserts undeclared-tool, parallel_tool_calls, required/named tool_choice and OutputLimit/UserStop semantics that four existing tests (tests.rs:320, 365, 407, 723) already cover for the same five dialects; the identical "non-EOS causes emit nothing" loop is copy-pasted into four unit tests; and every new per-dialect test re-runs its whole case list at every UTF-8 split, which the existing split-invariance tests already establish.

On the production side the clearest subtraction is that ToolDialect::parse is now dead in production — after this PR every path goes through parse_candidate or the new parse_eos, and parse survives only for test helpers — so making parse_candidate required removes a trait method, its default and five impls, and collapses the four parse_body(.., eos: bool) wrappers the PR had to add. Secondary items: TaggedTools::confirmed duplicates what parse_eos itself already rejects (I verified the undecided-prefix cases per dialect), the new calls += ToolBegin bump in TaggedOutput::finish appears unobservable, and docs/api.md states the new rule twice.

#10 [high] Coverage note: what was examined, what is minimal, and non-findings

Files read in full or in the changed regions, at PR head 09cc524:

Approximate added-line split (from the diff): tests ≈1150 (protocol/tests.rs 348, logprobs.rs 101, argument_tags 250, chatml 187, gemma 110, minimax 140, pipeline 105); production ≈120 (tagged.rs 38 net, argument_tags 30, chatml 19, gemma 20, minimax 27, pipeline 6); docs 17.

Keep, verified necessary (not findings):

Deliberately not flagged:

#3 [medium] Nit: docs/api.md states the EOS recovery rule twice (~11 lines)

docs/api.md adds the same rule twice:

Smaller version: keep 447-451 (it belongs with the parser overview) and delete 514-525; add nothing. The per-dialect exceptions the deleted block repeats ("strict calls missing their wire closer") are covered by the strict tool contract already documented, and the bare-header/trailing-text cases are the same error paths named in 447-451. Save ~11 lines.

#5 [medium] Should fix: TaggedTools::confirmed duplicates what parse_eos checks (~8 lines)

confirmed (helios/src/output/tagged.rs:219 field, :431 init, :698 let mut confirmed = true, :717-722 decision => arm, :760 init, :317 guard) adds ~8 lines and changes the starts_call match from _ => to decision =>. It is redundant with the eos-side validation, verifiable case by case:

starts_call returns None for a dialect only while the text after the opener is still a prefix of what would complete the call:

So the guard at tagged.rs:317 (!self.confirmed || in_json_string) can drop the confirmed term: parse_eos already refuses every body that an undecided opener could produce. Everything else in TaggedTools::finish stays. Save ~8 lines plus 2 changed match arms; tests unchanged and still passing (the "undecided opener still errors" assertions remain true via parse_eos). Caveat to state honestly in the report: the flag is a belt-and-braces guarantee claimed explicitly in the PR description, so this is a simplification to argue in review, not a defect.

#6 [medium] Nit: parse_body(eos: bool) plumbing across four dialects (~15 lines)

Four parallel .._body(body, tools, flag) wrappers were created so parse and the new entry point share one body:

#4 [low] Nit: duplicated ToolBegin counting and PlainText::parse_eos (~9 lines)

helios/src/output/tagged.rs:524-527 and 579-583 are the same expression twice, copied from the pattern already in the repo at helios/src/output/recipient.rs:503 and 606: events.iter().filter(|event| matches!(event, Event::ToolBegin { .. })).count() Replacing the four copies with one 3-line fn begun(events: &[Event]) -> usize (in output.rs next to Event) removes ~6 lines net and one duplicated pattern; nothing else changes. Also: TaggedTools::emit_calls (tagged.rs:224-246) exists only so push and finish share the event-building block that was previously inline in push. That is a genuine dedup (the PR added a second caller), so it is a fair subtraction already taken; no further action.

helios/src/output/pipeline.rs:49-51 — PlainText::parse_eos duplicates PlainText::parse (46-48) verbatim. It exists only because parse_eos has no default while every real dialect overrides it; give the trait a default that returns the same "tool parsing is not configured" error and the three-line override goes away (folded into the parse/parse_eos cleanup finding). Save ~6 + ~3 lines.

#7 [low] Nit: TaggedOutput::finish's call counter bump may be unobservable (~6 lines)

helios/src/output/tagged.rs:522-529 adds a 6-line TaggedOutput::finish arm to count Event::ToolBegins emitted by TaggedTools::finish, because finish could not previously emit calls. That bump exists for one reader: the self.calls == 0 newline-trim decision at tagged.rs:730, which runs inside parse — i.e. after finish has already run. TaggedOutput::finish calls self.push(Input::Text("")) before matching Mode::Tool (tagged.rs:519) and immediately returns the result; no parse call follows it. So the increment is invisible to every existing consumer.

Check in review: if no later reader of self.calls is reachable after finish (grep shows only tagged.rs:730/763 and those two increments at 524/579), the arm reduces to:

Mode::Tool => output.extend(self.tool.as_mut().unwrap().finish(cause)?),

restoring the pre-PR line and dropping 6 lines with no behaviour change. Counter-argument the author could make: calls also indexes ToolBegin events inside the finish-emitted vector — but emit_calls starts from self.index, which was already self.calls at construction (tagged.rs:763), so indices are correct without the bump. Save ~6 lines. Worth raising as "verify this bump is observable; if not, delete it".