Correctness, Contracts & System-Level Consequences — PR #677 review
Reviewed all six changed files at head f439f74 in full context, plus their direct callers and contracts: helios/src/server/request.rs (effort ladder), helios/src/frontend/mod.rs (resolve_effort), helios/src/frontend/tml.rs, helios/src/server/inference.rs, docs/api.md, AGENTS.md, and helios/src/output/tagged/kani_proofs.rs. No new locks, channels, threads, or shared caches exist anywhere in the diff — all state stays per-parser-instance — so there is no lock contention, head-of-line blocking, or failure blast-radius concern to report. Nothing in the diff samples or alters a rate/latency/admission metric; consumed_bytes accounting (tagged.rs:505-508) is untouched, so the metric/span check is clean. Memory retention is unchanged (same buffer, same 1 MiB bound).
Key findings
- Major — undocumented prompt shift on TMLv0 native models. Chat
reasoning_effort:"medium"now resolves toEffort::Highwith the raw string withheld, so TMLv0 renders numeric effort 0.9 instead of 0.7 for every such request (decode.rs:621-624,:684-686→request.rs:521→tml.rs:19-27). The description discloses the remap only for "Jinja templates distinguishingmediumfromhigh". - Major — the same 400 class is left open for
"high".Some("high") => Some(Effort::High)(decode.rs:625) never setsnormalized_chat_effort, sohighstill reaches the template verbatim and still fails on templates that reject it (tests/frontend/qwen38.json:3089-3099). - Major — quadratic rescan added to the output hot path.
Candidate::IncompleteValuere-runsD::parse_candidate(&self.buffer[..end])from byte 0 once per literal inner closer (tagged.rs:306-347), turning one linear scan per push into O(K·N) up to the unchanged 1 MiB bound. - Major — required docs contract not updated.
AGENTS.md:230requiresdocs/api.mdfor API-behaviour changes; no docs file is in the diff, anddocs/api.md:960-965still scopes named-level resolution to Responses/Messages only. - Minor — reasoning aliases are now honoured on every role, including
tool, which can produce a stray content-less message in the encoded prompt (decode.rs:184-193before the role branch at:194). - Minor — public API break in
output::tagged(Candidateenum +parse_candidatesignature) on functions that open PR #670 rewrites concurrently.
Finding 1 — Major: Chat "medium" silently raises TMLv0 effort from 0.7 to 0.9
helios/src/server/protocol/decode.rs:621-626
Some("medium") => {
normalized_chat_effort = protocol == Protocol::Chat;
Some(Effort::High)
}
Some("high") => Some(Effort::High),
Some("xhigh" | "max") => Some(Effort::Max),
helios/src/server/protocol/decode.rs:684-686
if key == "reasoning_effort" && (normalized_chat_effort || chat_nested_effort) {
continue;
}
helios/src/server/request.rs:515-523
if !options.contains_key("reasoning_effort") {
if let Some(effort) = opts.effort {
use super::inference::Effort;
let candidates: &[&str] = match effort {
Effort::Minimal => &["minimal", "low"],
Effort::Low => &["low"],
Effort::High => &["high", "medium"],
Effort::Max => &["max", "xhigh", "high", "medium"],
};
helios/src/frontend/tml.rs:19-27 and helios/src/frontend/mod.rs:829-835
const EFFORTS: [(&str, f64); 7] = [
("none", 0.0), ("minimal", 0.1), ("low", 0.2), ("medium", 0.7),
("high", 0.9), ("xhigh", 0.99), ("max", 0.99),
];
if self.prompt_encoder == PromptEncoder::TmlV0 {
return candidates
.iter()
.copied()
.find(|level| tml::effort_level(level))
fmt::effort_level accepts both high and medium, and the iterator order in request.rs:521 puts high first, so Effort::High always resolves to "high" → 0.9 on TMLv0 (Inkling 2 / tests/frontend/inkling2_tml.json (not opened)).
Before this PR: main's Chat path had no options.effort at all, so "medium" was copied verbatim into options.template and tml::effort (tml.rs:55-61) read it as 0.7.
Impact: every Chat request carrying "reasoning_effort": "medium" on a TMLv0 model renders a different prompt after upgrade — different prompt bytes, therefore different prompt_tokens and different prefix-cache keys, with no opt-in and no mention in the description (which scopes the change to Jinja templates). This is a cross-model behaviour change in shared code, which the charter asks to justify per supported matrix.
Fix (pick one): disclose the TMLv0 shift explicitly as a compatibility note and add a test that renders "medium" through TMLv0 at head; or reorder the ladder to &["medium", "high"] for Effort::High so a template that accepts medium keeps it (this also matches the historical behaviour and preserves the Qwen-style low/medium/xhigh vocabulary); or map Chat "medium" to Effort::Low/a new Medium variant if the intent is to keep 0.7.
Finding 2 — Major: "high" is left unnormalized, so the same HTTP 400 it fixes for medium remains for the most common level
helios/src/server/protocol/decode.rs:625
Some("high") => Some(Effort::High),
That arm sets options.effort but not normalized_chat_effort, so the continue at decode.rs:684-686 does not fire: the raw string is still inserted into options.template, and request.rs:515's !options.contains_key("reasoning_effort") guard then skips resolution entirely. The value reaches the template verbatim exactly as on main.
tests/frontend/qwen38.json:3089-3099
"name": "invalid_reasoning_effort",
"options": {
"reasoning_effort": "high"
},
"error": "Unexpected reasoning effort high. Supported types are xhigh (default), medium, and low."
Impact: the PR's stated root cause is "strict encoders rejected those strings with HTTP 400"; high is rejected by the Qwen3.8 template in-tree, so a Chat client sending the single most common named level still gets 400 on that model while none/minimal/medium now succeed. The behaviour is listed as intentional preservation in the description ("while preserving low, high, …"), but the asymmetry is not justified and it leaves the fix half-done for the level users actually send.
Fix: add normalized_chat_effort = protocol == Protocol::Chat; to the Some("high") arm — the value already maps to Effort::High, and resolve_effort then picks high where the template accepts it and medium where it does not. Add a decode test asserting the Qwen-style vocabulary case for "high", not only for "medium".
Finding 3 — Major: Candidate::IncompleteValue adds an O(K·N) full-prefix reparse to the output hot path
helios/src/output/tagged.rs:306-347
let calls = loop {
...
let end = self.search_from + end;
self.search_from += consumed;
match D::parse_candidate(&self.buffer[..end], &self.tools)? {
Candidate::Complete(calls) => { ... break calls; }
Candidate::InJsonString => {
self.in_json_string = true;
}
Candidate::IncompleteValue => {}
}
};
Main ran parse_candidate at most once per push and then fell back to a linear quote scan (main helios/src/output/tagged.rs:326-332: if let Some(calls) = D::parse_candidate(...) { ... break calls; } self.in_json_string = true;). The branch now loops, restarting parse_candidate at body offset 0 for every literal inner closer the dialect reports as IncompleteValue. Both dialect parsers restart at the body head each call — argument_tags.rs:25-27 (let body = body.trim(); let split = body.find("<arg_key>")...) and chatml.rs:105-109 — so previously validated arguments (including strict-schema validation at argument_tags.rs:40, :92-96 and chatml.rs:117, :182-186) are re-parsed and re-inserted on every iteration.
The bound is unchanged and generous: tagged.rs:303-305
if self.buffer.len() > 1024 * 1024 {
return Err("tool call exceeds the 1 MiB parser bound".into());
}
Impact: a GLM/ChatML call whose argument value contains K occurrences of the outer closer costs K passes over up to a 1 MiB prefix — roughly 87k closers × up to 1 MiB ≈ 90 GB of byte scanning inside a single push, plus K re-validations of the same JSON values, on the token-decode output path shared by all tagged models. This is a real regression for adversarial or merely verbose tool output (the very case the PR targets: a large pattern/script argument that mentions tool tags), and it is worse in the single-character streaming pattern the new tests exercise, where every new closer triggers another full-prefix parse. No new memory is retained, so this is CPU only — but it is on the hot path.
Fix: make the incomplete result carry a resume offset (e.g. IncompleteValue { resume_at: usize } or a per-argument cursor stored in the parser) and parse only self.buffer[resume_at..end], or cap the number of IncompleteValue rescans per push and fall back to plain scanning. Worth noting that open PR #670 already carries an Autobot finding about an O(k·n) prefix rescan in its parse_candidate path; this change introduces the same shape in push.
Finding 4 — Major: the API contract is not updated, and still describes the pre-PR scope
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 |
docs/api.md:960-965
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:
No file under docs/ is in the diff (pr_files lists only the six helios/src files).
Impact: after merge, docs/api.md is wrong in three places: (a) named-level resolution and none/minimal refusal semantics are now also true for Chat, but the doc scopes them to Responses/Messages; (b) the thinking / reasoning history aliases and the new HTTP 400 for non-string alias values are undocumented; (c) docs/api.md:539-547 / :596-628 never states that a literal outer closer inside a non-JSON argument value is argument text rather than a call terminator — the exact behaviour this PR makes deliberate. Open docs PR #172 will additionally record the pre-#677 GLM medium → Max behaviour in this same region.
Fix: add a docs commit to this PR (Chat named-level table, alias precedence, non-string rejection, and the literal-closer rule) or get an explicit maintainer ack that docs land in a follow-up, and note the ordering constraint against #172.
Finding 5 — Minor: reasoning aliases are read on every message role, including tool
helios/src/server/protocol/decode.rs:184-194
if let Some((key, text)) = ["reasoning_content", "thinking", "reasoning"]
.into_iter()
.find_map(|key| v.get(key).filter(|v| !v.is_null()).map(|v| (key, v)))
{
parts.push(Part::Reasoning(
text.as_str()
.ok_or_else(|| format!("{key} must be text"))?
.into(),
));
}
if role == Role::Tool {
The alias block runs before the Role::Tool branch, so a tool message (or a system/user message) carrying any of the three keys gains a Part::Reasoning. helios/src/server/inference.rs:303-311 flushes a message that has reasoning_content even when its content is empty (if current["content"] != "" || current.get("reasoning_content").is_some() || current.get("tool_calls").is_some()), so a tool result echoed with a reasoning field yields a stray content-less tool frame in the rendered prompt, and inference.rs:323-331 lowers the last message's reasoning into reasoning_content.
Fix: restrict the alias lookup to Role::Assistant (the only role where reasoning history is meaningful); the description's motivation — "clients store prior reasoning under those field names" across tool loops — is satisfied by assistant turns alone. Also state the all-roles scope of compatibility note (a) in the description.
Finding 6 — Minor: source-breaking public API change, colliding with open PR #670
helios/src/output/tagged.rs:31-39 (new public enum, exported through lib.rs:23 → output.rs:23 (not opened) → output/tagged)
pub enum Candidate {
Complete(Vec<(String, String)>),
InJsonString,
IncompleteValue,
}
helios/src/output/tagged.rs:49-52
fn parse_candidate(body: &str, tools: &[Value]) -> Result<Candidate> {
Self::parse(body, tools).map(Candidate::Complete)
}
The return type of a public trait method changes from Result<Option<...>> to Result<Candidate>, so any out-of-tree ToolDialect implementation breaks at compile time; the new enum also has no derives, unlike its sibling enums. More consequentially, open PR #670 (lukealonso) rewrites these same functions in tagged.rs/argument_tags.rs to add contract-supplied open/close delimiters, so the two cannot both be rebased trivially — merge order must be decided (#670 currently has red CI).
Fix: note the breaking change in the description, add #[derive(Debug)], and coordinate landing order with #670.
Areas verified sound (no finding)
- The three-state split is the right shape. Main's
Nonereally did mean "enter JSON quote mode" for every non-Someresult (main tagged.rs:326-332), which is the root cause the PR describes;tagged.rs:343-346now setsin_json_stringonly forCandidate::InJsonString. - End-of-sequence rejection is preserved for every dialect.
tagged.rs:266still returnsRejecton!self.confirmed || self.in_json_string, and each dialect still errors on a truncated call at EOS:argument_tags.rs:86-90(return if eos { Err("unterminated GLM argument value".into()) } else { Ok(Candidate::IncompleteValue) };),:121-128,chatml.rs:168-174,gemma_call.rs:186-193. Strict-tool validation is untouched. MiniMaxXml'sCompletemapping is a genuine no-op: itsCLOSEis"]<]minimax[>[</tool_call>"(minimax_xml.rs:194), so a plain</tool_call>in element text cannot start it.- Kani-checked surface and the 1 MiB bound are unchanged:
tagged/kani_proofs.rs:100-110still constructsTaggedToolswith the same nine fields, andeos_decision/select_candidate/partial_markerare unmodified (the PR does disclose Kani was not run). - No concurrency, contention, or failure-propagation change: nothing in the diff introduces shared state, locks, tasks, or cross-request coalescing; a malformed call can only fail its own parser instance.
- The DeepSeek V4.1 half of the intent works:
frontend/mod.rs:836-841resolvesEffort::High→highfor native DeepSeek encoders, which previously would have received the raw"medium"thatfrontend/deepseek.rsrejects — a real fix for that model.
Claim accuracy vs. the diff
Accurate: the alias precedence, the none/minimal/medium arms, nested-reasoning.effort gating (decode.rs:590-602 — top-level reasoning_effort must be absent or null), chat_template_kwargs still overriding (decode.rs:694-701), and the three-state Candidate mechanics all match the description.
Inaccurate or incomplete: (a) the medium → high remap is described as affecting only Jinja templates, but it also moves TMLv0 from 0.7 to 0.9 (Finding 1); (b) the description's claim to have addressed "HTTP 400 … rejected those strings" does not cover high, which remains rejected on Qwen-style templates (Finding 2); (c) the description claims the fix preserves "the 1 MiB buffer bound" — true for memory, but the CPU cost inside that bound becomes quadratic, which is not mentioned (Finding 3); (d) the SM120/BFCL/agentic_suite.py (not opened) evidence remains unreproducible in-repo (no harness, core id, command, or log), the same gap flagged on the author's #457.
Open questions / not found
- Is the TMLv0
medium0.7 → 0.9 shift intended? No maintainer statement, and no in-repo test asserts the TMLv0/Chat-mediumrendering. - Was
highdeliberately left raw because some templates reject it — and if so, how is that consistent with normalizingmediumfor the same reason? - Merge-order intent versus #670 on the same
tagged.rsfunctions: land #677 first, rebase onto #670, or split the two independent commits (0b042e56decode,f439f744output) as maintainers asked on #670? - Does a
docs/api.mdchange exist in a planned follow-up, and how should open PR #172 be reconciled after this lands? - Commit bodies and
Signed-off-bytrailers could not be read with the available tools; there is no linked issue for either defect.