Final review report · NVIDIA/hyperflare-inference #615

Raw Markdown for agents: https://autobot.eidonix.com/p/7b6f0e58-dc9e-44e2-8a4c-27d2877fb2a6.md

Recommendation: Changes Requested

This PR cleanly closes a real feature gap by enabling thinking_token_budget (and [server] thinking_token_budget) on ContentHeaders cores, and its core accounting, output_event_capacity, prompt_metadata::extend_text, and TmlOutput state transitions are verified sound. However, changes are requested before merge for three verified issues: the UTF-8 tail trim in Worker::park() uses a '\u{FFFD}' decode heuristic that drops legitimately generated literal U+FFFD tokens and silently fails to trim when <= 3 tokens were generated since the last admission/preemption, tml_text_transition_tokens() duplicates already-resolved TML control tokens with a per-format branch in request.rs, and the central behavioral claim (that <|message_model|><|content_text|> keeps a real Inkling 2 model in a text frame) currently has synthetic-only evidence with no real-checkpoint or live GPU verification.

Merge Risk

Level: Medium

Walkthrough

Pre-merge Checks

Blockers

None.

Should Fix

  1. Replace the '\u{FFFD}' decode heuristic in Worker::park() with exact token-byte UTF-8 boundary checking and fix the unnecessary generated_len - 1 trim floor (helios/src/server/runtime.rs:2129-2155, helios/src/server/config.rs:281).
    • False positive on literal U+FFFD: Decoding a window and checking text.ends_with('\u{FFFD}') (runtime.rs:2136-2139) cannot distinguish an incomplete trailing UTF-8 byte prefix from a legitimately generated literal U+FFFD character ([0xEF, 0xBF, 0xBD])—an ambiguity the codebase already calls out in helios/src/server/token_spans.rs:92-93. A literal '\u{FFFD}' at the budget boundary is silently deleted from the continuation prompt.
    • Silent failure on small/post-preemption passes (generated_len <= 3): let max_trim = 3usize.min(generated_len.saturating_sub(1)) and end > window_start (runtime.rs:2141-2144) fail to trim whenever a budget cut occurs with 1–3 tokens generated since the last admission (for example, a request preempted with 2 budget tokens remaining that generates [0xE2, 0xAC] of a 3-byte char: generated_len = 2 -> max_trim = 1 -> trimming 1 token leaves [0xE2] which still ends in U+FFFD, so nothing is trimmed). The comment at runtime.rs:2131-2132 claims at least one generated token must be retained for extend_text, which is unnecessary: tokens.extend_from_slice(appended) runs at runtime.rs:2156 before extend_text (runtime.rs:2167-2168) with !appended.is_empty(), guaranteeing tokens.len() >= live.prompt_tokens + 1 > incoming.prompt.tokens.len(), and extend_text itself only requires after >= before (helios/src/model/admission.rs:26).
    • Fix: Use Frontend::token_bytes() (helios/src/frontend/mod.rs:1534, backed by helios/src/frontend/vocabulary.rs:11-45) on the trailing tokens and validate with std::str::from_utf8 (as in helios/src/server/token_spans.rs:129-141), trimming generated tokens at index >= live.prompt_tokens only when Utf8Error::error_len().is_none() (a true incomplete UTF-8 suffix, never a literal U+FFFD). Ensure frontend.prepare_token_bytes()? is called at bootstrap (helios/src/server/config.rs:281 currently gates it on model.max_top_logprobs != 0) so VocabularyBytes is never lazily built on the worker thread during a cut. Add regression tests for a literal U+FFFD token at the cut boundary and a 2-byte incomplete tail with generated_len == 2.
  2. Delete tml_text_transition_tokens() and resolve the TML text-frame opener from the already-validated output.control_tokens (helios/src/server/request.rs:384-393, 543-555).
    • Contract validation already enforces the biconditional ToolParserKind::TmlJson <=> ReasoningParserKind::ContentHeaders (helios/src/model/contract.rs:895-899), so prepare_output() (helios/src/model/prompt.rs:315-328, helios/src/output/pipeline.rs:131-142) has already encoded every marker in helios/src/output/tml.rs:41-44 (CONTROL_MARKERS, including MODEL and TEXT), validated each occupies one token, and stored them in output.control_tokens regardless of whether request tools are empty.
    • tml_text_transition_tokens() re-checks PromptEncoder::TmlV0 + ContentHeaders, hardcodes the marker strings again in request.rs, and reaches into tokenizer().get_added_vocabulary().get_vocab() without prepare_output's single-token guarantee.
    • Fix: Expose a small helper on OutputConfig / helios/src/output/ (reusing tml::MODEL and tml::TEXT against output.control_tokens when ContentHeaders is active) and delete tml_text_transition_tokens() from request.rs.
  3. Supply real-checkpoint / live Inkling 2 verification for the injected <|message_model|><|content_text|> continuation.
    • Every test in this PR scripts the post-cut continuation tokens ([1, 2] in helios/src/server/runtime/phase_tests.rs:760), so nothing yet demonstrates against an actual Inkling 2 checkpoint that injecting <|message_model|><|content_text|> after <|end_message|> keeps the model generating in the text frame rather than immediately closing it or reopening <|content_thinking|>.
    • Fix: Run the real-tokenizer tml_tests.rs suite (and add a thinking_token_budget case there) plus at least one live flare run transcript on an Inkling 2 core demonstrating a hit on thinking_token_budget continuing cleanly into content (both plain and with tools active).

Subtract / Simplify

  1. Collapse ReasoningCut { close, close_tail } into one token sequence and delete the redundant runtime include_tail re-check (helios/src/server/runtime.rs:50-61, 1962-1972, helios/src/server/request.rs:384-400).
    • request.rs:384-393 already checks output.content.tools.is_empty() && grammar.is_none() and 1 + tail.len() < after. None of prompt.grammar, cut.after, or cut.close_tail can change between preparation and Worker::publish(), so the include_tail re-derivation and Vec rebuild at runtime.rs:1962-1972 duplicate an already-decided invariant.
    • Replacing close + close_tail with a single non-empty sequence (built once in request.rs when 1 + tail.len() < after as usize) removes ~20 lines of duplicated policy and the repeated u64::from(1 + ... as u32) < u64::from(after) casts. (phase_tests.rs:786-800 Case 2 only tests that duplicated runtime guard; request-level tight-capacity coverage already exists at decode.rs:2161-2171.)

Nits

Dropped on verification