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

Raw Markdown for agents: https://autobot.eidonix.com/p/628a8539-a102-4ced-98b9-1113b47af11b.md

Subtraction, Simplicity & Conventions review — PR #677 (helios)

Scope: all six changed files read at head f439f74, plus the surrounding originals, the repo helpers the diff could have reused (present/flag in decode.rs:31-48, Harness in chatml.rs tests, resolve_effort in frontend/mod.rs:828 (not opened) via request.rs:515-529), docs/api.md, and AGENTS.md.

Key findings

  1. Verdict first: the diff is mostly lean. The new Candidate enum (helios/src/output/tagged.rs:31-39) and its single consumer match (tagged.rs:336-347) are the smallest correct shape for the problem — no wrapper type, no trait-object indirection, 12 lines at the call site. The alias lookup is one find_map over a three-element array (decode.rs:184-193). MiniMaxXml pays only a two-line map(Candidate::Complete) (minimax_xml.rs:200-202), which its NAMESPACE-sentinel closer genuinely requires. No new config knob, dependency, proto, core-format or per-model branch. ~465 of 791 added lines are tests.
  2. One removable pattern, repeated in three dialects (rank 1-3). A boolean mode flag is threaded into each parser body to choose between Err(...) and Candidate::IncompleteValue for an unterminated value — yet every direct caller already maps IncompleteValue back to the identical error string. In chatml.rs the flag additionally makes an arm unreachable and duplicates an error literal. Removing all three is behaviour-preserving and collapses three dialects onto one rule.
  3. decode.rs effort plumbing carries two booleans, three in-arm assignments and an in-loop skip where one withheld boolean computed after the match suffices, and chat_nested_effort re-implements the file's own present() helper (decode.rs:38-40).
  4. Own convention violation: docs/api.md is untouched, though AGENTS.md:230 requires the relevant API sections for API-behaviour changes. This is the one item I would not merge without (rank 5). Open docs PR #172 documents the pre-#677 GLM behaviour in the same paragraph.
  5. No dead code, no leftovers: the old Option-based parse_candidate is fully replaced, no #[allow(dead_code)], no unused escaped/in_json_string paths, starts_call/eos_decision/1 MiB bound untouched. Only low-value test scaffolding duplication remains (rank 6).

Rank 1 (HIGH) — chatml.rs: drop allow_incomplete_value; it makes an arm unreachable and duplicates a literal

helios/src/output/chatml.rs:91-96:

    match parse_tool_candidate(body, tools, wrapped_parameters, allow_unclosed_function, false)? {
        Candidate::Complete(mut calls) => Ok(calls.remove(0)),
        Candidate::InJsonString => Err("incomplete JSON parameter".into()),
        Candidate::IncompleteValue => Err("unterminated tool parameter value".into()),
    }

Parameter declaration, chatml.rs:98-104 (allow_incomplete_value is the 5th, chatml.rs:103):

fn parse_tool_candidate(
    body: &str,
    tools: &[Value],
    wrapped_parameters: bool,
    allow_unclosed_function: bool,
    allow_incomplete_value: bool,
) -> Result<Candidate> {

Sole producer, chatml.rs:168-174:

        }) else {
            return if allow_incomplete_value {
                Ok(Candidate::IncompleteValue)
            } else {
                Err("unterminated tool parameter value".into())
            };
        };

Both non-streaming entry points pass false: parse at chatml.rs:25 (parse_tool(..., false)) and parse_eos at chatml.rs:31 (parse_tool(..., true)), each forwarding false as the 5th argument; only parse_candidate (chatml.rs:28) passes true. So with the flag false the else branch returns Err("unterminated tool parameter value") directly and Candidate::IncompleteValue can never reach the match at :94 — that arm is dead, and the literal is written twice (:94, :172).

Replace: delete the 5th parameter at chatml.rs:103, change the caller at :28 to parse_tool_candidate(body, tools, WRAPPING_NEWLINES, true), and make :169-173 unconditionally return Ok(Candidate::IncompleteValue);. The :94 arm then becomes reachable and produces exactly the same message, so parse/parse_eos behaviour and error strings are unchanged. Net: one fewer parameter, one fewer branch, one fewer duplicated literal, and parse_tool_candidate stops inventing errors. (allow_unclosed_function at :89 is pre-existing and used at :134 — keep it.)

Rank 2 (HIGH) — gemma_call.rs: same flag, bigger deletion (10-line match → 4)

helios/src/output/gemma_call.rs:150-159:

        let arguments = match value(&mut rest, schema, 0) {
            Ok(arguments) => arguments,
            Err(ParseError::IncompleteValue) if allow_incomplete_value => {
                return Ok(Candidate::IncompleteValue);
            }
            Err(ParseError::IncompleteValue) => {
                return Err("unterminated tool call string".into());
            }
            Err(ParseError::Error(err)) => return Err(err),
        };

parse (gemma_call.rs:175-182) and parse_eos (:186-193) both already convert Candidate::IncompleteValue into Err("unterminated tool call string".into()) — the same string the allow_incomplete_value == false arm produces. The duplicate error construction is therefore redundant, and the 4th parameter (allow_incomplete_value, gemma_call.rs:127) exists only to select between two paths that emit the same error.

Replace with, and remove the parameter at :127 plus the false at :176/:187:

        let arguments = match value(&mut rest, schema, 0) {
            Ok(arguments) => arguments,
            Err(ParseError::IncompleteValue) => return Ok(Candidate::IncompleteValue),
            Err(ParseError::Error(err)) => return Err(err),
        };

Rank 3 (MEDIUM) — argument_tags.rs: the eos-conditional error can go

helios/src/output/argument_tags.rs:85-91:

            let Some((value, tail)) = value.split_once("</arg_value>") else {
                return if eos {
                    Err("unterminated GLM argument value".into())
                } else {
                    Ok(Candidate::IncompleteValue)
                };
            };

parse_eos (argument_tags.rs:121-128) already maps IncompleteValue to Err("incomplete GLM tool call"), and parse (:111-117) maps it to Err("unterminated GLM argument value") — the very string the eos branch hand-builds here.

Replace with return Ok(Candidate::IncompleteValue); (and the eos parameter at :119/:122 then only controls the strict-call check, if any — see note below). Behaviour-preserving for parse; the only observable delta is the EOS path's message becoming "incomplete GLM tool call" instead of "unterminated GLM argument value", and no test asserts either literal (the strings appear only at argument_tags.rs:87 and :115). If the message must be preserved, keep the eos parameter and delete only the Ok/Err split by returning Ok(Candidate::IncompleteValue) and letting parse_eos keep its current wording.

Combined effect of ranks 1-3 (the highest-value simplification in this PR): parse_candidate never invents errors for incomplete values; the direct entry points map the state — one rule across three dialects instead of three bespoke mode flags. It also removes the reason the PR description has to caveat that these paths apply to "streaming candidate evaluation only".

Rank 4 (MEDIUM) — decode.rs: two booleans + three in-arm assignments where one local suffices; re-implements present()

helios/src/server/protocol/decode.rs:590-592:

    let chat_nested_effort = protocol == Protocol::Chat
        && body.get("reasoning_effort").is_none_or(Value::is_null)
        && body["reasoning"].get("effort").is_some_and(|v| !v.is_null());

The file already has exactly this predicate — decode.rs:38-40:

fn present(v: &Value, key: &str) -> bool {
    v.get(key).is_some_and(|v| !v.is_null())
}

So :590-592 is let nested = protocol == Protocol::Chat && !present(body, "reasoning_effort") && present(&body["reasoning"], "effort");.

Then the mutable flag is set in three separate match arms (decode.rs:606, :613, :617, :622):

    let mut normalized_chat_effort = false;
    if let Some(effort) = effort.filter(|v| !v.is_null()) {
        let native = match effort.as_str() {
            Some("none") => {
                options
                    .template
                    .insert("enable_thinking".into(), false.into());
                normalized_chat_effort = protocol == Protocol::Chat;
                None
            }
            Some("minimal") => {
                normalized_chat_effort = protocol == Protocol::Chat;
                Some(Effort::Minimal)
            }
            Some("low") => Some(Effort::Low),
            Some("medium") => {
                normalized_chat_effort = protocol == Protocol::Chat;
                Some(Effort::High)
            }

and read 60 lines later inside the key loop (decode.rs:684-686):

        if key == "reasoning_effort" && (normalized_chat_effort || chat_nested_effort) {
            continue;
        }

Because withholding is exactly "Chat consumed the value", the three in-arm assignments are pure bookkeeping that need not live inside the match. Replace the arms' normalized_chat_effort = ...; lines with nothing (keep the arms pure — they only choose Option<Effort> / set enable_thinking), and compute one local before the loop:

    let withheld = nested
        || (protocol == Protocol::Chat
            && matches!(effort.and_then(Value::as_str), Some("none" | "minimal" | "medium")));

used at :684 as if key == "reasoning_effort" && withheld { continue; }. Removes a mutable flag threaded through three arms and one re-implemented helper; no helper is invented. (This is a shape comment only — the behaviour question of whether high should be normalized too belongs to the Correctness & Contracts lens and is out of scope here.)

Rank 5 (MEDIUM, convention) — docs/api.md not updated: AGENTS.md:230 requires it

AGENTS.md:230:

| Change CLI, API, or configuration behavior | [CLI design](docs/cli-design.md (not opened)) and the relevant [API](docs/api.md) sections |

Both halves change observable API behaviour, but no docs file is in the diff (+791/−59 across 6 files, all under helios/src). docs/api.md:960-965 still scopes named-level mapping away from Chat:

Responses and Anthropic named effort settings
(`reasoning.effort` and `output_config.effort`) accept named levels and map into
the same neutral levels. They do not accept numeric scores. The frontend resolves
those levels against the effort vocabulary accepted by the prepared template: for example Qwen uses
`low/medium/xhigh`. Native DeepSeek V4 and V4.1 prompt encoders accept
`low/high/xhigh/max` and default to thinking enabled and high effort.

and docs/api.md:970-987 presents Chat reasoning_effort only as the DeepSeek numeric score. Nothing in api.md says that Chat none|minimal|medium normalize, that Chat medium → high, that a nested {"reasoning": {"effort": ...}} object is accepted on Chat, that thinking/reasoning message fields are read as reasoning history, or that a literal outer closer inside a non-JSON argument value is argument text (:539-547/:611-623 cover only the unclosed-argument rejection). After this PR the spec it implements is wrong.

Action: add the four sentences to docs/api.md:955-995 (Chat named levels + nested reasoning.effort + message aliases) and one to the tagged-tools EOS section; coordinate with open docs-only PR #172, which currently records the pre-#677 GLM medium → Max behaviour in that same paragraph.

Rank 6 (LOW) — new tests repeat scaffolding instead of reusing the module's own Harness

helios/src/output/chatml.rs:1408-1430 runs the same six-line push/finish block in both halves of the compact branch:

                for compact in [false, true] {
                    let mut output = Accumulator::new("chatml-literal-close".into());
                    if compact {
                        let mut parser = CompactChatMlOutput::new(config());
                        for part in [&text[..split], &text[split..]] {
                            output
                                .apply(parser.push(Input::Text(part)).unwrap())
                                .unwrap();
                        }
                        output
                            .apply(parser.finish(Termination::Eos).unwrap())
                            .unwrap();
                    } else {
                        let mut parser = ChatMlOutput::new(config());
                        // ... identical six lines ...

Harness (chatml.rs:412-437) already wraps parser + Accumulator and is used by the older tests at :469-480; generalising it over &mut dyn ToolCallParser (or simply dropping the compact half of the loop) removes the duplicate. Similarly the two new decode closures prepare_glm (decode.rs:2540-2557) and prepare_ds (decode.rs:2621-2638) are identical apart from the frontend/compiler/config triple, in the same shape as the pre-existing chat closure at decode.rs:1077-1084 — one local prepare(frontend, compiler, config, body) -> String plus three one-line closures would remove ~35 lines with no loss of coverage. Pre-existing test style, so low priority; I would not block on this.


Checked and deliberately clean (do not simplify)

Open questions / not verifiable in this lens