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
- Shared output/grammar envelope path: Widening
OutputPipeline::grammar_envelope'sreasoning_endoverride and looseningTHINK_TAGSvalidation affects all parser pairings, introducing silent grammar/parser mismatches onDsml + ThinkTags(custom)andXtml + ThinkTags. - Single-threaded response presentation hot path:
TaggedJson::parse_candidaterescans the accumulated tool buffer from byte 0 for each distinct JSON string containing the close delimiter, creating an O(k·n) worst case up to the 1 MiB buffer bound on the Tokio presentation task. - Wire & multi-PR surface: Protobuf additions (
TAGGED_JSON = 9,ToolParser.{open,close}) are backward-compatible for existing cores, but enum slot9andignition/preparation/contract.py:frontend()directly collide with open PR #500, and CI on0aeb2c1is currently failing.
Walkthrough
- Parameterized
THINK_TAGS(helios/src/model/contract.rs,helios/src/grammar.rs,helios/src/output/pipeline.rs,helios/src/output/tagged.rs,helios/model-contract.md): LoosensReasoningParserKind::ThinkTagsvalidation to accept any nonempty distinctopen/closepair, convertsOutputEnvelope.{reasoning_end,tool}toCow<'static, str>, widensOutputPipeline::grammar_envelope'sreasoning_endoverride, and adds dynamictool_open/tool_closefields toTaggedOutput/ThinkReasoning/TaggedTools. - New
ToolParserKind::TAGGED_JSON = 9(helios/proto/runtime_core.proto,helios/build.rs,helios/src/output/tagged_json.rs,helios/src/output.rs,helios/src/runtime_core/{describe,protobuf}.rs,helios/src/grammar/strict.rs,ignition/preparation/{contract.py,runtime_core_pb2.py (not opened)}): Adds optionalopen/closefields toToolParser(required nonempty/distinct forTAGGED_JSON, rejected on other kinds, omitted from/describewhen empty), implementsTaggedJsonoverTaggedOutput, regeneratesruntime_core_pb2.py(not opened), extendscontract.frontend()with optional delimiter kwargs, and explicitly rejectsstrict: truetool grammars forTaggedJson. - TP peer source-root propagation (
ignition/preparation/rank_group.py): Captures_EXTRA_ROOTS.get()inprepare_groupand passes it to spawned_peerworkers, wrappingprepare(...)insource_roots(extra_roots)so single-host TP peers compute the sameForwardCachepath as rank 0. - Struct-literal updates across tests (
flare-cli/tests/unverified_payload.rs,helios/src/output/argument_tags.rs,helios/src/server/*.rs): Populates the newToolParser.{open,close}fields in existing test fixtures and adds unit tests for customTHINK_TAGSmarkers,TaggedJson, contract validation, and protobuf wire decoding.
Pre-merge Checks
- [PASS] Security / malicious screen: No prompt-injection, unsafe code, or exfiltration vectors; malformed tool JSON fails closed and buffers remain bounded at 1 MiB (note the O(k·n) CPU rescan DoS edge case tracked in Should Fix).
- [PASS] Charter & value fit: Strong architectural alignment with keeping Helios small and model-agnostic (#267, #334) and fixing the root cause in
rank_group.py(#397); author@lukealonsois a priority contributor. - [WARN] Related / duplicate / conflict check: Direct collision with open PR #500 on
ToolParserKind = 9(pr/500helios/proto/runtime_core.proto:364ERNIE_XML = 9vs this PR's:465TAGGED_JSON = 9) andignition/preparation/contract.py:frontend(); coordinate merge order and renumber if #500 lands first. - [WARN] Tests & verification evidence: CI on
0aeb2c1is red,FLARE_TEST_TEMPLATE_DIRfixture tests were not run locally, therank_group.pyfix adds no test, and the paired externalhyperflare-recipesErgo PR is unlinked.
Blockers
-
Grammar/parser divergence on
Dsml + ThinkTags(custom)andXtml + 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:
DsmlOutputdelegates todeepseek_recipe::stream::output_parser::OutputParserwithout receivingreasoning.open/reasoning.close(pipeline.rs:111-116,dsml.rs:276-284), so it only recognizes DeepSeek's hardcoded</think>. Yetcontract.rs:911-916now accepts arbitraryThinkTagsdelimiters paired withToolParserKind::Dsml,helios/model-contract.md:287-291explicitly documents that pairing as supported, andpipeline.rs:293-304overwritesenvelope.reasoning_endwithreasoning.close—causing structured-output grammars to end reasoning on the custom marker whileDsmlOutputnever closes reasoning.FrontendContract::validateonly enforcesXtmlThink => Xtml(contract.rs:943-949), notXtml => XtmlThink(unlike the bidirectional checks forAtemandTmlJsonatcontract.rs:900-909). Convertingpipeline.rs:293-304from a positiveMmThink | ChannelThoughtmatch to!matches!(reasoning.kind, XtmlThink | RecipientHeaders | ContentHeaders)now overwrites XTML's compoundreasoning_end("<|close|>think<|sep|><|open|>response<|sep|>",pipeline.rs:245-249) withreasoning.closewhenXtmlis paired withThinkTags, diverging fromXtmlOutput(xtml.rs:15,114).
- Fix: In
FrontendContract::validate, requireToolParserKind::Xtmlto pair bidirectionally withReasoningParserKind::XtmlThink(matchingAtem/TmlJson), and restrict non-("<think>", "</think>")ThinkTagsdelimiters toTaggedOutput-backed tool parsers (rejecting customThinkTagsdelimiters withDsml). Guardpipeline.rs:293-304accordingly, updatehelios/model-contract.md:287-291to state that DSML uses standard<think>/</think>, and add unit tests covering both rejections/envelopes.
- Location:
-
PR description materially contradicts the shipped code (
docs/design-review.mdPrinciple 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-1485explicitly rejectsToolParserKind::TaggedJsonwith"strict function tool schemas are not supported for TaggedJson tool syntax", and this PR addsTaggedJsonto the rejection test atstrict.rs:2957. (The live validation'sjson_schemastructured-output test exercisesAnswerConstraint::Jsonviacompile_json_schema_in, not strict function-tool grammars.) - Description claims
TaggedJsonToolParsersupportsargumentsandparameterskeys, optionalid, and fallback to visible text on malformed blocks. Inhelios/src/output/tagged_json.rs, the type isTaggedJson(:12),parse_body(:56-68) reads only"arguments"(never"parameters"),"id"is never read or emitted (tagged.rs:271emitsid: None), and malformed blocks returnErr(:38-68, asserted byrejects_malformed_or_non_object_payloadsat:123-136). - Description states
ReasoningGateand thinking-budget truncation hardcoded<think>/</think>;ReasoningGatedoes not exist inhelios/src(the parser isThinkReasoningintagged.rs:53), andthinking_budget_close(helios/src/server/request.rs:569-590) already encoded&syntax.closedynamically before this PR.
- Description claims "along with strict tool-call grammar generation", but
- 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 thatstrict: truefunction tools are rejected forTAGGED_JSON.
- Location:
-
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
0aeb2c1so all required workflows pass before merge.
- Location: PR head
Should Fix
-
O(k·n) prefix rescan in
TaggedJson::parse_candidateon the single-threaded presentation path- Location:
helios/src/output/tagged_json.rs:16-33,83-88andhelios/src/output/tagged.rs:295-338. - Verified impact:
TaggedTools::pushbuffers up to 1 MiB (tagged.rs:295-297) and only fast-forwardsself.in_json_stringafterparse_candidatereturnsOk(None), resettingin_json_string = falseat 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 invokesends_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_stris not re-run inside strings becauseends_in_json_stringshort-circuits first.) - Fix: Add an incremental JSON-string scan mode for JSON-body dialects in
TaggedTools(e.g.,const JSON_BODY: bool = falseonToolDialectwith a monotonicscan_poscursor inTaggedToolssoin_json_string/escapedadvances once per byte in O(n) total), and deleteends_in_json_stringfromtagged_json.rs.
- Location:
-
Add a CPU-only unit test for peer
_EXTRA_ROOTSpropagation inrank_group.py- Location:
ignition/preparation/rank_group.py:44-75,295-311. - Verified impact:
pr_filesshows no test file added or modified for therank_group.pybugfix, even thoughtests/preparation/test_forward_cache_sources.pyandtests/preparation/test_native_processes.pyalready testsource_rootsandrank_group._peeron CPU. - Fix: Add a CPU-only test (in
tests/preparation/test_forward_cache_sources.pyor a new rank-group test) that bindssource_roots(...), invokesrank_group._peer(or a spawned child viamp.get_context("spawn")), and asserts_EXTRA_ROOTS.get()/ForwardCache(...).rootmatches the parent insideprepare(...).
- Location:
Subtract / Simplify
-
Replace the 15-line manual
TaggedJsonarm inOutputPipeline::grammar_envelope- Location:
helios/src/output/pipeline.rs:266-280. - Why:
reasoning_end: Some("</think>".into())andtool_ends_reasoning: falseare immediately overwritten by the post-pass atpipeline.rs:293-310, and the remaining fields duplicateTaggedOutput::<D>::grammar_envelope(helios/src/output/tagged.rs:497-508). - Simplification: Delegate
Some((ToolParserKind::TaggedJson, _, _))toTaggedOutput::<super::tagged_json::TaggedJson>::grammar_envelope(&config.content)and overrideenvelope.toolforToolParserKind::TaggedJsonin the existing post-pass right besidereasoning_end/tool_ends_reasoning. This removes ~12 lines, drops an.unwrap()onsyntax.tools, and deletes the dead"</think>"literal frompipeline.rs:271.
- Location:
-
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 != closeis duplicated between tools and reasoning, and the previously compact 6-line fixed-delimiter table was expanded into 5 verbose arms repeatingreasoning.open == ... && reasoning.close == .... - Simplification: Extract a tiny helper
fn valid_delimiters(open: &str, close: &str, fixed: Option<(&str, &str)>) -> booland keep the reasoning match as a 6-lineOption<(&str, &str)>table (ThinkTags => None, fixed kinds =>Some((open, close))).
- Location:
-
Deduplicate the JSON-string byte scanner (if not eliminated by Should Fix #1)
- Location:
helios/src/output/tagged_json.rs:16-33vshelios/src/output/tagged.rs:989-998. - Simplification: If incremental scanning in
TaggedToolsis not adopted immediately, factor the identical quote/escape loop into a singlepub(super) fn ends_in_json_string(text: &str) -> boolintagged.rsshared bycontainer_parameterandTaggedJson::parse_candidate.
- Location:
Nits
ignition/preparation/contract.py:118-120: Consider raisingValueErrorearly whenbool(tool_open) != bool(tool_close)(matchingcore_parameter's fail-fast style at:137-148) instead of deferring to Rust's generic"unsupported tool parser syntax parameters".helios/src/output/pipeline.rs:173-175: Update the doc comment ondeclared_markers("The contract holds only the parser kind") to note thatTaggedJsonreadsopen/closefrom the contract.docs/api.md:499-535: DocumentTAGGED_JSONtool syntax (including EOS omission rules and lack ofstrict: truesupport) and customTHINK_TAGSdelimiters alongside the other parsers already enumerated there.- Consider splitting the
ignition/preparation/rank_group.pypeer source-root fix into its own PR so the preparation bugfix and Helios parser feature can be reviewed and reverted independently.
Dropped on verification
- Claim that
TaggedJson::parse_candidatere-runsserde_json::from_stron every false close inside a string, and thatTaggedToolsalready tracksin_json_stringincrementally from byte 0 (Correctness lens #3): Verified false. Athelios/src/output/tagged_json.rs:83-88,ends_in_json_string(body)returnsOk(None)beforeSelf::parse_bodyis called, soserde_jsonis not re-run inside strings; and athelios/src/output/tagged.rs:298-338,TaggedTools.in_json_stringonly fast-forwards past a string afterparse_candidatereturnsOk(None), not continuously from byte 0. Retained the accurate O(k·n)ends_in_json_stringrescan issue in Should Fix #1. - Claim that
FrontendContract::validateshould requireTHINK_TAGSdelimiters to encode as single control tokens / exist in the vocabulary (Correctness lens #4): Dropped.FrontendContract::validate(helios/src/model/contract.rs:880-970) is tokenizer-free structural validation, anddocs/api.md:503-505explicitly supports multi-token text reasoning delimiters matched as text; enforcing single-token control tokens would break supported multi-token delimiters. Retained the verifiedDsml/Xtmlincompatibility from that finding in Blocker #1. - Claim that the
is_empty()guards inhelios/src/output/tagged.rscan never fire and should be deleted (Subtraction lens #4): Verified false/dangerous.tagged.rs:707(.filter(|marker| !marker.is_empty())) already existed onmainand is required forMode::Verbatimwheneverself.reasoning.close_token == true(which setsmarkers[3] = "") orPlainText(OPEN = "",CLOSE = ""); deleting it would causetext.starts_with("")to always returntrueand break structured outputs. The other guards also protectPlainTextand unconfiguredTaggedJsonfromstr::match_indices("")matching every character boundary. - Claim that
rank_group._peer'sextra_roots=()should be a required positional parameter becauseprepare_groupis the only caller, and that wrappingif exporting:adds unnecessary diff noise (Subtraction lens #5): Verified false.tests/preparation/test_native_processes.py:228-229callsrank_group._peer(...)directly with 10 positional arguments; removing the default would break that test. Wrapping theif exporting: ... else: ...block once is cleaner than duplicating the context manager in both branches. - Claim that
export_modelon peers might also needbind_source_roots: Verified unnecessary; inspectedignition/preparation/runtime_core.py:343-442and confirmedexport_modeldoes not callsource_identity()(onlyaot.py:845-853insideprepare(...)reads_EXTRA_ROOTSon peer ranks).