Final review report · NVIDIA/hyperflare-inference #677

Raw Markdown for agents: https://autobot.eidonix.com/p/ca4eb139-8776-4b9d-bfe7-977f5caac04e.md

Recommendation: Changes Requested

Both core problems are real—the three-state Candidate split in helios/src/output/ cleanly fixes literal closing tool tags inside non-JSON argument values without weakening EOS rejection or strict-tool validation, and the Chat Completions alias lookup preserves multi-turn reasoning history across reasoning_content, thinking, and reasoning. However, this PR should not merge as-is: withholding Chat "reasoning_effort": "medium" and mapping it to Effort::High silently shifts TMLv0 (Inkling 2) effort from 0.7 to 0.9 and breaks the existing in-repo golden test prompts_match_tml_renderers_token_for_token (tests/frontend/inkling2_tml.json:318-341). In addition, Candidate::IncompleteValue introduces an O(K·N) full-prefix reparse on the output presentation hot path, "high" remains unnormalized for Qwen3.8-style templates, and docs/api.md is not updated.

Merge Risk

Level: Medium

Walkthrough

Pre-merge Checks

Blockers

  1. Chat "reasoning_effort": "medium" silently shifts TMLv0 (Inkling 2) effort from 0.7 to 0.9 and breaks the existing golden test prompts_match_tml_renderers_token_for_token
    • Location: helios/src/server/protocol/decode.rs:621-624, :684-686; helios/src/server/request.rs:515-527; helios/src/frontend/mod.rs:828-835; helios/src/frontend/tml.rs:19-35, :55-61; helios/src/server/request/tml_tests.rs:104-114; tests/frontend/inkling2_tml.json:318-365.
    • Verified behavior & impact: Because decode.rs:621-624 maps Chat "medium" to Effort::High and sets normalized_chat_effort = true, :684-686 withholds "medium" from options.template. request.rs:515-527 then resolves Effort::High with candidates = &["high", "medium"] via Frontend::resolve_effort. For PromptEncoder::TmlV0 (frontend/mod.rs:829-834), tml::effort_level accepts both "high" (0.9) and "medium" (0.7), so "high" wins first and renders 0.9 instead of 0.7. This directly breaks the existing #[ignore]d golden test prompts_match_tml_renderers_token_for_token (tml_tests.rs:104-114), which feeds tests/frontend/inkling2_tml.json:318-341 ("name": "effort_medium", Chat "reasoning_effort": "medium") through Protocol::Chat and asserts token-for-token equality with effort = 0.7 (token 22, vs effort_high 0.9 token 24). It also silently shifts prompt tokens and prefix-cache keys for TMLv0 Chat clients without disclosure (the PR description scopes the medium → high note to Jinja templates only).
    • Note on non-fixes: Simply reordering Effort::High to &["medium", "high"] does not work—it would break tests/frontend/inkling2_tml.json:3383-3391 (equivalent_requests asserts Responses {"reasoning": {"effort": "medium"}} maps to effort_high = 0.9) and would regress GLM-5.3 itself, because resolve_effort (frontend/mod.rs:853-864) probes Jinja templates only via .render(...).is_ok(), and GLM-5.3's template does not raise on "medium" (it falls back to "max"), so accepted includes "medium".
    • Fix: Preserve native Chat "medium" on encoders that explicitly define a distinct "medium" level—for example, keep top-level Chat "medium" in options.template (or pass it as an advisory effort that TmlV0 resolves to "medium" while encoders without native "medium" resolve to "high"), and add a unit test in decode::native_prompt_tests verifying Chat "reasoning_effort": "medium" through PromptEncoder::TmlV0 produces 0.7 while Responses {"reasoning": {"effort": "medium"}} still produces 0.9. (If maintainers instead explicitly want Chat "medium" to become 0.9 on TMLv0 as well, update tests/frontend/generate_inkling2_fixtures.py (not opened) and tests/frontend/inkling2_tml.json and disclose the TMLv0 breaking change in the PR description and docs/api.md.)

Should Fix

  1. Candidate::IncompleteValue introduces an O(K·N) full-prefix reparse on the output presentation hot path

    • Location: helios/src/output/tagged.rs:303-348, helios/src/output/argument_tags.rs:25-98, helios/src/output/chatml.rs:98-188, helios/src/output/gemma_call.rs:123-167.
    • Verified behavior & impact: On main, TaggedTools::push called parse_candidate at most once before switching to linear JSON quote-skipping (in_json_string = true). With Candidate::IncompleteValue => {}, the loop in tagged.rs:306-348 advances self.search_from past each literal closing tag and re-invokes D::parse_candidate(&self.buffer[..end], &self.tools) from byte 0 of self.buffer on every subsequent inner closing tag. All three dialects restart from the beginning of body, re-parsing and re-validating every completed argument and rescanning the entire open value up to end each time. Within the 1 MiB buffer bound (tagged.rs:303-305), an argument containing K occurrences of a 12-byte </tool_call> (worst case K ≈ 87,381) triggers triangular O(K·N) scanning (~K·N/2 ≈ 4.5 × 10^10 byte inspections, ~45 GB of scanning plus repeated JSON/schema validation) on the Tokio response presentation task—the exact same O(k·n) rescan pattern flagged on #670.
    • Fix: Avoid re-running parse_candidate until the currently open value can actually terminate—analogous to how InJsonString skips directly to the next unescaped " in TaggedTools::push (tagged.rs:307-323). For example, let IncompleteValue carry or advance to the dialect's value terminator ("</arg_value>" for ArgumentTags, "<|\"|>" for GemmaCall, next parameter_end/parameter_start/</function> for FunctionTags) so scanning an open value is O(N) total across the 1 MiB buffer. If this adds a state field to TaggedTools, update helios/src/output/tagged/kani_proofs.rs:100-110 and verify with cargo kani per docs/design-review.md:221-251.
  2. Chat "high" (and "max") are left unnormalized, leaving the same HTTP 400 open on Qwen3.8 templates

    • Location: helios/src/server/protocol/decode.rs:625-626, :684-686; helios/src/server/request.rs:515-527; tests/frontend/qwen38.json:3089-3099.
    • Verified behavior & impact: decode.rs:625-626 maps "high" and "xhigh" | "max" to Effort::High / Effort::Max without setting normalized_chat_effort, so :687-688 still copies them verbatim into options.template and request.rs:515 skips frontend.resolve_effort. While keeping "xhigh" raw is necessary so DeepSeek V4.1 retains score 75 instead of max's 100 (verified at decode.rs:2650-2654 and helios/tests/deepseek_requests.rs:460), leaving "high" (and "max") raw causes strict templates like Qwen3.8 (tests/frontend/qwen38.json:3089-3099: "Unexpected reasoning effort high. Supported types are xhigh (default), medium, and low.") to keep returning HTTP 400. Normalizing "high" and "max" through resolve_effort still resolves to "high" / "max" on DeepSeek V4/V4.1, GLM-5.3, Kimi K3 (helios/tests/fixtures/templates/kimi3/chat_template.jinja:83-85), and TMLv0, while resolving to "medium" / "xhigh" on Qwen3.8.
    • Fix: Include "high" and "max" in Chat normalization (leaving "xhigh" raw so DeepSeek V4.1 preserves 75 vs 100) and add a Qwen-vocabulary (['low', 'medium', 'xhigh']) test case in decode::native_prompt_tests.
  3. Update docs/api.md for the observable API behavior changes (AGENTS.md:230)

    • Location: docs/api.md:539-547, :599-628, :960-995; AGENTS.md:230.
    • Verified behavior & impact: AGENTS.md:230 requires updating the relevant docs/api.md sections when changing API behavior, and no file under docs/ is modified. docs/api.md:960-987 currently scopes named effort resolution strictly to Responses and Messages and documents Chat reasoning_effort only as the DeepSeek numeric score; it does not mention Chat named-level normalization, nested reasoning.effort on Chat, message-level thinking/reasoning aliases and their non-string HTTP 400 validation, or that literal outer closing tool tags inside non-JSON argument values remain argument text. Open docs PR #172 also edits this same GLM effort paragraph with pre-#677 behavior.
    • Fix: Update docs/api.md:960-995 and the tagged tool parsing section (:599-628) in this PR to document the exact shipped behavior, and coordinate wording/merge order with #172.

Subtract / Simplify

  1. Delete the redundant allow_incomplete_value / eos incomplete-value mode flags and dead match arms across all three dialects

    • Locations: helios/src/output/chatml.rs:91-104, :168-174; helios/src/output/gemma_call.rs:123-128, :150-159, :175-193; helios/src/output/argument_tags.rs:85-91, :111-128.
    • Detail: In chatml.rs and gemma_call.rs, non-streaming callers (parse and parse_eos) pass allow_incomplete_value = false, so the inner helpers return Err(...) directly and make the Candidate::IncompleteValue arms in parse_tool (chatml.rs:94) and GemmaCall::{parse,parse_eos} (gemma_call.rs:178,189) completely unreachable while duplicating identical error strings. Deleting allow_incomplete_value in both files and unconditionally returning Ok(Candidate::IncompleteValue) preserves exact behavior and exact error messages. In argument_tags.rs:85-91, parse_body similarly branches on if eos even though parse (:115) and parse_eos (:124) already map Candidate::IncompleteValue (making :124's IncompleteValue arm unreachable; note eos itself is still needed for :32, :41, :44). Always returning Ok(Candidate::IncompleteValue) at :86 (and mapping it to "unterminated GLM argument value" or "incomplete GLM tool call" in parse_eos) unifies all three dialects onto one rule.
  2. Reuse present() and replace the mutable normalized_chat_effort flag in decode.rs

    • Location: helios/src/server/protocol/decode.rs:38-40, :590-592, :606-629, :684-686.
    • Detail: :590-592 open-codes !present(body, "reasoning_effort") && present(&body["reasoning"], "effort") despite present() already existing at :38-40. Likewise, let mut normalized_chat_effort = false; mutated across three separate match arms can be replaced by a single immutable let withheld_chat_effort = ...; computed once before the :677 loop.

Nits

Dropped on verification