Explore scratchpad · NVIDIA/hyperflare-inference #615

Raw Markdown for agents: https://autobot.eidonix.com/p/775c8d34-707a-45b6-b884-6ca9a27649d8.md

#1 [high] Change: what PR #615 does, file by file (size +562/−31, 6 files)

PR #615, head 2652c06, base main, +562/−31 across 6 files. Branch feat/helios-tml-thinking-budget. Author newjordan (FIRST_TIME_CONTRIBUTOR), opened/updated 2026-11-29 19:04, no reviews, no comments, no CI checks.

Actual diff (verified by reading pr_diff):

  1. helios/src/server/request.rs (+32/−3):
    • prepare_validated_inference: when budget < max_new_tokens, builds close_tail = tml_text_transition_tokens(frontend, config) if output.content.tools.is_empty() && grammar.is_none() and 1 + tail.len() < after; else empty. Sets max_new_tokens = budget; ReasoningCut { close, close_tail, after, output }.
    • New fn tml_text_transition_tokens(frontend, config) -> Vec<u32>: requires frontend.prompt_encoder() == PromptEncoder::TmlV0 and config.contract.frontend.reasoning.kind == ReasoningParserKind::ContentHeaders; then looks up added-vocabulary ids for "<|message_model|>" and "<|content_text|>", returns vec![model, text] or empty.
    • thinking_budget_close: was if !matches!(start, Reasoning | Content) { return Ok(None) }; now supported_start = matches!(Reasoning|Content) || ((RecipientFrame|RecipientHeader) && syntax.kind == ContentHeaders). Note the config.contract.frontend.reasoning lookup moved before the start check (so None reasoning syntax still returns Ok(None) for any start).
    • Note: RecipientHeaders is explicitly NOT widened (only ContentHeaders) — description says "RecipientHeaders behavior unchanged".
  2. helios/src/server/runtime.rs (+76/−22):
    • ReasoningCut gains pub close_tail: Vec<u32> field (with doc comment).
    • Worker::publish() budget branch: builds sequence = [close] + close_tail if !cut.close_tail.is_empty() && request.incoming.prompt.grammar.is_none() && 1 + close_tail.len() < cut.after; calls request.close_reasoning(token, eos) per token, collecting injected; breaks on stopped (sets budget_stop), abandons on error. Records each injected token via scheduler.record_decoded_token, increments reasoning_budget_cuts once, metrics.progress(0, injected.len(), ...). remaining = cut.after.saturating_sub(injected.len() as u32) (was cut.after - u32::from(forced)). appended = &injected when forced (was slice::from_ref(&cut.close)).
    • Worker::park(): new UTF-8 trimming block before tokens.extend_from_slice(appended): applies only if !appended.is_empty() and there are generated tokens; decodes an 8-token window tokens[len-8..] (clamped to live.prompt_tokens); if text ends with U+FFFD, tries trim 1..=min(3, generated_len-1) and truncates at the first trim where the window no longer ends with U+FFFD (and end > window_start). Guarantees at least one generated token remains.
    • Test updated: ReasoningCut { close: 8, close_tail: Vec::new(), after: 20, ... } in runtime tests.
  3. helios/src/server/config.rs (+48/−0): new test block in existing bootstrap test: builds tokenizer with TML special tokens, prompt_encoder=3 (TmlV0?), thinking_token_budget=16, ContentHeaders reasoning with open "<|content_thinking|>" / close "<|end_message|>", TmlJson tools; asserts Bootstrap::load succeeds and loaded.server.thinking_token_budget == Some(16).
  4. helios/src/server/protocol/decode.rs (+192/−0): one new test tml_content_headers_thinking_budget_prepares_close_and_optional_text_frame_tail in native_prompt_tests: builds a byte-level BPE tokenizer with the 14 TML special tokens, loads contract fixtures helios/tests/support/contracts/inkling2_frontend.json["text"], then asserts: uncapped cases (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 (after<=3) → close_tail empty; tools present → close_tail empty; tool_choice=none → tail restored; response_format json_object (grammar) → tail empty; Messages thinking.budget_tokens=16 → same cut.
  5. helios/src/server/runtime/phase_tests.rs (+202/−0): budget_cut helper gains close_tail: Vec::new(); two new tests:
    • reasoning_budget_injects_content_headers_close_tail_and_accounts_for_capacity: 3 cases (capacity 5 → injects [end, model, text], parked prompt tokens [0, model, think, 0, end, model, text], max_new_tokens 2, carried.generated_tokens 6, cuts metric 1, final finish (1,8,"length"), OutputPipeline decodes 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: byte-level fixture with bytes 0xE2/0xAC/0xA2 = U+2B22; 1-byte and 2-byte partial tails trimmed from parked prompt, complete char kept; and with appended empty (unforced continuation via budget_cut? — actually reasoning_cut set but reasoning closed) the partial tail is preserved.
  6. docs/api.md (+12/−6) in the thinking_token_budget section (~line 814): documents ContentHeaders support, silent <|message_model|><|content_text|> tokens when no tools/grammar, UTF-8 tail trimming, and changed 400-condition wording to "when output starts in reasoning or a content-header frame".

#2 [high] Why: the problem, prior art (#167) and how long it has been wanted

The problem the PR addresses is a gap in an existing, merged feature, not a new feature request.

#3 [high] Related work: #167 (origin), #457 (TMLv0 ContentHeaders), #582 (touches same park path), #541 (metric consumer)

#4 [high] Change: behaviour beyond the description (metric/stop accounting, truncated injection, decode-window heuristics)

Verified from the diff and surrounding code, not stated in the description:

  1. A second opaque token is pushed through the output parser and stop matcher. Active::close_reasoning() (helios/src/server/runtime.rs:431-444) runs grammar.advance + incoming.observe_token + carried.generated_tokens += 1 + emit_output. The PR routes every close_tail token through it, so <|message_model|> and <|content_text|> are counted as generated tokens, pass through TokenStops/text_stops matching, and can set budget_stop if a user token-stop sequence ends with them. The docs say only "Forced close tokens count as generated tokens within the output limit" — which now means 1 or 3 tokens, not one. docs/logprobs-design.md:19 still says "Forced tokens, such as the thinking_token_budget close, have no logprob entry", unchanged by this PR.

  2. The close token is no longer necessarily the only recorded token. scheduler.record_decoded_token is now called once per injected token (runtime.rs:1991-1995), so injected.len() tokens enter the decoded-history/copy-proposal index rather than one.

  3. injected is truncated when stopped is true. The loop breaks on stopped, pushing the token into injected but skipping the rest of the tail; budget_stop = true then ends the request, so close_tail may never be emitted even when capacity allowed it — an unmentioned partial-injection path (contrast the "all-or-nothing" wording in the description, which refers only to the grammar/capacity guards).

  4. UTF-8 trimming depends on a decode of the last 8 tokens returning trailing U+FFFD. The window is tokens[len-8..] clamped to live.prompt_tokens; the check is decode(...).is_ok_and(|t| t.ends_with('\u{FFFD}')). Trimming loop requires end > window_start. If the model emitted more than 8 tokens of nothing but an incomplete character, or the decoder does not surface U+FFFD (incremental vs. batch decode behaviour differs), no trim happens. It also only trims when appended is non-empty — i.e. only on a forced cut, not on preemption (park_if_preempted passes &[], runtime.rs:2121) nor on unforced continuation.

  5. A silent data-loss path the description does not mention: trimming drops up to 3 already-generated tokens from the continuation's prompt. Those tokens were already emitted to the client as text in the first pass (they went through the Decoder/stops), so they are not duplicated, but the model's re-prefilled context no longer matches what the client saw. carried.generated_tokens (prompt accounting) still counts live.generated_tokens (runtime.rs:2158-2162), unaffected by the trim.

  6. No test asserts the trimming case where trimming is impossible. The tests cover 1-byte, 2-byte, complete character, and appended empty — not "window_start boundary reached" (the end > window_start guard) nor "more than 3 trailing partial tokens".

  7. The close_tail guard duplicates in three places with the same predicate 1 + tail.len() < after but different types: request.rs:386 (u64::from(1 + tail.len() as u32) < u64::from(after)), runtime.rs:1962-1965 (u64::from(1 + cut.close_tail.len() as u32) < u64::from(cut.after)). Both are strict <, i.e. after must be at least 4 for the 2-token tail. Startup validation (validate_thinking_budget) uses the same thinking_budget_close, so the [server] default is now accepted at bootstrap for ContentHeaders — that is the config.rs test.

  8. thinking_budget_close reordering: the Some(syntax) = &config.contract.frontend.reasoning lookup now runs before the start match, so for OutputStart::Reasoning|Content cores with no reasoning syntax the result is the same (Ok(None)), but the function no longer short-circuits on start alone. No behaviour change found, but it is a restructuring, not a pure widening.

  9. Not implemented although related: RecipientHeaders (kind 5) stays unsupported for frame starts; OutputStart::ToolBody stays unsupported. The description says RecipientHeaders behaviour is unchanged, which matches.

  10. The config.rs test is written against a fabricated tokenizer plus a hand-written contract, not a real Inkling 2 checkpoint; the decode.rs test loads helios/tests/support/contracts/inkling2_frontend.json (verified: text.reasoning = {kind 6 ContentHeaders, open <|content_thinking|>, close <|end_message|>}, assistant_marker <|message_model|>, tools kind 8) into a synthetic byte-level BPE tokenizer.

#6 [high] Project fit: charter alignment on API completeness vs the model-agnostic/evidence rules

Charter points (read via read_charter):

Where it lines up

#7 [high] Claims and evidence: what is backed by the diff, what is only self-reported, what is unrun

Claims vs what backs them (all quoted from the PR description unless noted).

Backed by the diff/tests (verified by reading them)

Test numbers (as claimed, not reproducible here)

Claimed but NOT done / not evidenced

#8 [high] Reach: who is affected — all reasoning formats get UTF-8 trimming, TMLv0 cores get budgets, operators and metrics consumers

Who/what is affected (verified in code, not claimed).

Users / API surface

Operators / configuration and defaults

Compatibility / dependencies

Deployment risk surface

#10 [high] Research summary

I prepared the case file for PR #615 (helios: support thinking_token_budget for ContentHeaders and trim incomplete UTF-8 tails on cut), covering all eight angles with nine scratchpad entries.

What I established. The change is additive over #167 (merged 2026-11-02, yatesdr), which created the whole hard-reasoning-budget feature and deliberately rejected formats that could not honour a cap — TMLv0/ContentHeaders starts at OutputStart::RecipientFrame, which thinking_budget_close() did not accept, so both per-request and [server] thinking_token_budget returned HTTP 400 on Inkling 2 cores. #615 widens that function, adds tml_text_transition_tokens() (literal <|message_model|>/<|content_text|> from the added vocabulary) as ReasoningCut::close_tail, injects it through Active::close_reasoning() in publish(), and adds a U+FFFD-heuristic trim of up to 3 trailing generated tokens inside Worker::park(). Production code is only ~+156/−25; the rest is tests and docs.

Beyond the description (high importance for a reader). Injected tail tokens are routed through the stop/grammar path and counted as generated tokens, record_decoded_token is now called per injected token, injected can be truncated mid-tail when a user token stop matches, and — most importantly — the UTF-8 trim is gated only on !appended.is_empty(), so it silently applies to every reasoning format's forced cuts (up to 3 already-emitted tokens dropped from the continuation prompt), reaches further than "ContentHeaders" implies, and does not cover preemption or the plain output limit.

Related work and tensions. #457 (open, same day, reviewed) rewrites exactly the TMLv0 TmlOutput/"header without content" and unnamed-header grammar semantics that the injected <|message_model|><|content_text|> sequence depends on, with no cross-reference either way; #582 (open, approved) edits the same park prompt-rewrite path and needs a rebase. Charter fit is mixed: it lines up with "implement or reject API fields" and Messages support, but sits against "keep the runtime model-agnostic" (format-keyed branch with hardcoded literals in the request layer) and against the evidence rule (CPU tests only, no live Inkling 2 run, real-checkpoint #[ignore] tests unrun, no CI checks on the head commit).

Process/community. Ready-for-review, unlabelled, untriaged, zero comments, zero reviews, no CI, never updated since opening; author is a first-time contributor with no prior history; area owners are Luke Alonso / Martin Vit / yatesdr, and the budget code is yatesdr's. No issue anywhere reports this gap, so demand is documented only by the code gap itself.

All file:line citations, the claim-by-claim evidence mapping, the reach analysis (users, models, operators, metrics, docs) and the process facts are in the scratchpad entries (1, 4, 7, 8 are high importance).

#12 [high] File map: where every piece of the change lives, with line anchors for reviewers

Changed files (6, +562/−31) and the anchors a reviewer needs:

  1. helios/src/server/request.rs (+32/−3)

    • 368-407 request preparation: the reasoning_cut block; new close_tail construction at 384-393.
    • 543-555 new tml_text_transition_tokens() (TmlV0 + ContentHeaders gate; literal "<|message_model|>"/"<|content_text|>" lookup at 550-554).
    • 557-578 thinking_budget_close() widened: supported_start at 567-569; single-token close requirement at 573-577. NOTE the Some(syntax) = &config.contract.frontend.reasoning lookup moved above the start match (564-566), a restructuring beyond a pure widening.
    • Unchanged but load-bearing: 369/375-377 the HTTP 400 message; 381 budget < max_new_tokens gate.
  2. helios/src/server/runtime.rs (+76/−22)

    • 50-61 ReasoningCut + close_tail field (doc comment 53-57).
    • 431-444 Active::close_reasoning() — reused unchanged per injected token.
    • 1950-2017 Worker::publish() budget branch: include_tail at 1962-1965, sequence build 1966-1972, per-token loop 1973-1989, injected bookkeeping 1991-1999, remaining at 2011, appended at 2013.
    • 2121 park_if_preempted passing &[] (the path the trim deliberately does not cover).
    • 2125-2198 park(): new UTF-8 trim block 2129-2155, tokens.extend_from_slice(appended) 2156, metadata extend 2167-2168.
    • 3393-3399 runtime unit test updated for the new field.
    • Related unchanged code: 68-88 Prompt::output_event_capacity (comment at 69-70 still says "A reasoning cut's forced token is part of after").
  3. helios/src/server/config.rs (+48/−0): entirely a new test block inside the existing bootstrap test (~663-708), building a TML tokenizer + ContentHeaders/TmlJson contract, thinking_token_budget=16, asserting load succeeds. Startup validation itself is unchanged: 400/411-438 validate_thinking_budget calls thinking_budget_close.

  4. helios/src/server/protocol/decode.rs (+192/−0): one test, tml_content_headers_thinking_budget_prepares_close_and_optional_text_frame_tail, in native_prompt_tests (starts ~2031). Builds a synthetic byte-level BPE tokenizer + 14 TML added tokens, loads helios/tests/support/contracts/inkling2_frontend.json["text"], then asserts uncapped / plain / tight-capacity 29-31 / tools / tool_choice=none / json_object grammar / Messages budget cases.

  5. 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); reasoning_budget_park_trims_incomplete_utf8_tail_without_affecting_plain_continuation (~825, uses byte-level tokens E2/AC/A2 = U+2B22).

  6. docs/api.md (+12/−6): the thinking_token_budget section, 813-833 (new 817-825 text) and the 400-condition sentence 830-833.

Supporting unchanged files a reviewer will want: helios/src/output/tml.rs:25-44 (CONTROL_MARKERS literals), 79-93 (prompt_start → RecipientFrame), 150-152 (reasoning_open = Body{Thinking, model:true}), 224-311 (state machine: END between frames closes nothing), 305-309; helios/src/model/contract.rs:68 (kind enum), 891-907 (ContentHeaders defaults), 923; helios/src/model/admission.rs:25-56 (extend_text monotonicity); helios/tests/support/contracts/inkling2_frontend.json:8-14, 21-25; helios/src/server/metrics.rs:1090 (reasoning_budget_cuts_total).

#5 [medium] People and recent activity: first-time contributor, untouched since opening, no CI, no review

#9 [medium] Process: ready-for-review, unlabelled, zero CI, zero reviews, never updated since opening

Process state, all verified from read_item/pr_files/orientation packet:

#11 [medium] Community: no comments, reviews or reactions at all; contrast with same-day neighbours

Community interest in #615 is literally zero, verified from read_item(615):