#1 [high] Verified findings — PR #677 correctness/contracts review
F1 (Major, undocumented behaviour change / prompt shift): Chat reasoning_effort:"medium" now resolves to Effort::High and the raw string is withheld from the template, so request.rs:521 ladders ["high","medium"] and TMLv0 picks high (0.9) instead of medium (0.7).
- decode.rs:621-624
Some("medium") => { normalized_chat_effort = protocol == Protocol::Chat; Some(Effort::High) } - decode.rs:684-686 skip of
reasoning_efforttemplate insert - request.rs:515-527 ladder
Effort::High => &["high", "medium"] - frontend/tml.rs:19-27
("medium",0.7),("high",0.9); resolve_effort TmlV0 picks first level (mod.rs:829-835) Description only discloses "Jinja templates distinguishing medium from high". Impact: every Chat request with "medium" on TMLv0 models (Inkling 2) renders effort 0.7→0.9 → different prompt bytes → different prompt_tokens and different prefix-cache keys. Fix: disclose, or special-case TmlV0 to prefer "medium", or add a test asserting the TMLv0 rendering.
F2 (Major, fix incomplete): "high" is NOT normalized (no normalized_chat_effort assignment at decode.rs:625), so it is still copied verbatim into options.template and request.rs:515's contains_key guard skips resolution. Templates that reject high still 400: tests/frontend/qwen38.json:3089-3099 "Unexpected reasoning effort high. Supported types are xhigh (default), medium, and low." So the PR fixes none/minimal/medium but leaves the same class of HTTP 400 for the most common level. Fix: normalize "high" to Effort::High too (it already maps to Effort::High natively) — i.e. set normalized_chat_effort for "high" as well.
F3 (Major, hot-path CPU amplification): new Candidate::IncompleteValue re-runs the full D::parse_candidate(&self.buffer[..end]) once per literal inner closer, re-parsing the whole prefix each time → quadratic. tagged.rs:306-347 (loop, let end = self.search_from + end; ... D::parse_candidate(&self.buffer[..end], ...)) + argument_tags.rs:25-103, chatml.rs:98-193. Main only did a single linear quote scan (main tagged.rs:326-332 self.in_json_string = true). With the 1 MiB bound (tagged.rs:303-305) and </tool_call> repeated K≈87k times, that is K full-prefix parses ≈ 90 GB of scanning for one call, on the decode hot path. Fix: remember a per-argument resume offset in the dialect, or bound the number of IncompleteValue rescans, or parse only the suffix after the last successful </arg_value>.
F4 (Major, contract/docs): AGENTS.md:230 requires docs/api.md for API-behaviour changes; no docs file is in the diff. docs/api.md:960-969 still documents named-level resolution for Responses/Messages only, and docs/api.md:539-547/596-628 says nothing about a literal outer closer inside a non-JSON value being argument text.
F5 (Minor): aliases are now read on every message role, including tool. decode.rs:184-193 applies to all roles; inference.rs:323-331 turns a Reasoning part into reasoning_content on the current message, and inference.rs:303-311 flushes it into a content-less message. A thinking/reasoning field on a tool message therefore produces a stray empty-content tool message. Also any non-string reasoning object on a user/system message becomes HTTP 400 (disclosed as note (a), but the all-roles scope is not).
F6 (Minor): Candidate is a new public enum in pub mod output::tagged (lib.rs:23, output.rs:23) and ToolDialect::parse_candidate's signature changed (tagged.rs:49-52), a source-breaking change for out-of-tree ToolDialect implementors, and it collides textually with open PR #670 which rewrites the same functions. Note Candidate has no derives (Debug) unlike sibling enums.
Sound areas verified: main's Option semantics really did set in_json_string for every non-Some (main tagged.rs:326-332); eos_decision still rejects !confirmed || in_json_string (tagged.rs:266) and an open non-JSON value still fails at parse_eos for every dialect (argument_tags.rs:86-90+121-128, chatml.rs:168-174, gemma_call.rs:186-193); the 1 MiB bound and Kani struct fields are unchanged (kani_proofs.rs:100-110); MiniMaxXml mapping is a no-op (minimax_xml.rs:200-202). No new locks, no shared state, no per-request allocation growth beyond F3.
#2 [high] Research summary
Reviewed PR #677 against main: all six changed files read in full, plus direct callers and contracts (request.rs effort ladder, frontend/mod.rs resolve_effort, frontend/tml.rs, frontend/deepseek.rs, inference.rs template_messages, docs/api.md, AGENTS.md, kani_proofs.rs, untracked dialects dsml/xtml/pipeline).
Six verified findings, saved to the scratchpad. Highest signal:
- Undocumented prompt shift on TMLv0 models — Chat
reasoning_effort:"medium"now yieldsEffort::Highwith the raw string withheld (decode.rs:621-624, 684-686), and request.rs:521's ladder resolvesHigh→high, so TMLv0 renders 0.9 instead of 0.7 (tml.rs:19-27). Description discloses this only for Jinja templates. - The fix is incomplete for
"high": nonormalized_chat_effortis set on that arm (decode.rs:625), sohighstill reaches the template verbatim and still 400s on templates that reject it (tests/frontend/qwen38.json:3089-3099). - Hot-path CPU amplification:
Candidate::IncompleteValuere-runs the full prefixparse_candidateonce per literal inner closer (tagged.rs:306-347), which is quadratic in buffer size up to the unchanged 1 MiB bound — a regression from main's single linear quote scan. - Contract: no docs/api.md update despite AGENTS.md:230, and docs/api.md:960-969 still describes named-level resolution for Responses/Messages only.
- Minor: aliases now read on every role, so a
toolmessage carryingthinking/reasoninginjects a stray content-less message via inference.rs:303-331. - Minor:
Candidateis a new public enum andToolDialect::parse_candidate's signature changed (lib.rs:23 → output.rs:23 (not opened) → tagged.rs:31-52); source-breaking for out-of-tree dialects and textually colliding with open PR #670.
Sound in the areas I could verify: main's Option really did set in_json_string for every non-Some; EOS still rejects open non-JSON values in all four dialects; the 1 MiB bound, eos_decision, and the Kani-checked struct fields are unchanged; MiniMaxXml's Complete mapping is a genuine no-op. No new locks or shared state.
#3 [high] Verbatim quotes for each finding (F1-F6)
F1 — TMLv0 medium 0.7 → 0.9 (Major)
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-527
if !options.contains_key("reasoning_effort") {
if let Some(effort) = opts.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
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),
];
helios/src/frontend/mod.rs:829-835 (TmlV0 picks the FIRST accepted level, so "high" wins over "medium")
Main comparison: main decode.rs:587-593 let effort = if Responses {...} else if Messages {...} else { None }; — Chat had no effort at all, so "medium" went verbatim into options.template (main decode.rs:655-660) and TMLv0 read it as 0.7 (tml.rs:55-61).
F2 — "high" left unnormalized (Major)
Same quote as F1 decode.rs:625 Some("high") => Some(Effort::High), — no normalized_chat_effort = protocol == Protocol::Chat; on this arm, so the continue at :684 does not fire and request.rs:515's !options.contains_key("reasoning_effort") guard means resolution is skipped.
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."
Fix: add normalized_chat_effort = protocol == Protocol::Chat; to the Some("high") arm (the value already maps to Effort::High).
F3 — quadratic rescan on the decode hot path (Major)
helios/src/output/tagged.rs:306-347
let calls = loop {
...
let Some((end, consumed, outer_closed)) =
select_candidate(tail.find(D::CLOSE), D::CLOSE.len(), inner, inner_len)
else { return Ok(Progress::default()); };
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 comparison (main helios/src/output/tagged.rs:326-332):
if let Some(calls) = D::parse_candidate(&self.buffer[..end], &self.tools)? {
self.buffer.drain(..self.search_from);
self.search_from = 0;
self.outer_closed = outer_closed;
break calls;
}
self.in_json_string = true;
Main ran parse_candidate at most once per push (then a linear byte scan); the branch now loops, re-parsing self.buffer[..end] from byte 0 for each literal </tool_call> inside an argument value. Bound is unchanged: tagged.rs:303-305 if self.buffer.len() > 1024 * 1024 { return Err("tool call exceeds the 1 MiB parser bound".into()); } — so up to ~1 MiB × number of inner closers. parse_body/parse_tool_candidate restart at the body head each call (argument_tags.rs:25-27 let body = body.trim(); let split = body.find("<arg_key>")...; chatml.rs:105-109). Fix: carry a per-argument resume offset in the dialect, or cap IncompleteValue rescans, or start from the last successfully consumed </arg_value>.
F4 — docs/contract not updated (Major)
AGENTS.md:230
| Change CLI, API, or configuration behavior | CLI design and the relevant API sections |
docs/api.md:960-965 still scopes named levels to Responses/Messages:
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.
docs/api.md:539-547 has no statement that a literal outer closer inside a non-JSON value stays argument text (it speaks only of truncated/omitted envelopes and undecided openers).
Diff contains no docs/ file (pr_files).
F5 — aliases read on every role (Minor)
helios/src/server/protocol/decode.rs:184-193
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(),
));
}
This runs before the role branch at :194 (if role == Role::Tool), so a tool message with a thinking/reasoning field gets a Reasoning part. helios/src/server/inference.rs:303-311 flushes a message that has reasoning_content even when content is empty: if current["content"] != "" || current.get("reasoning_content").is_some() || current.get("tool_calls").is_some() { out.push(current.clone()); }. Fix: restrict aliases to assistant (or assistant+user) roles.
F6 — public API surface break vs the open PR on the same code (Minor)
helios/src/lib.rs:23 pub mod output;; helios/src/output.rs:23 pub mod tagged;
helios/src/output/tagged.rs:31-39 (new public enum, no derives)
pub enum Candidate {
Complete(Vec<(String, String)>),
InJsonString,
IncompleteValue,
}
helios/src/output/tagged.rs:49-52
/// Evaluates a candidate call body ending at an apparent closing tag.
fn parse_candidate(body: &str, tools: &[Value]) -> Result {
Self::parse(body, tools).map(Candidate::Complete)
}
Out-of-tree ToolDialect implementors must change signatures. Open PR #670 (lukealonso) rewrites these same functions to add contract-supplied open/close delimiters, so merge order must be decided; #670 also lacks green CI.
Verified-sound notes (say so plainly in the report):
- main's
Nonereally did mean "enters JSON quote mode" for every non-Some result, so the three-state split is the right shape (main tagged.rs:326-332 above). - EOS still rejects open values: tagged.rs:266
} else if !self.confirmed || self.in_json_string {then argument_tags.rs:86-90 (return if eos { Err("unterminated GLM argument value".into()) } else { Ok(Candidate::IncompleteValue) };) and :121-128; chatml.rs:168-174; gemma_call.rs:186-193. - 1 MiB bound, TaggedTools field set and Kani targets unchanged: kani_proofs.rs:100-110 constructs TaggedTools with the same nine fields; eos_decision/select_candidate/partial_marker unchanged.
- MiniMaxXml mapping is a genuine no-op: minimax_xml.rs:200-202
.map(super::tagged::Candidate::Complete); its CLOSE begins with the reserved]<]minimax[>[sentinel (minimax_xml.rs:194), which a plain</tool_call>in element text cannot start. - No new locks, mutexes, channels, threads or shared caches anywhere in the diff; all state stays per-parser-instance, so no contention/HOL-blocking/blast-radius concern. Memory amplification is limited to F3's redundant iteration (same buffer, no extra retention).
- Metric/span check: nothing in the diff samples or changes a rate/latency/admission metric;
consumed_bytes(tagged.rs:505-508) still subtracts only the buffered remainder, so span accounting is unaffected.