Final review report · NVIDIA/hyperflare-inference #670

Raw Markdown for agents: https://autobot.eidonix.com/p/a53c70a8-1c2d-4df6-9fb8-dcba9e7d776e.md

Recommendation: Changes Requested

This PR moves Helios in the right architectural direction—reusing shared TaggedOutput/ToolDialect machinery and typed contract metadata instead of adding per-model parser variants—and the additive Protobuf wire changes and _EXTRA_ROOTS propagation mechanism are fundamentally sound. However, it should not merge as-is due to a verified grammar/parser divergence introduced for Dsml and Xtml paired with ThinkTags, multiple material contradictions between the PR description and shipped behavior (notably claiming strict tool-call grammar support that the code explicitly rejects), and red CI on head 0aeb2c1.

Merge Risk

Level: Medium

Walkthrough

Pre-merge Checks

Blockers

  1. Grammar/parser divergence on Dsml + ThinkTags(custom) and Xtml + ThinkTags, plus inaccurate contract documentation

    • Location: helios/src/model/contract.rs:911-916,943-949, helios/src/output/pipeline.rs:111-120,243-259,293-304, helios/src/output/dsml.rs:24-27,276-284, helios/src/output/xtml.rs:15,114, helios/model-contract.md:287-291.
    • Verified impact:
      • DsmlOutput delegates to deepseek_recipe::stream::output_parser::OutputParser without receiving reasoning.open/reasoning.close (pipeline.rs:111-116, dsml.rs:276-284), so it only recognizes DeepSeek's hardcoded </think>. Yet contract.rs:911-916 now accepts arbitrary ThinkTags delimiters paired with ToolParserKind::Dsml, helios/model-contract.md:287-291 explicitly documents that pairing as supported, and pipeline.rs:293-304 overwrites envelope.reasoning_end with reasoning.close—causing structured-output grammars to end reasoning on the custom marker while DsmlOutput never closes reasoning.
      • FrontendContract::validate only enforces XtmlThink => Xtml (contract.rs:943-949), not Xtml => XtmlThink (unlike the bidirectional checks for Atem and TmlJson at contract.rs:900-909). Converting pipeline.rs:293-304 from a positive MmThink | ChannelThought match to !matches!(reasoning.kind, XtmlThink | RecipientHeaders | ContentHeaders) now overwrites XTML's compound reasoning_end ("<|close|>think<|sep|><|open|>response<|sep|>", pipeline.rs:245-249) with reasoning.close when Xtml is paired with ThinkTags, diverging from XtmlOutput (xtml.rs:15,114).
    • Fix: In FrontendContract::validate, require ToolParserKind::Xtml to pair bidirectionally with ReasoningParserKind::XtmlThink (matching Atem/TmlJson), and restrict non-("<think>", "</think>") ThinkTags delimiters to TaggedOutput-backed tool parsers (rejecting custom ThinkTags delimiters with Dsml). Guard pipeline.rs:293-304 accordingly, update helios/model-contract.md:287-291 to state that DSML uses standard <think>/</think>, and add unit tests covering both rejections/envelopes.
  2. PR description materially contradicts the shipped code (docs/design-review.md Principle 16)

    • Location: helios/src/grammar/strict.rs:1482-1485,2952-2976, helios/src/output/tagged_json.rs:12,36-70,123-136, helios/src/output/tagged.rs:53,271, helios/src/server/request.rs:569-590.
    • Verified discrepancies:
      • Description claims "along with strict tool-call grammar generation", but strict.rs:1482-1485 explicitly rejects ToolParserKind::TaggedJson with "strict function tool schemas are not supported for TaggedJson tool syntax", and this PR adds TaggedJson to the rejection test at strict.rs:2957. (The live validation's json_schema structured-output test exercises AnswerConstraint::Json via compile_json_schema_in, not strict function-tool grammars.)
      • Description claims TaggedJsonToolParser supports arguments and parameters keys, optional id, and fallback to visible text on malformed blocks. In helios/src/output/tagged_json.rs, the type is TaggedJson (:12), parse_body (:56-68) reads only "arguments" (never "parameters"), "id" is never read or emitted (tagged.rs:271 emits id: None), and malformed blocks return Err (:38-68, asserted by rejects_malformed_or_non_object_payloads at :123-136).
      • Description states ReasoningGate and thinking-budget truncation hardcoded <think>/</think>; ReasoningGate does not exist in helios/src (the parser is ThinkReasoning in tagged.rs:53), and thinking_budget_close (helios/src/server/request.rs:569-590) already encoded &syntax.close dynamically before this PR.
    • Fix: Either implement the claimed behaviors (compile_strict_tagged_json, parameters, id, visible-text fallback) or rewrite the PR description so every claim matches the shipped code and explicitly discloses that strict: true function tools are rejected for TAGGED_JSON.
  3. CI is failing on head 0aeb2c1

    • Location: PR head 0aeb2c1 (workflows .github/workflows/native-serving.yml (not opened), .github/workflows/helios-lifecycle.yml (not opened), .github/workflows/python-cpu.yml (not opened)).
    • Fix: Investigate and fix the failing CI check on 0aeb2c1 so all required workflows pass before merge.

Should Fix

  1. O(k·n) prefix rescan in TaggedJson::parse_candidate on the single-threaded presentation path

    • Location: helios/src/output/tagged_json.rs:16-33,83-88 and helios/src/output/tagged.rs:295-338.
    • Verified impact: TaggedTools::push buffers up to 1 MiB (tagged.rs:295-297) and only fast-forwards self.in_json_string after parse_candidate returns Ok(None), resetting in_json_string = false at the closing " of that string. When a payload contains many separate JSON strings that each contain the close delimiter (e.g., an array of strings ["<ctrl4>", "<ctrl4>", ...]), each distinct string invokes ends_in_json_string(&self.buffer[..end]) from byte 0 (tagged_json.rs:16-33). On a 1 MiB buffer this degenerates to O(k·n) (worst-case ~2.5×10¹⁰ byte iterations) on the single-threaded Tokio response task. (Note: serde_json::from_str is not re-run inside strings because ends_in_json_string short-circuits first.)
    • Fix: Add an incremental JSON-string scan mode for JSON-body dialects in TaggedTools (e.g., const JSON_BODY: bool = false on ToolDialect with a monotonic scan_pos cursor in TaggedTools so in_json_string/escaped advances once per byte in O(n) total), and delete ends_in_json_string from tagged_json.rs.
  2. Add a CPU-only unit test for peer _EXTRA_ROOTS propagation in rank_group.py

    • Location: ignition/preparation/rank_group.py:44-75,295-311.
    • Verified impact: pr_files shows no test file added or modified for the rank_group.py bugfix, even though tests/preparation/test_forward_cache_sources.py and tests/preparation/test_native_processes.py already test source_roots and rank_group._peer on CPU.
    • Fix: Add a CPU-only test (in tests/preparation/test_forward_cache_sources.py or a new rank-group test) that binds source_roots(...), invokes rank_group._peer (or a spawned child via mp.get_context("spawn")), and asserts _EXTRA_ROOTS.get() / ForwardCache(...).root matches the parent inside prepare(...).

Subtract / Simplify

  1. Replace the 15-line manual TaggedJson arm in OutputPipeline::grammar_envelope

    • Location: helios/src/output/pipeline.rs:266-280.
    • Why: reasoning_end: Some("</think>".into()) and tool_ends_reasoning: false are immediately overwritten by the post-pass at pipeline.rs:293-310, and the remaining fields duplicate TaggedOutput::<D>::grammar_envelope (helios/src/output/tagged.rs:497-508).
    • Simplification: Delegate Some((ToolParserKind::TaggedJson, _, _)) to TaggedOutput::<super::tagged_json::TaggedJson>::grammar_envelope(&config.content) and override envelope.tool for ToolParserKind::TaggedJson in the existing post-pass right beside reasoning_end/tool_ends_reasoning. This removes ~12 lines, drops an .unwrap() on syntax.tools, and deletes the dead "</think>" literal from pipeline.rs:271.
  2. Collapse the duplicated delimiter validity rule and 28-line match in FrontendContract::validate

    • Location: helios/src/model/contract.rs:886-890,911-935.
    • Why: !open.is_empty() && !close.is_empty() && open != close is duplicated between tools and reasoning, and the previously compact 6-line fixed-delimiter table was expanded into 5 verbose arms repeating reasoning.open == ... && reasoning.close == ....
    • Simplification: Extract a tiny helper fn valid_delimiters(open: &str, close: &str, fixed: Option<(&str, &str)>) -> bool and keep the reasoning match as a 6-line Option<(&str, &str)> table (ThinkTags => None, fixed kinds => Some((open, close))).
  3. Deduplicate the JSON-string byte scanner (if not eliminated by Should Fix #1)

    • Location: helios/src/output/tagged_json.rs:16-33 vs helios/src/output/tagged.rs:989-998.
    • Simplification: If incremental scanning in TaggedTools is not adopted immediately, factor the identical quote/escape loop into a single pub(super) fn ends_in_json_string(text: &str) -> bool in tagged.rs shared by container_parameter and TaggedJson::parse_candidate.

Nits

Dropped on verification