#1 [high] Major: unmasked rejection path may turn a draft mismatch into a terminal 500
helios/src/grammar.rs:744-755 try_advance_unmasked:
let consumed = match self.matcher.try_consume_tokens(&[token]) {
Ok(consumed) => consumed,
Err(error) => { return self.fail(Error::Admission(AdmissionError::Grammar(...))) }
};
if consumed == 0 { return Ok(false); }
So the clean "Ok(false) without poisoning" rollback documented at grammar.rs:715-717 depends entirely on llguidance returning Ok(0) (not Err) for a disallowed in-vocabulary token. On Err, fail() sets self.error irrecoverably.
Runtime consequence: helios/src/server/runtime.rs:1900-1919 — any Err becomes
request.incoming.fail(ExecutionError::Completion(Failure::caused_by("grammar advancement failed: ..."))) + stopped, i.e. a terminal 500/terminal SSE error for a request that device masking would simply never have sampled. On main this was impossible.
Test coverage gap: the only forbidden tokens exercised are EOS (premature EOS) and padded OOV ids — grammar.rs test unmasked_advancement_matches_masked_decisions_and_defers_mask_sync (~1851-1920) uses try_advance_unmasked(256)/(257) (eos ids), tokenizer_vocab, model_vocab-1, and post-stop b'a'; runtime test speculative_grammar_reasoning_rolls_back_forbidden_token_including_premature_eos (phase_tests.rs:7458) only uses EOS as the forbidden token. In speculative_grammar_reasoning_runs_pipelined_and_transitions_on_close_with_overshoot the forbidden 4 overshoot tokens are never validated: the !is_open transition is pushed first and the rest of the burst is skipped (runtime.rs:1889-1892).
Fix: on Err, treat as rollback (record the failure only for reporting, keep parser state by cloning the matcher before the attempt, or validate against the synced mask) instead of failing the whole request; and add a test with an in-vocabulary, non-EOS, grammar-forbidden token mid-burst.
#2 [high] Major: every reasoning->answer transition re-prefills the whole reasoning trace and drains the frame window
helios/src/server/runtime.rs:2407-2428 park_grammar_transition -> park_with_tokens(..., publish_terminal=false, ...) (runtime.rs:2431-2449) calls self.scheduler.cancel(handle) instead of finish, so no terminal snapshot is published. The readmitted request's prompt is live.tokens()[..exact_len] (runtime.rs:2418) with exact_len = live.prompt_tokens + emitted (runtime.rs:2070). The only checkpoint that can serve that prefix is the prompt-end checkpoint (checkpoint_accounting is just carried over, runtime.rs:2473), so the entire reasoning trace R = exact_len - prompt_end must be recomputed with GraphKind::Restore + chunked GraphKind::Prefill.
Verified in the tests by construction: phase_tests.rs:7388-7390 exercises exactly Restore then a single-token Prefill (// "c"), i.e. the test only ever re-prefills 1 token; real reasoning traces are thousands.
System-level cost the description under-states ("one slot transition ... + one queued frame of discarded overshoot"):
- O(R) prefill work and KV/page traffic injected at the exact moment the answer starts, on every grammar-constrained thinking request.
- Prefill is not a two-frame operation: docs/scheduling-runtime-design.md:548-552 ("Prefill ... drain the window") and helios/src/scheduler.rs:1085-1094 mean the re-prefill also removes pipelining from every other request sharing the batch for its duration — the opposite of the PR's headline benefit for concurrent requests.
- If the prompt checkpoint was evicted (the PR's own caveat), the whole prompt is re-prefilled.
Fix/ask: at minimum publish a checkpoint at the reasoning boundary (the publish() path already can publish a terminal snapshot with KV reuse — see the let_publish_cut special case at runtime.rs:2071-2076, which acknowledges the win), and give a measured cost model for R in the description.
#4 [high] Major: drop_reasoning discards the budget decoder for every parser except Atem/TmlJson
helios/src/server/request.rs:408-426 eligibility:
let grammar_reasoning = grammar.is_some().then(|| output.as_ref().filter(|out| {
out.content.start == ...::Reasoning || envelope.as_ref().is_some_and(|env| {
env.recipient.is_some() && matches!(out.content.start, ...::RecipientHeader | ...::RecipientFrame) })
}).cloned()).flatten();
Combined with Incoming::spec() (runtime.rs:275-286) this flips grammar_constrained for requests the operator never opted in for, with no flag/setting/metric/CLI (checked: no config field added anywhere in the diff; Prompt/Incoming are internal).
More importantly the eligibility is broader than "an open reasoning region". For Atem/TmlJson, OutputPipeline::grammar_envelope (helios/src/output/pipeline.rs:203-209) hands the whole envelope to the grammar with start: config.content.start, and Incoming::allow_reasoning_reentry (runtime.rs:262-273) keys only on ToolParserKind — so every reasoning re-open in such an envelope re-enters speculative mode (runtime.rs:2121-2152), not just the first header the description describes. Each of those transitions pays the full re-prefill described in scratchpad entry 2.
Also note the diagnostic asymmetry: when reasoning closes, drop_reasoning = !request.incoming.allow_reasoning_reentry() (runtime.rs:2109) — for QwenCoder/Dsml/Glm/Xtml/MiniMaxXml/GemmaCall parsers the worker-side Active.reasoning decoder is dropped (runtime.rs:2451-2453) even though prompt.reasoning_cut may still be pending, so the budget path at runtime.rs:2208-2240 sees request.reasoning == None; close_allowed/forced then silently skip budget enforcement for the rest of that request. Only the Atem/TmlJson path keeps it. Worth confirming with the #615 author (thinking_token_budget for ContentHeaders) whether a mid-generation close on the other parsers is reachable — the PR has no test for it.
#6 [high] Process/charter findings and sound areas
-
Charter #210: the PR states "Expected performance improvement (not yet measured on a live GPU)" and lists live CUDA serving/throughput benchmarks under "Unrun checks". A performance PR with no served-workload A/B fails the charter's "Bring real evidence" rule; the Autobot review of #619 called the same gap a charter violation. Predecessor #615 was merged on a review that required live GB10/SM121 serving evidence in the same files.
-
Scope vs the motivating report (#530): #530's json_schema measurement used
enable_thinking: false, i.e. requests that start inOutputStart::Contentand stay device-constrained under this PR's rule (asserted at phase_tests.rs:8037-8053). The answer-JSON phase and its batch-wide feedback barrier (helios/src/scheduler.rs:1085-1094) are unchanged, so the PR does not move the numbers it was written for. PR never cites #530. -
Docs coherence (verified by reading): docs/core-design.md:1242-1248 still says "While any constrained request is in the decode batch, the loop runs one step in flight"; docs/scheduling-runtime-design.md:548-552 still lists "grammar" as requiring completion feedback; helios/model-contract.md:236-238 same. Only docs/api.md:645-658, docs/core-design.md:1694-1707, docs/mtp-design.md:410-432 were updated.
-
Test hygiene: all cited tests run with
--release(grammar.rs/phase_tests.rs) where the newdebug_assert!(!self.mask_dirty)guards inmask()/allows()(grammar.rs:677-692) compile out, so the guard the PR added to protect the deferred-mask invariant is never exercised. Suggested: run at least the new grammar unit test in a debug profile in CI. -
Positive/verified-sound notes for the report: admission change (admission.rs:109-131) correctly gates
grammar_maskon the flag andpacking.rs:803emitsGrammarEnabled=0;Admission::validatestill acceptsgrammar_mask: None(admission.rs:88-92);advance()now syncs a dirty mask first (grammar.rs:785-787); the preemption path leavesgrammar_reasoning_modeuntouched (runtime.rs:2395-2405) and phase_tests.rs:7763-7809 covers it; no protobuf/kernel ABI/graph change; existing cores load unchanged.
#7 [high] Report framing: transition cost disclosure vs measurement gap
Correction/framing note for the final report: the PR description does disclose the transition cost ("cancel + Restore from the pinned prompt/prefix checkpoint + chunked Prefill over the reasoning tokens since that checkpoint"), so the finding must be framed as an unquantified system-level consequence, not a description inaccuracy:
- O(R) re-prefill at the reasoning/answer boundary on every grammar-constrained thinking request, plus a window drain (prefill is single-frame, scheduler.rs:1085-1094 / scheduling-runtime-design.md:548-552) that suppresses two-frame pipelining for co-batched unconstrained requests for the duration — i.e. the PR's headline benefit is revoked for the transition interval, and adds queue latency for bystanders.
- Neither side measured. Charter #210 requires an A/B on a served workload.
Also verified correct while reading: the readmission prompt+remaining sum is invariant-preserving (exact_len + remaining = prompt_end + budget + after), so the new park paths do not create context-headroom rejections, matching the preemption path (runtime.rs:2395-2405, 2470-2490).
#8 [high] Research summary
I completed the Correctness, Contracts & System-Level Consequences lens on PR #626, opening every changed file plus the runtime/scheduler/metrics/model-packing/doc call sites it depends on. Notes with exact citations, verbatim quotes, severity and fixes are in my scratchpad (entries 1-7).
Headline: the mechanism is real and internally coherent — grammar_constrained=false during speculative reasoning correctly lifts both the width clamp and the feedback barrier, admission gates grammar_mask on the new flag and GrammarEnabled=0 follows, advance() now syncs a dirty mask first, preemption preserves the mode, and no protobuf/kernel/graph contract changed. The problems are in what the new boundary path does to a live server and to the guarantees the repo documents.
Findings:
- Major — terminal-error blast radius in the unmasked path.
try_advance_unmaskedreturnsOk(false)only when llguidance yieldsOk(0); anyErrcallsfail(), andWorker::completeturns that intoExecutionError::Completion(a 500) for a token device masking would simply never have sampled (grammar.rs:744-755 → runtime.rs:1900-1919). Neither the grammar test nor the runtime rollback test ever exercises an in-vocabulary, non-EOS forbidden token — overshoot tokens are never validated at all. Plus a brand-new undocumented terminal path "grammar rejected token with no remaining output capacity" (runtime.rs:1955-1961), and?on the transition loop (runtime.rs:2156-2165) aborts the frame for all lanes if one park fails. - Major — the transition re-prefills the entire reasoning trace and drains the frame window.
park_grammar_transitionusesscheduler.cancel(no terminal snapshot) and readmits the full prefix, so R reasoning tokens are recomputed byRestore+ chunkedPrefill; the tests only ever re-prefill one token. Prefill is single-frame, so for its duration co-batched unconstrained requests lose the very pipelining this PR sells, and a prompt-checkpoint miss re-prefills the prompt too. Disclosed but unquantified; no served-workload measurement (charter #210). - Major — the budget decoder is dropped for every parser except Atem/TmlJson.
drop_reasoning = !allow_reasoning_reentry()nullsActive.reasoning, after which thethinking_token_budgetblock at runtime.rs:2208-2240 can never force-close; untested. Also eligibility and re-entry are broader than described (any reasoning re-open re-enters speculative mode, each paying finding 2), and the whole behaviour is automatic with no flag, metric or CLI opt-out. - Minor/Major — observability and contracts lose coverage.
flare_constrained_max_inflightandflare_mixed_grammar_decode_steps_totalnow exclude grammar-attached speculative-reasoning lanes, so themodel-contract.md:438-441invariant ("must remain one") is vacuous for the requests it exists to watch; three sibling doc statements (core-design.md:1242-1248, scheduling-runtime-design.md:548-552, model-contract.md:236-238) still contradict the rewritten text. - Minor — behaviour/compat. Every transition reseeds (
park_with_tokens→continuation_seed), so identical request+seed now yields a different stream than onmain, dependent on burst boundaries; undisclosed. The newdebug_assert!(!mask_dirty)guards are compiled out of every cited--releasetest run. - Process. No #530 citation, and #530's
enable_thinking:falseworkload lands entirely in the unchanged device-constrained phase; CI onf7907a2failed and is unexplained.
#9 [high] CONSOLIDATED: verbatim evidence for each finding (report source)
Source of truth for the final report. All line numbers verified at head f7907a2.
F1 (Major) — unmasked rejection path can 500 a request device masking would never have failed
helios/src/grammar.rs:715-722 (doc claim):
/// Validates and consumes a token generated without device mask enforcement.
/// Returns `Ok(false)` without modifying parser state when the token is
/// forbidden; defers full vocabulary mask computation until `sync_mask`.
pub fn try_advance_unmasked(&mut self, token: u32) -> Result<bool> {
if let Some(error) = &self.error {
return Err(error.clone());
}
helios/src/grammar.rs:744-755 (reality — Err poisons via fail(), only Ok(0) rolls back):
let consumed = match self.matcher.try_consume_tokens(&[token]) {
Ok(consumed) => consumed,
Err(error) => {
return self.fail(Error::Admission(AdmissionError::Grammar(Failure::boxed(
format!("grammar advancement failed: {error:#}"),
error.into_boxed_dyn_error(),
))));
}
};
if consumed == 0 {
return Ok(false);
}
helios/src/server/runtime.rs:1900-1919 (Err -> terminal request failure):
let allowed = match request
.incoming.prompt.grammar.as_mut().unwrap()
.try_advance_unmasked(token.token)
{
Ok(allowed) => allowed,
Err(error) => {
request.incoming.fail(
ExecutionError::Completion(Failure::caused_by(
format!("grammar advancement failed: {error}"),
error,
)).into(),
);
stopped.push(token.request);
continue;
}
};
helios/src/server/runtime.rs:1955-1961 (new terminal path, reachable when remaining==0 / context headroom exhausted):
} else {
request.incoming.fail(Error::execution(
ExecutionError::Completion,
"grammar rejected token with no remaining output capacity",
));
stopped.push(token.request);
}
Test-gap proof: grammar.rs test ~1851-1920 uses only eos ids (256/257), tokenizer_vocab, model_vocab-1, post-stop b'a'; phase_tests.rs:7458-7595 rolls back only premature EOS. In phase_tests.rs:7301-7455 the forbidden overshoot 4 is never validated because runtime.rs:1889-1892 skips the rest of the burst:
if stopped.contains(&token.request)
|| transitions.iter().any(|t| t.handle == token.request)
{
continue;
}
helios/src/server/runtime.rs:2156-2165 (? on the transition loop aborts the whole frame for every lane):
self.retire(&stopped)?;
for transition in transitions {
self.park_grammar_transition(
transition.slot, transition.exact_len, transition.emitted,
transition.remaining, transition.speculative_reasoning,
transition.drop_reasoning,
)?;
}
Fix: clone the matcher (or validate against the synced mask) so a disallowed token rolls back instead of poisoning; contain park errors per transition; add an in-vocabulary non-EOS forbidden-token test.
F2 (Major) — reasoning->answer transition re-prefills the whole trace and drains the frame window
helios/src/server/runtime.rs:2407-2428:
fn park_grammar_transition(
&mut self, slot: usize, exact_len: usize, emitted: u32, remaining: u32,
speculative_reasoning: bool, drop_reasoning: bool,
) -> Result<()> {
let handle = self.active[slot].as_ref().unwrap().request;
let live = self.scheduler.request(handle)?;
let tokens = live.tokens()[..exact_len].to_vec();
self.park_with_tokens(slot, tokens, emitted, remaining, false,
Some(speculative_reasoning), drop_reasoning)
helios/src/server/runtime.rs:2445-2449 (cancel, so no terminal snapshot / no KV reuse):
if publish_terminal {
self.scheduler.finish(handle)?;
} else {
self.scheduler.cancel(handle)?;
}
exact_len = live.prompt_tokens + emitted (runtime.rs:2070); only the prompt-end checkpoint can serve it, so R reasoning tokens are recomputed.
helios/src/scheduler.rs:1085-1088 (prefill is single-frame) + docs/scheduling-runtime-design.md:548-550 ("Prefill, scored prefill, mixed execution, resume, vision, and state operations drain the window").
Tests confirm by construction: phase_tests.rs:7388-7390 = Restore then a one-token Prefill.
PR's own acknowledgement that KV reuse is the desired shape: the let_publish_cut special case at runtime.rs:2071-2076.
The description DOES disclose the cost ("one slot transition (cancel + Restore ... + chunked Prefill over the reasoning tokens since that checkpoint)") but neither side is measured, and the bystander window-drain consequence is not mentioned.
F3 (Major) — budget decoder dropped for every parser except Atem/TmlJson
helios/src/server/runtime.rs:2109 (drop_reasoning derived only from parser kind) and 2451-2453:
let mut active = self.clear_active_slot(slot).unwrap();
if drop_reasoning {
active.reasoning = None;
}
Consequence at runtime.rs:2239-2240 (request.reasoning.take().unwrap() is behind a reasoning_cut.is_some() guard but reasoning is now None):
let cut = request.incoming.prompt.reasoning_cut.take().unwrap();
let forced =
request.reasoning.take().unwrap().reasoning_open() && close_allowed;
=> after a mid-generation close with a non-Atem/TmlJson tool parser, thinking_token_budget can no longer force-close. No test.
Eligibility breadth: runtime.rs:262-273 allow_reasoning_reentry keys only on ToolParserKind; runtime.rs:2121-2152 re-enters on every reasoning re-open (not only the first header). Each re-entry pays F2.
No opt-out: diff adds no config/setting/CLI/metric field; Prompt/Incoming are internal (request.rs:408-426 is the sole producer).
F4 (Minor/Major) — metric + contract coverage lost; three stale doc statements
helios/src/server/runtime.rs:3259-3281:
let (mut constrained, mut unconstrained) = (false, false);
for lane in &step.lanes {
if scheduler.request(lane.request)?.grammar_constrained {
constrained = true;
} else {
unconstrained = true;
}
}
combined with runtime.rs:281-282 grammar_constrained: self.prompt.grammar.is_some() && !self.speculative_grammar_reasoning().
helios/model-contract.md:436-440: "flare_constrained_max_inflight records the maximum outstanding executor frames immediately after a successful constrained submission. It is zero before any constrained submission and must remain one afterward." — now vacuous for grammar-attached reasoning lanes; no replacement metric.
Stale, contradicts the rewritten text: docs/core-design.md:1242-1248 ("While any constrained request is in the decode batch, the loop runs one step in flight"), docs/scheduling-runtime-design.md:548-552 ("Unknown or stale costs, grammar, copy-only proposals ... require completion feedback"), helios/model-contract.md:236-238 ("Host-fed pending tokens, grammar, host stops ... require completion feedback").
Updated only: docs/api.md:645-658, docs/core-design.md:1694-1707, docs/mtp-design.md:410-432.
F5 (Minor) — reseeding, debug_assert, UTF-8/overshoot hygiene
helios/src/server/runtime.rs:2469-2471:
let seed = active.carried.seed.unwrap_or(incoming.prompt.sampling.seed);
let generated_tokens = active.carried.generated_tokens + generated;
incoming.prompt.sampling.seed = continuation_seed(seed, generated_tokens);
Every close/rejection reseeds -> same request+seed yields a different stream than main, dependent on burst boundaries. Undisclosed.
helios/src/grammar.rs:677-692: debug_assert!(!self.mask_dirty, "sync_mask must run before reading a deferred grammar mask") in mask()/allows(); every cited test runs --release so the guard is never exercised.
F6 (Process/charter)
No live-GPU evidence (PR's "Unrun checks"), against charter "Bring real evidence ... #210"; #615 merged with live GB10/SM121 evidence in the same files. PR never cites #530, and #530's measurement used enable_thinking:false (starts in OutputStart::Content, asserted constrained at phase_tests.rs:8037-8053), so the answer-JSON phase and its barrier are untouched. CI failed on f7907a2, unexplained.
Verified sound (say so plainly)
- admission.rs:109-131 gates
grammar_maskon the flag;Admission::validate(admission.rs:88-92) acceptsNone; packing.rs:803 emitsGrammarEnabled=0. - grammar.rs:785-787
advance()syncs a dirty mask first;refresh_mask_available/failclearmask_dirty. - runtime.rs:2395-2405 preemption park leaves
grammar_reasoning_modealone; covered at phase_tests.rs:7763-7809. - readmission arithmetic is invariant-preserving (exact_len + remaining = prompt_end + budget + after), so no new context-headroom rejections.
- No protobuf / kernel ABI / CUDA-graph change; existing cores load unchanged; only
Admission::from_promptgained an in-crate parameter andPrompta field.
#3 [medium] Minor/Major: constrained_max_inflight metric no longer covers grammar-attached requests
helios/src/server/runtime.rs:3259-3281 observe_submission classifies lanes only by scheduler.request(lane.request)?.grammar_constrained. Because Incoming::spec() now sets grammar_constrained = grammar.is_some() && !speculative_grammar_reasoning() (runtime.rs:281-282), a request that still carries prompt.grammar is counted as unconstrained while it runs at width 8 with two frames in flight.
Consequences:
flare_constrained_max_inflight(helios/src/server/metrics.rs:1248-1253) andflare_mixed_grammar_decode_steps_total(metrics.rs:464-471) under-report: the operator-visible signal thathelios/model-contract.md:438-441describes — "records the maximum outstanding executor frames immediately after a successful constrained submission ... must remain one afterward" — is now vacuous for exactly the requests it exists to track, and nothing new reports grammar-attached frames.- The contract sentence at helios/model-contract.md:236-238 ("Host-fed pending tokens, grammar, host stops, ... require completion feedback") is now false for the reasoning phase, and no contract line was added (compare model-contract.md:438-441, untouched).
- docs/core-design.md:1242-1248 still asserts "While any constrained request is in the decode batch, the loop runs one step in flight"; docs/scheduling-runtime-design.md:548-552 still lists "grammar" among things that "require completion feedback". Both contradict the rewritten paragraphs in docs/core-design.md:1694-1707 and docs/mtp-design.md.
Fix: report deferred-mask reasoning explicitly (e.g. keep counting grammar-attached lanes in a new metric or rename the existing one) and update the three stale statements in the same PR.
#5 [medium] Minor: seed changes mid-generation and a new undocumented terminal error path
helios/src/server/runtime.rs:2431-2453 and 2469-2471: every transition goes through park_with_tokens, which re-derives
let seed = active.carried.seed.unwrap_or(incoming.prompt.sampling.seed);
let generated_tokens = active.carried.generated_tokens + generated;
incoming.prompt.sampling.seed = continuation_seed(seed, generated_tokens);
On main a grammar request ran to completion in one admission, so sampling.seed stayed the client's seed for the whole generation. After this PR every reasoning-close (and every rejected token, runtime.rs:1940-1954) reseeds mid-generation, so the same request+seed produces a different token stream than on main, and the stream depends on burst boundaries (how many tokens overshoot was discarded). This is an unannounced behavioral/compat change; the description does not mention it.
helios/src/server/runtime.rs:1955-1961 new terminal path:
} else {
request.incoming.fail(Error::execution(ExecutionError::Completion,
"grammar rejected token with no remaining output capacity"));
stopped.push(token.request);
reachable when remaining == 0 or exact_len >= limits.max_sequence_tokens at rejection time. On main the device mask made such a sample impossible, so this is a new 500/terminal-SSE error code path with no documented client-facing behavior and no test (helios/model-contract.md:425-431 only describes generic 500s).
Also: for transition in transitions { self.park_grammar_transition(..)? } (runtime.rs:2156-2165) propagates errors with ?; park_grammar_transition calls self.scheduler.request(handle)? and clear_active_slot(slot).unwrap() (runtime.rs:2416-2418, 2450). A failure there aborts complete() for all lanes in the frame after some transitions were already parked — the remaining active slots keep stale admissions/state for a frame the scheduler already accounted for. Prefer per-transition error containment like the surrounding stopped handling.