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
- Silent prompt/prefix-cache shift and golden-test breakage on TMLv0 (
Inkling 2): Chat requests with"reasoning_effort": "medium"change from0.7to0.9, breakinghelios/src/server/request/tml_tests.rs:104-114(tests/frontend/inkling2_tml.json:318-341) and shifting prompt token IDs and prefix-cache keys on upgrade. - Output presentation hot-path CPU regression:
TaggedTools::push(helios/src/output/tagged.rs:306-348) restartsD::parse_candidatefrom byte 0 on every literal inner closer inside an open value (O(K·N)up to the 1 MiB buffer bound), risking stalls on the Tokio response task for tag-heavy or repetitive tool arguments. No new locks, threads, shared caches, or cross-request failure blast radius are introduced. - Multi-PR collision surface: Open PR #670 (lukealonso) modifies the same
ToolDialect/TaggedTools::push/parse_candidateregion ofhelios/src/output/tagged.rsandargument_tags.rsand addsTaggedJsonimplementingToolDialect::parse_candidate; landing order and rebase must be coordinated.
Walkthrough
helios/src/server/protocol/decode.rs:chat_messages(:184-193) reads the first non-null ofreasoning_content,thinking,reasoningand rejects non-string values naming the offending key.options(:590-638,:677-690) accepts nestedreasoning.efforton Chat Completions when top-levelreasoning_effortis absent or null, normalizes top-level"none","minimal", and"medium"viaenable_thinking: false/options.effortwhile withholding those raw strings fromoptions.template, preserves numeric/unknown top-level passthrough andchat_template_kwargsprecedence, and rejects unsupported nestedreasoning.effortvalues.- Added isolated unit tests (
:2429-2656) exercising realdecode+prepare_inferenceon Jinja andDeepseekV41encoders.
helios/src/output/tagged.rs:- Introduced
pub enum Candidate { Complete(Vec<(String, String)>), InJsonString, IncompleteValue }(:31-39) and updatedToolDialect::parse_candidate(:50-52) to returnResult<Candidate>. - Updated
TaggedTools::push(:336-347) to setself.in_json_string = trueonly onCandidate::InJsonStringand keep scanning past the inner closing tag onCandidate::IncompleteValue, preserving the 1 MiB buffer limit (:303-305) andeos_decision(:257-271).
- Introduced
helios/src/output/{argument_tags.rs,chatml.rs,gemma_call.rs,minimax_xml.rs}:- Updated
ArgumentTags,FunctionTags(ChatMlOutput/CompactChatMlOutput), andGemmaCallto returnCandidate::IncompleteValuefor open argument/parameter/<|"|>-quoted string values during candidate evaluation while retainingparse/parse_eoserrors for unterminated values; adaptedMiniMaxXml(minimax_xml.rs:200-202) toCandidate::Complete(its closer is namespace-prefixed). - Added exhaustive two-part UTF-8 split, single-character streaming, strict-tool, and EOS/non-EOS termination unit tests across all four dialects.
- Updated
Pre-merge Checks
- [PASS] Security / malicious screen: No unsafe code, secret/exfiltration vectors, or prompt-injection paths; malformed/unterminated calls still fail closed at EOS and the 1 MiB parser buffer bound is preserved (
O(K·N)CPU rescan tracked under Should Fix). - [WARN] Charter & value fit: Aligned with documented OpenAI API support and keeping Helios model-agnostic, but bundles two independent fixes in one PR, omits required
docs/api.mdupdates (AGENTS.md:230), and does not disclose the TMLv00.7 → 0.9shift in the PR description (docs/design-review.mdPrinciple 16). - [WARN] Related / duplicate / conflict check: Not a duplicate, but directly conflicts with open PR #670 (
helios/src/output/tagged.rsandargument_tags.rs, plustagged_json.rs(not opened)'sToolDialect::parse_candidatesignature) and interacts with open docs PR #172 (docs/api.mdGLM effort wording). - [WARN] Tests & verification evidence: All new Rust unit tests are isolated, mutate no process-global state, and exercise real production entry points;
helios/src/output/tagged/kani_proofs.rstargets are structurally unchanged. However, the#[ignore]d Inkling 2 golden testprompts_match_tml_renderers_token_for_token(helios/src/server/request/tml_tests.rs:104-114) is broken by this change, and the external SM120/BFCL/agentic_suite.py(not opened) claims have no in-tree harness, core ID, command, or log (agentic_suite/BFCLdo not exist in-repo).
Blockers
- Chat
"reasoning_effort": "medium"silently shifts TMLv0 (Inkling 2) effort from0.7to0.9and breaks the existing golden testprompts_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-624maps Chat"medium"toEffort::Highand setsnormalized_chat_effort = true,:684-686withholds"medium"fromoptions.template.request.rs:515-527then resolvesEffort::Highwithcandidates = &["high", "medium"]viaFrontend::resolve_effort. ForPromptEncoder::TmlV0(frontend/mod.rs:829-834),tml::effort_levelaccepts both"high"(0.9) and"medium"(0.7), so"high"wins first and renders0.9instead of0.7. This directly breaks the existing#[ignore]d golden testprompts_match_tml_renderers_token_for_token(tml_tests.rs:104-114), which feedstests/frontend/inkling2_tml.json:318-341("name": "effort_medium", Chat"reasoning_effort": "medium") throughProtocol::Chatand asserts token-for-token equality witheffort = 0.7(token22, vseffort_high0.9token24). It also silently shifts prompt tokens and prefix-cache keys for TMLv0 Chat clients without disclosure (the PR description scopes themedium → highnote to Jinja templates only). - Note on non-fixes: Simply reordering
Effort::Highto&["medium", "high"]does not work—it would breaktests/frontend/inkling2_tml.json:3383-3391(equivalent_requestsasserts Responses{"reasoning": {"effort": "medium"}}maps toeffort_high=0.9) and would regress GLM-5.3 itself, becauseresolve_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"), soacceptedincludes"medium". - Fix: Preserve native Chat
"medium"on encoders that explicitly define a distinct"medium"level—for example, keep top-level Chat"medium"inoptions.template(or pass it as an advisory effort thatTmlV0resolves to"medium"while encoders without native"medium"resolve to"high"), and add a unit test indecode::native_prompt_testsverifying Chat"reasoning_effort": "medium"throughPromptEncoder::TmlV0produces0.7while Responses{"reasoning": {"effort": "medium"}}still produces0.9. (If maintainers instead explicitly want Chat"medium"to become0.9on TMLv0 as well, updatetests/frontend/generate_inkling2_fixtures.py(not opened) andtests/frontend/inkling2_tml.jsonand disclose the TMLv0 breaking change in the PR description anddocs/api.md.)
- Location:
Should Fix
-
Candidate::IncompleteValueintroduces anO(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::pushcalledparse_candidateat most once before switching to linear JSON quote-skipping (in_json_string = true). WithCandidate::IncompleteValue => {}, theloopintagged.rs:306-348advancesself.search_frompast each literal closing tag and re-invokesD::parse_candidate(&self.buffer[..end], &self.tools)from byte 0 ofself.bufferon every subsequent inner closing tag. All three dialects restart from the beginning ofbody, re-parsing and re-validating every completed argument and rescanning the entire open value up toendeach time. Within the 1 MiB buffer bound (tagged.rs:303-305), an argument containingKoccurrences of a 12-byte</tool_call>(worst caseK ≈ 87,381) triggers triangularO(K·N)scanning (~K·N/2 ≈ 4.5 × 10^10byte inspections, ~45 GB of scanning plus repeated JSON/schema validation) on the Tokio response presentation task—the exact sameO(k·n)rescan pattern flagged on #670. - Fix: Avoid re-running
parse_candidateuntil the currently open value can actually terminate—analogous to howInJsonStringskips directly to the next unescaped"inTaggedTools::push(tagged.rs:307-323). For example, letIncompleteValuecarry or advance to the dialect's value terminator ("</arg_value>"forArgumentTags,"<|\"|>"forGemmaCall, nextparameter_end/parameter_start/</function>forFunctionTags) so scanning an open value isO(N)total across the 1 MiB buffer. If this adds a state field toTaggedTools, updatehelios/src/output/tagged/kani_proofs.rs:100-110and verify withcargo kaniperdocs/design-review.md:221-251.
- Location:
-
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-626maps"high"and"xhigh" | "max"toEffort::High/Effort::Maxwithout settingnormalized_chat_effort, so:687-688still copies them verbatim intooptions.templateandrequest.rs:515skipsfrontend.resolve_effort. While keeping"xhigh"raw is necessary so DeepSeek V4.1 retains score75instead ofmax's100(verified atdecode.rs:2650-2654andhelios/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"throughresolve_effortstill 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 preserves75vs100) and add a Qwen-vocabulary (['low', 'medium', 'xhigh']) test case indecode::native_prompt_tests.
- Location:
-
Update
docs/api.mdfor 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:230requires updating the relevantdocs/api.mdsections when changing API behavior, and no file underdocs/is modified.docs/api.md:960-987currently scopes named effort resolution strictly to Responses and Messages and documents Chatreasoning_effortonly as the DeepSeek numeric score; it does not mention Chat named-level normalization, nestedreasoning.efforton Chat, message-levelthinking/reasoningaliases 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-995and the tagged tool parsing section (:599-628) in this PR to document the exact shipped behavior, and coordinate wording/merge order with #172.
- Location:
Subtract / Simplify
-
Delete the redundant
allow_incomplete_value/eosincomplete-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.rsandgemma_call.rs, non-streaming callers (parseandparse_eos) passallow_incomplete_value = false, so the inner helpers returnErr(...)directly and make theCandidate::IncompleteValuearms inparse_tool(chatml.rs:94) andGemmaCall::{parse,parse_eos}(gemma_call.rs:178,189) completely unreachable while duplicating identical error strings. Deletingallow_incomplete_valuein both files and unconditionally returningOk(Candidate::IncompleteValue)preserves exact behavior and exact error messages. Inargument_tags.rs:85-91,parse_bodysimilarly branches onif eoseven thoughparse(:115) andparse_eos(:124) already mapCandidate::IncompleteValue(making:124'sIncompleteValuearm unreachable; noteeositself is still needed for:32,:41,:44). Always returningOk(Candidate::IncompleteValue)at:86(and mapping it to"unterminated GLM argument value"or"incomplete GLM tool call"inparse_eos) unifies all three dialects onto one rule.
- Locations:
-
Reuse
present()and replace the mutablenormalized_chat_effortflag indecode.rs- Location:
helios/src/server/protocol/decode.rs:38-40,:590-592,:606-629,:684-686. - Detail:
:590-592open-codes!present(body, "reasoning_effort") && present(&body["reasoning"], "effort")despitepresent()already existing at:38-40. Likewise,let mut normalized_chat_effort = false;mutated across three separate match arms can be replaced by a single immutablelet withheld_chat_effort = ...;computed once before the:677loop.
- Location:
Nits
helios/src/server/protocol/decode.rs:184-194: Reasoning aliases are read before theRole::Toolbranch on every message role. Whilereasoning_contentwas already outside the role check onmain, expanding it to generic keys"thinking"and"reasoning"means atoolmessage carrying those keys causeshelios/src/server/inference.rs:303-332,358to flush a stray content-less{"role":"tool","content":"","reasoning_content":...}message before the tool result (which templates like Kimi K3 reject athelios/tests/fixtures/templates/kimi3/chat_template.jinja:42-49), andsystem/developermessages fail atinference.rs:258-261. Consider restricting the alias lookup torole == Role::Assistant.helios/src/output/tagged.rs:31-39: Add#[derive(Debug, PartialEq, Eq)]topub enum Candidateto match sibling enumsOutputStart(:15) andEosDecision(:234).- PR scoping: The Chat decode changes (
0b042e56) and tagged output parser changes (f439f744) are completely independent; splitting them into two PRs would allow the output parser fix to rebase/land alongside #670 without being held up by the effort-normalization contract.
Dropped on verification
- Out-of-tree semver breaking-change warning on
ToolDialect::parse_candidate/Candidate(tagged.rs:31-52): Dropped as low-signal—per the project charter roadmap (#6), the Helios Rust crates are not published yet; the actual merge hazard is the in-repo conflict with open PR #670, tracked under Merge Risk and Pre-merge Checks. - Proposed fix to reorder
Effort::Highto&["medium", "high"]: Dropped as incorrect—verified againsttests/frontend/inkling2_tml.json:3383-3391(Responsesmediummust resolve toeffort_high=0.9) andhelios/src/frontend/mod.rs:853-864(GLM-5.3's template does not raise on"medium", so&["medium", "high"]would send"medium"to GLM and cause it to fall back to"max"). - Asymmetry between rejecting unknown nested
reasoning.effortvs passing through unknown top-levelreasoning_effort(decode.rs:627-628): Dropped as intentional and required—top-level Chatreasoning_effortmust continue reaching native encoders/templates to preserve padded values like" low "(tests/frontend/inkling2_tml.json:759) and encoder-specific validation/error messages (tests/frontend/inkling2_tml.json:3530,helios/tests/deepseek_requests.rs:470-480), whereas nestedreasoning.effortfollows Responses validation. - Minor upstream inaccuracies corrected rather than repeated: Corrected the worst-case scan estimate in
TaggedTools::pushfrom~90 GBto the triangular sumK·N/2 ≈ 45 GB, and corrected theargument_tags.rseosnote (eosstill guards lines:32,:41, and:44, not only strict calls). - Test-scaffolding deduplication (
chatml.rs:1408-1430vsHarness,decode.rs:2540-2638): Dropped as low-signal—chatml.rs:412-437'sHarnessis hardcoded toChatMlOutput(not generic overToolDialect), and thedecode.rsclosures follow the existing style innative_prompt_tests.