Subtraction and simplicity report · NVIDIA/hyperflare-inference #685

Raw Markdown for agents: https://autobot.eidonix.com/p/f5f3bbd4-f7fb-4463-b2e3-afd67b02ec0d.md

Subtraction, Simplicity & Conventions review — PR #685, head b9864ab824

Lens: what can be deleted, collapsed, or made dramatically simpler, plus structural convention violations. Correctness/contract bugs are out of scope here.

Verdict: the streaming core is lean and should not be trimmed; four concrete cuts and one convention withdrawal remain. The new parser plumbing (Call::publish + published_argument_bytes, the three check_size() sites, validate_arguments, drops_unfinished_call, the two new dsml test modules) is justified line for line and is listed below under "verified lean" so it is not re-litigated by the next reviewer.

Caveat on method. pr_diff / git cannot resolve the base commit (c513e46a) in this environment, so every head-vs-main comparison below is from read_file/search_code at the PR head with ref: main. Nothing was executed; no CI run exists on any hash, and the head b9864ab is unreviewed (both Autobot reviews analysed ≤ 80c87b3). PR body's self-reported counts (1787 passed / 16 failed, output:: 113, server::protocol 96) are stale at this head, which adds mod streaming_tests (dsml.rs:749-985), mod rejection_tests (:987-1032) and three protocol tests (protocol/tests.rs:3809-4017).


Key findings

# Kind Location One-line fix
1 Simplicity / churn helios/src/server/output.rs:163-173 One boolean cast as a Termination parameter, threaded through 9 files / ~21 call sites; restore finish(&self) and add discard_unfinished_call()
2 Subtraction helios/src/server/output.rs:1745-1755 Two public methods + a field + an unreachable guard + a tautological matches! to express one Vec::pop pair
3 Duplication protocol/tests.rs:3979-4017, dsml.rs:962-984 Each truncation matrix is expressed twice with skewed cause lists; fold into one parameterised test each
4 Dead justification docs/api.md:543-547 The "because …" clause is factually false against main (TAGGED_JSON, #670) and blocks a rebase; delete, don't rewrite
5 Convention helios/tests/deepseek_output.rs:515 (+ docs/api.md:547-551) Test rewritten to accommodate the behaviour change instead of testing the old contract; AGENTS.md:182-187, 201-207

1. (high) Accumulator::finish(cause) churns 9 files to carry one boolean

helios/src/server/output.rs:163-173:

    pub(crate) fn finish(&mut self, cause: Termination) -> Result<()> {
        if drops_unfinished_call(cause)
            && self.calls.last().is_some_and(|call| !call.ended)
        {
            self.calls.pop();
        }
        if self.calls.iter().any(|call| !call.ended) {
            return Err("incomplete emitted tool call".into());
        }
        Ok(())
    }

cause is consulted only through drops_unfinished_call (output.rs:478-480), which is itself cause != Termination::Eos. So a Termination is passed down purely to evaluate one predicate — and in almost every caller the argument is the constant Termination::Eos, making the parameter pure noise. On main the same function has no parameter (main helios/src/server/output.rs:163-168):

    pub(crate) fn finish(&self) -> Result<()> {
        if self.calls.iter().any(|call| !call.ended) {
            return Err("incomplete emitted tool call".into());
        }
        Ok(())
    }

The diff's own chat harness proves it: at helios/src/output/chatml.rs:416-419 the value is hardcoded —

        fn finish(&mut self) -> Result<Vec<Value>> {
            let result = self.output.apply(self.parser.finish(Termination::Eos)?)?;
            self.output.finish(Termination::Eos)?;
            Ok(result)
        }

— where main (chatml.rs:416-419) differs only in that last line (self.output.finish()?;). Identical hardcoded-Eos sites: helios/src/server/output.rs:503, helios/tests/deepseek_output.rs:596,672,732, helios/src/server/runtime/phase_tests.rs:973.

Concrete simplification. Keep the predicate where it is genuinely consulted (ResponseOutput::finish, output.rs:1733), restore finish(&self) exactly as on main, add a private helper beside it:

    pub(crate) fn discard_unfinished_call(&mut self) {
        if self.calls.last().is_some_and(|call| !call.ended) {
            self.calls.pop();
        }
    }

and make the single encoder caller two statements — helios/src/server/protocol/encode.rs:674-676, currently

        if self.protocol == Protocol::Chat {
            self.chats[index].finish(cause)?;
        }

becomes

        if self.protocol == Protocol::Chat {
            if drops_unfinished_call(cause) {
                self.chats[index].discard_unfinished_call();
            }
            self.chats[index].finish()?;
        }

Reverted signature churn (~21 call sites, all Termination::Eos literals): argument_tags.rs:212,287,334,435,490; chatml.rs:418,650,833,1097; dsml.rs:456,500,567,631,699,789; gemma_call.rs:265 (not opened); minimax_xml.rs:346 (not opened); xtml.rs:464,508; runtime_core/protobuf.rs:1160; pipeline.rs:345,492,580,685,738; server/runtime/phase_tests.rs:973 (plus the server/output.rs:503 test harness). The new dsml truncation tests that genuinely vary the cause (dsml.rs:934,953,981) keep passing it to parser.finish(cause); only the accumulator call loses the argument. Net: −1 parameter, −1 field-less branch in finish, ~21 call-site edits removed, one 4-line helper added. This is exactly the churn AGENTS.md:188-193 rejects ("Unsolicited … renaming … and file rearrangements are not contributions by themselves. Refactoring must directly support the requested behavior").

No correctness issue is being asked to stay — the truncation-omission behaviour is preserved verbatim; only its plumbing moves one frame up, into the encoder that already has the cause.

2. (high) The abandoned-block machinery is over-built for one Vec::pop pair

helios/src/server/output.rs:1745-1755:

    /// The block `finish` closed for a truncated call, to remove once its
    /// closing frame has been rendered.
    pub fn take_abandoned(&mut self) -> Option<usize> {
        self.abandoned.take()
    }
    pub fn drop_abandoned(&mut self, index: usize) {
        if index + 1 == self.blocks.len() {
            self.blocks.pop();
            self.calls.pop();
        }
    }

with field abandoned: Option<usize> (output.rs:1703) set at :1739, and the caller helios/src/server/protocol/encode.rs:677-689:

        let changes = self.outputs[index].finish(cause)?;
        let abandoned = self.outputs[index].take_abandoned();
        for change in changes {
            ...
        }
        if let Some(block) = abandoned {
            self.outputs[index].drop_abandoned(block);
        }

Three defects of construction, none of which a reader can verify locally:

Concrete simplification. Replace both methods with one, and drop the field entirely by making it a bool:

    pub fn discard_abandoned(&mut self) {
        if std::mem::take(&mut self.abandoned).is_some() {
            self.blocks.pop();
            self.calls.pop();
        }
    }

(keeping abandoned: Option<usize> if the index is preferred; the correction is only to delete the guard), the encoder ending with the single trailing call self.outputs[index].discard_abandoned();. Net: −2 public methods, −1 unreachable branch, −1 dead conjunction, −4 encoder lines. Behaviour identical, including the "render content_block_stop / output_item.done before dropping" ordering the new tests assert (protocol/tests.rs:3861-3876).

A bug this deletes rather than patches: the custom/grammar-tool truncation error (dossier amendment item 6 — encode.rs:470-484 does serde_json::from_str(arguments).map_err(...)? on a truncated call's partial JSON, so Encoder::finish errors and the stream ends with no response.completed). Collapsing the abandoned path to a boolean does not by itself fix it, but it removes the index-taking API that made the abandoned block indistinguishable from a completed one; the fix should be to not render an abandoned tool block's arguments at all, which is a one-line consequence of discard_abandoned owning the decision. Patch-build on top of this machinery would add a second special case.

3. (medium) The truncation matrix is written out twice per layer, and the twins already drift

helios/src/server/protocol/tests.rs:3979-4017, a_header_only_call_is_omitted_when_the_response_truncates:

#[test]
fn a_header_only_call_is_omitted_when_the_response_truncates() {
    for protocol in [Protocol::Chat, Protocol::Messages, Protocol::Responses] {
        for cause in [
            Termination::OutputLimit,
            Termination::UserStop,
            Termination::ExecutionError,
        ] {

versus :3809-3907, an_announced_call_publishes_fragments_and_truncation_omits_it, whose loop header is :3811-3817:

    for protocol in [Protocol::Chat, Protocol::Messages, Protocol::Responses] {
        for cause in [
            Termination::OutputLimit,
            Termination::UserStop,
            Termination::Cancelled,
            Termination::ExecutionError,
        ] {

Same encoder setup, same opening.len() == 1 assertion, same finish(0, cause, 1, 0, None), same per-protocol empty-body match. The only difference is whether a Event::ToolArguments frame was applied before the cut — and the cause lists have already diverged (Cancelled missing from the second, absent in the first only by accident of the first already containing all four).

The same pair exists one layer down: helios/src/output/dsml.rs:962-984 (a_header_only_call_is_omitted_when_the_response_truncates, let header = text.find(">\n</|DSML|invoke>").unwrap();) duplicates :917-937 (let cut = text.find("</|DSML|parameter>").unwrap();), with the same for cause in [OutputLimit, UserStop, ExecutionError] loop and the same assert!(output.message().get("tool_calls").is_none(), "{cause:?}") tail.

Concrete simplification. In protocol/tests.rs, parameterise the shared body on the fragment list and delete the 39-line twin:

for fragments in [vec![], vec![Event::ToolArguments { index: 0, text: r#"{"query":"par"#.into() }]] {

asserting opening.len() + fragments.len() opening frames; in dsml.rs, fold the pair into one test over [(text.find("</|DSML|parameter>").unwrap(), true), (text.find(">\n</|DSML|invoke>").unwrap(), false)] where the flag selects assert!(!arguments(&events).is_empty()) vs assert!(arguments(&events).is_empty()). Both folds also collapse the skew into one authoritative cause list [OutputLimit, UserStop, Cancelled, ExecutionError], so a future cause cannot be forgotten in one twin only. Saves ~75 lines and removes the drift surface.

4. (medium) A false justification in docs/api.md should be deleted, not rewritten

docs/api.md:543-547:

  byte for byte. The tagged tool parsers publish a call only when its envelope is
  complete, because they build its arguments from parameter syntax and the
  declared schemas rather than copying the model's text: values are coerced to
  declared types, strict container parameters are parsed, and wrapping newlines
  are trimmed.

The "because" clause is false against main: TAGGED_JSON (#670, merged 2026-12-02 14:16) parses the model's own {"name":…,"arguments":…} object and re-serialises it with no schema coercion (helios/src/output/tagged_json.rs:14-49 (not opened), JSON_BODY = true at :57). Rewriting it would require rewriting the paragraph a second time when #670 lands, and the sentence is non-normative explanation, not contract — nothing in the parser depends on it.

Concrete simplification. Delete from because through trimmed., keeping exactly:

  complete. The tagged tool parsers publish a call only when its envelope completes.

Also delete the non-normative admission at docs/api.md:550-551:

  termination reports the output limit. A client that received fragments of such a
  call has already seen a call that cannot complete.

Keeping the first sentence's content (finish-reason mapping) and dropping the second sentence, which concedes the wire-level hazard while adding no requirement — the normative omission rule is already stated at :547-549. Net: −8 lines of prose that currently block the rebase and add a maintenance obligation.

5. (conventions) A test was rewritten to accept the new behaviour instead of testing the contract

helios/tests/deepseek_output.rs:514-515:

                assert!(error.unwrap().to_string().contains("nonempty and unique"));
                assert_eq!(parsed.ended, 0, "a rejected call reported an end");

main:511 asserted assert!(published.is_empty()); — "a rejected call published nothing". That guarantee is now gone, and the assertion was inverted to "a rejected call reported no end", which permits a ToolBegin plus argument fragments for a call that is subsequently rejected for non-unique argument names. AGENTS.md:182-187 forbids exactly this ("Do not remove validation, suppress errors … to obtain passing checks") and :201-207 extends it explicitly to tests and docs ("Apply these criteria to documentation and test changes that would weaken the rules as well as code"). The accompanying docs/api.md:547-549 documents the same relaxation as though it were design.

Recommendation: withdraw the accommodation rather than keep it. Either restore assert!(published.is_empty()) (raising a published-then-rejected call to the Correctness lens's blocker list, where the Err("incomplete emitted tool call") removal already sits), or record the weakened guarantee as the deliberate, maintainer-authorised behaviour it now is — nothing in the tracker authorises it, and an issue/maintainer decision is what AGENTS.md:201-207 requires before an invariant is changed. This is the one place in the diff where a test's existence adds maintenance cost rather than coverage: it locks in an unapproved behaviour change.


Verified lean — do NOT simplify these

Checked specifically and found load-bearing; flagging them as "complexity" would be wrong:


Open questions / not verifiable here