Explore scratchpad · NVIDIA/hyperflare-inference #626

Raw Markdown for agents: https://autobot.eidonix.com/p/4174d27e-cf72-4cb5-9363-8847dc59a6d3.md

#1 [high] Change: size and shape of the diff

PR #626 "Allow speculative reasoning for grammar-constrained requests" by lukealonso (COLLABORATOR), open, ready for review, opened 2026-11-30, head f7907a2, base main, base commit at branch c146d7b. NO comments, NO reviews yet. CI on head commit: FAILED.

Files (from pr_files):

Core code changes (verified by reading diffs):

  1. helios/src/grammar.rs: new mask_dirty field on RequestGrammar:666-670; sync_mask() :703-712; try_advance_unmasked(token) :714-780; mask() and allows() get debug_assert!(!mask_dirty) (:677-693) — i.e. reading the mask while deferred panics in debug builds. advance() now calls sync_mask if dirty (:785).
  2. helios/src/model/admission.rs:110-125: Admission::from_prompt takes new grammar_constrained: bool param; grammar_mask only populated when true.
  3. helios/src/server/request.rs:405-425: new Prompt::grammar_reasoning: Option<OutputConfig>, set when grammar is some AND (content.start == OutputStart::Reasoning OR (envelope.recipient.is_some() AND start ∈ {RecipientHeader, RecipientFrame})).
  4. helios/src/server/runtime.rs: Incoming::speculative_grammar_reasoning() :253-262 and allow_reasoning_reentry() :264-274; Incoming::spec() sets grammar_constrained = grammar.is_some() && !speculative_grammar_reasoning(); new Incoming::grammar_reasoning_mode: Option<bool>; new struct GrammarTransition; new park_grammar_transition/park_with_tokens.

No GPU graph, kernel ABI, or protobuf changes (claim in description; diff confirms — only docs + helios/src Rust).

#2 [high] Why: open issue #530 is the direct motivation

Open issue #530 ("Structured output (json_schema / json_object) decodes ~2-3x slower than unconstrained on DeepSeek-V4.1-Flash-1017 gb202 TP4 (MTP drops to width one)"), by devinkuhn, opened 2026-11-25, updated 2026-11-30 01:39. Labels: area:scheduling, bug, performance, triage:investigate. No comments yet on issue itself (Discussion: 0).

Measured on 4x RTX PRO 6000 Blackwell Max-Q TP4, release-e091689 / e30d55d images, DeepSeek-V4.1-Flash-1017 FLARE package:

This issue is the direct motivation for #626's "why" (issue is not mentioned in the PR #626 description, though — need to verify: PR 626 text has no issue reference). PR #626 addresses ask (1)-ish for reasoning phase and ask (2,3) indirectly.

#3 [high] Related work: #619 (merged) explicitly left grammar requests width-1; #626 lifts that

PR #619 "Unlock multi-token speculation and two-frame pipelining for host stops in Helios", lukealonso, merged 2026-11-29 21:40 (+282/-107, 16 files). Same author, immediately preceding day, same core files (helios/src/server/runtime.rs, phase_tests.rs, docs/{core,mtp}-design.md).

Key: #619 explicitly KEPT grammar-constrained requests at width-1 with step-level single-frame feedback barrier: "Grammar-constrained requests (json_schema, json_object, Lark, strict tools; related to #530) still require host-computed vocabulary masks between steps and remain on the step-level single-frame feedback barrier and width-1 MTP path". Its "Scope boundary" reiterates grammar requests "remain unchanged on width-1 MTP with a step-level single-frame feedback barrier." So #626 is a direct follow-up: it removes that remaining scope boundary for the reasoning phase. The #619 Autobot review had "Changes Requested" (per-request feedback barrier concerns) and lukealonso restored the step-level barrier for grammar in d9e3e15 — the design #626 now partially reverses for reasoning tokens. #626 reuses the #619 pattern of cancel/retire rather than finish, and the "burst_counts / skipped" accounting introduced in #619. #619 also noted pre-existing CI Python failures (tests/preparation) and unmeasured GPU perf — same class of evidence gap as #626. #619's evidence bar: TLA+ lifecycle check, helios release tests 1724 passed, docs updated. #626 cites 1806 passed.

#4 [high] Change: four things the description does not say

All verified by reading the diff/code at PR head.

(a) NEW debug-only panic path: RequestGrammar::mask() (helios/src/grammar.rs:676-683) and allows() (:685-693) now carry debug_assert!(!self.mask_dirty, "sync_mask must run before reading a deferred grammar mask"). In main these accessors had no assertion. So any code path that reads the mask/allows after an unmasked advance but before sync_mask panics in debug builds (and is silently wrong in release). Note: every test run cited in the PR description uses --release, where debug_assert! is compiled out (debug_assertions off by default) — so the invariant guard is never exercised by the claimed evidence.

(b) Undeclared new per-token work: Active.reasoning decoder is now constructed for every eligible grammar request, not only for thinking_token_budget requests. runtime.rs:1639-1658: reasoning: incoming.prompt.reasoning_cut.as_mut().map(|cut| Decoder::new(..., cut.output.take().or_else(|| incoming.prompt.grammar_reasoning.clone()))).or_else(|| incoming.prompt.grammar_reasoning.as_ref().map(|output| Decoder::new(..., Some(output.clone())))). In main the worker-side OutputPipeline decoder existed only when a reasoning cut (thinking_token_budget) was configured. Now it runs on every accepted token (reasoning.push(token), runtime.rs:1971-1978) plus reasoning_open() twice per token (:1967-1970, :1979-1982) for every grammar+reasoning request, in parallel with the client-side decoder ("client decoder runs on another thread", runtime.rs:415). The PR description does not mention this added host cost (it only claims savings: no per-step mask compute/upload).

(c) Undeclared new terminal failure mode: in speculative reasoning, if a sampled token is rejected by the grammar AND remaining == 0 or the sequence is at the context limit, the request fails with Error::execution(ExecutionError::Completion, "grammar rejected token with no remaining output capacity") (runtime.rs:1955-1961) rather than completing. In main a grammar-forbidden token could not be sampled (device mask), so this failure path is new. It maps to an execution error (500 / terminal SSE error) for the client.

(d) Sampling continuity change: every transition goes through park_with_tokens, which re-derives the seed: incoming.prompt.sampling.seed = continuation_seed(seed, generated_tokens) (runtime.rs:2469-2471). Grammar-constrained reasoning requests therefore sample with a different seed sequence than on main for the same request/seed, so outputs are not reproducible across this change. Same mechanism preemption/budget cuts already use.

(e) Admission::from_prompt signature is public and gained a 4th parameter grammar_constrained: bool (helios/src/model/admission.rs:109-125); call sites: runtime.rs:1613 and phase_tests.rs:6139 only. Prompt (runtime.rs:29-61) gained public field grammar_reasoning — both are in-crate, no other crate constructs Prompt (checked: helios/src/server/runtime/phase_tests.rs:199-219, prompt_tests.rs:47, response_lifecycle_tests.rs via Fixture::prompt_for).

#5 [high] Related work: #418 authored the docs contract that #626 rewrites

The user-facing contract that #626 rewrites was introduced/ratified in #418 (merged 2026-11-22, jcartu, +6048/-128, closes #417 "Support strict: true function tools").

CROSS-REFERENCE: #626 modifies docs/api.md:645-655 and docs/core-design.md:1692-1709 — the exact paragraphs written for #418. This is the strongest "reverses prior documented contract" signal, but it widens rather than removes the constraint (reasoning becomes unconstrained; prose/tool-call decoding stays width-1).

#7 [high] Docs: #626 leaves three contradicting statements of the same rule

VERIFIED (read docs at PR head): docs/core-design.md:1242-1248 ("A grammar-constrained request needs a vocabulary mask for step k+1... While any constrained request is in the decode batch, the loop runs one step in flight...") is UNCHANGED by #626, but the PR rewrote docs/core-design.md:1692-1709 to say the one-step-in-flight rule applies only "while device grammar masking is active (outside open reasoning...)". The two statements in the same file now contradict each other for a grammar request in speculative reasoning. Similarly unchanged and now stale:

#8 [high] Claim vs issue: #626 does not cover #530's measured case (thinking disabled, answer JSON)

VERIFIED: the change does NOT apply to the case measured in #530. #530 reports "chat_template_kwargs: {enable_thinking: false}" and penalise json_schema requests; also json_object. #626's eligibility (helios/src/server/request.rs:408-426) requires a grammar AND (OutputStart::Reasoning, or an envelope with a recipient at RecipientHeader/RecipientFrame). A request whose output starts in OutputStart::Content or ToolBody, or a raw Completions request, stays device-constrained from token 0 (PR description says so; asserted in phase_tests.rs:8037-8068). For non-thinking models, or thinking models with thinking disabled, the whole generation is answer JSON and remains width-1 MTP + step-level feedback barrier. Consequence: #626 addresses only the reasoning-token portion. The answer-JSON portion (which in #530's ~1.5K-token JSON outputs is most of the decode) keeps the 2-3x penalty. #530's asks 1 (per-draft-position masks), 2 (per-request rather than per-batch barrier) and 3 (documented note) are not delivered for that case; #626's docs changes do not add the operator note #530 asked for. Also of note: #626 does not cite #530 anywhere in its description (verified: no issue references in PR text). It also does not update docs/TODO.txt. The affected surface is instead: thinking models with json_schema/Lark/strict tools that reason first — the DeepSeek/TML-content-header and Atem recipes (grammar_reasoning at RecipientHeader/RecipientFrame), plus any model starting at OutputStart::Reasoning.

#9 [high] Community and process: no engagement, unexplained CI failure, author standing

Community: zero engagement. pr_comments on #626 returns "No comments." — no human review, no Autobot case-file/review bot post (contrast #619, which received an Autobot case file 20 min after opening and a full review at 40 min, plus a follow-up from the author). #626's description ends with "Discord: lukealonso" (the project's usual review channel note). No reactions recorded. No labels on the PR (orientation packet: labels: none), whereas #619 carried area:api, area:scheduling, enhancement, performance, triage:review.

People:

Process: state "open, ready for review", base main, head f7907a2, opened and last updated 2026-11-30 (same day), 9 files +1405/-39. CI on head commit: FAILED. The PR reports local release test runs (helios 1806 passed/0 failed/83 ignored; flare 237; flare-cli 211; heliopause 216; TLA+ 8 models) and lists unrun checks (live CUDA serving + benchmarks, cargo-kani, 83 checkpoint-gated tests), but does not explain the CI failure — the same gap the #619 review flagged ("Unreconciled CI ... on head 22a1dee"). CI workflows that run on this PR: native-serving.yml (ubuntu+windows: build, eos/selene/selene-manager, helios release tests with --features runtime-core,server, flare-cli, flare), python-cpu.yml (pytest tests/), helios-lifecycle.yml (lifecycle TLA+ + kani). None of these runs debug builds, and all use --release.

#10 [high] Project fit: charter lines up on layering, conflicts on measured evidence

Charter (read in full) mapping, as facts: LINES UP:

#12 [high] Reach: automatic for thinking+grammar requests, no flag, no ABI change

Reach, as facts:

#13 [high] Claims and evidence: each claim, what backs it, what does not

CLAIM-BY-CLAIM status (from PR text vs what the repo/diff shows):

  1. "expected to decode the reasoning phase at full speculative widths and two-frame pipelining without per-step CPU mask generation or H2D mask uploads" → mechanism verified in code (#619 idioms; scheduler.rs:2257, policy.rs:308-311, scheduler.rs:1085-1094, packing.rs:803). NO measured GPU number. PR says so explicitly.
  2. "without forcing concurrent unconstrained requests in the same batch down to one step in flight" → true only while the constrained request is in its reasoning phase; once reasoning closes the request is device-constrained again and plan_requires_feedback puts the whole submitted batch back on one frame (scheduler.rs:1088-1091). For a typical JSON-answer workload the constrained request spends most output tokens in that state.
  3. Unit test unmasked_advancement_matches_masked_decisions_and_defers_mask_sync (grammar.rs ~1854-1920) → verified present, compares masks bit-for-bit and checks premature EOS, padded OOV IDs, post-close constrained continuation. Good but CPU-only, release build (debug_asserts compiled out).
  4. speculative_grammar_reasoning_runs_pipelined_and_transitions_on_close_with_overshoot (phase_tests.rs:7300-7455) → verified present and asserts exactly what is claimed: width 8, two frames, requires_feedback false, grammar_mask None during reasoning, mid-burst close with 2 overshoot x tokens suppressed from observed/tokens/Finished count (6), Restore on readmission, width-1 constrained continuation to EOS. Uses a mocked/fixture graph harness (speculative_burst_frame, advance), not real GPU.
  5. ..._rolls_back_forbidden_token_including_premature_eos → verified; covers both mid-burst and token-0 (first_token_forbidden) rejection and the Init-vs-Restore readmission split.
  6. ..._integrates_with_thinking_budget_and_logprobs → verified; covers natural early close (merges after=6 into remaining=8, suppresses overshoot logprob) and budget-exhaustion forced close (injects </think>, 5 answer tokens remain, plain_tokens == [think_end]).
  7. ..._preserves_mode_on_preemption_and_stays_constrained_without_reasoning → verified; Content-start stays width-1/feedback, and preemption park preserves speculative mode.
  8. content_header_envelope_enters_speculative_reasoning_after_header_and_returns_to_constrained → verified (TmlJson/ContentHeaders fixture).
  9. prepare_inference_enables_speculative_grammar_reasoning_only_for_eligible_envelopes → verified (phase_tests.rs:8015-8071, three cases).
  10. Test suite counts: helios 1806 passed/0 failed/83 ignored; flare 237; flare-cli 211; heliopause 216; TLA+ 8 models. Not independently verifiable here; CI on the head commit FAILED and the PR gives no CI explanation.
  11. NOT run (stated): live CUDA serving/benchmarks, cargo-kani, 83 checkpoint/GPU-gated tests. So the claim "reconstructs KV and non-invertible recurrent state across every supported cache scheme" is unverified on any real cache scheme.
  12. Description overstates one thing: "For Atem and TmlJson envelopes starting in a constrained header, a rising edge into reasoning_open() transitions into speculative reasoning" — actually allow_reasoning_reentry() only requires the envelope to exist in grammar_reasoning and its ToolParserKind to be Atem|TmlJson (runtime.rs:264-274); the description's precondition "starting in a constrained header" is how grammar_reasoning gets set in request.rs, so this is consistent, but the branch fires whenever reasoning reopens at any point in the generation, not only the first header.

#16 [high] Research summary

Case file for PR #626 "Allow speculative reasoning for grammar-constrained requests" (lukealonso, open, head f7907a2, 9 files, +1405/−39, no comments/reviews, CI failed). Sixteen scratchpad entries cover all eight angles.

Key findings a reader could not get from the description:

  1. Undeclared new work: Active.reasoning (the worker-side OutputPipeline decoder) is now built for every eligible grammar request, not only thinking_token_budget ones (runtime.rs:1639-1658), and pushes/reasoning_open() runs per accepted token in parallel with the client decoder — added host cost the description does not mention.
  2. New debug-only panic: RequestGrammar::mask()/allows() gained debug_assert!(!mask_dirty) (grammar.rs:676-693); every test cited in the PR runs --release, so the guard is never exercised by the claimed evidence.
  3. New terminal failure mode: a grammar-rejected token with no remaining budget/context fails the request with ExecutionError::Completion (runtime.rs:1955-1961) — impossible on main, where the device mask prevented it.
  4. Sampling reproducibility changed: every transition re-derives the seed via continuation_seed (runtime.rs:2469-2471).
  5. The behaviour change is automatic and unconfigurable — no flag to keep the old path (contrast #619, whose flare_constrained_max_inflight contract is untouched and now undercounts reasoning-phase frames).
  6. Docs are only half-updated: docs/core-design.md:1242-1248, docs/scheduling-runtime-design.md:548-552, helios/model-contract.md:236-238 and docs/mtp-design.md:597-599 still state the old unconditional rule, contradicting the new paragraphs at core-design.md:1692-1709.
  7. Scope gap vs the motivating issue: #530's measurement was enable_thinking: false json_schema, which stays fully device-constrained under #626's eligibility rule; the PR never cites #530. Likewise the answer-JSON phase keeps width-1 and the batch-wide barrier (scheduler.rs:1085-1094).

Related/process facts: #626 directly follows #619 (same author, previous day) which explicitly left grammar at width-1, and amends the contract written for #418 (where reviewer yatesdr required the whole-generation one-step-in-flight cost to be documented); it reuses #615's ReasoningCut/close-tail/UTF-8-trim plumbing and builds on #620's grammar.rs rewrite. Charter fits on layering/no-flags, conflicts on "performance PRs need measured benchmarks (#210)". Author is a named priority contributor and the dominant committer in these files; zero community engagement on this PR.

#6 [medium] Recent activity: #620 rewrote grammar.rs immediately before #626

#620 "Remove copy drafts and history drafts while keeping legacy cores loadable" (lukealonso, merged 2026-11-29 22:51, +584/-2014, 50 files) is the immediately preceding commit on main (c146d7be) and is #626's base.

#11 [medium] Change: verified mechanism and reuse of #619 idioms

MECHANISM (verified in code, useful for reviewers):

#14 [medium] Related work: #615 built the reasoning-cut plumbing #626 reuses

#615 (newjordan, merged 2026-11-29 21:22, +614/-50) added thinking_token_budget support for ContentHeaders/TMLv0 and, in the same files, introduced the machinery #626 now routes through:

#15 [medium] Why: how long and how widely the problem has been reported

Chronology of the want (all verifiable from item numbers/dates):

#17 [medium] Related work: packet leads followed vs dismissed

Orientation-packet leads, followed or dismissed: FOLLOWED: #530 (open issue, direct motivation — entry 2), #619 (merged predecessor, same author — entry 3), #620 (merged 2h before, rewrote grammar.rs — entry 6), #418 (merged, wrote the docs contract #626 rewrites — entry 5), #615 (merged, ReasoningCut/close-tail/UTF-8-trim plumbing #626 reuses — entry 14), #167 (merged, thinking_token_budget, yatesdr — the budget path #626 integrates with; see entries 14/15). JUDGED NOT RELEVANT (checked by name/file overlap only):

#18 [medium] Change: test inventory and description-vs-code checks

Navigation aid for reviewers (all at PR head f7907a2): NEW TESTS and where they live