Repository navigation
fix(helios): preserve Chat reasoning aliases, normalize Chat effort levels, and allow literal closing tool tags in O(N) - #677
Conversation
|
A case file has been opened for 677. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedBoth core fixes are sound—the three-state
Walkthrough
Merge Risk: Medium · up to
|
…evels, and allow literal closing tool tags in O(N)
OpenAI-compatible Chat Completions requests and tagged tool-call parsers hit
two failure modes in Helios:
1. Chat Completions message decoding read only `reasoning_content` and ignored
`thinking` and `reasoning` aliases on assistant messages, dropping prior
reasoning across multi-turn tool loops. In addition, named top-level
`reasoning_effort` strings (`none`, `minimal`, `medium`, `high`, `max`) were
copied verbatim into `options.template["reasoning_effort"]` instead of being
resolved against the prepared encoder's effort vocabulary, causing strict
templates (such as Qwen3.8 on `high`/`max`) and native DeepSeek encoders (on
`none`/`minimal`/`medium`) to return HTTP 400 and fallback templates (such
as GLM-5.3 on `medium`) to fall through to `max`. Nested `reasoning.effort`
on Chat Completions was ignored.
2. Tagged tool-call dialects (`ArgumentTags`, `FunctionTags`, `GemmaCall`)
returned `Result<Option<Vec<(String, String)>>>` from
`ToolDialect::parse_candidate`, where `None` signaled only an open JSON
string. When a non-JSON string argument (`<arg_value>`, `<parameter=...>`,
or `<|"|>`) contained a literal outer closing tool tag (`</tool_call>` or
`<tool_call|>`), `TaggedTools::push` split the call body at the inner tag
and aborted the request with an unterminated-value error.
Before this change, `chat_messages` read only `reasoning_content`, Chat
Completions passed named `reasoning_effort` strings directly into
`options.template`, `Frontend::resolve_effort` accepted any Jinja level that
did not raise an error (treating fallback-branch `medium` as supported),
`TaggedTools::push` handled only JSON string skipping, and `docs/api.md`
documented named effort normalization only for Responses and Messages. After
this change:
- `helios/src/server/protocol/decode.rs`: `chat_messages` reads the first
non-null of `reasoning_content`, `thinking`, or `reasoning` on `Role::Assistant`
messages (keeping non-assistant roles isolated from generic `thinking` and
`reasoning` keys) and rejects non-string values naming the offending field.
`options` accepts nested `reasoning.effort` on Chat Completions when
top-level `reasoning_effort` is absent or null, and normalizes top-level
named `none`, `minimal`, `low`, `medium`, `high`, and `max` through
`options.effort` / `enable_thinking` while keeping `xhigh`, numeric scores,
padded/unknown top-level strings, explicit `enable_thinking`, and
`chat_template_kwargs` overrides intact.
- `helios/src/server/inference.rs`, `helios/src/server/request.rs`, and
`helios/src/frontend/mod.rs`: added `Effort::Medium` (`&["medium", "high"]`)
for top-level Chat `"medium"` so `PromptEncoder::TmlV0` (`Inkling 2`)
preserves its native `0.7` level on Chat Completions while Responses
`reasoning.effort: "medium"` remains `Effort::High` (`0.9`). In
`Frontend::resolve_effort`, Jinja probing compares rendered output against an
unknown-effort sentinel so fallback-branch templates (such as GLM-5.3's
`low`/`high`/`else -> max`) exclude fallback-only `"medium"` and resolve
`Effort::Medium` to `"high"`, while strict templates (such as Qwen3.8's
`low`/`medium`/`xhigh`) resolve `"high"` to `"medium"` and `"max"` to
`"xhigh"`.
- `helios/src/output/{tagged.rs,tagged/kani_proofs.rs,argument_tags.rs,chatml.rs,gemma_call.rs,minimax_xml.rs}`:
replaced `Option` with `#[derive(Debug, PartialEq, Eq)] pub enum Candidate
{ Complete(...), InJsonString, IncompleteValue }`, added
`ToolDialect::scan_value_end` and `TaggedTools::in_value` (updated
`eos_decision` and `kani_proofs.rs` accordingly) so an open non-JSON argument
value scans linearly in O(N) for its dialect terminator (`</arg_value>`,
`</parameter>` / `<parameter=` / `</function>`, or `<|"|>`) without reparsing
the prefix on repeated inner closing tags, and kept direct `parse` and
`parse_eos` rejection of unterminated values unchanged without redundant mode
flags. Rebased cleanly over NVIDIA#670 (`TaggedJson` and parameterized delimiters).
- `docs/api.md`: updated the tagged tool-call and reasoning/effort sections to
document assistant reasoning aliases, Chat named effort normalization and
nested `reasoning.effort`, encoder-specific effort resolution (including
TMLv0 Chat `0.7` vs Responses `0.9`), and O(N) literal closing-tag handling.
Claimed result: preserves multi-turn assistant reasoning across `thinking` and
`reasoning` aliases, resolves Chat Completions named efforts and nested
`reasoning.effort` consistently across Jinja, DeepSeek, and TMLv0 encoders
without breaking TMLv0's `0.7` Chat `medium` contract or DeepSeek-V4.1's
`xhigh` (`75`) and numeric scores, and parses literal outer closing tool tags
inside non-JSON tagged arguments in O(N) time while preserving strict tool
validation, the 1 MiB buffer bound, and EOS truncation rejection. No model core
format or wire schema changes are introduced.
Validation and limitations (CPU, `FLARE_TEST_TEMPLATE_DIR` prepared via
`tests/frontend/prepare_templates.py`):
- `cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server`:
1,841 unit tests passed (47 ignored) and 62 integration tests passed (37
ignored), 0 failed — including new tests for assistant-only reasoning aliases,
effort normalization across GLM-style fallback Jinja, Qwen3.8-style strict
Jinja, TMLv0, and DeepSeek-V4.1, two-part UTF-8 splits and single-character
streaming across all four dialects, and 40,000-tag (~480 KiB) linear-scan
stress tests for `ArgumentTags`, `ChatMlOutput`, and `GemmaCall`.
- `FLARE_INKLING2_TEST_SNAPSHOT=... cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server -- --ignored tml_tests`:
6 passed, 0 failed (including `prompts_match_tml_renderers_token_for_token`).
- `cargo test --locked --release --manifest-path flare/Cargo.toml`: 254 passed
(4 ignored), 0 failed.
- `cargo test --locked --release --manifest-path flare-cli/Cargo.toml`: 245
passed (3 ignored), 0 failed.
- `cargo check --locked --release --manifest-path helios/Cargo.toml` passed
across default, `frontend`, `images`, `server`, and `runtime-core,server`.
- Limitations: `cargo-kani` and `cargo-mutants` are not installed on the
validation host, so `helios/src/output/tagged/kani_proofs.rs` (updated for
`TaggedTools::in_value` and `eos_decision`) was reviewed directly rather than
executed with `cargo kani`. GPU-gated ignored tests were not run on CPU.
Design-Signed-Off-By: Brandon M. Music; design-review=2e5b
Signed-off-by: Brandon M. Music <266531604+brandonmmusic-max@users.noreply.github.com>
f439f74 to
c897437
Compare
|
Rebased onto
Validated on CPU: |
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Ready To MergeAll Round 1 blockers, should-fix items, and the
Walkthrough
Merge Risk: Low · up to
|
Why this change is needed
OpenAI-compatible Chat Completions clients and tagged tool-call parsers encounter two failure modes in Helios request decoding and output parsing:
helios/src/server/protocol/decode.rs,helios/src/frontend/mod.rs):chat_messagesread onlyreasoning_contentand ignoredthinkingandreasoningaliases on assistant messages, dropping prior reasoning across multi-turn tool loops when clients store reasoning under those field names.reasoning_effortstrings (none,minimal,medium,high,max) were copied verbatim intooptions.template["reasoning_effort"]instead of being normalized against the prepared encoder's effort vocabulary. Strict templates rejected out-of-vocabulary levels with HTTP 400 (such as Qwen3.8 onhigh/maxand native DeepSeek encoders onnone/minimal/medium), fallback templates (such as GLM-5.3) fell through tomaxonmedium, and nestedreasoning.effortobjects on Chat Completions were ignored.helios/src/output/):ToolDialect::parse_candidatereturnedResult<Option<Vec<(String, String)>>>whereNonesignaled only an open JSON string, causingTaggedTools::pushto enter JSON quote-skipping mode until the next unescaped double quote. When a non-JSON string argument in GLM argument-tag syntax (<arg_key>...<arg_value>...</arg_value>), ChatML function-tag syntax (<parameter=...>...</parameter>), or Gemma call syntax (<|"|>...<|"|>) contained a literal outer closing tool tag (</tool_call>or<tool_call|>),TaggedTools::pushsplit the call body at the inner tag and the dialect parser aborted the request with an unterminated-value error.What changed
Before this change,
chat_messagesread onlyreasoning_content, Chat Completions forwarded namedreasoning_effortstrings directly intooptions.template,Frontend::resolve_effortaccepted any Jinja level that did not raise an error (treating fallback-branchmediumas supported),TaggedTools::pushsupported only JSON quote-skipping, anddocs/api.mddocumented named effort resolution only for Responses and Messages.After this change:
helios/src/server/protocol/decode.rs:chat_messagesreads the first non-null ofreasoning_content,thinking, orreasoningonRole::Assistantmessages (keeping non-assistant roles isolated from genericthinkingandreasoningkeys) and rejects non-string values naming the offending field.optionsusespresent()to accept nestedreasoning.efforton Chat Completions when top-levelreasoning_effortis absent or null, and replaces the mutable tracking flag with an immutablewithheld_chat_effortbinding covering top-levelnone(enable_thinking=false),minimal,low,medium,high, andmax, while preserving raw passthrough forxhigh(so DeepSeek-V4.1 keeps score75vsmax's100), numeric scores, padded/unknown top-level strings, explicitenable_thinking, andchat_template_kwargsoverrides.helios/src/server/inference.rs,helios/src/server/request.rs, andhelios/src/frontend/mod.rs:Effort::Medium(&["medium", "high"]) for top-level Chat"medium"soPromptEncoder::TmlV0(Inkling 2) preserves its native0.7level on Chat Completions (tests/frontend/inkling2_tml.json:318-341), while Responsesreasoning.effort: "medium"staysEffort::High(0.9).Frontend::resolve_effortto compare rendered output against an unknown-effort sentinel so fallback-branch templates (such as GLM-5.3'slow/high/else -> max) exclude fallback-only"medium"and resolveEffort::Mediumto"high", while strict templates (such as Qwen3.8'slow/medium/xhigh) resolve"high"to"medium"and"max"to"xhigh".helios/src/output/{tagged.rs,tagged/kani_proofs.rs,argument_tags.rs,chatml.rs,gemma_call.rs,minimax_xml.rs}:TaggedJsonand parameterized delimiters).Optionwith#[derive(Debug, PartialEq, Eq)] pub enum Candidate { Complete(...), InJsonString, IncompleteValue }and addedToolDialect::scan_value_endplusTaggedTools::in_value(updatingeos_decisionandkani_proofs.rs). AfterCandidate::IncompleteValue,TaggedTools::pushscans linearly in O(N) for the dialect's value-ending boundary (</arg_value>,</parameter>/<parameter=/</function>, or<|"|>) instead of reparsing from byte 0 on every inner closing tag.argument_tags.rs,chatml.rs, andgemma_call.rswhile keeping directparseandparse_eosrejection of unterminated values unchanged.docs/api.md:reasoning.effort(including TMLv0 Chat0.7vs Responses0.9and Qwen/GLM/DeepSeek vocabularies), and O(N) literal closing-tag handling inside non-JSON tagged argument values.Claimed benefit and compatibility impact
thinkingandreasoningaliases without affecting non-assistant roles, normalizes Chat Completions named efforts and nestedreasoning.effortacross Jinja, DeepSeek, and TMLv0 encoders without breaking TMLv0's0.7Chatmediumgolden contract or DeepSeek-V4.1'sxhigh(75) and numeric scores, and parses literal outer closing tool tags inside non-JSON tagged arguments in O(N) time while preserving strict tool validation, the 1 MiB buffer bound, and EOS truncation rejection.thinkingorreasoningfields on Chat Completions assistant messages now return HTTP 400; (b) malformed adjacent calls where an unclosed argument value precedes a second call's closing tag remain ambiguous at the text-delimiter level; (c) no model core format or wire schema changes are introduced.Supporting evidence and limitations
FLARE_TEST_TEMPLATE_DIRgenerated bytests/frontend/prepare_templates.py):cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server: 1,841 unit tests passed (47 ignored) and 62 integration tests passed (37 ignored), 0 failed, including new unit tests covering assistant-only reasoning aliases, effort normalization across GLM-style fallback Jinja, Qwen3.8-style strict Jinja, TMLv0, and DeepSeek-V4.1, two-part UTF-8 splits and single-character streaming across all four dialects, and 40,000-tag (~480 KiB) linear-scan stress tests forArgumentTags,ChatMlOutput, andGemmaCall.FLARE_INKLING2_TEST_SNAPSHOT=... cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server -- --ignored tml_tests: 6 passed, 0 failed, includingprompts_match_tml_renderers_token_for_token.cargo test --locked --release --manifest-path flare/Cargo.toml: 254 passed (4 ignored), 0 failed.cargo test --locked --release --manifest-path flare-cli/Cargo.toml: 245 passed (3 ignored), 0 failed.cargo check --locked --release --manifest-path helios/Cargo.tomlpassed across default,frontend,images,server, andruntime-core,server.cargo-kaniandcargo-mutantsare not installed on the validation host, sohelios/src/output/tagged/kani_proofs.rs(updated forTaggedTools::in_valueandeos_decision) was reviewed directly rather than executed withcargo kani. GPU-gated ignored tests were not executed on CPU.Discord: Brandonmusic