Recommendation: Ready To Merge
All Round 1 review findings (exact UTF-8 boundary checking, removing the PromptEncoder::TmlV0 branch/hardcoded markers from request.rs, collapsing ReasoningCut to a single close: Vec<u32>, real Inkling-2 tokenizer and live SM121 serving verification, and all three nits) are verified cleanly resolved at head 7dde009. No blockers or regressions were introduced: capacity arithmetic, grammar/tool gating, prompt metadata/vision invariants, and TmlOutput state transitions all hold under direct inspection. Wait for CI to run green on 7dde009 before merging.
Merge Risk
Level: Low
helios/src/server/runtime.rs(Worker::publishandWorker::park) is a shared single-threaded worker path; the newtrim_incomplete_utf8_tail()runs only on forced reasoning cuts (!appended.is_empty()), inspects at most 8 trailing generated tokens viaO(1)pre-initializedFrontend::token_bytes()lookups, and leaves preemption (park_if_preemptedpassing&[]), unforced continuations, and uncapped requests untouched.Bootstrap::load()(helios/src/server/config.rs:281) now callsfrontend.prepare_token_bytes()?unconditionally; all current cores (max_top_logprobs == 20 != 0) already executed this at startup, and initializing eagerly avoids a synchronous worker-thread stall on the first forced cut for legacymax_top_logprobs == 0cores.- No wire/ABI, captured-graph, scheduler state-machine, or lock/contention changes are introduced; verified conflict-free with open PRs
#457and#582.
Walkthrough
helios/src/output/tml.rs(46-57) &helios/src/output/pipeline.rs(26-41): Addstml::text_frame_opener()reusingtml::MODELandtml::TEXTagainst already-validated single-tokenoutput.control_tokens, and exposesOutputConfig::reasoning_close_tail()whenReasoningParserKind::ContentHeadersis active with no tools.helios/src/server/request.rs(380-400,539-560): Widensthinking_budget_close()to acceptOutputStart::RecipientFrameandOutputStart::RecipientHeaderfor single-tokenContentHeadersclose delimiters (leavingRecipientHeadersunchanged), and buildsReasoningCut::close: Vec<u32>once at preparation time—appendingoutput.reasoning_close_tail()only whengrammar.is_none()andtokens.len() + tail.len() < after as usize.helios/src/server/config.rs(279-281,663-696): Callsfrontend.prepare_token_bytes()?unconditionally inBootstrap::load()and adds aContentHeaders[server] thinking_token_budgetbootstrap validation test.helios/src/server/runtime.rs(50-69,417-461,1994-2048,2156-2177): CollapsesReasoningCut::closetoVec<u32>, enforces single-token grammar advancement (cut.close.len() == 1 && grammar.allows(cut.close[0])), emits every injected close token throughActive::close_reasoning()and decoded history/progress metrics while subtractinginjected.len()fromcut.after, and trims trailing incomplete UTF-8 byte tokens (Utf8Error::error_len().is_none()) at indices>= live.prompt_tokensinWorker::park()before appending forced close tokens.docs/api.md(813-835) & tests (helios/src/server/protocol/decode.rs:2032-2194,helios/src/server/request/tml_tests.rs:355-416,helios/src/server/runtime/phase_tests.rs:679-869): DocumentsContentHeaderssupport, silent<|message_model|><|content_text|>opener injection, and cross-format UTF-8 tail trimming on forced cuts; adds synthetic, worker-loop, UTF-8 edge-case (includinggenerated_len == 1, 2and literalU+FFFD), and real Inkling-2 tokenizer snapshot tests.
Pre-merge Checks
- [PASS] Security / malicious screen: No prompt-injection attempts, unsafe code, external I/O, or credential/trust-boundary changes.
- [PASS] Charter & value fit: Implements the documented
thinking_token_budgetAPI across Chat/Responses/Messages forContentHeaderscores without per-model branches in the server layer; format markers live inhelios/src/output/tml.rs. - [PASS] Related / duplicate / conflict check: Additive over
#167; verified zero behavioral or file conflict with open#457(non-empty header EOS check cannot fire on<|message_model|><|content_text|>) or open#582(readmitted prompt is strictly longer thanlive.prompt_tokens,P' >= P + 1). - [WARN] Tests & verification evidence: Substantive CPU unit/worker tests, real Inkling-2-Mini tokenizer snapshot tests (
6/6--ignored), and liveGB10/SM121serving across 7 scenarios are reported passing, but no CI status checks are recorded on head7dde009yet (confirm CI passes before merge).
Blockers
None.
Should Fix
None.
Subtract / Simplify
None.
Nits
helios/src/server/runtime.rs:433-435(trim_incomplete_utf8_tail):let Ok(bytes) = frontend.token_bytes(token) else { return; };silently skips trimming on error even thoughpark()already returnsResult<()>(runtime.rs:2156) andBootstrap::load()validatesprepare_token_bytes()?(config.rs:281). Propagating?would avoid a silent no-op fallback if an unexpected lookup failure ever occurred.helios/src/server/protocol/decode.rs:2033-2110: The new test repeats ~77 lines of ByteLevel BPE tokenizer + temp-file +GrammarCompilersetup already implemented inrenderer()(decode.rs:1035-1154) in the same test module; parametrizingrenderer()(or extracting a shared helper) would reduce test boilerplate without losing coverage.helios/src/output/pipeline.rs:29-40:reasoning_close_tail(&self)allocates aVec<u32>fromOption<[u32; 2]>; returningOption<[u32; 2]>directly would avoid the temporary allocation beforetokens.extend(...)athelios/src/server/request.rs:386-389.docs/api.md:817-820: Optional wording note—the doc accurately states that incomplete UTF-8 tail tokens are trimmed from the re-prefilled continuation context, and could optionally mention that client-streamed reasoning text before the cut may still end with a replacement character (U+FFFD) when a cut splits a multi-byte character (matching existing forced-cut behavior onmain).
Dropped on verification
- Streaming rollback / client-visible
U+FFFD(Correctness F1, Major): Onmain, a forced cut landing mid-character already flushesU+FFFDto the client when the forced close token pushes throughIncrementalDecoder. This PR does not regress client output, repairs the continuation prompt as accurately documented indocs/api.md:817-820, and adding multi-token streaming hold-back was neither requested in Round 1 nor warranted; demoted to a minor optional doc nit. - Trimming preemption / narrowing trim scope (Correctness F2, Dossier): Claiming preemption (
park_if_preempted) has the "identical hazard" and should also trim is incorrect: preemption injects no close token, so the client'sIncrementalDecoderstill holds the partial UTF-8 bytes awaiting the continuation byte—trimming them on preemption would cause the model to re-emit the character and corrupt client output. Trimming across all reasoning formats on forced cuts is explicitly disclosed in the PR title, description, anddocs/api.md:817-820, and keepsWorker::park()format-agnostic. - Stop-matching injected tokens & "undocumented" 1→3
generated_tokensaccounting (Correctness F3): Both the PR description ("What changed") anddocs/api.md:824-825explicitly state that forced close tokens count as generated tokens within the output limit;metrics.progress(0, injected.len(), ...)is consistent withcarried.generated_tokensandcut.after.saturating_sub(injected.len() as u32).Active::close_reasoningmatchesmain(#167), EOS does not triggerbudget_stop(runtime.rs:501-503), and an explicit user stop token cleanly terminates viaTermination::UserStopinTmlOutput::finish()(tml.rs:371-395). config.rs:281prepare_token_bytes()as "undeclared / whole-VRAM-scale boot cost" (Correctness F4, Subtraction #1, Dossier #5): Explicitly disclosed in the PR description's "What changed" section;VocabularyBytesis host RAM (zero VRAM); every current exported core already hasmax_top_logprobs == 20 != 0(docs/logprobs-design.md:21) and already ranprepare_token_bytes()at boot; eager preparation prevents a synchronous full-vocab decode stall on the GPU worker thread during the first forced cut on legacymax_top_logprobs == 0cores.- Collapsing
trim_incomplete_utf8_tailwhileloop to a singlestd::str::from_utf8(&raw)(Subtraction #4): Incorrect simplification—ifwindow_start = tokens.len().saturating_sub(8).max(prompt_tokens)lands mid-character on an earlier multi-byte sequence (or an earlier stray byte appears in the 8-token window),raw[0]haserror_len() == Some(1), so a singlefrom_utf8(&raw)would return early and fail to trim a genuine trailing incomplete UTF-8 suffix. Thewhile pos < raw.len()loop (runtime.rs:441-455) is necessary. - Dropping
if grammar.is_none()atrequest.rs:385as a duplicate guard (Subtraction #5): Incorrect simplification—request.rs:385omits the 2-token tail so grammar-constrained requests still get a 1-token[<|end_message|>]close; removing it would prepare a 3-tokencut.closethatruntime.rs:1997(cut.close.len() == 1) would reject, silently disabling forced reasoning cuts for all structured-output TMLv0 requests. - Secondary test-scaffolding claim on
config.rs:663-694(Subtraction #2):config.rs:664clones the existing test'stokenizerand addsCONTROL_MARKERSrather than rebuilding a fourth tokenizer from scratch. - Stale doc/comment claims (
runtime.rs:67-68,docs/cli-design.md,docs/logprobs-design.md:19):runtime.rs:68already readsforced tokens(fixed in7dde009);docs/cli-design.md:1337,1367,1417is format-neutral and delegates format details todocs/api.md;docs/logprobs-design.md:19already readsForced tokens, such as the thinking_token_budget close, have no logprob entry. - Potential conflicts with
#457and#582(Dossier & Correctness):#457'sHeaderWithoutContentonly fires on non-empty model headers (at > 0) closed without a content-kind token, never on[<|end_message|>, <|message_model|>, <|content_text|>].#582's(raw_anchor, prompt_tokens)latch is unaffected becausetrim_incomplete_utf8_tailnever truncates belowlive.prompt_tokensandtokens.extend_from_slice(appended)appends>= 1token, guaranteeing the readmitted prompt is strictly longer thanlive.prompt_tokens(P' >= P + 1 > P).