#1 [high] PR #677 Subtraction/Simplicity review — findings
PR #677 (helios): +791/-59, 6 files, head f439f74. All new code read at head.
F1 (HIGH) chatml.rs — allow_incomplete_value mode flag adds an unreachable arm + duplicates an error string.
helios/src/output/chatml.rs:91-96 verbatim:
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()),
}
Both callers (parse chatml.rs:24-26 and parse_eos :30-32) pass allow_incomplete_value = false, and the only producer of IncompleteValue is chatml.rs:168-174:
}) else {
return if allow_incomplete_value {
Ok(Candidate::IncompleteValue)
} else {
Err("unterminated tool parameter value".into())
};
};
So Candidate::IncompleteValue at :94 is unreachable, and the literal "unterminated tool parameter value" appears twice (:94, :172).
Replace: drop the 5th parameter allow_incomplete_value from parse_tool_candidate (chatml.rs:98-104) and make the else unconditionally return Ok(Candidate::IncompleteValue);. The :94 arm then becomes reachable and produces exactly the same message as before, so parse/parse_eos behaviour and messages are unchanged. Net: −1 param, −1 branch, −1 duplicated literal.
F2 (HIGH) gemma_call.rs — same flag, same fix, larger gain (kills a 10-line match). helios/src/output/gemma_call.rs:150-159 verbatim:
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 (:175-182) and parse_eos (:186-193) both already map Candidate::IncompleteValue => Err("unterminated tool call string".into()) — the identical message as the allow_incomplete_value == false path. So remove the allow_incomplete_value parameter (:127), collapse to:
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),
};
Behaviour-preserving; removes a 4-arg→4-value mode flag and 4 lines.
F3 (MEDIUM) argument_tags.rs — same pattern: eos-conditional error at :85-91 can go.
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 (:121-128) already maps IncompleteValue to an error; replace with return Ok(Candidate::IncompleteValue);. Only delta: the EOS error message becomes "incomplete GLM tool call" instead of "unterminated GLM argument value" (no test asserts the string; grep shows the literal only at argument_tags.rs:87/115). Same shape as F1/F2 → three dialects, one rule: parse_candidate never invents errors for incomplete values; the direct entry points map the state.
(Side effect worth reporting: F1+F2+F3 remove the reason the semantics need documenting as "streaming candidate evaluation only".)
F4 (MEDIUM) decode.rs — two booleans + three assignments + inside-loop skip; also ignores existing helpers 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());
and :606-629 sets normalized_chat_effort = protocol == Protocol::Chat; in three arms (none :613, minimal :617, medium :622), then :684:
if key == "reasoning_effort" && (normalized_chat_effort || chat_nested_effort) {
continue;
}
present(v, key) exists at decode.rs:38-40 (v.get(key).is_some_and(|v| !v.is_null())), so :590-592 is a re-implementation: let nested = protocol == Protocol::Chat && !present(body, "reasoning_effort") && present(&body["reasoning"], "effort");
Since withholding is exactly "Chat consumed the value", the three in-arm assignments collapse to one post-match expression:
let mut withheld = nested;
// match arms stay pure: they only choose Option<Effort> / enable_thinking
withheld |= protocol == Protocol::Chat
&& matches!(effort.and_then(Value::as_str), Some("none" | "minimal" | "medium"));
used at :684 as if key == "reasoning_effort" && withheld. Removes a mutable flag threaded through 3 match arms and duplicates no helper.
F5 (MEDIUM, convention) docs/api.md not updated — AGENTS.md:230 requires the API docs for API behaviour changes. docs/api.md:960-965 still says only "Responses and Anthropic named effort settings (reasoning.effort and output_config.effort) accept named levels", and :970 frames Chat reasoning_effort as the DeepSeek numeric score only; there is no statement that Chat none|minimal|medium normalize, that medium→high, that nested reasoning.effort is accepted on Chat, that thinking/reasoning message aliases are read, or that a literal outer closer inside a non-JSON argument value is argument text (:539-547 / :611-623 cover only unterminated-argument rejection). This PR changes observable API behaviour in both halves, so the spec it implements is now wrong; open docs PR #172 documents the pre-#677 GLM behaviour in the same paragraph.
F6 (LOW) new tests duplicate scaffolding and ignore the module's existing Harness.
helios/src/output/chatml.rs:1408-1430 for compact in [false, true] { ... if compact { push loop; finish } else { push loop; finish } } repeats the identical 6-line push/finish block twice, although Harness (chatml.rs:412-437) already wraps parser+Accumulator and is used by the older tests at :469-480. Either generalise Harness over the parser (&mut dyn ToolCallParser) or drop the compact loop half. Same boilerplate repeated in the new tests at argument_tags.rs:790-825, gemma_call.rs:376-412, minimax_xml.rs:450-480 (pre-existing style, so low priority).
Verdict: decode half is otherwise lean (single alias find_map at decode.rs:184-193; Candidate enum with only two real states is the smallest correct shape for tagged.rs:31-39 and the match at tagged.rs:336-347 is 12 lines with no wrapper). No dead config knobs, no new dependencies, no speculative generality beyond the mode flags in F1-F3.
#3 [high] Research summary
Reviewed PR #677 through the subtraction/simplicity lens: read all six changed files at head (f439f74) plus the surrounding originals, the existing helpers they could have used (present/field in decode.rs, Harness in chatml.rs tests, resolve_effort/Effort ladders in request.rs, docs/api.md), and AGENTS.md conventions. Findings saved to the scratchpad (2 notes).
The recurring, high-value finding is one pattern repeated in three dialects: a boolean mode flag threaded into the parser body to decide whether an unterminated value is an error or Candidate::IncompleteValue, when every direct caller already maps IncompleteValue back to the identical error string.
chatml.rs:91-96+:98-104+:168-174— theallow_incomplete_valueparameter makes theCandidate::IncompleteValuearm inparse_toolunreachable (both callers passfalse) and duplicates the literal"unterminated tool parameter value". Removing the parameter and returningOk(Candidate::IncompleteValue)unconditionally from theelsemakes the same message reachable with one fewer param and branch.gemma_call.rs:150-159— same flag;parseandparse_eosalready mapIncompleteValueto the same"unterminated tool call string", so the match collapses from 10 lines to 4 and the 4th parameter disappears.argument_tags.rs:85-91—eos-conditional error for the same case;parse_eosalready handlesIncompleteValue.decode.rs:590-592,:606-629,:684-686— two booleans with three in-armnormalized_chat_effort = protocol == Protocol::Chat;assignments and an in-loopcontinue; expressible as onewithheldbool computed once after the match, andchat_nested_effortre-implements the file's ownpresent()helper (decode.rs:38-40).docs/api.mduntouched although AGENTS.md:230 requires it for API-behaviour changes;:960-965/:970still describe Chatreasoning_effortas the DeepSeek numeric score only and say named-level mapping is Responses/Messages-only. Open docs PR #172 documents the pre-#677 behaviour in that paragraph.- Low: new output tests repeat parser+Accumulator boilerplate (chatml.rs:1408-1430 duplicates an identical push/finish block across the
compactbranch) instead of reusing the module's existingHarness(chatml.rs:412-437), and the two new decode closures (:2540-2557,:2621-2638) are byte-identical apart from the frontend triple (~35 lines could collapse into one helper).
The core of the change — the three-state Candidate enum and the 12-line match at tagged.rs:336-347, the single alias find_map at decode.rs:184-193 — is already lean and idiomatic; no dead config knobs, dependencies, or speculative generality beyond the three mode flags above.
#4 [high] Report skeleton: verdict, ranked suggestions, what checked clean
PR #677, Subtraction/Simplicity & Conventions lens. Basis: read all 6 changed files at head f439f74, plus originals around them, docs/api.md, AGENTS.md, and the helpers the diff could have reused (present/field/flag decode.rs:14-48, Harness chatml.rs:412-437, resolve_effort frontend/mod.rs:828 via request.rs:515-529).
VERDICT (say plainly): the change is mostly lean. The three-state Candidate enum (tagged.rs:31-39) and its consumer match (tagged.rs:336-347) are the minimal correct shape — no wrapper type, no trait-object indirection, 12 lines at the call site; the alias lookup (decode.rs:184-193) is one find_map over a 3-element array; no new config knob, dependency, proto or core-format change; MiniMaxXml pays only a 2-line map(Candidate::Complete) (minimax_xml.rs:200-202) and that is genuinely required by its NAMESPACE-sentinel closer, not speculative generality. 465 of 791 added lines are tests. Suggestions below are spare-part removal, not redesign.
ONE PATTERN, THREE SITES (rank 1-3; highest value, all behaviour-preserving):
Rank 1 — chatml.rs. allow_incomplete_value param makes an arm unreachable and duplicates an error literal. Site: chatml.rs:91-96 (caller passes false at chatml.rs:24-26 and :30-32), param at chatml.rs:98-104, producer at chatml.rs:168-174. Fix: drop the 5th param, else { return Ok(Candidate::IncompleteValue); }, delete the now-reachable-duplicate concern — same messages out.
Rank 2 — gemma_call.rs:150-159 with param at :127. parse (:175-182) and parse_eos (:186-193) already map IncompleteValue to "unterminated tool call string", so the guard arm is redundant; collapse to Err(ParseError::IncompleteValue) => return Ok(Candidate::IncompleteValue); 10 lines → 4, one fewer param.
Rank 3 — argument_tags.rs:85-91. eos-conditional Err/Ok inside the body; parse_eos (:121-128) already errors on IncompleteValue. Fix: return Ok(Candidate::IncompleteValue);. Only observable delta: the EOS message becomes "incomplete GLM tool call" instead of "unterminated GLM argument value"; no test asserts either literal (grep: literals only at argument_tags.rs:87, :115). Combined effect of 1-3: parse_candidate never invents errors for incomplete values; the direct entry points map the state — one rule for three dialects, and the "streaming candidate evaluation only" caveat in the description stops being necessary.
Rank 4 — decode.rs effort plumbing. See note 1 F4 (chat_nested_effort at :590-592 re-implements present() from :38-40; normalized_chat_effort set in three match arms at :613/:617/:622 and read at :684). Concrete: let nested = protocol == Protocol::Chat && !present(body, "reasoning_effort") && present(&body["reasoning"], "effort"); plus one withheld bool computed after the match with matches!(effort.and_then(Value::as_str), Some("none" | "minimal" | "medium")), used at :684. Keep match arms pure.
Rank 5 — CONVENTION (AGENTS.md:230): API-behaviour change, zero docs. Verified docs/api.md:960-965 ("Responses and Anthropic named effort settings (reasoning.effort and output_config.effort) accept named levels") and :970 (Chat reasoning_effort presented only as the numeric DeepSeek score) — no statement of Chat none|minimal|medium normalization, medium→high, nested reasoning.effort on Chat, thinking/reasoning history aliases, or that a literal outer closer inside a non-JSON argument value is argument text (docs/api.md:539-547 and :611-623 cover only the unclosed-argument rejection). Open docs PR #172 would document the pre-#677 GLM behaviour in that same paragraph, so #677 makes the spec it implements wrong. This is the one finding I would not merge without.
Rank 6 (LOW) — test scaffolding duplication: chatml.rs:1408-1430 repeats the identical 6-line push/finish block in both compact branches although Harness (chatml.rs:412-437) already wraps parser+Accumulator and is used by older tests at :469-480; the two new decode closures (decode.rs:2540-2557 prepare_glm, decode.rs:2621-2638 prepare_ds) are identical apart from the frontend triple, same shape as the pre-existing chat closure at decode.rs:1077-1084 (~35 lines → 1 helper). Pre-existing style, so low priority; do not push hard.
NOT findings (checked, deliberately clean): no dead code left behind (Option fully replaced, no #[allow(dead_code)]); starts_call/eos_decision/1 MiB bound untouched; MiniMaxXml::Candidate::Complete mapping justified; no per-model branches added in shared output layer; no new flags/config/proto; test count claim not verifiable but out of this lens's scope.
#2 [medium] decode.rs new tests: duplicated prepare closures
In the same new test chat_normalizes_reasoning_effort_and_accepts_nested_reasoning_object (helios/src/server/protocol/decode.rs:2519 onward), prepare_glm (decode.rs:2540-2557) and prepare_ds (decode.rs:2621-2638) are the same 18 lines with only the frontend/compiler/config triple changed:
let prepare_glm = |extra: Value| {
let mut body = json!({"messages": [{"role": "user", "content": "Hello"}]});
body.as_object_mut()
.unwrap()
.extend(extra.as_object().unwrap().clone());
let decoded = decode(Protocol::Chat, body, false).unwrap();
crate::server::request::prepare_inference(
&glm_frontend, None, &glm_compiler, &glm_config, &decoded.request, 0, false,
)
.unwrap()
.rendered_prompt
};
and the render closure at decode.rs:2440-2468 in the sibling new test is the same shape with a fixed messages array. Replace all three with one local fn prepare(frontend: &Frontend, compiler: &GrammarCompiler, config: &ModelConfig, body: Value) -> String and three one-line closures. −~35 lines, no loss of coverage. Same "extend a bare body then prepare" pattern already exists at decode.rs:1077-1084 (chat), so the helper generalises an existing idiom rather than inventing one.