Recommendation: Changes Requested
All five Round-1 blockers from 150f705 have been cleanly resolved at 68fe22f—Worker::publish() now applies pending_grammar_park before park_if_preempted, try_with_gpu_codec_locked uses non-blocking CopyEngineGate::try_enter_offload_batch, upward_extrapolation_floor and predict(0, 0) separate positive-fill bounds from zero_fill, Lifecycle.tla and check.py --mutations now cover all new park/toggle transitions and guards, and live SM120 flare run A/B benchmarks substantiate Bucket 1 and legacy-core compatibility. However, direct source verification at 68fe22f caught one new numeric/logic bug introduced in the PrefillCostModel::fit rework (pos_u_max == 0.0 in wide_or_full_positive at helios/src/scheduler/cost.rs:451-456), which causes a zero_fill-only GraphKind::Mixed model to emit constant_nanos = Some(decode_ns), under-pricing full-chunk prefills by ~47× and inflating service_rates across competing requests until a positive-fill step runs. Fix that defect (plus the remaining minor run_spans clone and wave-token barging items below) and this will be ready to merge.
Merge Risk
Level: Medium
GraphKind::Mixedzero-fill-only constant-predictor defect: Observing a single decode-only (work == 0)Mixedstep after startup or TTL expiry marks the graphconstant_nanos = Some(decode_ns), pricingwork > 0prefills at1×decode latency inmixed_candidates,next_progress,continuation_candidate, andservice_rates(where inflatedtoken_ratedistorts utility normalization across all competing requests).- Default MTP-5 latency trade-off & lock-order reversal: The disclosed live SM120 A/B shows a +32% median
</think>→content delta under default MTP 5 at 20,648 prompt tokens (40.9 → 54.1 ms) whenpause_for_drainwaits for a second speculative frame that overshoots and rolls back; separately, the capture path reverses#628'sgpu.codec→CopyEngineGateorder (deadlock-free with the non-blocking try path, pending@yatesdrsign-off). - Large four-surface diff &
#715conflict: 24 files (+2,954/−591) spanning runtime lifecycle, KV offload codec/gate, Mixed cost modeling, and TLA+/mutation verification, with direct textual and documentation overlap incost.rsanddocs/scheduling-runtime-design.mdagainst open#715.
Walkthrough
- Grammar-transition KV preservation & lifecycle verification (
helios/src/model/{mod,admission,packing}.rs,helios/src/scheduler.rs(not opened),helios/src/scheduler/policy.rs,helios/src/server/runtime.rs,verification/helios-lifecycle/{Lifecycle.tla,README.md (not opened),check.py},phase_tests.rs): Replaces(grammar_mask, grammar_enabled)withAdmissionGrammar::{Disabled, UnmaskedEnabled, Masked(Vec<i32>)}(admission.rs:61-90,packing.rs:803(not opened)); cachescan_toggle_grammar_in_placeonWorker(runtime.rs:1409-1410); routes transitions throughdecide_grammar_transition(runtime.rs:523-545) with scheduler-firstset_grammar_constrained(runtime.rs:2390-2399, 2455-2465); orderspending_grammar_parkahead ofpark_if_preemptedinWorker::publish()(runtime.rs:2561-2594, 2790-2792); and modelsPaused/PauseForPark/FinishForPark/ToggleGrammarinLifecycle.tla:11, 60-78with 6 new mutation guards incheck.py:458-508. - KV offload restore partitioning & non-blocking
CopyEngineGate(helios/src/offload/{copy_gate.rs,transfer/codec.rs}): AddsCopyEngineGate::try_enter_offload_batchsharingoffload_must_wait/take_offload_lease(copy_gate.rs:171-210), routes capture through blocking gate-then-codec (codec.rs:881-889) and foreground restores through non-blockingcodec.try_lock()thengate.try_enter_offload_batch()(codec.rs:895-906), and partitions restore windows viapartition_restore_pages_by(codec.rs:697-702, 840-877) without allocating a duplicateroutesVec. - Stratified
GraphKind::Mixedcost model (helios/src/scheduler/{cost,policy,service}.rs): Trackspos_u_min/pos_u_max/pos_t_at_umaxover positive-fill strata (cost.rs:144-153, 351-375), anchorspredict(0, 0)onhas_zero_fill(cost.rs:187-196), sharesclamp_nanos(cost.rs:79-87), namesMixedContextSlope(cost.rs:601-608), and updatesdocs/{api,core-design,mtp-design,prefix-cache-offload,scheduling-runtime-design}.md.
Pre-merge Checks
- [PASS] Security / malicious screen: Pure host-side scheduling, runtime lifecycle, and codec synchronization; no new dependencies, ABI/Protobuf/kernel changes, or prompt-injection attempts.
- [WARN] Charter & value fit: Model-agnostic Helios placement with live SM120 A/B and legacy-core verification for Bucket 1 (
3.32×–4.53×faster under--mtp-draft-tokens 0), but bundles four subsystems, discloses an ungated +32% MTP-5 regression at 20.6K tokens, and lacks whole-model A/B for Buckets 2–3. - [WARN] Related / duplicate / conflict check: Genuinely additive over
#525/#626/#628/#645and cites#530, but reverses#628's capture-path lock order (needs@yatesdrack) and conflicts with open#715incost.rsanddocs/scheduling-runtime-design.md. - [PASS] Tests & verification evidence: All reported Rust crate suites, 4 live SM120 GPU codec tests, 1,115 pytest tests, 10/10 TLA+ models (623,904 observed transitions), and 56/56
--mutationspass; remaining gap is the Layer-2scripts/scheduling_simrun noted under Should Fix.
Blockers
PrefillCostModel::fitmarks azero_fill-onlyGraphKind::Mixedmodel as a constant predictor (pos_u_max == 0.0inwide_or_full_positive), pricing full-chunk prefills at1×decode-only latency and inflatingservice_rates(helios/src/scheduler/cost.rs:451-456, 144-153, 183-206, 322-343, 762-803;helios/src/scheduler/policy.rs:546-549, 948, 1752-1898;helios/src/scheduler/service.rs:353-379)- Verified defect: When a
GraphKind::Mixedentry observes a decode-only step (work == 0, routinely emitted bymixed_candidatesatpolicy.rs:1821-1839) before any positive-fill step—either at startup or after a 30 s TTL expiry—PrefillCostModel::observe(cost.rs:322-324) populates onlyself.zero_fill(u = 0.0, h = 0.0), leavingpos_u_max == 0.0(cost.rs:365-374). Infit()(cost.rs:451-456):
Thelet wide_or_full_positive = pos_u_max == 0.0 || pos_u_max >= 1.0 - 1e-9 || (pos_u_max - pos_u_min) >= 0.15; let constant_nanos = (best_theta[1] == 0.0 && best_theta[2] == 0.0 && wide_or_full_positive) .then_some(clamp_nanos(best_theta[0]));pos_u_max == 0.0disjunct treats "zero positive-fill evidence" as "wide or full positive-fill coverage," emittingconstant_nanos = Some(decode_ns)and storingdecode_nsinestimate.nanos(cost.rs:342, 1118). - Concrete counterexample & downstream impact: On
Mixed(4, 1, 2048)with 2 ms decode-only latency and ~95 ms true full-chunk prefill, observing one decode-only step setsconstant_nanos = Some(2_000_000)andestimate.nanos = 2_000_000. Until a positive-fill step executes on that shape:predict(2048, 0)short-circuits onconstant_nanos(cost.rs:184-186)—and note that simply removingpos_u_max == 0.0 ||is not sufficient on its own becauseupward_extrapolation_floor(cost.rs:145) also requiresself.pos_u_max > 0.0, sopredict(2048, 0)would still returntheta[0] = 2_000_000(~47× under-priced).mixed_candidates(policy.rs:1756, 1872-1898) seesvariable_cost = false, prices every prompt candidate atdecode_ns, andis_unmeasured_candidate(policy.rs:546-549) returnsfalsebecauseestimate.nanos != 0, letting the mispriced candidate compete asPlanOrigin::Ordinary.service_rates(service.rs:354-379) computestoken_rate = 2048 * 1e6 / 2e6 = 1,024 tok/ms(~47× inflated), distorting service-rate normalization across all competing prefill requests even when thatMixedgraph is not selected.- Both new tests (
cost.rs:1764-1900,policy_tests.rs:9510-9576(not opened)) observe a positive-fill sample before querying positive-fill predictions and therefore miss this state.
- Fix:
- Drop
pos_u_max == 0.0 ||fromwide_or_full_positive(cost.rs:451-452) so a zero-fill-only model is never markedconstant_nanos = Some(...). - Expose
pub fn has_positive_fill(&self) -> bool { self.pos_u_max > 0.0 }onPrefillPredictor. Keeppredict(0, 0)returning the valid measured decode-only cost (do not collapsemixed_entrytoSome(None)globally), while on positive-fill queries (work > 0) when!predictor.has_positive_fill(), return0inmixed_candidates/next_progress/continuation_candidate(sois_unmeasured_candidateatpolicy.rs:547properly treats positive-fill on that shape as discovery viaduration_ns == 0) and skip it inservice_ratesprefill normalization (service.rs:373). - Add a unit test in
cost.rsobserving onlymixed_step(4, 1, 2048, None)(at init and post-TTL) and assertingpredict(0, 0) == decode_ns,!predictor.is_constant(),!predictor.has_positive_fill(), and that positive-fill queries do not price full-chunk prefill at decode-only latency.
- Drop
- Verified defect: When a
Should Fix
-
Eliminate the remaining per-page
Vec<DeviceSpan>clone inrestore_window'sGpuBatcharm (helios/src/offload/transfer/codec.rs:716-724;helios/src/offload/transfer/gpu_codec.rs:1693-1700)pages(codec.rs:685-693) already owns each page'sVec<DeviceSpan>, yetcodec.rs:716-717still allocates and clones every per-page vector (let run_spans: Vec<Vec<DeviceSpan>> = slice.iter().map(|(_, _, _, sp)| sp.clone()).collect();) solely becausedecode_pages_batch_to_devicetakes&[Vec<DeviceSpan>]—partially contradicting the PR description's claim that partitioning avoids cloning per-pageDeviceSpanvectors.- Fix: Mirror
copy_spans_batch(codec.rs:1062) by changingspans_per_pageindecode_pages_batch_to_device(gpu_codec.rs:1697) to&[impl AsRef<[DeviceSpan]>](or&[&[DeviceSpan]]) and passing borrowed slicesslice.iter().map(|(_, _, _, sp)| sp.as_slice()).collect::<Vec<_>>().
-
Prevent
CopyEngineGate::try_enter_offload_batchfrom consuming wave tokens armed for blocked offload waiters (helios/src/offload/copy_gate.rs:55-68, 171-210;docs/prefix-cache-offload.md:102-106)maybe_arm_offload_wave(copy_gate.rs:61-62) sizesoffload_wave_remaining = offload_batches_waitingspecifically for threads parked inenter_offload_batch. Becauseoffload_must_wait(:171-175) allows entry whenturn == Turn::Offload && offload_wave_remaining > 0,try_enter_offload_batch(:204-210) callstake_offload_leaseand decrementsoffload_wave_remaining, potentially flippingturn = Turn::Peerbefore woken waiters run and contradictingdocs/prefix-cache-offload.md:104-105("without blocking or consuming a gate wave token").- Fix: Return
Noneintry_enter_offload_batchwhenSelf::offload_must_wait(&state) || (state.turn == Turn::Offload && state.offload_batches_waiting > 0)so non-waiting foreground tries fall back to CPU during a waiter-reserved offload wave without stealing waiter tokens.
-
Address the disclosed default-MTP-5 latency delta, Layer-2 simulator check, and
@yatesdrlock-order ack (helios/src/server/runtime.rs:538-541;helios/src/offload/transfer/codec.rs:879-889;docs/design-review.md:109-115, 195-206)- Under default MTP 5 at 20,648 prompt tokens on the tested
Qwen4-35B-A3Bcore,pause_for_drainregresses median</think>→content latency by +32% (40.9 → 54.1 ms) because waiting for Frame 2 before rolling back on</think>\n\n{overshoot delays slot readmission compared tomain's immediatecancel(). Confirm whether this trade-off is acceptable for default MTP-5 deployments on cores lackingValueSource::GrammarEnabledor gatepause_for_drainwhen speculative overshoot is expected. - Obtain
@yatesdr's sign-off on reversing#628's capture-path lock order (codec.rs:879-889), and runscripts/scheduling_sim/learning.py --preset validate(matching#645's precedent;scripts/scheduling_sim/learning_scenarios.py:63(not opened) already includes mixed scenarios) or split Bucket 3 if whole-modelMixedvalidation is deferred.
- Under default MTP 5 at 20,648 prompt tokens on the tested
Subtract / Simplify
- Pass
AdmissionGrammardirectly toAdmission::from_continuation(helios/src/model/admission.rs:160-193;helios/src/server/runtime.rs:1731-1737): Replaces the two independentgrammar_mask_active/grammar_enabledbooleans, the 3-arm match,#[allow(clippy::too_many_arguments)], and the duplicate-bool pass-through infrom_prompt. - Construct
GrammarParkonce per transition match (helios/src/server/runtime.rs:2401-2427, 2467-2493): Buildinglet park = GrammarPark { ... };before eachmatch decide_grammar_transition(...)deletes ~26 lines of duplicated struct literals acrossCheckpointParkandRollback. - Fold non-row CPU/singleton restore into
CpuBatch(helios/src/offload/transfer/codec.rs:548-583, 630-655):decode_pages_cpu_batchalready special-casesitems.len() == 1; routing non-row CPU/singleton pages through it removes the duplicated CPU tail ofrestore_single_unitand one of the two pure-Literaltransform_nschecks. - Unify
prefill_context_slopes/mixed_context_slopesand deduplicate sampling-graph matching (helios/src/scheduler/cost.rs:601-621, 892-958;helios/src/server/runtime.rs:552-561): Sharing one context-slope helper trimscost.rsand shrinks the conflict surface with#715; sharing aGraphOperation::samples()helper avoids a fourth manual enumeration of the seven sampling graph operations.
Nits
- State the capture-path lock-ordering invariant (
CopyEngineGatebeforegpu.codec, with non-blocking try-both on foreground restores) explicitly indocs/prefix-cache-offload.md:96-107. - Cache
speculativealongsidecan_toggle_grammar_in_placeonWorkerinstead of recomputing!self.config.speculative_widths.is_empty()atruntime.rs:1409, 1729, 2140. - Coordinate merge order / rebase on
cost.rsanddocs/scheduling-runtime-design.mdwith open#715.
Dropped on verification
- Round-1 Blockers 1–4 and Round-1 Should Fix 1–3 (all resolved at
68fe22f): Verified fixed inruntime.rs:2561-2594, 2790-2792(publish/preemption order),codec.rs:895-906+copy_gate.rs:204-210(non-blockingtry_enter_offload_batch),cost.rs:144-153, 187-196(pos_u_min/pos_u_maxfloor andhas_zero_fillguard),Lifecycle.tla+check.py:458-508(TLA+ & 6 new mutations),runtime.rs:1409-1410, 2390-2399, 2455-2465(cachedcan_toggle_grammar_in_place+ scheduler-first toggle), and all 5 docs. - Upstream Gates Audit escalating
scripts/scheduling_simto a Round-2 Blocker: Kept in Should Fix 3 rather than Blocker to avoid moving goalposts—Round 1 placed this in Should Fix 3, andscripts/scheduling_sim/uses scalar per-graph costs without(fill, kv_context)NNLS strata (same as merged#645). - Upstream Code Audit inaccuracies on Blocker 1: Dropped the false claim that pre-PR
mainproducedu = 1/2048on decode-onlyMixedsteps (maincost.rs:606did not attachPrefillCostModeltoMixed), dropped the unsafe suggestion to havemixed_entryreturnSome(None)globally when!has_positive_fill()(which would discard validpredict(0, 0)decode-only costs), and scoped the persistence claim accurately (self-corrects once a positive-fill step executes on that shape, while distortingservice_ratesandPlanOrigin::Ordinarybefore then). - Upstream Subtraction S2 (
grammar_updated"live panic" and replacingcopy_from_slicewithmask.to_vec()): Dropped—verified atruntime.rs:1731-1737, 2160, 2247-2264, 2392-2399, 2454-2465that!speculative_grammarwithprompt.grammar.is_some()guaranteesAdmissionGrammar::Masked, and replacingcopy_from_slicewithAdmissionGrammar::Masked(mask.to_vec())would introduce a per-decode-token heap allocation on the hot path. - Upstream Subtraction S4 (merging
mixed_candidatesloops atpolicy.rs:1844-1898), S5 (mixed_entryOption<Option<_>>), and S8 (copy_spans_batchgeneric<S: AsRef<[DeviceSpan]>>): Dropped—S4's constant-costelsearm deliberately hoistsscore_decodersout of theprefill_slotsloop; S5 intentionally mirrorsprefill_entry(cost.rs:728-756); and S8's generic is required because capture (codec.rs:395, 466) passes ownedVec<DeviceSpan>while restore (codec.rs:575, 646) passes&[DeviceSpan]. - Unobservable CI status and stale-base diff hunks: Excluded per review standards.