Repository navigation
helios: support thinking_token_budget for ContentHeaders and trim incomplete UTF-8 tails on cut - #615
Conversation
|
A case file has been opened for 615. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedCloses a real feature gap and the core accounting is sound, but three verified issues need changes: the
Walkthrough
Merge Risk: Medium · up to
|
…omplete UTF-8 tails on cut
Models using TMLv0 content-header reasoning (ReasoningParserKind::ContentHeaders,
such as Inkling-2) begin generation in OutputStart::RecipientFrame and delimit
reasoning frames with <|content_thinking|> ... <|end_message|>. Currently
thinking_budget_close rejects OutputStart::RecipientFrame and
OutputStart::RecipientHeader, so both per-request thinking_token_budget and
[server] thinking_token_budget return an unsupported-format error on TMLv0 cores
even though TmlOutput::reasoning_open already tracks open thinking frames. In
addition, closing a TMLv0 frame with <|end_message|> alone returns to frame
boundary state where the model can open a second uncapped thinking frame, and
hard token cutoffs in Worker::park can slice a multi-byte UTF-8 sequence before
appending forced close tokens, leaving dangling lead bytes in the re-prefilled
continuation prompt.
Before: thinking_budget_close accepted only OutputStart::Reasoning and
OutputStart::Content; ReasoningCut carried a single close token;
Bootstrap::load prepared Frontend::token_bytes only when max_top_logprobs != 0;
and Worker::park appended forced close tokens directly after live.tokens()
without checking for incomplete trailing UTF-8 byte sequences.
After:
- helios/src/output/tml.rs and helios/src/output/pipeline.rs: add
tml::text_frame_opener and OutputConfig::reasoning_close_tail to resolve
[<|message_model|>, <|content_text|>] directly from the already-validated
single-token output.control_tokens when ReasoningParserKind::ContentHeaders is
active and no tools are active.
- helios/src/server/request.rs: extend thinking_budget_close to accept
OutputStart::RecipientFrame and OutputStart::RecipientHeader for
ReasoningParserKind::ContentHeaders with a single-token close delimiter, and
construct ReasoningCut::close as a single non-empty Vec<u32> once at
preparation time (appending output.reasoning_close_tail() when grammar is
absent and close.len() + tail.len() < after as usize, leaving at least one
visible output token after the frame header). Omitting thinking_token_budget
(including reasoning_effort="none" or enable_thinking=false) leaves requests
uncapped.
- helios/src/server/config.rs: call frontend.prepare_token_bytes()
unconditionally at bootstrap so VocabularyBytes is never built lazily on the
worker thread during a forced cut.
- helios/src/server/runtime.rs: change ReasoningCut::close to Vec<u32>, emit
the prepared sequence through Active::close_reasoning in Worker::publish
(recording each injected token in decoded history and metrics and subtracting
injected.len() from cut.after), and add trim_incomplete_utf8_tail in
Worker::park when appended is non-empty. The helper inspects exact token bytes
via Frontend::token_bytes and std::str::from_utf8, dropping trailing generated
tokens at indices >= live.prompt_tokens only when Utf8Error::error_len() is
None (preserving literal U+FFFD tokens and complete multi-byte characters, and
handling passes with generated_len <= 3 cleanly before extending with
appended). Preemption (appended empty) is unchanged.
- docs/api.md: document ContentHeaders support, UTF-8 incomplete-tail trimming
on forced cuts across all reasoning formats, and silent TMLv0 text-frame
control token injection when no tools or grammar are active.
- Tests in config.rs, protocol/decode.rs, request/tml_tests.rs, and
runtime/phase_tests.rs cover [server] thinking_token_budget bootstrap
validation, synthetic and real Inkling-2 tokenizer request preparation,
Worker sequence injection and capacity accounting, and exact UTF-8 trimming
(including literal U+FFFD preservation and generated_len == 1 and 2 passes).
Claimed benefit: enables per-request thinking_token_budget, Anthropic Messages
thinking.budget_tokens hard caps, and [server] thinking_token_budget defaults on
TMLv0 ContentHeaders cores without inserting visible transition text, keeps
plain-text continuations inside Body::Text without re-entering thinking while
preserving tool calls and grammars, and prevents truncated multi-byte UTF-8
suffixes from leaking across forced cuts for all reasoning formats.
Evidence and limitations: verified against main@2147cd4:
- CPU release suites (FLARE_TEST_TEMPLATE_DIR from prepare_templates.py):
helios (--features runtime-core,server -- --skip engram::) 1,685 lib + 62
integration passed (0 failed, 46 ignored, including
response_lifecycle_tests::native_responses_match_lifecycle_model and
unread_response_keeps_its_budget_through_a_reasoning_continuation);
flare 242 passed (0 failed, 4 ignored); flare-cli --tests compiled cleanly.
- Real Inkling-2 tokenizer (FLARE_INKLING2_TEST_SNAPSHOT=/tmp/inkling2-tokenizer):
server::request::tml_tests:: (-- --ignored) 6/6 passed (0 failed), including
thinking_budget_prepares_content_headers_cut.
- Live GPU serving on NVIDIA GB10 (SM121, prepared Inkling-2-Mini core via
flare run): verified HTTP 200 and flare_reasoning_budget_cuts_total increments
on plain Chat Completions (budget=32 and 64, including multi-byte Unicode
prompt — clean text continuation with reasoning_tokens=32/64 and zero U+FFFD),
tools-active Chat Completions (budget=32 -> clean get_weather tool_call),
json_object grammar (budget=32 -> valid JSON {"answer":391}), Anthropic
Messages (budget_tokens=48 -> thinking + text blocks, stop_reason=end_turn),
uncapped reasoning_effort="none" (0 cuts), and [server] thinking_token_budget
= 64 (/v1/models advertisement and automatic cut).
Limitations: engram:: io_uring tests hit the host's unprivileged 8 MiB
RLIMIT_MEMLOCK (CI raises memlock to 64 MiB; engram is untouched); the TLA+ TLC
runner (verification/helios-lifecycle/check.py) was not run locally because
Java/tla2tools.jar is not installed (no scheduler, admission, cache-ownership,
or rank-coordination code changed, and the Rust response-lifecycle conformance
test passed); live serving tested single-GPU SM121 text-only Inkling-2-Mini.
Signed-off-by: Jordan Newman <newjordan@gmail.com>
Design-Signed-Off-By: Antigravity (Gemini); design-review=2e5b
2652c06 to
7dde009
Compare
|
Addressed all findings from the review:
@flare-autobot please re-review. |
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Ready To MergeAll Round 1 findings are verified resolved at head
Walkthrough
Merge Risk: Low · up to
|
Why
Models using TMLv0 content-header reasoning (
ReasoningParserKind::ContentHeaders, such asInkling-2-MiniandInkling-2-Small) begin generation at a frame boundary (OutputStart::RecipientFrame) and enclose reasoning inside<|content_thinking|> ... <|end_message|>. Currentlythinking_budget_close()inhelios/src/server/request.rsaccepts onlyOutputStart::ReasoningandOutputStart::Content, so both per-requestthinking_token_budgetand[server] thinking_token_budgetfail with an unsupported-format error on TMLv0 cores even thoughTmlOutput::reasoning_open()already tracks open thinking frames and<|end_message|>is a single control token.Two frame-boundary issues also affect hard reasoning cuts:
<|content_thinking|>frame with<|end_message|>alone returns the model toState::Frame, where it can immediately open a second<|content_thinking|>frame after the one-shotReasoningCuthas been consumed.Worker::park()).What changed
helios/src/output/tml.rs,helios/src/output/pipeline.rs):OutputConfigexposed no follow-on frame-opener helper for reasoning cuts.tml::text_frame_opener()andOutputConfig::reasoning_close_tail(), which resolves[<|message_model|>, <|content_text|>]directly from the already-validated single-tokenoutput.control_tokenswhenReasoningParserKind::ContentHeadersis active andoutput.content.tools.is_empty().helios/src/server/request.rs,helios/src/server/config.rs):thinking_budget_close()returnedOk(None)forOutputStart::RecipientFrameandOutputStart::RecipientHeader, rejecting both per-request and[server] thinking_token_budgetonContentHeaderscores;ReasoningCutcarried a singleclose: u32; andBootstrap::load()calledfrontend.prepare_token_bytes()only whenmodel.max_top_logprobs != 0.thinking_budget_close()acceptsOutputStart::RecipientFrameandOutputStart::RecipientHeaderwhenReasoningParserKind::ContentHeadersis configured with a single-token close delimiter (RecipientHeadersbehavior is unchanged).prepare_validated_inference()constructsReasoningCut::close: Vec<u32>once, appendingoutput.reasoning_close_tail()only whengrammar.is_none()and1 + tail.len() < after as usize(leaving at least one output token after the frame header so partial headers are never injected).Bootstrap::load()preparesVocabularyBytesunconditionally so token-byte lookup never initializes lazily on the worker thread. Omittingthinking_token_budget(including withreasoning_effort="none"orenable_thinking=false) continues to leave requests uncapped, and no visible transition text is inserted.helios/src/server/runtime.rs):Worker::publish()injected a singlecut.closetoken, andWorker::park()appended forced close tokens directly ontolive.tokens().ReasoningCut::closeholds the preparedVec<u32>sequence. When reasoning is open at the cap and any grammar allows the single-token close,Worker::publish()emits each token incut.closethroughActive::close_reasoning(), records every injected token in decoded history and progress metrics, and subtractsinjected.len()fromcut.after(preservingoutput_event_capacity()and totalgenerated_tokens). InWorker::park(), whenappendedis non-empty,trim_incomplete_utf8_tail()inspects exact token bytes viaFrontend::token_bytes()andstd::str::from_utf8(), dropping trailing generated tokens at indices>= live.prompt_tokensonly whenUtf8Error::error_len().is_none(). Valid characters—including legitimately generated literalU+FFFDtokens—are preserved, small passes (generated_len <= 3, e.g., after preemption) trim cleanly beforetokens.extend_from_slice(appended)restorestokens.len() > incoming.prompt.tokens.len(), and preemption (appendedempty) and unforced continuations are untouched.docs/api.md,helios/src/server/config.rs,helios/src/server/protocol/decode.rs,helios/src/server/request/tml_tests.rs,helios/src/server/runtime/phase_tests.rs):docs/api.mdto documentContentHeaderssupport, UTF-8 incomplete-tail trimming across all reasoning formats on forced cuts, and silent TMLv0 text-frame opener tokens when no tools or grammar are active.[server] thinking_token_budgetbootstrap validation, synthetic and real Inkling-2 tokenizer request preparation (tml_tests.rs),Workersequence injection andOutputPipelinedecoding, and exact UTF-8 trimming (1-byte/2-byte incomplete tails,generated_len == 1and2, literalU+FFFDpreservation, complete multi-byte preservation, and unforced continuation preservation).Claimed benefit
thinking_token_budget(Chat Completions, Responses, Messages), Anthropicthinking.budget_tokenshard caps, and[server] thinking_token_budgetdefaults onContentHeaders/ TMLv0 cores instead of returning HTTP 400.Body::Textvia silent control tokens (<|message_model|><|content_text|>) without inserting visible transition text, while leaving tool calls and structured output grammars unobstructed.Worker::park()without dropping literalU+FFFDtokens or affecting preemption and unforced continuations.Supporting evidence and limitations
main@2147cd4(withFLARE_TEST_TEMPLATE_DIRprepared viatests/frontend/prepare_templates.py):cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server -- --skip engram:::1,685 passed, 0 failed, 46 ignored(lib, includingresponse_lifecycle_tests::native_responses_match_lifecycle_model,unread_response_keeps_its_budget_through_a_reasoning_continuation, and all new TMLv0/UTF-8 tests) plus62 passed, 0 failedacross integration test binaries.cargo test --locked --release --manifest-path flare/Cargo.toml:242 passed, 0 failed, 4 ignored.cargo check --locked --release --manifest-path flare-cli/Cargo.toml --tests: compiled cleanly.FLARE_INKLING2_TEST_SNAPSHOTwiththinkingmachines/Inkling-2-Minitokenizer.json):cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server server::request::tml_tests:: -- --ignored:6 passed, 0 failed(prompts_match_tml_renderers_token_for_token,message_endpoints_are_prefixes_of_longer_conversations,outputs_match_reference_parses,images_preserve_reference_order_feature_spans_and_message_endpoints,structured_output_grammars_constrain_frames, and newthinking_budget_prepares_content_headers_cut).NVIDIA GB10,SM121, preparedInkling-2-Minicore served via this branch's releaseflare runbinary):thinking_token_budget=32/64,max_tokens=256,seed=7):budget=32):HTTP 200,flare_reasoning_budget_cuts_total 0 -> 1,reasoning_tokens=32, continued immediately incontent("# Step-by-Step Explanation of Merge Sort's O(n log n) Complexity...").17 * 23,budget=64):HTTP 200,cuts 1 -> 2,reasoning_tokens=64,finish_reason="stop",content="17 * 23 = 17 * (20 + 3) = 340 + 51 = **391**.".— “quote” ⬢ café 世界 …,budget=32):HTTP 200,cuts 2 -> 3,reasoning_tokens=32,finish_reason="stop", clean UTF-8contentwith zeroU+FFFD.tools=[get_weather],thinking_token_budget=32):HTTP 200,cuts 3 -> 4,reasoning_tokens=32,finish_reason="tool_calls",content=null,tool_calls=[{"name":"get_weather","arguments":"{\"city\":\"Tokyo\"}"}](confirming<|end_message|>alone preserves tool invocation frames).response_format={"type":"json_object"},thinking_token_budget=32):HTTP 200,cuts 4 -> 5,reasoning_tokens=32,finish_reason="stop",content='{"answer":391}'./v1/messages,thinking={"type":"enabled","budget_tokens":48}):HTTP 200,cuts 5 -> 6,stop_reason="end_turn", emitted boththinkingandtextblocks cleanly.reasoning_effort="none"(no budget):HTTP 200,cuts 6 -> 6(no cut triggered),finish_reason="stop",content="ready".[server] thinking_token_budget = 64: started cleanly,/v1/modelsadvertisedflare.thinking_token_budget: 64, and a Chat request omitting a per-request budget hitcuts=1,reasoning_tokens=64,finish_reason="stop", with complete text output.engram::io_uringtests were skipped in the main run because two tests hitENOMEM(io_uring_register_buffers) under the host's unprivileged8 MiBRLIMIT_MEMLOCK(the Linux CI workflow raises memlock to64 MiB;engramis untouched).verification/helios-lifecycle/check.py) was not executed locally becausejava/tla2tools.jaris not installed on this host (no scheduler, admission, cache-ownership, or rank-coordination code changed, and the Rustresponse_lifecycle_tests::native_responses_match_lifecycle_modelandunread_response_keeps_its_budget_through_a_reasoning_continuationchecks ran and passed).SM121text-onlyInkling-2-Mini;Inkling-2-Small, vision inputs, andTP > 1were not live-tested.Discord: frosty40