#1 [high] PR #615 overview + files inspected
PR #615 (newjordan) head 2652c06, base main@2147cd4. +562/-31 over 6 files.
- request.rs:384-400 builds
close_tailvia newtml_text_transition_tokens()(request.rs:543-555) whenoutput.content.tools.is_empty() && grammar.is_none()and1+tail.len() < after;thinking_budget_close()(request.rs:557-578) now acceptsRecipientFrame|RecipientHeaderwhen reasoning kind == ContentHeaders. - runtime.rs:51-61
ReasoningCut.close_tail; publish() cut branch runtime.rs:1950-2017 injects[close] + close_tailthroughActive::close_reasoning(runtime.rs:431-444), onerecord_decoded_tokenper token (1992-1995),metrics.progress(0, injected.len(), ...)(1999),remaining = cut.after.saturating_sub(injected.len())(2011),appended = &injected(2013). - park() runtime.rs:2125-2198: new UTF-8 trim block 2129-2155 gated only on
!appended.is_empty()(i.e. every forced cut in every format), trims up to 3 trailing whole tokens, keeps ≥1 generated token, thenextend_text(incoming.prompt.tokens.len(), tokens.len())(2167-2168). - Invariant verified: orig_prompt + budget + injected + (after - injected) == orig_prompt + original max_new_tokens, so the context-length invariant of validate_prompt is preserved; tokens.len() > incoming.prompt.tokens.len() holds so extend_text's strict-monotonicity requirement (admission.rs:25-56) is satisfied.
- Verified parser behavior: TmlOutput::new maps RecipientFrame->State::Frame, RecipientHeader->Header{model:true} (tml.rs:131-137);
<|end_message|>in Body->Frame (tml.rs:305-309); MODEL->Header, TEXT->Body{Text, model:true} (tml.rs:277-284). So the injected pair legally re-enters Body::Text and the client pipeline publishes it as content (phase test asserts reasoning "a", content "bc"). prompt_start(tml.rs:79-93) will report OutputStart::Content for the re-prefilled prompt ending in<|content_text|>, so the re-admitted continuation is parsed as a text frame.
#2 [high] Findings: PR #615 correctness/contracts/system lens
FINDING 1 (Major): UTF-8 trim is format- and grammar-agnostic; it silently drops up to 3 already-published tokens from the re-prefilled prompt for EVERY reasoning format and even under an active grammar.
- runtime.rs:2133
if !appended.is_empty() && tokens.len() > live.prompt_tokens {— appended is&injectedfor any forced cut (runtime.rs:2013), so DeepSeek V4.1/XTML/ThinkTags/Recipient cuts (close_tail empty -> appended=[close]) also trim. - Contrast: the tail injection is grammar-gated (runtime.rs:1962-1965
request.incoming.prompt.grammar.is_none()), the trim is not; so withresponse_format+ budget, a partial UTF-8 char at the cut is removed from the prompt while the worker/client grammar was already advanced over that token (runtime.rs:1822-1838 and Active::close_reasoning runtime.rs:432-438). Grammar state and prompt history diverge; the mask can force a continuation that no longer composes with the JSON emitted so far. - docs/api.md:817-823 documents the trimming inside the ContentHeaders paragraph only ("For TMLv0 content-header reasoning (
ContentHeaders) ... Any incomplete multi-byte UTF-8 tail tokens at the cut boundary are trimmed"), which understates reach. - No test covers a non-TML format or a grammar-constrained forced cut (phase_tests.rs:825-900 only uses a TML-ish fixture with budget_cut).
Fix: gate the trim on the cut that requested it (carry a flag on ReasoningCut or only trim when
close_tailnon-empty / ContentHeaders) or at minimum ongrammar.is_none(); and document the reach if kept generic.
FINDING 2 (Minor->Major): literal U+FFFD is indistinguishable from a provisional one, so a legitimately generated replacement character is silently deleted.
- runtime.rs:2136-2153 tests
text.ends_with('\u{FFFD}')on a plainfrontend.decode, with no byte-level confirmation. - The repo already documents the ambiguity: token_spans.rs:92-93 "Exact byte ranges distinguish a literal U+FFFD from provisional UTF-8 replacement".
- Byte-fallback tokenizers can produce U+FFFD as real content (stops.rs:340-355 builds
<0xEF><0xBF><0xBD>), so[..., ef, bf, bd]decodes to "\u{FFFD}" and the code truncates it from the prompt. Fix: confirm with exact bytes (e.g. thetoken_bytes/byte_startsmachinery already used by token_spans) or require the trailing tokens' raw bytes to be an incomplete UTF-8 prefix.
FINDING 3 (Minor): trim silently gives up in the documented-certain cases it claims to fix.
- runtime.rs:2141-2153:
max_trim = 3.min(generated_len-1)andend > window_start; when the incomplete sequence reaches the window start (few generated tokens, or a partial char at the tail of the prompt) nothing is trimmed and no diagnostic is emitted, yet docs/api.md:821-823 assert the tail tokens are trimmed. Fix: state the bound, or trim againstincoming.prompt.tokens.len()rather than the 8-token window start.
FINDING 4 (Minor): the injected tail is not all-or-nothing on a user token stop.
- runtime.rs:1973-1989 breaks out of the sequence loop when
close_reasoningreportsstopped, so<|message_model|>can be injected without<|content_text|>, leaving TML inState::Header(tml.rs:277-284) and terminating the request (budget_stop -> reason "length" at runtime.rs:2055). PR text says "(all-or-nothing whengrammar.is_none()and1 + cut.close_tail.len() < cut.after)". Fix: pre-check token stops/allowsfor the whole sequence, or roll back and park onclosealone.
FINDING 5 (Minor, accounting/metrics): per-token accounting triples the hidden-token charge per cut.
- runtime.rs:1992-1999 (one
record_decoded_token+metrics.progress(0, injected.len(), ...)per token) and runtime.rs:2063 inject 3 tokens intogenerated_tokens/usage.completion_tokensand intoflare_generated_tokens_totalwhere main injected 1;reasoning_budget_cutsstill counts 1 (unchanged semantics for #541 dashboards).prompt_tokens(runtime.rs:2059-2062) does not reflect the extra 3. - Note docs/api.md:823-824 does mention forced tokens count as generated tokens, but not that the count per cut went 1 -> 3.
FINDING 6 (Minor, architecture/charter): hardcoded marker literals in the request layer.
- request.rs:543-555 keys on
PromptEncoder::TmlV0+ReasoningParserKind::ContentHeadersand hardcodes "<|message_model|>"/"<|content_text|>", duplicating tml::CONTROL_MARKERS (tml.rs:25-44). The repo already exposes them viaOutputPipeline::envelope_markers(ToolParserKind::TmlJson)(pipeline.rs:131-141) anddeclared_markers(pipeline.rs:147-177), andprepare_output(model/prompt.rs:319-328) resolves control tokens throughfrontend.encode. Charter: keep helios model-agnostic / no per-model branches (#267/#334). Fix: read the two openers from the prepared control-token set or add a declared text-opener to the contract.
FINDING 7 (evidence): no CI on head; no live Inkling 2 evidence; #[ignore] real-checkpoint TML tests unrun; the synthetic phase test drives a scripted token stream, so "the injected pair keeps a real model in a text frame" is unverified (PR "Limitations" acknowledges the run gaps but not that the central behavioral claim rests on a fixture).
Also: PR text "no visible transition text is inserted" is correct (docs/api.md:825) — verified via TmlOutput (Header->Body{Text} emits only subsequent text).
SOUND (verified, do not report): output_event_capacity (runtime.rs:68-88) still bounds publications because budget+after == original max_new_tokens and each injected token emits <=1 event; after reduced by injected.len() at runtime.rs:2011 keeps prompt+remaining == original limit so validate_prompt's context check (admission.rs:154-169) is unaffected; extend_text monotonicity (admission.rs:25-56) holds because at least one generated token survives; preemption passes &[] (runtime.rs:2121) and never trims; no platform-specific (Unix/Windows) code touched; no wire/proto/captured-graph contract change (ReasoningCut is in-process).
#3 [high] Research summary
I reviewed all six changed files plus their direct callees (TmlOutput, OutputPipeline, IncrementalDecoder, TokenStops/TextStops, Admission/PromptMetadataMut, scheduler decoded-history, metrics, http decoder) and the docs they touch.
Headline: the change is largely sound in its accounting. I verified that output_event_capacity still bounds publications (budget + after == the original limit, and after is reduced by injected.len() at runtime.rs:2011), that the context-length invariant in admission.rs:154-169 is preserved by construction, that extend_text monotonicity holds because at least one generated token always survives, that preemption still passes &[] and never trims, that the injected <|message_model|><|content_text|> legally re-enters Body::Text in TmlOutput (so the client pipeline publishes it as content, not reasoning), and that no wire/proto/captured-graph or platform-specific code is touched.
The main issue is that the UTF-8 trim in Worker::park() (runtime.rs:2129-2155) is gated only on !appended.is_empty(), so it fires for every forced reasoning cut in every format — including grammar-constrained requests, where the tail injection itself is gated on grammar.is_none() (runtime.rs:1962-1965). That silently deletes already-grammar-advanced, already-published tokens from the re-prefilled prompt, diverging grammar state from prompt history, while docs/api.md:817-823 documents the behavior only for TMLv0/ContentHeaders. Related: the U+FFFD test cannot distinguish a legitimate generated replacement character from a provisional one (the repo notes this distinction explicitly at token_spans.rs:92-93), the trim silently no-ops when the partial sequence reaches the 8-token window start, and the injected tail is not actually all-or-nothing on a user token stop (runtime.rs:1973-1989 breaks mid-sequence, leaving TML in State::Header), contradicting the PR's "all-or-nothing" wording. Minor items: per-cut hidden-token accounting went from 1 to up to 3 in generated_tokens/usage while prompt_tokens does not reflect it, and the new helper hardcodes <|message_model|>/<|content_text|> in the request layer even though OutputPipeline::envelope_markers(TmlJson) / declared_markers already expose exactly those literals (charter's model-agnostic rule). Evidence is CPU-only with a synthetic tokenizer; the central claim that the injected pair keeps a real Inkling 2 model in a text frame is unverified, and no CI exists on the head commit.
Full findings with verbatim quotes, severities, impact and fixes are in scratchpad note 2.
#4 [high] Verbatim quotes + coverage gaps backing each finding
Companion to note 2. Every quote below was read directly from the PR head (2652c06).
F1 (trim is format/grammar-agnostic). The trim gate, helios/src/server/runtime.rs:2133:
if !appended.is_empty() && tokens.len() > live.prompt_tokens {
versus the tail injection, which is grammar-gated, runtime.rs:1962-1965:
let include_tail = !cut.close_tail.is_empty()
&& request.incoming.prompt.grammar.is_none()
&& u64::from(1 + cut.close_tail.len() as u32)
< u64::from(cut.after);
appended is &injected for any forced cut (runtime.rs:2013: let appended: &[u32] = if forced { &injected } else { &[] };), so DeepSeek V4.1 / XTML / ThinkTags / Recipient / DSML cuts (which have empty close_tail, injected == [close]) trim too. Docs scope it to TML, docs/api.md:817-821:
reasoning (ContentHeaders), when no tools or grammar are active and output capacity
remains beyond the frame opener, Flare also emits the silent <|message_model|><|content_text|>
control tokens after <|end_message|> so continuation enters a text frame directly;
when tools or a grammar are active, only <|end_message|> is emitted. Any incomplete
multi-byte UTF-8 tail tokens at the cut boundary are trimmed from the re-prefilled
continuation context before the close token is appended.
Grammar/state divergence: the worker advanced the grammar over those tokens (runtime.rs:1822-1838 open grammar.advance, and Active::close_reasoning runtime.rs:432-438), and the client decoder already emitted their text, yet the token disappears from the parking prompt (runtime.rs:2150 tokens.truncate(end);) so the re-admitted continuation's mask no longer matches what was produced.
Fix options: put a trim_utf8 (or keep_tail_tokens) flag on ReasoningCut and set it only in the TML path of request.rs:384-393; or add && request.incoming.prompt.grammar.is_none(); then scope docs/api.md:821-823 to what remains.
F2 (literal U+FFFD cannot be distinguished). runtime.rs:2136-2139:
if self
.frontend
.decode(&tokens[window_start..], false)
.is_ok_and(|text| text.ends_with('\u{FFFD}'))
{
The repo states the distinction is only available with bytes — helios/src/server/token_spans.rs:92-93:
// Exact byte ranges distinguish a literal U+FFFD from provisional UTF-8
// replacement, and map every byte token of one character to its start.
A byte-fallback tokenizer really can emit U+FFFD content — helios/src/server/stops.rs:340-341 vocab contains "<0xEF>", "<0xBF>", "<0xBD>" and stops.rs:454 tests TextStops::new(&frontend, vec!["\u{fffd}".into()]). Such a tail is silently truncated instead of kept.
Fix: require the trailing tokens' raw bytes (frontend.token_bytes, used at token_spans.rs:56) to be an incomplete UTF-8 prefix before trimming, or reuse byte_starts' exact-range logic.
F3 (silent no-op). runtime.rs:2141-2153:
let max_trim = 3usize.min(generated_len.saturating_sub(1));
for trim in 1..=max_trim {
let end = tokens.len() - trim;
if end > window_start
&& self
.frontend
.decode(&tokens[window_start..end], false)
.is_ok_and(|text| !text.ends_with('\u{FFFD}'))
{
tokens.truncate(end);
break;
}
}
If the partial sequence straddles window_start (runtime.rs:2135: let window_start = tokens.len().saturating_sub(8).max(live.prompt_tokens);) every candidate fails end > window_start, so nothing is trimmed and nothing is reported — while docs/api.md:821-823 assert the trimming happens.
Fix: bound the scan by incoming.prompt.tokens.len() plus a wider window, or document the bound.
F4 (tail not all-or-nothing). runtime.rs:1973-1982:
for token in sequence {
match request.close_reasoning(token, &self.config.eos_token_ids)
{
Ok(stopped) => {
injected.push(token);
if stopped {
budget_stop = true;
break;
}
}
close_reasoning returns a user token-stop match via Active::emit_output (runtime.rs:431-444 -> 466-478 TokenStops::push), so <|message_model|> can be injected without <|content_text|>, leaving TmlOutput in State::Header { model: true } (tml.rs:272-284: MODEL => State::Header { model: true }) and finishing with reason "length" (runtime.rs:2055). The PR body claims "(all-or-nothing when grammar.is_none() and 1 + cut.close_tail.len() < cut.after)".
F5 (accounting). runtime.rs:1991-1999:
if forced && !abandon {
for &token in &injected {
self.scheduler
.record_decoded_token(request.request, token)?;
}
self.metrics
.reasoning_budget_cuts
.fetch_add(1, Ordering::Relaxed);
self.metrics.progress(0, injected.len(), 0, 0, 0, 0);
}
plus runtime.rs:2063 generated_tokens: request.carried.generated_tokens + generated, and metrics.rs:1055-1056 ("Committed generated tokens, including host-forced tokens, EOS and tokens subsequently withheld by text stops."). Main charged 1 token per cut; this charges up to 3 into usage/flare_generated_tokens_total while prompt_tokens (runtime.rs:2059-2062) does not reflect the 3 tokens added to the prompt. docs/api.md:823-824 only says forced tokens count as generated tokens, not that the per-cut count tripled.
F6 (hardcoded literals in the request layer). request.rs:543-555:
fn tml_text_transition_tokens(frontend: &Frontend, config: &ModelConfig) -> Vec {
if frontend.prompt_encoder() != crate::frontend::PromptEncoder::TmlV0
|| config.contract.frontend.reasoning.as_ref().map(|r| r.kind)
!= Some(crate::model::contract::ReasoningParserKind::ContentHeaders)
{
return Vec::new();
}
let vocab = frontend.tokenizer().get_added_vocabulary().get_vocab();
match (vocab.get("<|message_model|>"), vocab.get("<|content_text|>")) {
The same literals already flow through pipeline.rs:135 (ToolParserKind::TmlJson => &super::tml::CONTROL_MARKERS) and pipeline.rs:147-177 declared_markers, and prepare_output resolves control tokens with frontend.encode (model/prompt.rs:319-328). Charter: model-agnostic runtime, no per-model branches (#267/#334).
F7 (evidence). PR body's own limitations: TLA+ runner not executed; #[ignore] real-checkpoint tml_tests.rs (needs FLARE_INKLING2_TEST_SNAPSHOT) and live GPU flare run not re-run. All new runtime tests use Fixture::with_template synthetic tokenizers (phase_tests.rs:680-900), i.e. a scripted token stream, so the claim that <|message_model|><|content_text|> keeps a real Inkling 2 model in a text frame is unproven. No CI checks on head 2652c06.
TEST GAPS (concrete): no test drives the trim on a non-TML cut (e.g. budget_cut with close_tail empty on a </think> syntax), no test with prompt.grammar = Some(..) and a brace cut (the case where F1 bites hardest), no test for a literal-U+FFFD tail (F2), none for continuation with a user token stop mid-tail (F4), and none where the partial sequence reaches window_start (F3).
DOCS NOT UPDATED (search hits only, files not opened in full): docs/logprobs-design.md:19 ("Forced tokens, such as the thinking_token_budget close, have no logprob entry." — singular, still accurate in spirit), docs/cli-design.md:1337/1367/1417 describe [server] thinking_token_budget without the TMLv0/ContentHeaders case.
VERIFIED-SOUND (do not report as issues): event-capacity bound holds (runtime.rs:68-88; budget + after unchanged, after reduced by injected.len() at 2011); context invariant holds (admission.rs:154-169) because prompt grows by exactly injected.len(); extend_text monotonicity holds (admission.rs:25-56) since generated_len >= 1 survives; preemption path passes &[] (runtime.rs:2121) so it never trims; prompt_start (tml.rs:79-93) reports Content for the re-prefilled prompt ending in <|content_text|>, so the continuation parses as a text frame; the phase test's OutputPipeline assertion (reasoning "a", content "bc", phase_tests.rs:760-775) confirms no visible transition text; no Unix/Windows divergence, no wire/proto/core-ABI change (ReasoningCut is in-process).