Case file: PR #615 — helios: support thinking_token_budget for ContentHeaders and trim incomplete UTF-8 tails on cut
Repository NVIDIA/hyperflare-inference · head 2652c06 on feat/helios-tml-thinking-budget · base main (branched at 2147cd4) · +562/−31 across 6 files · open, ready for review · opened and last updated 2026-11-29 19:04 · no CI checks, no reviews, no comments, no labels.
Key findings
- The change is additive over a merged feature (#167), not a new capability.
thinking_token_budgetandReasoningCutwere created by #167 ("Add a hard reasoning-token budget and DeepSeek V4.1 sampling ranges", yatesdr, merged 2026-11-02, commit902c88e2), which deliberately rejected formats that cannot honour a hard cap. #615 widens that rejection forContentHeaderscores and extends the cut with a two-token tail. It reverses no prior work. - The UTF-8 trimming half reaches far beyond
ContentHeaders. The trim block inWorker::park()(helios/src/server/runtime.rs:2133-2155) is gated only on!appended.is_empty()— i.e. any forced reasoning cut in any format (DeepSeek/XTML/ThinkTags/Recipient/DSML). It silently drops up to 3 already-generated tokens from the re-prefilled continuation prompt for those formats too (runtime.rs:2150). The description credits this only in a single bullet ("across all reasoning formats"), and no test covers a non-TML format. - Accounting and stop-path behaviour is undeclared. Injected tail tokens are routed through
Active::close_reasoning()(runtime.rs:431-444), so<|message_model|>/<|content_text|>incrementcarried.generated_tokens, pass through grammar advance andobserve_token, and can trigger a user token-stop (budget_stop), which truncates the tail mid-sequence (runtime.rs:1973-1989) — contradicting the "all-or-nothing" framing in the description.record_decoded_tokennow runs once per injected token (runtime.rs:1991-1995), andmetrics.progress(0, injected.len(), …)(runtime.rs:1999,helios/src/server/metrics.rs:333-347) makes clustergenerated_tokenscount 3 tokens where it previously counted 1. - A same-day, open PR (#457) rewrites exactly the parser and grammar semantics the injected sequence depends on, with no cross-reference in either direction: #457 makes an unnamed model header without content an EOS error and changes
tool_unnamed/content-header grammar rules. #615 injects<|message_model|><|content_text|>— an unnamed model header immediately followed by a content-kind marker. The grammar side is guarded (grammar.is_none()); the parser side is not. - Evidence is CPU-only and self-reported. No CI checks exist on the head commit, so the 1,685-test claim is unverified by automation here. The change's central behavioural claim — that an Inkling 2 model, after the injected
<|message_model|><|content_text|>, continues in a text frame rather than re-opening thinking — is exercised only against a synthetic byte-level BPE tokenizer plushelios/tests/support/contracts/inkling2_frontend.json; the#[ignore]real-checkpoint TML tests (needingFLARE_INKLING2_TEST_SNAPSHOT) and live GPU serving were not run. - Project-fit tension with the charter's model-agnostic rule. The new helper keys on
PromptEncoder::TmlV0+ReasoningParserKind::ContentHeadersand hardcodes the literals<|message_model|>and<|content_text|>in the request-preparation layer (request.rs:543-555), while the contract declaresreasoning.open/closebut no text opener. It follows the existingCONTROL_MARKERSpattern inhelios/src/output/tml.rs:25-44rather than inventing a new one, but it is a format special-case in helios. - Process state is cold: first-time contributor, unlabelled/untriaged, zero discussion, zero reviews, never updated since opening — while the same-day TMLv0 PR #457 and the same-file PR #582 both drew reviews.
1. The change
Six files, +562/−31; branch feat/helios-tml-thinking-budget; single squashed commit signed "Jordan Newman". Production code is roughly +156/−25 — config.rs's +48 and much of decode.rs/phase_tests.rs are tests.
helios/src/server/request.rs (+32/−3)
- Request preparation builds
close_tailwhenoutput.content.tools.is_empty() && grammar.is_none()and1 + tail.len() < after(request.rs:384-393), then setsmax_new_tokens = budgetand constructsReasoningCut { close, close_tail, after, output }(request.rs:394-400). - New
tml_text_transition_tokens()(request.rs:543-555): requiresfrontend.prompt_encoder() == PromptEncoder::TmlV0and contractreasoning.kind == ContentHeaders, then returnsvec![model, text]fromtokenizer().get_added_vocabulary().get_vocab()for"<|message_model|>"and"<|content_text|>", else empty. thinking_budget_close()widened (request.rs:557-578):supported_startnow also acceptsOutputStart::RecipientFrame | OutputStart::RecipientHeaderwhensyntax.kind == ContentHeaders(567-569), still requiring a single-token close (573-577). Note theSome(syntax) = &config.contract.frontend.reasoninglookup moved above the start check (564-566) — a restructuring, not only a widening; behaviour forReasoning|Contentstarts is unchanged because the old code also returnedOk(None)with no syntax.
helios/src/server/runtime.rs (+76/−22)
ReasoningCutgainspub close_tail: Vec<u32>with a doc comment (runtime.rs:50-61).Worker::publish()budget branch (1950-2017):include_tailre-checksgrammar.is_none()and1 + close_tail.len() < cut.after(1962-1965); buildssequence=[close] + close_tail(1966-1972); loopsrequest.close_reasoning(token, eos)(1973-1989), breaking onstopped(setsbudget_stop) and abandoning on error; then per-tokenscheduler.record_decoded_token, onereasoning_budget_cutsincrement,metrics.progress(0, injected.len(), 0, 0, 0, 0)(1991-1999);remaining = cut.after.saturating_sub(injected.len() as u32)(2011, replacingcut.after - u32::from(forced));appended = &injectedwhen forced (2013).Worker::park()(2125-2198): new trim block (2129-2155) beforetokens.extend_from_slice(appended)(2156). Window istokens[len-8..]clamped tolive.prompt_tokens(2135); ifdecode(window)ends with'\u{FFFD}'(2136-2139), trytrim1..=min(3, generated_len-1)(2141), truncating at the firsttrimwhereend > window_startand the shortened window no longer ends in U+FFFD (2142-2153). At least one generated token always survives, keepingtokens.len() > incoming.prompt.tokens.len()forprompt_metadata::extend_text(2131-2132,2167-2168; monotonicity enforced athelios/src/model/admission.rs:25-56).park_if_preemptedstill passes&[](runtime.rs:2121), so preemption never trims.- Runtime unit test mechanically updated for the new field (
runtime.rs:3393-3399).
helios/src/server/config.rs (+48/−0): purely a new test block inside the existing bootstrap test (~663-708) building a TML tokenizer, a ContentHeaders contract (<|content_thinking|>/<|end_message|>), TmlJson tools and thinking_token_budget = 16, asserting Bootstrap::load succeeds and the value is loaded. Startup validation itself is untouched: validate_thinking_budget (config.rs:400, 411-438) simply calls the widened thinking_budget_close.
helios/src/server/protocol/decode.rs (+192/−0): one new test tml_content_headers_thinking_budget_prepares_close_and_optional_text_frame_tail (~2031-2223) in native_prompt_tests, asserting: uncapped (no budget / reasoning_effort="none" / enable_thinking=false) → no cut, max_new_tokens = 32; plain Chat budget 16 → close=<|end_message|>, close_tail=[model,text], after=16; budgets 29/30/31 → empty tail; tools present → empty tail; tool_choice="none" → tail restored; response_format json_object (grammar) → empty tail; Messages thinking.budget_tokens=16 → same cut.
helios/src/server/runtime/phase_tests.rs (+202/−0): budget_cut helper gains close_tail: Vec::new() (417); reasoning_budget_injects_content_headers_close_tail_and_accounts_for_capacity (680) with three cases (capacity 5 → injects [end, model, text], parked prompt [0, model, think, 0, end, model, text], max_new_tokens 2, carried.generated_tokens 6, cuts metric 1, finish (1, 8, "length"), OutputPipeline yields reasoning_content "a", content "bc"; capacity 3 → [end] only, generated_tokens 4; reasoning already closed → nothing injected, max_new_tokens 5); reasoning_budget_park_trims_incomplete_utf8_tail_without_affecting_plain_continuation (~825) using bytes 0xE2/0xAC/0xA2 = U+2B22, covering 1-byte and 2-byte partial tails (trimmed), a complete character (kept), and the appended-empty continuation (partial tail preserved).
docs/api.md (+12/−6), section at 813-842: documents ContentHeaders support and the silent <|message_model|><|content_text|> emission when no tools/grammar (817-825), UTF-8 tail trimming (821-823), forced close tokens counting as generated tokens and being omitted from logprobs (823-824), and rewrites the 400-condition sentence to "when output starts in reasoning or a content-header frame" (830-833).
What the description does not say — see Key finding 2 and 3 for the four substantive items (format-agnostic trim, mid-tail truncation on a user token stop, per-token decoded-history/metric accounting, 3-token usage inflation). Small extras: docs/logprobs-design.md:19 (not opened) still speaks of "the thinking_token_budget close" in the singular; runtime.rs:68-70's output_event_capacity comment still says "A reasoning cut's forced token is part of after" (the invariant survives because after is reduced by injected.len(), but the comment is stale for the 3-token case); docs/cli-design.md:1337 (not opened)/1367/1417 still describes [server] thinking_token_budget without the TMLv0/ContentHeaders case.
What the description says that the change does not do: nothing material. RecipientHeaders (kind 5) is explicitly left unsupported for frame starts, matching the text; OutputStart::ToolBody also stays unsupported (unmentioned either way). The trim's claim to "eliminate dangling incomplete UTF-8 byte tokens … across all reasoning formats" is true only for forced cuts — the identical hazard on preemption (park_if_preempted, runtime.rs:2121) and at the plain output limit is untouched.
2. The why
The problem is a gap in a shipped feature rather than a new request. thinking_token_budget (per-request and [server] default) came from #167 (merged 2026-11-02, +1899/−98 over 31 files), which introduced thinking_budget_close(), ReasoningCut, the park/re-admit cut path, reasoning_budget_cuts_total (helios/src/server/metrics.rs:1090), ServerConfig::validate_thinking_budget (config.rs:411-438) and the /v1/models advertisement — and stated: "On formats that cannot honour a hard cap, thinking_token_budget is rejected while Messages thinking.budget_tokens keeps its documented advisory meaning." #167's live evidence was DeepSeek V4.1 Flash TP4 on 4× RTX PRO 6000 SM120 only; it drew no recorded discussion.
TMLv0 ContentHeaders cores (Inkling 2 Mini/Small) begin generation at OutputStart::RecipientFrame/RecipientHeader (helios/src/output/tml.rs:87-91, state mapping 132-136; reasoning_open() is Body{Thinking, model:true} at 150-152). Before this PR, thinking_budget_close returned Ok(None) for those starts, so a per-request budget hit the HTTP 400 at request.rs:369/375-377 and the [server] default failed bootstrap at config.rs:416-435.
How long and how widely it has been wanted: no independent evidence. Searches for thinking_token_budget in issues return nothing, and searches for ContentHeaders/budget/UTF-8-replacement-character phrasings found no issue or PR reporting the gap. The TMLv0 content-header path is itself young (~9 days old at PR time; #304/#433 brought Inkling 2 Small/Mini, #405 made declared markers controls), and the budget is ~4 weeks old. The UTF-8 half likewise has no prior report; it is plausible from code — the old code appended cut.close directly onto live.tokens() and extend_text only pads positions (helios/src/model/admission.rs:25-56), so a mid-character byte-level BPE tail would persist in the re-prefilled prompt.
3. Related work
- #167, merged, yatesdr — origin of the entire feature. #615 is strictly additive: it widens the accept list and adds a field to
ReasoningCut; it does not reverse or supersede #167, and it edits #167's owndocs/api.mdtext (813-833). - #457, open, brandonmmusic-max, +431/−7, labels
area:api/bug/model:inkling-small/triage:review, last updated 2026-11-29 03:33 — "Fail untyped TML model headers at EOS and align TMLv0 content-header and strict-tool grammars withTmlOutput". It changeshelios/src/output/tml.rs(TmlOutput,AnswerState,finish()erroring at EOS for a header without content) andhelios/src/grammar.rs(not opened) /grammar/strict.rs(not opened) (compile_content_headers,tool_unnamed, preamble-then-tool ending). Direct interaction: #615 injects<|message_model|><|content_text|>— an unnamed model header immediately followed by a content-kind marker, i.e. exactly the "header without content" shape #457 adds new EOS error handling for and exactly the "unnamed header" grammar rule #457 changes. #615 guards the grammar path withgrammar.is_none()(request.rs:384,runtime.rs:1962-1963), but the parser path is not guarded, and neither PR references the other. #457 was updated the same day #615 opened and already has a full changes-requested review. - #582, open, FujitsuPolycom, approved 2026-11-29 by voipmonitor — "helios: avoid splitting prefill on zero-budget checkpoint anchors". Its review cites
helios/src/server/runtime.rs:2106-2121, the veryparkprompt-rewrite path #615 edits (2125-2168at this head); #582 also needs a rebase. Both in flight over the same function. - #541, open, jere357 — "Add a Prometheus and Grafana monitoring example" documents
reasoning_budget_cuts_total, whose semantics #615 keeps (one increment per cut) while changing the generated-token counters around it. #548/#560 (open, WynnD) rework per-request metrics and runtime instants, adjacent ground. - #396 (merged) / #281 (closed) — earlier added-vocabulary and literal-special-token handling that
tml_text_transition_tokensreads through (get_added_vocabulary().get_vocab()). - File churn:
helios/src/server/runtime.rshas 20+ items in 180 days (#554, #483, #560, #576, #540, #548, #549, #334, #301, #607, #497, #505, #579, #102, #504, #507, #479, #416, #459 …) — one of the most contended files in the repo. - Competing or superseding PRs: none found. No other open PR targets
thinking_token_budgetorContentHeadersbudgets.
4. Recent activity
helios/srcin the last 60 days:eee6a9fa(#581, CUDA graph priority),0c25e88f(#613, deferred_prefill checkpoints / shared_pages / wire prepares),9a054b49(#608),5df8edd3(#607),e6bc2b5e(#580),dad2fa56(#497),fb32cd39(#598),8e40b3a6(TP deadline errors). Per the orientation packet, none of them touch the six files this PR changes, so the change builds on a stable base and does not conflict with or reverse the latest work; the "no commits since branching touching its files" check is the packet's own, unverified by a rebase.- The functional neighbourhood is very recent: #167 (Nov 2) the budget; #405 (Nov 20) declared markers as controls; #304/#433 Inkling 2 Small/Mini. #615 is the first attempt to bridge the budget and the TMLv0 content-header parser.
- docs/ in the same window is dominated by Luke Alonso (379 commits), including the doc-policy commits.
5. People
- Author: newjordan —
FIRST_TIME_CONTRIBUTOR, 0 merged/closed/open PRs or issues in 180 days; commit2652c067authored as "Jordan Newman"; Discordfrosty40given in the description. No prior standing in the project. - Area owners (
helios/src, 180 days): Luke Alonso (224 commits), Martin Vit (52), yatesdr (47). docs: Luke Alonso (379), Martin Vit (55), yatesdr (47). - Who owns the code being changed: the budget machinery is yatesdr's (#167); the TMLv0 content-header parser/grammar work is brandonmmusic-max (#457), yatesdr (#304, #405) and joshua cartu (#418). None of them has engaged with #615.
- Who has engaged: nobody. No reviewer requested or assigned, no comments, no reactions, no autobot case file posted (contrast #457, which received an intake report 2026-11-24 and a full changes-requested review the same day, and #582, which got a human review within ~1.5 hours and an approval on 2026-11-29).
6. Project fit (charter, roadmap, docs)
Lines up:
- "Support the documented Chat Completions, Completions, Responses, and Messages APIs (including token counting)" and the Messages-API target (charter lines 23, 33): the PR turns an HTTP 400 into a working hard cap for
thinking_token_budgetand Anthropicthinking.budget_tokens, and updatesdocs/api.md:813-850. - "Don't silently ignore API fields — either implement it according to the spec or reject it": the field moves from reject to implement for one more format.
- "PR descriptions: four parts — why, what changed, claimed result, evidence": the description has all four plus a limitations section.
docs/TODO.txt:176-179asks whether default request parameters deserve a config mechanism "beyond[server] thinking_token_budget" — this PR extends that setting's reach, consistent with the open TODO rather than resolving it.
Cuts against:
- "Keep the runtime small and model-agnostic … shouldn't accumulate per-model branches (#267, #334)" and "No per-model special cases or flags":
tml_text_transition_tokenskeys onTmlV0+ContentHeadersand hardcodes the marker literals (request.rs:543-555); the contract declaresreasoning.open/closebut no text opener, so the PR does not add a declared field. It mirrorsCONTROL_MARKERS(helios/src/output/tml.rs:25-44), so it is consistent with existing style, but it is a format-keyed branch in the request layer. - "Bug fixes need to address the root cause (#397)": the UTF-8 repair is a U+FFFD heuristic at one call site (park, forced cuts only), not a general decoder/history fix; preemption and the plain output limit keep the same hazard.
- "Bring real evidence (#210)" and the supported-matrix rule ("check interactions across every supported model, cache scheme, parallel layout …"): evidence is CPU test suites on synthetic tokenizers; no live
flare runon an Inkling 2 core, no before/after,#[ignore]real-snapshot tests unrun. #457 and #582 both supply live SM120 evidence. docs/TODO.txt:5still lists "[ ] Qualifystrict: truefunction tools on a TMLv0 core" — TMLv0 is not fully qualified, and this PR does not touch that (nor does it need to).- Non-goals: not violated (no new model, hardware or backend).
- Contributor policy: newjordan is not a priority contributor; the charter says such PRs are judged on merits and any missing piece is spelled out in review.
7. Claims and evidence
Backed by the diff (verified in code):
thinking_budget_closeacceptsRecipientFrame/RecipientHeaderforContentHeaderswith a single-token close —request.rs:567-577.tml_text_transition_tokensresolves the two markers from added vocabulary —request.rs:543-555.- Guards:
TmlV0+ContentHeaders, no tools, no grammar,1 + tail.len() < after—request.rs:384-393; thetool_choice="none"case making tools empty is asserted in the decode test. - Injection, per-token recording,
afterreduction preservingoutput_event_capacity()(runtime.rs:68-88) —runtime.rs:1959-2017. - Trim of up to 3 tokens retaining ≥1 generated token, preemption and unforced continuation untouched —
runtime.rs:2129-2155,2121,2013. - New tests exist in all four test locations listed in §1.
Claimed, self-reported, unverified here:
- "1,685 passed, 0 failed, 45 ignored" (
--features runtime-core,server -- --skip engram::) plus "62 passed" integration binaries;engram::"39 passed, 2 failed" attributed toRLIMIT_MEMLOCK8 MiB andio_uring_register_buffersOOM (engram is untouched — confirmed: no engram file in the diff); flare "242 passed"; flare-clicargo checkclean. No CI exists on the head commit ("no checks"), so none of these numbers is machine-confirmed in the repo.
Not done / not evidenced:
- TLA+ TLC runner not executed (no
java/tla2tools.jar); justified because no scheduler state machine changed — consistent with the diff, which only adds accounting calls inruntime.rs. - Real-checkpoint
#[ignore]tests (tml_tests.rs(not opened),FLARE_INKLING2_TEST_SNAPSHOT) and live GPUflare runnot re-run — the main gap, since the whole point is Inkling 2 behaviour. - No demonstration (curl transcript, sample stream) that the injected
<|message_model|><|content_text|>actually yields a text continuation instead of a second<|content_thinking|>frame on a real model; only the synthetic fixture asserts the prepared cut and the decoded output of a scripted token stream. - No benchmark for the extra
frontend.decodecalls now executed insideparkon the cut path (bounded to ≤4 per cut, but on the worker thread). - No test for the trim's fallback branches:
end > window_startboundary, more than 3 trailing partial tokens, or a decode that does not surface U+FFFD. - The premise that
<|end_message|>closes the thinking frame is verified from the contract fixture (helios/tests/support/contracts/inkling2_frontend.json:8-14, 21-25) and theContentHeadersdefaults (helios/src/model/contract.rs:891-907 (not opened), 923).
8. Reach
- Users/API: clients sending
thinking_token_budget(Chat Completions, Responses, Messages) or Anthropicthinking.budget_tokenson aTmlV0/ContentHeaderscore go from HTTP 400 (request.rs:369, 375-377) to a working hard cap, only whenbudget.tokens() < max_new_tokens(request.rs:381). All reasoning formats gain the trim on forced cuts, with up to 3 already-emitted tokens dropped from the continuation prompt. - Models:
PromptEncoder::TmlV0+ReasoningParserKind::ContentHeaders— Inkling 2 Mini/Small (and the vision block carries the same kind in the fixture). Everything else is affected only through the format-agnostic trim. - Operators/config:
[server] thinking_token_budgetnow bootstraps on those cores instead of failing validation (config.rs:411-438); no new keys, flags or defaults;/v1/modelsadvertisement unchanged (docs/api.md:835-842). Metricflare_reasoning_budget_cuts_totalstill counts one per cut, butgenerated_tokensnow includes 1–3 injected tokens; dashboards built on #541 will see the shift. Client-visibleusage.completion_tokenscan include 3 hidden control tokens where it used to include 1. - Compatibility: no wire/protobuf/core-ABI change (
ReasoningCutis in-process); exported cores and ignition unaffected; grammar state machines never see the tail (suppressed at bothrequest.rs:384andruntime.rs:1962-1963). - Documentation:
docs/api.mdupdated;docs/logprobs-design.md:19(not opened) anddocs/cli-design.md:1337 (not opened)/1367/1417not updated;docs/TODO.txt:5still open. - Deployment risk surface:
parkserves preemption, cuts and re-admission; the new path adds up to 4 decodes per forced cut on the worker thread and introduces a new terminal shape (partial tail +budget_stop).
9. Process
Open, "ready for review" (not draft); head 2652c067e9dd79945fbb76ddd69c25c7907c0a05; no labels (untriaged — compare #457's area:api/bug/model:inkling-small/triage:review); no CI checks; no reviews, no comments; no reactions; opened and never updated since 2026-11-29 19:04; same-day as a batch of main merges (#613, #608, #607). +562/−31 over 6 files, of which 442 lines are tests. Title and branch follow repo convention. Description meets the charter's four-part standard and adds a limitations section. Single squashed commit.
10. Open questions / what could not be found
- Does the injected
<|message_model|><|content_text|>actually keep a real Inkling 2 model inside a text frame? No real-checkpoint or live-serving evidence in the PR; only synthetic fixtures and the contract JSON. Cannot be answered from the repository. - How does the injected unnamed model header interact with #457's "header without content" EOS error path? The two PRs never reference each other and #457 is unreviewed-by-#615's-author; a reviewer would need both heads together to decide whether the sequence is legal under #457's
TmlOutput. - Is dropping up to 3 already-emitted tokens from the continuation prompt acceptable for every format (the trim is not ContentHeaders-specific)? No note in the description, no test, no doc beyond
docs/api.md:821-823which is framed under the TMLv0 paragraph. - Why is the marker pair hardcoded in
request.rsrather than declared in the contract (reasoning.open/closeexist; no text opener)? Possible charter friction (#267/#334); not discussed anywhere. - Would the U+FFFD heuristic fire reliably on the real tokenizer? It depends on
frontend.decodesurfacing'\u{FFFD}'for a partial sequence in batch mode; no test asserts the negative (no-trim) branch or >3-token tails. - Any user reports of the HTTP 400? None found in issues, PRs or discussions; demand is documented only by the code gap and #167's design note.
- Still mergeable? The packet says no
maincommits since2147cd4touched the changed files, so probably yes, but no rebase or CI run confirms it — and #582 in flight on the same function will force a resolution.