Case file: PR #626 — Allow speculative reasoning for grammar-constrained requests
Author lukealonso (COLLABORATOR; Discord: lukealonso). Open, marked ready for review, opened 2026-11-30, head f7907a2, base main (base commit c146d7b). 9 files, +1405/−39. No comments, no reviews, no labels. CI on the head commit: failed.
Key findings
- Undeclared new host work. The worker-side
Active.reasoningdecoder is now constructed for every eligible grammar request, not only forthinking_token_budgetrequests (helios/src/server/runtime.rs:1639-1660: thereasoning_cutbranch falls back toor_else(|| incoming.prompt.grammar_reasoning…)). It then runspushand tworeasoning_open()queries per accepted token (runtime.rs:1967-1978) in parallel with the client-side decoder ("client decoder runs on another thread",runtime.rs:415). The description only claims savings (no per-step mask compute/upload). - New debug-only panic path.
RequestGrammar::mask()andallows()gaineddebug_assert!(!self.mask_dirty, …)(helios/src/grammar.rs:677-692), so reading a deferred mask panics in debug builds and is silently stale in release. Every test cited in the description runs--release(debug assertions compiled out), so the guard is never exercised by the claimed evidence. - New terminal failure mode. A grammar-rejected token with no remaining output budget or context headroom fails the request:
Error::execution(ExecutionError::Completion, "grammar rejected token with no remaining output capacity")(runtime.rs:1955-1961). Onmainthe device mask made such a sample impossible, so this is a new 500/terminal-SSE-error path. - Sampling is no longer reproducible across the change. Every transition goes through
park_with_tokens, which re-derivesincoming.prompt.sampling.seed = continuation_seed(seed, generated_tokens)(runtime.rs:2469-2471). The same request and seed yield different tokens than onmain. - Automatic, unconfigurable behaviour change. No flag, setting, metric or CLI option; there is no way to keep the old whole-generation width-1 path for the reasoning phase (
Prompt/Incomingfields are internal). - Docs only half-updated. The rewritten paragraphs (
docs/core-design.md:1692-1707,docs/api.md:647-655,docs/mtp-design.md) contradict statements the PR leaves untouched: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,helios/model-contract.md:236-238,docs/mtp-design.md:597-599. - Scope gap against the motivating report. The PR never cites #530, and #530's measurement used
enable_thinking: falsejson_schema — a request that starts inOutputStart::Contentand therefore stays device-constrained from token 0 under this PR's eligibility rule (helios/src/server/request.rs:408-426; asserted atphase_tests.rs:8037-8068). The answer-JSON phase, and the batch-wide feedback barrier it imposes (helios/src/scheduler.rs:1085-1094), are unchanged. - No measured performance evidence, and the CI failure is unexplained — the same gap flagged in the review of #619.
The change
Size and shape (verified from pr_files): docs/api.md +8/−4, docs/core-design.md +11/−5, docs/mtp-design.md +15/−2, helios/src/grammar.rs +156/−0, helios/src/model/admission.rs +4/−4, helios/src/server/request.rs +20/−0, helios/src/server/runtime.rs +327/−19, helios/src/server/runtime/phase_tests.rs +863/−4, helios/src/server/runtime/prompt_tests.rs +1/−1. No protobuf, kernel ABI, CUDA-graph or core-format file appears in the diff, so the description's "existing exported model cores work without re-export" is consistent with the diff.
Mechanism (verified in code, for reviewers):
- Eligibility:
Prompt::grammar_reasoningis set inprepare_inferencewhen a grammar exists and the output either starts atOutputStart::Reasoningor the envelope has a recipient and the start isRecipientHeader/RecipientFrame(helios/src/server/request.rs:408-426). Content starts, tool-body starts and raw Completions getNone. - Admission:
Admission::from_prompttakes a newgrammar_constrained: booland populatesgrammar_maskonly when true (helios/src/model/admission.rs:109-125). Call sites:runtime.rs:1613andphase_tests.rs:6139. Withfalse, packing emitsGrammarEnabled = 0(helios/src/model/packing.rs:803(not opened)) and nothing is uploaded per step. - Width and pipelining:
Incoming::spec()setsgrammar_constrained = grammar.is_some() && !self.speculative_grammar_reasoning()(runtime.rs:275-286; predicate at:252-260). That alone lifts the width clamp and the feedback barrier —helios/src/scheduler.rs:2253-2259,helios/src/policy.rs:301-314(not opened), andscheduler.rs:1085-1094are untouched. - Validation and boundary:
Worker::complete()validates each accepted token withtry_advance_unmasked(runtime.rs:1900-1963); on reasoning close (:2060-2120) or rejection (:1921-1962) it records aGrammarTransition, parks viapark_grammar_transition(:2407-2428) andpark_with_tokens(publish_terminal=false), and cancels the live slot (scheduler.cancel,:2448) so the queued second frame drains into aretiringslot (see #619's Cancel→Retiring→Complete→Free lifecycle, covered byLifecycle.tla). Overshoot tokens are suppressed with the #619skipped = burst_counts[slot] − positionidiom (:1941,:2068,:2133). - Re-entry: an unconditional false→true
reasoning_open()edge re-enters speculative mode for Atem/TmlJson envelopes (runtime.rs:2121-2152, predicateallow_reasoning_reentry:262-273), requiring the grammar not stopped/accepting andremaining > 1. - Budget interplay:
sync_mask()is called beforegrammar.allows(cut.close[0])(runtime.rs:2217-2238) andgrammar_reasoning_mode = Some(false)on the continuation pass (:2280-2282).
What the description does not say: items 1–4 and 6 in Key findings, plus:
Admission::from_promptis a public in-crate API that gained a fourth parameter;Promptgained a public fieldgrammar_reasoning(runtime.rs:44). No other crate constructsPrompt.- The described precondition "for Atem and TmlJson envelopes starting in a constrained header" is looser in code:
allow_reasoning_reentryfires on any reasoning re-opening for such envelopes, not only the first header.
What the description says that the code does not quite do: nothing material found. All named functions and tests exist at head (see "Claims and evidence").
Test inventory (all at head f7907a2):
helios/src/grammar.rs:~1854-1920—unmasked_advancement_matches_masked_decisions_and_defers_mask_sync.helios/src/server/runtime/phase_tests.rs:7300-7455—speculative_grammar_reasoning_runs_pipelined_and_transitions_on_close_with_overshoot;:7457-7595rollback incl. premature EOS and token-0 rejection;:7598-7735thinking-budget and logprobs;:7736-7815preemption and Content-start;:7820-8012TmlJson content-header envelope;:8015-8071eligibility.- Helper
enable_speculative_worker(phase_tests.rs:7290-7298) fixes width 8 and builds frames from a fixture model config — synthetic graph scheduling, not CUDA.
The why
- #530 (open, devinkuhn, 2026-11-25, labels area:scheduling/bug/performance/triage:investigate, 0 comments) is the direct motivation, though #626 never cites it. Measured on 4× RTX PRO 6000 Blackwell Max-Q TP4 with DeepSeek-V4.1-Flash-1017: json_schema 55 tok/s vs 176 unconstrained (35-39 vs 59-70 under load, ~1.8×); json_object 57 tok/s; production comparison vLLM median 21.5 s / 1 of 203 timeouts vs Flare 54.8 s / 85 of 450 timeouts with json_schema. Three asks: per-draft-position grammar-mask MTP, per-request rather than per-batch one-step-in-flight, and an operator-facing docs note until fixed. It quotes the very sentences
docs/mtp-design.mdanddocs/core-design.md(#626 rewrites the core-design one only). - Timeline: #167 (yatesdr, merged 2026-11-02) introduced
thinking_token_budgetand its grammar interaction; #417→#418 (merged 2026-11-22) ratified the whole-generation constraint and measured its cost (3.49 s vs 1.09 s median strict call at C8, 8.59 s vs 2.43 s at C32 on SM120 TP4 DSML; ordinary-decode throughput during overlap essentially unchanged, 987 vs 981 tok/s at C8 and 1917 vs 1949 at C32); #530 raised the complaint 5 days before this PR; #619 (2026-11-29) explicitly declined to fix it. No maintainer reply on #530 in the issue itself. - The problem is therefore ~8 days old as a documented contract and 5 days old as a filed bug. No duplicate issue or competing PR exists (searches for "grammar speculative reasoning", "per-draft-position grammar masks MTP width", "one step in flight constrained batch" return only #626/#530/#619).
Related work
- #619 (merged 2026-11-29 21:40, same author, +282/−107, 16 files) is the immediate predecessor and the design #626 partially reverses for reasoning tokens. #619's text: grammar-constrained requests "still require host-computed vocabulary masks between steps and remain on the step-level single-frame feedback barrier and width-1 MTP path", reiterated in a "Scope boundary". Its review had "Changes Requested" (per-request feedback-barrier concerns) and the author had restored the step-level barrier for grammar in commit
d9e3e15— exactly the barrier #626 now skips during reasoning. - #418 (merged 2026-11-22, jcartu, closes #417) wrote the contract #626 edits: the entire-generation grammar rule, the width-one/one-step-in-flight rule, and its measured cost. Reviewer yatesdr explicitly demanded in review round 2 (2026-11-21) that the one-step-in-flight cost be documented ("A request with an active strict tool is grammar-constrained for its whole generation … so the one-step-in-flight window lasts as long as that request decodes"). #626 rewrites
docs/api.md:647-655anddocs/core-design.md:1692-1707— the paragraphs written for #418 — but widens rather than removes the constraint (reasoning becomes unconstrained; prose/tool-call decoding stays width-1). - #620 (merged 2026-11-29 22:51, same author, +584/−2014, 50 files) is #626's base commit
c146d7band rewrotehelios/src/grammar.rs(+20/−174: removedcopy_masksand copy-specific mask cloning, removedCOPY_GRAMMAR_MASK/COPY_GRAMMAR_COUNTuploads). #626 buildsmask_dirty/sync_mask/try_advance_unmaskeddirectly on top of that freshly rewritten file. - #615 (merged 2026-11-29 21:22, newjordan, +614/−50) supplied the plumbing #626 routes through:
ReasoningCut { close, after, output }(runtime.rs:53-61),OutputConfig::reasoning_close_tail(),trim_incomplete_utf8_tail()inWorker::park(), andActive::close_reasoning(). #626'ssync_mask()beforegrammar.allows(cut.close[0])is needed precisely because #615's call site would otherwise read a deferred mask. #615's review recommended "Ready To Merge" with live GB10/SM121 serving evidence — a live-serving bar applied to a neighbouring PR in the same files. - #167 (merged 2026-11-02, yatesdr) introduced
thinking_token_budget, whose interaction with grammar (#626 integrates with it) already existed. - Packet leads dismissed as unrelated after checking (not dependencies, possibly minor rebase friction): #457 (open TML header EOS/grammar alignment, same TmlJson area), #548/#560 (per-request metrics; share
runtime.rs/docs/api.md), #621, #554, #483, #458, #461, #500 (voipmonitor ERNIE parsers also touchgrammar.rs— rebase attention if both land). No open PR supersedes or competes with #626.
Recent activity
- Nothing on
mainsincec146d7btouches any of #626's files; no conflict with currentmain. - The area moved fast immediately before:
c146d7be#620 (grammar.rs rewrite),59adc480#540,e0290571#586,6cb7e3b7#619 (the speculation unlock),e4d8eb60#615 (reasoning budget for ContentHeaders), all 2026-11-29. #626 is the seventh change to this subsystem in roughly a week and the third by lukealonso in two days. - #626 builds on #619 and #615 explicitly (same idioms: cancel/retire rather than finish, burst_counts/skipped accounting,
ReasoningCut), and partially reverses #619's stated scope boundary for the reasoning phase.
People
- lukealonso — GitHub association COLLABORATOR; named in the charter as a priority contributor. 25 merged PRs in 180 days, 0 closed, 0 open; areas helios/src (19), docs (15), ignition/preparation (8), flare-cli/src (6), tests/preparation (6). Dominant committer: 228 commits in helios/src and 383 in docs over 180 days. This is their second speculation PR in two days.
- yatesdr (47 commits in helios/src) wrote #167's budget and was the reviewer whose comments shaped the #418 grammar contract that #626 edits.
- Martin Vit (52 commits in helios/src) works in the area but has not engaged.
- jcartu authored #418/#505 (admission.rs, request.rs) and has not engaged; newjordan authored #615 (the ContentHeaders budget path #626's Atem/TmlJson branch touches) and has not engaged; devinkuhn filed #530 and has not engaged.
- Nobody has commented on #626.
Community
Zero engagement: no human review, no Autobot case file or review post (contrast #619, which drew an Autobot case file ~20 min after opening and a full review ~40 min later plus an author follow-up), no reactions, no labels (contrast #619's area:api/area:scheduling/enhancement/performance/triage:review). The PR ends with "Discord: lukealonso", the project's usual review-channel note, so review may be happening off-GitHub — but nothing is recorded.
Project fit
Lines up:
- Charter: "Keep the runtime small and model-agnostic" / "No per-model special cases or flags" — no model-name branch, no flag; eligibility is derived from envelope shape and
ToolParserKind(request.rs:408-426,runtime.rs:262-273). - Charter: "PR descriptions: expect four parts (why / what changed / claimed result / evidence)" — all four present, plus an explicit "Unrun checks" list.
- Design placement: the PR argues for host-side validation instead of per-model rollback kernels, consistent with keeping computation in Helios/contract layer.
Tensions:
- Charter: "Bring real evidence. Performance PRs need benchmarks showing an actual speedup over main on a served workload (#210)." The PR states its own gap: "Expected performance improvement (not yet measured on a live GPU)"; "performance claims above are expectations, not measured GPU numbers". The Autobot review of #619 called the same gap a charter violation.
- Charter: "Supported matrix & compatibility: check interactions across every supported model, cache scheme, parallel layout, multi-host setup, and hardware target… Check state and CUDA-graph transitions". The new path's correctness rests on Restore + chunked Prefill reconstructing exact KV and non-invertible recurrent state "across every supported cache scheme" — exercised only by CPU-side fixture-graph tests; 83 checkpoint/GPU-gated tests and all live serving were not run.
- Documentation coherence (see Key finding 6): three sibling statements of the same rule were left contradicting the new text.
Claims and evidence
| Claim | Backing | Gap |
|---|---|---|
| Reasoning phase decodes at full speculative width with two-frame pipelining and no per-step mask compute/upload | Mechanism verified: grammar_constrained=false → scheduler.rs:1085-1094/:2253-2259/policy.rs:301-314; admission.rs:109-125 → packing.rs:803 (not opened) |
No GPU measurement (PR states this) |
| Concurrent unconstrained requests no longer drop to one step in flight | True only while the constrained request is inside open reasoning; once it closes, plan_requires_feedback puts the whole submitted batch back on one frame (scheduler.rs:1088-1091) |
For a typical answer-JSON workload most tokens are in the constrained phase |
| Unit tests listed in the description | All seven tests exist at the cited locations and assert what is claimed (mask bit-for-bit equality, width 8 + !requires_feedback + grammar_mask.is_none(), overshoot suppression, Restore on readmission, width-1 continuation to EOS, budget forced close, preemption) |
CPU fixture graphs only; --release, so the new debug_assert invariant is never exercised |
| Suite results: helios 1806 passed/0 failed/83 ignored; flare 237; flare-cli 211; heliopause 216; 8 TLA+ models | Stated in the description | Not independently verifiable here; CI on head failed with no explanation |
| "Reconstructs KV and non-invertible recurrent state across every supported cache scheme" | Design argument (reuses existing Restore + chunked Prefill) | Unverified on any real cache scheme; checkpoint/GPU tests ignored |
| Benefit outweighs transition cost except for very short reasoning or uncached prompt checkpoints | Cost model in the description | Neither side of the trade-off measured |
Reach
- Who is affected: every client sending
response_formatjson_schema/json_object, a Larkgrammar, or a strict function tool against a model whose output starts in reasoning or in a recipient/content header (Atem, TmlJson/ContentHeaders, DSML recipes). Those are exactly the requests #530 complains about — but only their reasoning phase. - Operators/config: no new flag, setting, metric or CLI option; not disableable. Contrast #619, whose
flare_constrained_max_inflightcontract (helios/model-contract.md:438-441) stays "must remain one" and now under-describes reasoning-phase frames. - Compatibility: no protobuf, kernel ABI, core-format or CUDA-graph change; existing exported cores load unchanged; no recipe changes needed (unlike #620, which needed local-inference-lab/hyperflare-recipes#94).
- Behavioural compatibility: different token stream for the same request+seed (
runtime.rs:2469-2471), and a new terminal errorExecutionError::Completion"grammar rejected token with no remaining output capacity" (runtime.rs:1955-1961). - Documentation:
docs/api.md,docs/core-design.md#native-replay-loop,docs/mtp-design.mdupdated;docs/core-design.md:1242-1248,docs/scheduling-runtime-design.md:548-552,helios/model-contract.md:236-238,docs/mtp-design.md:597-599stale. #530's requested operator-facing docs note is not added. - Low-severity edge:
park_with_tokensslices whole tokens withouttrim_incomplete_utf8_tail(), so a dropped overshoot could leave an incomplete multi-byte UTF-8 tail in the re-prefilled continuation; the preemption park path also skips trimming, so this matches existing behaviour rather than introducing a new class.
Process
Open, ready for review, same-day age, no labels, no reviewers requested or engaged, head f7907a2, CI failed and unexplained. The PR reports four local release test suites and the TLA+ lifecycle check, and honestly lists unrun checks (live CUDA serving and throughput benchmarks, cargo-kani, 83 checkpoint/GPU-gated helios tests). The CI gap repeats the criticism made of #619 ("Unreconciled CI … on head"). CI workflows for this PR (native-serving.yml, python-cpu.yml, helios-lifecycle.yml) all run release builds with --features runtime-core,server, so none would catch the new debug-only assertion.
Open questions
- Why did CI fail on
f7907a2, and is it the same Python/preparation flakiness #619 noted? - Was any live serving or throughput measurement taken out-of-band (the PR says "not in this environment"; the Discord channel may hold numbers)? Without it the PR does not satisfy the charter's #210 benchmark rule.
- Does the reasoning-phase win actually move #530's numbers, given its measurement was
enable_thinking: false(no reasoning phase at all)? If the intent is to move that issue, the answer-JSON phase needs per-draft-position masks or a per-request barrier — neither is in this PR. - Is the added always-on
Active.reasoningdecoder acceptable cost, and does the debugmask_dirtyassertion hold along every path (it is untested in the cited--releaseruns)? - Should the three stale doc statements (
core-design.md:1242-1248,scheduling-runtime-design.md:548-552,model-contract.md:236-238, plusmtp-design.md:597-599) be updated in this PR or a follow-up? - Does the new
ExecutionError::Completionfailure path need a documented client-facing error, and are seed changes acceptable for existing seeded workloads?