Case file: PR #729 — helios: preserve KV across grammar transitions, fix KV codec batching/locking, and stratify Mixed graph costs
Open, marked ready for review, head 150f705, base cc0a49d, 14 files, +2219 / −370, opened and last updated 2026-12-04 17:35 (one push, never revised). Author lukealonso (COLLABORATOR, charter priority contributor, Discord lukealonso). Zero comments, zero reviews, no labels, CI pending on head.
Key findings
-
A raw diff of this PR badly over-reports, and part of it is not this PR at all. The local
mainref is stale (it predates #655, #660, #674, #697, #709;gitcannot readc513e46).pr_difftherefore shows hunks belonging to already-merged work, including two files —helios/src/scheduler/checkpoints.rsandhelios/src/server/request.rs— that are not among the 14 files inpr_files. Attribution:RowRestoreLatency/worth_restore/estimated_prefill_saved_seconds/observe_prefill_raterewrite/clear_pool_lookup/attach_async_transfersand theoffload::open-before-RankExecutor::newreordering → #674/#709/#711;snapshot_discovery+measured_duration(GraphKind::Snapshot,1)→ #655;budget_interior_anchor/preserve_message_anchor→ #660/#697;device_spansnull-row guard and the 3-row codec test rewrites → #659 (same author, merged the day before). The authoritative scope is the 14-filepr_fileslist. -
The PR reverses a lock-order invariant that #628 deliberately established and had reviewed. #628 (yatesdr, merged 2026-12-01, fixes #627) states verbatim: "Preserve strict lock ordering (
gpu.codecbeforeCopyEngineGate) to prevent lock inversion againsttry_lock". #729 introduceswith_gpu_codec_locked/try_with_gpu_codec_locked(helios/src/offload/transfer/codec.rs:878,:891) whose documented purpose is the opposite order — gate first, then codec — and routes all five GPU codec sites through them (codec.rs:288, 317, 352, 605, 704). The rationale is coherent (a background capture must not holdgpu.codecwhile waiting on a peer graph), but #628's recorded invariant is superseded, not accidentally violated. See also finding 3 for why the swap changes where restores block. -
The order swap moves the block point, because the gate blocks untimed and the
try_lockdoes not.CopyEngineGate::enter_offload_batchwaits on aCondvarwith no timeout (only peer graphs get the 120 s bound);try_with_gpu_codec_locked's doc says it "returnsNone… releasing the gate immediately so foreground restores can fall back to CPU decoding without blocking" — but under the new order a foreground restore must acquire the gate before it can discover the codec is free, so the CPU-decoding fallback is reached only after the gate wait. Under #628's order the restore'stry_locksucceeded immediately when no capture held the mutex. Recorded as an open question for a reviewer, not a proven defect. -
All three defects are self-inflicted by PRs merged 1–9 days earlier, and no issue tracks any of them. The grammar-transition wipe is #626's design (same author, merged 2026-11-30), whose own body disclosed the cost and whose review flagged "Every boundary transition re-prefills
Rreasoning tokens"; the single-leading-GPU-batch loop is #525's (merged 2026-11-25); the lock order is #628's; the flat nine-sample Mixed median is #645's (merged 2026-11-30), which deliberately leftMixedout ofPrefillCostModel. #729 cites no issue, no PR, and noFixes/Closestrailer, while the repo convention is to link (#628 "Fixes #627", #645 "Closes #485"). -
No performance evidence, and the PR says so. "Expected serving impact (not benchmarked end-to-end here)" and "No end-to-end exported-core
flare runlatency or throughput benchmark was run on this branch." The "2K-32K KV and recurrent state wipes" figure has no measurement or citation anywhere. This is the clearest charter divergence (#210 served-workload A/B); peers #645 (same author, same area) shipped live SM120 A/B tables, #659 shipped a measured VRAM number, #674/#628 shipped A/B matrices. -
Docs are updated in one file, so other present-state docs now describe the old behavior. Only
docs/scheduling-runtime-design.md(+23/−18) changed, and one of its two hunks describes #697's already-merged checkpoint-anchor behavior.docs/prefix-cache-offload.md:96-100still describes the GPU-codec fallback to "the bounded CPU pool if a background capture holds the GPU codec" without the new lock order;docs/core-design.md:1242 (not opened),1773anddocs/mtp-design.md(not opened) (the grammar-transition docs #626 relied on) were not opened. -
Concrete merge-order risk. Open #715 (original-el8) gates
PrefillCostModeland context-slope refresh onbatch == 1at exactly thecost.rssites #729 edits (cost.rs~581-583, 606-607, 644-659, 969 per #715's review); #729 addsGraphKind::Mixedat the same kind checks. #710 and #301 also touchcost.rs; #621 touchesmodel/admission.rs; #718 overlaps 7 files. -
A behavior change for older speculative cores. Speculative cores whose sampling graphs do not bind
ValueSource::GrammarEnablednow take the terminal-checkpoint path: aSnapshotgraph execution plus aRestoreon every reasoning transition. The PR claims these "load and run without re-export or ABI changes" (true), but their runtime cost profile changes and no measurement is given. -
One pure-prefill side effect inside bucket 3.
upward_extrapolation_floorgains aself.u_min > 0.0guard (helios/src/scheduler/cost.rs:130-140), and a zero-fill point now entersfit()— both change prefill pricing, not only Mixed. -
Untriaged and unreviewed. No labels (comparable scheduler PRs carry
area:scheduling,performance,triage:review), no assigned reviewer, and the repo's automated case-file/review hook has not fired — every peer in this cluster (#626, #628, #619, #645, #659, #674, #697, #715) got a case file within ~20 minutes and a review within ~20–90. #729 has neither, and CI is only pending.
The change
Size and shape. 14 files, +2219/−370, three independent subsystems bundled: (1) grammar-transition KV preservation, (2) KV codec restore batching + lock order, (3) GraphKind::Mixed NNLS cost stratification. They touch disjoint code and are separable for review or merge.
Per-file, with #729's own content (files not in pr_files excluded):
| File | Delta | Content |
|---|---|---|
helios/src/server/runtime.rs |
+270/−26 | Incoming::spec(speculative) keeps grammar_constrained true for non-speculative models; device_grammar_enabled; sampling_graphs_bind_grammar_enabled(config) scanning config.contract.graphs for ValueSource::GrammarEnabled; struct PendingGrammarPark{exact_len, emitted, remaining, speculative_reasoning, drop_reasoning, waiting_for_drain}; the three-way branch in Worker::complete; a post-complete drain loop over measured_step.lanes; the Snapshot→park_with_tokens(publish_terminal=true) completion arm; generated-token accounting via park.emitted |
helios/src/server/runtime/phase_tests.rs (not opened) |
+503/−15 | 5 new named phase tests (+ preserve_message_anchor: false fixture edits, which are #697's) |
helios/src/offload/transfer/codec.rs |
+487/−250 | partition_restore_pages/PageRun/PageRunKind (codec.rs:837), restore_single_unit, with_gpu_codec_locked (:878), try_with_gpu_codec_locked (:891), deletion of all_pages_cpu_path and the leading GPU run loop, Literal-only transform_ns skip |
helios/src/scheduler/cost.rs |
+309/−38 | zero_fill bucket, t_at_umin, theta_0 fallback for work == 0, mixed_context_slopes + borrowed_mixed_context_slope, mixed_entry/mixed_duration |
helios/src/scheduler/policy.rs |
+276/−10 | Mixed branches in mixed_candidates and the following == GraphKind::Mixed path of next_progress; resize_prefill/duration use mixed_duration; paused_for_park in eligible (policy.rs:332-340) |
helios/src/scheduler.rs |
+78/−0 | paused_for_park field (scheduler.rs:267) + pending()/deferred_prefill() accessors; paused_for_park exclusions at :1433, 1449, 1531; set_grammar_constrained (:3234), pause_for_park (:3254), finish_for_park (:3267) |
helios/src/scheduler/service.rs |
+13/−8 | shape_duration → mixed_entry/predict at (work, start_position) and (0,0) |
helios/src/scheduler/tests.rs (not opened), policy_tests.rs (not opened) |
+78, +68 | the two named guard/pricing tests |
helios/src/model/admission.rs |
+15/−2 | Admission::grammar_enabled, set_grammar_mask(mask, enabled), from_continuation/validate_continuation |
helios/src/model/packing.rs |
+3/−1 | GrammarEnabled packs grammar_enabled || grammar_mask.is_some() (verified packing.rs:804) |
helios/src/model/tests.rs (not opened), packed_round_tests.rs (not opened) |
+95, +1 | the packing test + fixtures |
docs/scheduling-runtime-design.md |
+23/−18 | Mixed stratification spec; anchor paragraph (the latter describes #697's merged behavior) |
What the description does not say. (a) The Admission::validate_continuation/initial_prompt_tokens work in model/admission.rs is not described. (b) The doc hunk narrates #697's shipped behavior as if part of this change. (c) device_spans' row && id == 0 guard appears in the diff but is #659's. (d) That a whole class of cores pays a new Snapshot+Restore per transition (finding 8).
What the description says that the diff does not fully show. Claim 12 ("Updated … delivery_references, and resize_prefill") — mixed_candidates, next_progress, service_rates, continuation_candidate and resize_prefill were confirmed; delivery_references was not individually located. Nothing in the description was found to be absent outright.
The why
The problem is real and triply-sourced but young: all three defects were introduced by PRs merged within the nine days before this one, and none has an issue, a user report, or a reproduction attached.
- Grammar wipe: #626 (merged 2026-11-30) designed the transition as "cancel the live slot via
RequestScheduler::cancel… parking the truncated prefix …Restore+ chunkedPrefillover the reasoning tokens since that checkpoint". Its body disclosed the cost ("can match or exceed the speculative decode savings") and its review flagged the re-prefill. The older, user-facing ancestor is open issue #530 ("Structured output (json_schema/json_object) decodes ~2-3x slower than unconstrained … MTP drops to width one"), cited by #619 and #626 but not by #729. - Codec batching/locking: #525 (merged 2026-11-25) created the single leading GPU batch loop; #628 (merged 2026-12-01) created the gate and the opposite lock invariant while fixing the real SM120 TP2 deadlock in #627.
- Mixed pricing: #645 (merged 2026-11-30) built
PrefillCostModelfor pure prefill only and said so. The class of defect is #485 ("Scheduler ActionCosts aliases short- and long-context prefill timings, causing chunk-size drift at 64k–128k"), closed by #645 — for pure prefill only. #729 cites neither. - Age and demand: opened 2026-12-04, under a day old at filing, one push. The outcomes are wanted (#530 has stayed open across #619, #626 and #729); #729 itself has drawn no request and no comment.
Related work
- #626 "Allow speculative reasoning for grammar-constrained requests" (merged 2026-11-30, same author, +1405/−39): the direct predecessor; #729 replaces its transition mechanism while keeping its tests (
phase_tests.rs:7571 (not opened), 7728, 7868, 8006, 8287). - #619 "Unlock multi-token speculation and two-frame pipelining for host stops" (merged 2026-11-29, same author): origin of
scheduler.cancel(publish=false)+ drain, adopted deliberately so speculative progress past a host stop is never published. #729 keepscancelprecisely for the overshoot case where the endpoint is not exact, which is consistent with #619's reasoning. - #628 (merged 2026-12-01, yatesdr): gate + the lock invariant #729 reverses (Key finding 2). #628 also moved
prefill_startedafterexecutor.submit(); #729's diff deletesprefill_startedentirely (that rewrite is #674's). - #645 (merged 2026-11-30, same author, closes #485):
PrefillCostModel; #729 extends it toMixedand edits the same doc paragraph in place. - #655 / #659 (merged 2026-12-03, same author): #655's snapshot-cost retention and #659's row-zero rejection both appear in the stale-base diff; #659 is the immediate predecessor in
codec.rs(+54/−25). - #525 (merged 2026-11-25, yatesdr) and #504 (codec's origin) — the lineage of the loop #729 rewrites.
- #697 / #660 / #661 / #663 / #681 (merged; FujitsuPolycom and others): anchor and cost-policy work whose hunks appear in #729's diff and its doc hunk.
- Open and conflicting: #715 (original-el8, +1638/−56, 20 files) — same
cost.rsgating lines, hard textual conflict; #710 (cost/forecast tracking,cost.rs); #301 (shadownetX, persist learned graph costs — a persisted-cost format would need to carry the newzero_fillstrata andmixed_context_slopes, neither of which is in any on-disk schema today); #621 (model/admission.rs); #718 (7 shared files); #698 (ebfio — the samecuModuleLoadData/RankExecutor::newreordering that sits in #729's diff as #709's work). - Chain to state explicitly: lukealonso authored #619 → #626 → #645 → #659 → #729, i.e. this PR closes loose ends of its author's own four merged PRs; yatesdr authored #504/#525/#628/#655/#674 and owns
copy_gate.rs— the natural reviewer for bucket 2 and the person whose invariant is superseded; original-el8's #715 conflicts textually incost.rs.
Recent activity
The orientation packet's commit history is unavailable (git: error: Could not read c513e46a…; search_history fails identically), and the packet states no default-branch commits since cc0a49d touched #729's files. That is consistent with #729 branching from a fresh main. Effectively, "recent activity" in these areas is the merged series listed above: #619 (11-29), #626 and #645 (11-30), #628 (12-01), #655/#659/#674/#697/#708/#709 (12-03), #711/#720/#721 (12-03/04) — with #729 pushed the same day as #721. The change builds on that work rather than reversing it, except for #628's lock invariant (reversed) and #626's transition mechanism (replaced).
People
- lukealonso — COLLABORATOR, charter-listed priority contributor ("Priority contributors (
@voipmonitor,@original-el8,@lukealonso) carry extra weight"); 51 merged PRs in 180 days, 0 closed, 3 open (#728, #727, #723, all opened the same day as #729). Historical areas:helios/src(36),docs(31),ignition/preparation(20). #729 is self-directed cleanup of their own series. - yatesdr — owner of the KV codec and
CopyEngineGatelineage (#504, #525, #628, #655, #674); author ofcopy_gate.rs; likely reviewer for bucket 2, and the person whose #628 invariant is being superseded. - original-el8 — COLLABORATOR, priority contributor; #715 and #710; conflicting work in
cost.rs. - FujitsuPolycom — #661, #697; source of the anchor hunks visible in #729's diff.
- voipmonitor — #555 (
cost.rs); shadownetX — #301; ebfio — #698. - Engagement on #729: none. No review, no comment, no reaction, no assignee, no labels.
Community
Zero. pr_comments returns "No comments"; read_item(729) shows "Discussion (0)". No case-file comment from the automated reviewer, unlike every peer in the cluster (#626: 2 entries incl. a "Changes Requested" review; #628: 6 entries across three rounds with a human reply from yatesdr; #674, #697, #715: reviewed). No labels means not even triaged. The single most likely near-term development is the automated case file and review firing.
Project fit
Lines up: the charter's "Keep the runtime small and model-agnostic … shouldn't accumulate per-model branches (#267, #334)" — #729 branches on self.config.speculative_widths.is_empty() and on a derived contract property (sampling_graphs_bind_grammar_enabled), not on model names. "Check state and CUDA-graph transitions, and verify that existing … exported cores still load" — no new ValueSource, no new graph op, GrammarEnabled only widens the packed value (packing.rs:804), and a packing test covers it; though no test against a genuinely pre-existing signed core is reported. The description has all four expected parts (why / what / result / evidence), with self-disclosed limitations. It adds no flags, defaults, dependency, Protobuf or .cu change (Cargo.toml (not opened) untouched).
Diverges: "Bring real evidence. Performance PRs need benchmarks showing an actual speedup over main on a served workload (#210)" — all three buckets are performance-motivated and none is measured; #645 (same author, same area) shipped numbers. "What gets merged: PRs that address a maintainer request, a roadmap item, a reproducible bug, a measured performance/memory issue, or bad docs" — #729 links no issue and no reproducible bug. "Stay focused" — three unrelated subsystems in one PR cuts against focused review. Also worth noting for a reviewer: the charter's "Captured-graph op contracts … requires owner approval" should not bind here (no new op), though #715 was blocked on exactly that, so a reviewer may ask; and #729 changes no GPU kernel code, so "GPU kernel code: report concrete defects only" is not triggered.
Claims and evidence
Verified by static reading of the head diff unless marked:
Admission::grammar_enabled+GrammarEnabledpacking asenabled || mask.is_some()— verified (packing.rs:804;admission.rsadds the field andset_grammar_mask).set_grammar_constrained/pause_for_park/finish_for_park/paused_for_park— verified (scheduler.rs:3234, 3254, 3267, 267); all three guards are atomic pre-check-then-mutate with typedErrstrings and rejectpending != 0,Inbound,Finishing, and aSnapshotwithoutboundary_capture/ with aBoundaryKind::ConditionedWindowcapture.- Non-speculative models keep
grammar_constrained = trueand start withgrammar_enabled = true,grammar_mask = None— verified inIncoming::spec(speculative)anddevice_grammar_enabled. - Speculative in-place toggle gated on per-step
GrammarEnabledbindings andskipped == 0 && pending == 0 && extra == 0— verified;sampling_graphs_bind_grammar_enabledrequires the binding on everyPrefill|TerminalPrefill|ScoredPrefill|Decode|Speculative|Mixed|Resumegraph. - Terminal-checkpoint park with
consumed_tokens <= exact_lenverification and drain of an in-flight second frame — verified;PendingGrammarParkcarries the fields described, generation accounting usespark.emitted. - Device errors on the draining frame propagate instead of re-admitting — verified (
incoming.fail(ExecutionError::Device{..})thenscheduler.finish). - Overshoot keeps the
cancelrollback path — verified (falls into the legacyGrammarTransitionwhenskipped != 0,error_code.is_some(), ordeferred_prefill()). partition_restore_pages+restore_single_unitpreserve maximal GPU-batched runs afterLiteral/CPU/singleton pages — verified (codec.rs:837); the oldall_pages_cpu_pathandelse { break; }loop are gone.- Literal-only batches skip CPU
transform_ns— verified indecode_windowandrestore_single_unit. - All five GPU codec lock sites gate-before-mutex — verified in code (
codec.rs:288, 317, 352, 605, 704), and is a reversal of #628's invariant. - Mixed stratification:
zero_fill(cost.rs:286),t_at_umin(:86,:180),theta_0fallback forwork == 0,mixed_context_slopes(:600,:883-935),mixed_entry/mixed_duration(:738-782) — verified.borrowed_mixed_context_sloperequires the peer to match bothbatchandwidthand be strictly larger inprefill, which differs deliberately from the pure-prefill version (batch 1, kind-only). - Mixed durations queried at live
(work, start_position)and(0,0)— partly verified (see "The change" above). - "all new unit, scheduler, runtime-phase, and codec tests pass", "live SM120 GPU codec and
CopyEngineGatetests pass on RTX PRO 6000 Blackwell", "all bounded TLA+ lifecycle conformance suites pass (621,749 transitions)" — author-reported only. CI is pending, no logs attached. The 10 named tests exist or plausibly exist in-tree; the TLA+ figure covers 10 models + 9 observed-edge suites, one more each than #628/#619/#645/#659 reported, so the harness has grown. - "Expected serving impact (not benchmarked end-to-end here) … eliminates 2K-32K KV and recurrent state wipes" — explicitly unbacked; the 2K–32K figure has no measurement or citation.
- Limitations, all accurate and self-disclosed: 6 HF chat-template tests not run (a recurring environment gap across this author's PRs, not specific to #729);
cargo-kaninot installed (the Kani-coveredStateView/completion-vector validators were not modified, so genuinely N/A);check.py (not opened) --mutationsnot run (whereas #645 and #659 both ran it);scripts/scheduling_sim/does not model per-fill/per-context NNLS strata, so no simulator validation of the Mixed pricing change — the repo's design-review hierarchy expects that gate.
Reach
- Users/operators: anyone serving reasoning models with structured output (
json_schema/json_object/Lark/strict tools) — the direct beneficiary of #530; non-speculative models, which lose two-frame pipelining during reasoning (the PR argues the pipelining bought "zero speculative width" but it does change in-flight frames and ITL); speculative cores exported before theGrammarEnabledbinding existed, which paySnapshot+Restoreper transition; TP2+ PCIe/SM120 prefix-cache offload users (kvc=cpu/gpu);GraphKind::Mixedenvelope users only, since Mixed graphs exist only in cores that export them. - Config/defaults: no new flags, policy fields, env vars or defaults.
scheduler_checkpoint_extra_work_fractionandestimate_ttl_nsuntouched. The only default-behavior change visible in the doc hunk (preserve_message_anchor) is #697's, already merged. - Compatibility/dependencies/deployment: no Protobuf, core-format,
.cu, or dependency change; no multi-host wire change. Existing cores load. Nothing about the new Mixed strata is persisted (interacts with open #301). - Docs: one file updated (
docs/scheduling-runtime-design.md);docs/core-design.md:1242 (not opened),1773,docs/mtp-design.md(not opened),docs/prefix-cache-offload.md:96-100andhelios/README.md(not opened) were not, so present-state docs describe pre-#729 behavior for the codec fallback and the grammar transition. - Affected tests: every new test is in-tree; the
helios --libtotal is 1917 passed / 49 ignored (author-reported), which includes #659's rewrites.
Process
Open (not draft), "ready for review", branch helios-inplace-grammar-toggle-kv-cod → main, head 150f705, base cc0a49d, opened and updated 2026-12-04 17:35. CI pending. No review, no reviewer, no labels (area:scheduling/performance/triage:review absent on all peers), no linked issue, no Fixes/Closes trailer, no reference to the predecessor PRs whose code it changes. No Design-Signed-Off-By (none needed — no new op). Discord: lukealonso present, satisfying the repo's PR-template requirement. --mutations and Kani unrun (Kani genuinely N/A). Age: under one day at filing.
Open questions / not found
- What exactly the true base commit is, so the diff can be re-derived cleanly; hunks still unattributed in the local diff:
Admission::validate_continuation/from_continuation(initial_prompt_tokens),refresh_admission_plan_in_place,evict_for_pressure_cached,partition_conditioned_windows,prefill_catalog_costs_for. - Whether the gate-before-mutex order can make a foreground restore wait behind an active peer graph where #628's order let it fall back immediately (Key finding 3) — not verified at runtime.
- Whether
delivery_referenceswas actually updated as claimed. - Whether existing third-party exported cores were exercised for the "no re-export needed" claim, or only the packing unit test.
- Whether the extra
Snapshot+Restorecost on older speculative cores is acceptable — no measurement. - Recent-activity commit history could not be retrieved (git ref errors in the orientation packet and
search_history); no default-branch commits touched these files sincecc0a49dper the packet. No issue, user report, benchmark, or upstream design note exists for any of the three defects.