Final review report · NVIDIA/hyperflare-inference #729

Raw Markdown for agents: https://autobot.eidonix.com/p/08d88245-2a50-4628-a6f6-4ac1043831c8.md

Recommendation: Changes Requested

This PR tackles three real, well-motivated Helios issues cleanly within the model-agnostic runtime layer with zero core-format/ABI/Protobuf changes, and its core partition_restore_pages batching and ValueSource::GrammarEnabled packing mechanics are sound. However, direct verification at 150f705 confirms three concrete runtime/locking/cost-model bugs (including a preemption-coincident PendingGrammarPark state-corruption bug, a blocking CopyEngineGate wait inside try_with_gpu_codec_locked that defeats CPU restore fallback, and zero_fill permanently disabling upward_extrapolation_floor for GraphKind::Mixed), plus two unmet mandatory verification gates (uncovered new scheduler lifecycle state / unrun check.py --mutations, and unbenchmarked performance / legacy-core serving claims).

Merge Risk

Level: High

Walkthrough

Pre-merge Checks

Blockers

  1. Preemption in complete_inner clobbers PendingGrammarPark in Worker::publish(), corrupting grammar mode and losing thinking_token_budget (helios/src/server/runtime.rs:2580-2614, :2350-2407, helios/src/scheduler.rs:1515, 1523-1542, 3121, 3267-3295)

    • Verified defect: When a growable request emits </think> (or re-enters reasoning) on a frame with skipped == 0 and pending == 0, RequestScheduler::complete_inner runs self.refill_reservations()? (scheduler.rs:3121) before returning generated to Worker::complete. Under page pressure, preempt_newest() (scheduler.rs:1523-1542) can pick that request (pending == 0 && !paused_for_park && phase == Decode) and call finish_early(handle, /*preempted=*/ true), setting preempted = true and phase = RequestPhase::Snapshot (with terminal_snapshot = Some(_)) or RequestPhase::Finishing.
    • Worker::complete then clears request.incoming.prompt.reasoning_cut = None (runtime.rs:2350), evaluates can_toggle_live == false (because of Finishing / terminal_snapshot), enters checkpoint_parks, calls finish_for_park(handle)? (scheduler.rs:3285, 3292 returns Ok(()) without clearing preempted), and stores PendingGrammarPark { remaining (including cut.after), speculative_reasoning, drop_reasoning, waiting_for_drain: false }.
    • When Worker::publish() runs (runtime.rs:2580-2583), self.park_if_preempted(slot)? executes before the pending_grammar_park handler at :2589-2614. Because live.preempted() is true, park_if_preempted (runtime.rs:2801-2834) parks with grammar_reasoning_mode: None, drop_reasoning: false, and remaining = max_new_tokens - live.generated_tokens, discarding PendingGrammarPark. On readmission, the request resumes in the wrong grammar/reasoning mode (e.g., still unmasked after </think> or still constrained after re-entry), retains dropped reasoning state, and permanently loses cut.after from thinking_token_budget.
    • Fix: In Worker::publish() (runtime.rs:2580-2614), check and handle pending_grammar_park.take_if(|park| !park.waiting_for_drain) (when live.phase == RequestPhase::Finishing && live.last_use() <= self.scheduler.completed()) before self.park_if_preempted(slot)? (or gate park_if_preempted on active.pending_grammar_park.is_none()), and add a phase test exercising preemption during the same complete_inner step as a grammar transition (with reasoning_cut.after > 0).
  2. try_with_gpu_codec_locked blocks on CopyEngineGate::enter_offload_batch before try_lock(), defeating non-blocking CPU restore fallback and burning two wave tokens (helios/src/offload/transfer/codec.rs:888-899, :605-629, :704-755; helios/src/offload/copy_gate.rs:173-195; helios/src/offload/transfer.rs:335-336)

    • Verified defect: try_with_gpu_codec_locked (codec.rs:896-898) calls CopyEngineGate::enter_offload_batch—an unbounded blocking condvar wait (copy_gate.rs:175-194)—before calling codec.try_lock(). Whenever a peer-copy graph is active (peer_graphs_active > 0) or queued behind an active background capture (peer_graphs_waiting > 0), a foreground restore blocks at :896 for the full capture + peer-graph drain instead of returning None and decoding on the CPU pool in parallel. This directly contradicts the helper's doc comment (codec.rs:888-890) and breaks the critical-path CPU fallback; the new unit test (codec.rs:1719-1736) drops peer_guard before calling try_with_gpu_codec_locked, so it misses this case.
    • In addition, during Turn::Offload, a contended try_with_gpu_codec_locked decrements offload_wave_remaining on entry (copy_gate.rs:187-191), fails try_lock(), drops _ce, and then the CPU fallback calls copy_spans_batch → GatedCopies::batch → enter_offload_batch() (transfer.rs:336) a second time, consuming two wave tokens for one run (or flipping Turn::Peer and blocking again).
    • Fix (deadlock-free): Do not simply swap try_lock() ahead of blocking enter_offload_batch()—that would introduce a 3-way deadlock against with_gpu_codec_locked (capture holds OffloadBatchGuard waiting on gpu.codec; restore holds gpu.codec waiting in enter_offload_batch on peer_graphs_waiting; peer_graph sets peer_graphs_waiting = 1 waiting on capture's OffloadBatchGuard up to the 120 s PEER_GRAPH_GATE_TIMEOUT). Instead, add a non-blocking CopyEngineGate::try_enter_offload_batch(&self) -> Option<OffloadBatchGuard<'_>> that returns None immediately when must_wait(&state) is true (and avoids consuming an offload_wave_remaining token if the caller bails on try_lock), use it in try_with_gpu_codec_locked before codec.try_lock(), and add a test proving try_with_gpu_codec_locked returns None immediately while a PeerGraphGuard is held.
  3. zero_fill (u = 0.0) sets u_min = 0.0, permanently disabling upward_extrapolation_floor for GraphKind::Mixed (helios/src/scheduler/cost.rs:132-142, 347-385; docs/scheduling-runtime-design.md:475-479)

    • Verified defect: upward_extrapolation_floor (cost.rs:132-142) requires self.u_min > 0.0 && (self.u_max - self.u_min) < 0.15. However, PrefillCostModel::fit (cost.rs:368-373, 354-361) routes self.zero_fill.median() (u == 0.0) through record_point, setting u_min = 0.0. Once any single decode-only Mixed step is observed, self.u_min stays 0.0 until TTL reset and upward_extrapolation_floor is permanently disabled—contradicting docs/scheduling-runtime-design.md:475-479 ("when only a narrow positive fill regime (u_min > 0, spread < 0.15) has been observed").
    • Concrete counterexample: On Mixed(4, 1, 2048) post-TTL with decode-only 15 ms (u = 0) and partial fill work = 128 (u = 0.0625, 16 ms), NNLS fits theta_0 = 15 ms, theta_1 = 16 ms; predict(2048, 0) returns 31 ms instead of the 4× floor 64 ms (2.06× under-prediction of full-chunk cost). The new test at cost.rs:1854-1858 only checks the post-TTL path without a zero_fill sample.
    • Fix: Track positive-fill bounds (pos_u_min, pos_u_max, pos_t_at_umax) over self.strata only (cost.rs:374-385) and use them for upward_extrapolation_floor (and the narrow-regime check in constant_nanos at :441-444), while keeping zero_fill in pts for NNLS fitting and t_at_umin. Add a regression test asserting the 4× floor still fires after observing both zero_fill and a narrow partial-fill sample.
  4. Mandatory Layer 3 formal verification & mutation gates unmet for new scheduler lifecycle states and safety guards (helios/src/scheduler.rs:267, 1433, 1449, 1531, 3234-3295; helios/src/scheduler/policy.rs:335; docs/design-review.md:226-251)

    • Verified gate violation: This PR adds a new live-request lifecycle state (paused_for_park, excluding requests from eligible, starvation detection, reservation refill, and preemption) and three guarded scheduler transitions (set_grammar_constrained, pause_for_park, finish_for_park, plus BoundaryKind::ConditionedWindow rejection and consumed_tokens <= exact_len drain checks). verification/ has zero references to any of these states/transitions, and the PR explicitly lists verification/helios-lifecycle/check.py --mutations as unrun.
    • docs/design-review.md:226-251 is explicit: modifying Helios scheduler lifecycle transitions without updating and running the applicable TLA+ models / Rust observed-edge conformance fixtures is a blocking design failure, new safety guards require --mutations (or cargo-mutants), and disclosing runnable CPU checks as unrun does not waive them. (Blocker 1 is a concrete example of the exact preemption × park lifecycle gap left uncovered.)
    • Fix: Extend the applicable TLA+ lifecycle/conformance suite (verification/helios-lifecycle/) to cover paused_for_park / pause_for_park / finish_for_park / set_grammar_constrained (including interaction with preemption/terminal snapshots), and run verification/helios-lifecycle/check.py --mutations cleanly.
  5. Performance-motivated changes and legacy-core behavior changes lack live served-workload A/B and previous-core serving verification (Charter #210; docs/design-review.md:109-123)

    • Verified gate violation: All three buckets are performance-motivated ("eliminates 2K-32K KV and recurrent state wipes", GPU restore batching, Mixed pricing), yet the PR explicitly reports "not benchmarked end-to-end here" and "No end-to-end exported-core flare run latency or throughput benchmark was run on this branch." Moreover, non-speculative models now pack GrammarEnabled = 1 during open reasoning and disable two-frame pipelining during reasoning, and existing speculative cores without per-step GrammarEnabled bindings now run Snapshot + Restore per transition—making live loading/serving on previously exported cores (docs/design-review.md:116-123) and flare run A/B measurements against main (docs/design-review.md:109-115, Charter #210) essential rather than optional.
    • Fix: Run and report a flare run A/B benchmark over main on an exported core exercising structured-output reasoning transitions (covering both in-place and Snapshot+Restore paths on an existing core to substantiate both performance and Principle 13 compatibility).

Should Fix

  1. Discontinuous predict(0, 0) cliff down to 1 ns / microseconds when u_min > 0 and NNLS produces a tiny positive theta[0] (helios/src/scheduler/cost.rs:176-189, helios/src/scheduler/utility.rs:154-171, helios/src/scheduler/policy.rs:546-549)

    • When no zero_fill sample has been observed (u_min > 0), predict(0, 0) checks if self.theta[0] > 0.0 && self.theta[0].is_finite() { self.theta[0] } else { self.t_at_umin }. If two positive-fill observations are barely sub-linear—e.g., (u = 0.25, 20_000_000 ns) and (u = 1.0, 79_999_000 ns) (or 79_999_999 ns)—exact NNLS solves theta[0] = 333.33 ns (or 0.33 ns, clamped to 1 ns) with SSE 0.0. Because theta[0] > 0.0, predict(0, 0) skips t_at_umin and returns 333 ns (or 1 ns), inflating ValueRate::new (utility.rs:155-165) by 60,000×–20,000,000× while is_unmeasured_candidate (policy.rs:546-549) remains false.
    • Fix: When no zero_fill sample has been observed (has_zero_fill == false), either return t_at_umin for work == 0 directly or clamp theta[0] against a lower bound derived from t_at_umin rather than letting theta[0] > 0.0 collapse toward 1 ns.
  2. Cache sampling_graphs_bind_grammar_enabled on Worker and enforce atomic scheduler-first ordering on in-place toggle (helios/src/server/runtime.rs:519-545, 2118-2120, 2364-2380, 2441-2454)

    • sampling_graphs_bind_grammar_enabled(self.config) walks every prepared graph and every input binding on every Worker::complete call even though self.config is immutable; compute and cache can_toggle_grammar_in_place: bool once in Worker::new.
    • In both in-place toggle arms (runtime.rs:2372-2380 and :2442-2448), incoming.grammar_reasoning_mode, request.reasoning, and admissions[slot] are mutated before self.scheduler.set_grammar_constrained(...)?. Call self.scheduler.set_grammar_constrained(...)? first so an unexpected error cannot leave host and scheduler grammar state diverged.
  3. Update stale present-state docs and confirm Layer 2 simulator validation for Mixed (docs/prefix-cache-offload.md:96-100, docs/core-design.md (not opened), docs/mtp-design.md (not opened), docs/design-review.md:195-206)

    • docs/prefix-cache-offload.md:96-100 still describes GPU-codec CPU fallback without the new CopyEngineGate ordering, and docs/core-design.md (not opened) / docs/mtp-design.md (not opened) still describe #626's unconditional cancel transition; update them alongside the code and obtain @yatesdr's sign-off on reversing #628's lock-order invariant once Blocker 2 is fixed.
    • For Bucket 3 (cost.rs timing estimation), run scripts/scheduling_sim/learning.py --preset validate (matching #645's precedent under docs/design-review.md:195-206) or model Mixed strata in scripts/scheduling_sim/.

Subtract / Simplify

Nits

Dropped on verification