Code correctness report · NVIDIA/hyperflare-inference #715

Raw Markdown for agents: https://autobot.eidonix.com/p/592e79a1-cb8a-49d9-b3e0-cb3e16bcbb1f.md

Deep Code Correctness & Hot-Path Audit — PR #715 @ 4e3e2c3

Partitioning (per the large-PR rule): 34 files, ~2,030 changed lines across 3+ subsystems → partitioned into 3 disjoint concurrent slices: (s2) helios scheduler core, (s3) helios manifest/catalog/packing/selection, (s1) ignition + scripts/scheduling_sim + verification/. s2 exhausted its turn budget without a written report (its notes are cited below as s2#1/#2); I audited the core of its slice myself (policy.rs:1240-1335, 1507-1798, 2040-2408, cost.rs:820-1000, scheduler.rs:420-490, 2820-3140, checkpoints.rs:890-990).

Verdict: no Blocker. No hot-path complexity regression. 1 Major finding (vacuous-verification hole) and 6 Minor findings (two of them test-claim defects where the new test asserts the wrong error). The packed-prefill scheduler mathematics, cohort selection, tie-breaks, and boundary guards are sound.


Finding 1 — Major: lifecycle checker passes with the new packed-prefill transitions silently absent

Diff site: verification/helios-lifecycle/check.py:18, 22, 33-34, 95-103 Callee/caller consulted: helios/src/scheduler/lifecycle_tests.rs:840 (pre-existing scheduler_matches_lifecycle_model), :849-946 (new packed_prefill_scheduler_matches_lifecycle_model), :934-937 (its Rust-side non-vacuity guard), :939-945 (LIFECYCLE_EDGE / PACKED_PREFILL_LIFECYCLE_COVERAGE emission).

Verbatim (check.py:18,22,95-103):

TEST = "scheduler::lifecycle_tests::"
CHECKS = [("Lifecycle", TEST, "LIFECYCLE_EDGE ", 14),
...
def parse_observations(output, module, prefix, width):
    edges = [json.loads(line.removeprefix(prefix))
             for line in output.splitlines() if line.startswith(prefix)]
    if not edges:
        raise RuntimeError(f"{module} test produced no transitions")

The entire scheduler::lifecycle_tests:: suite is one cargo test filter and all LIFECYCLE_EDGE lines are merged into the single Lifecycle stream. The only guard that packed transitions were observed at all is the global non-empty check at line 98, which the unchanged scheduler_matches_lifecycle_model (lifecycle_tests.rs:840) always satisfies. The test's own non-vacuity assertion (lifecycle_tests.rs:934-937, packed_non_terminal && packed_terminal && cancel_during_packed && stale_packed_plan) lives inside the Rust test and is bypassed if that test is not selected.

Counterexample: rename the new test to packed_prefill_lifecycle_model (or narrow its #[cfg]). cargo test scheduler::lifecycle_tests:: -- --nocapture then matches one test, exits 0 with "1 passed", parse_observations sees only base-model edges, and run_observed_checks still prints "Checked N observed Rust transitions against Lifecycle.tla" — the checker green-lights the PR with zero packed-prefill coverage. Same hole for the CHECKPOINT_RESERVATION entry at check.py:33-34 (already a suite prefix).

Fix: make each Rust test its own observation source and assert non-emptiness per source, e.g. add ("PackedPrefill", "scheduler::lifecycle_tests::packed_prefill_scheduler_matches_lifecycle_model", "LIFECYCLE_EDGE ", 14); or parse the PACKED_PREFILL_LIFECYCLE_COVERAGE states=… edges=… line already emitted at lifecycle_tests.rs:941-945 and fail when edges == 0.


Finding 2 — Minor: the two new pack_step packing guards are unreachable, and the new test that claims to cover them asserts the scheduler's message instead

Diff site: helios/src/model/packing.rs:422-439; test: helios/src/model/tests.rs:2829-2853 Callee/caller consulted: helios/src/model/inputs.rs:35 (step.validate_mixed()?;) and :93 (inputs.pack(&frame)); helios/src/scheduler.rs:436-463.

if graph.kind.is_prefill() && graph.batch >= 2 {
    let mut total_tokens = 0usize;
    for lane in &frame.step.lanes {
        if lane.tokens > graph.tokens {
            return Err("packed prefill lane exceeds per-request token capacity".into());

ScheduledStep::validate_mixed (scheduler.rs:445-463) already rejects exactly these conditions:

.any(|lane| lane.tokens == 0 || lane.tokens > self.token_capacity)
...
.try_fold(0usize, |sum, lane| sum.checked_add(lane.tokens))
.is_none_or(|sum| sum > self.packed_token_capacity)

inputs.pack( appears only at model/inputs.rs:93, always after the validate_mixed() at model/inputs.rs:35, so packing.rs:426 and packing.rs:437 cannot fire. The new test nonetheless claims them:

let err = pack_inputs(&mut inputs, &cfg, &scheduler, &over_p, &admissions)
    .expect_err("packed prefill must enforce aggregate packed token capacity");
assert!(err.to_string()
    .contains("packed prefill lanes exceed their captured geometry"), ...);

That string is verbatim scheduler.rs:462, not either new packing.rs message — so the assertion passes because the packing guards never ran. (The genuinely live new packing guard, image-conditioned-lane rejection at packing.rs:429-431, is properly asserted at tests.rs:2855-2863.)

Counterexample: ScheduledStep { kind: TerminalPrefill, batch_capacity: 4, token_capacity: 128, packed_token_capacity: 256, lanes: [64,128,128] } → error raised at inputs.rs:35.

Fix: either add a test that calls Inputs::pack() on a hand-built InputStep so the packing guards actually run, or delete packing.rs:422-439 (keeping 429-431) so the duplicated invariant cannot drift.


Finding 3 — Minor: the "Reject P > prefill_chunk_size" catalog test is not isolated, and the manifest layer never enforces the chunk bound

Sites: helios/src/model/tests.rs:2710-2719; helios/src/model/catalog.rs:273-280; helios/src/execution/manifest.rs:449-467, 885-891; new test helios/src/execution/tests.rs:1405-1439.

// Reject P > prefill_chunk_size in catalog::validate.
let mut over_m = m.clone();
over_m.graphs.iter_mut()
    .find(|g| g.name == packed_graph.name).unwrap()
    .packed_token_capacity = 576;
assert!(catalog::validate(&cfg, &over_m).is_err());

Graph is B=4, W=128, cfg.limits.prefill_chunk_size = 512. 576 > B*W = 512, so the first geometry conjunct (manifest.rs:458, packed <= batch.saturating_mul(width)) already rejects it; the chunk clause is satisfied (512 <= 512). The case proves nothing about the clause it is labelled for. Separately, ExecutionManifest::validate passes max_chunk = None (manifest.rs:890) into the helper whose last conjunct is max_chunk.is_none_or(|chunk| packed <= chunk) (manifest.rs:465), so manifest-level validation accepts B=4,W=128,P=512 against prefill_chunk_size = 256; only catalog::validate rejects it. Latent (all serving paths go through catalog::validate — server/config.rs:214, server/runtime.rs:703), not a live hole.

Fix: change the test case to B=8, W=128, P=1024 with prefill_chunk_size = 512 (only the chunk clause can reject it), and either thread the chunk size into the manifest call or drop max_chunk for one enforcement point.


Finding 4 — Minor: both simulator geometry validators accept packed shapes Helios rejects

Sites: scripts/scheduling_sim/model.py:43-49 and identically scripts/scheduling_sim/timing.py:37-43

if self.prefill_batch_capacity >= 2:
    if not self.prefill_capacity or self.decode_capacity or self.width != 1:
        raise ValueError("packed prefill graphs must be prefill-only with width 1")
    if not (max(self.prefill_batch_capacity, self.prefill_capacity)
            <= self.packed_token_capacity
            <= self.prefill_batch_capacity * self.prefill_capacity):
        raise ValueError("invalid packed prefill token capacity")

Helios additionally requires packed >= 64, packed.is_multiple_of(64) (helios/src/execution/manifest.rs:464-465) and P <= prefill_chunk_size (:467); docs/packed-prefill-design.md:64 states "64-aligned".

Counterexample: Graph(..., prefill_capacity=64, prefill_batch_capacity=2, packed_token_capacity=100) passes the simulator (max(2,64)=64 <= 100 <= 128) and choose/run will model a (B=2,W=64,P=100) replay that Helios rejects (100 % 64 != 0). Likewise W=2,B=2,P=4 passes the sim but fails P >= 64.

Fix: add and self.packed_token_capacity >= 64 and self.packed_token_capacity % 64 == 0 to both __post_init__s.


Finding 5 — Minor: Ignition GraphSignature omits P <= prefill_chunk_size, so export succeeds and the core then fails to load

Sites: ignition/preparation/execution.py:80-92 vs ignition/preparation/model.py:32-39

80  if self.kind in ("prefill", "terminal_prefill") and self.batch_capacity >= 2:
81      if (not 2 <= self.batch_capacity <= MAX_CONCURRENCY
82              or self.packed_token_capacity < 64
83              or self.packed_token_capacity % 64
84              or self.packed_token_capacity >= 1 << 31
85              or self.token_capacity > self.packed_token_capacity
86              or not self.batch_capacity <= self.packed_token_capacity <= self.batch_capacity * self.token_capacity):

GraphSignature.__post_init__ has no access to the chunk; only PreparedModel (model.py:32-39) checks it. PreparedExecution owns manifest()/start_executor()/serve_rank() (execution.py:407-481) and is what tests/preparation/test_execution.py::_execution builds.

Counterexample: GraphSignature("terminal_prefill", 4, 256, packed_token_capacity=2048) with server_config["prefill_chunk_size"] = 512 → accepted by execution.py, manifest emitted at :426-427, rejected at Helios core load (catalog.rs:273 → manifest.rs:467).

Fix: validate in PreparedExecution.__init__ where the config is available, mirroring model.py:34-39.

Otherwise execution.py:78-96 is equivalent to valid_packed_prefill_geometry for B >= 2 (2 <= B <= MAX_CONCURRENCY, P >= 64, P % 64 == 0, P < 2**31, W <= P, B <= P <= B*W, all four vision binding names, and draft_tokens rejected more strictly than Helios — a superset, not a hole).


Finding 6 — Minor: direct mode keys B >= 2 prefill graphs but can never use them, failing at admission instead of at Layout construction

Site: ignition/direct/scheduler.py:200-201, 288-293, 320-327

200  elif signature.kind in ("prefill", "terminal_prefill") and signature.batch_capacity >= 2:
201      key += (signature.packed_token_capacity,)
290  if kind in ("prefill", "terminal_prefill"):
291      return sorted({key[2] for key in self.graphs if len(key) == 3 and key[0] == kind and key[1] == 1})

Key isolation is correct: a packed key is (kind,B,W,P) (len 4) and packed_shapes (:317-318) selects len 5, so packed prefill keys cannot alias solo (kind,B,W) or speculative (kind,B,W,P,D) keys. But capacities()/graph() never see the len-4 keys, and Layout.of accepts them without checking that solo B == 1 prefill also exists.

Counterexample: a model whose only prefill graphs are ("terminal_prefill", 4, 128, 512) → Layout.of builds fine; the first plan() hits prefill_kind → self.graph("prefill", tokens) and raises AdmissionError("no prepared prefill graph holds N") (:327) deep in direct execution.

Fix: raise in Layout.of when both capacities("prefill") and capacities("terminal_prefill") are empty but a B >= 2 prefill key exists.


Verified correct (audited against callee/enum definitions, no defect found)

select_packed_prefill_cohort (policy.rs:1518-1619) — sound. Verified against best_cohort (utility.rs:177-198), ValueRate (utility.rs:148-173), Candidate (policy.rs:116-131), REQUEST_LANES = 64.

packed_prefill_offers (policy.rs:1657-1721) — sound. continuation promoted/ready split (:1678-1700) matches following_kind (policy.rs:1043-1065) and eligible/request_kind (policy.rs:338-379) semantics; prefill_plans is threaded by &mut so PrefillSlotPlan caching (policy.rs:526-533) is shared across all packed shapes and the solo loop at :1877-1915 — no redundant recomputation, no per-shape Vec/HashMap allocation anywhere in the packed fast path (fixed [_; REQUEST_LANES] arrays and two sort_unstable_by over ≤64 elements per shape).

packed_prefill_lane_compatible (policy.rs:1723-1752) — sound. TerminalPrefill => true is intentional and pinned by PR test #3 (h1 at 256/300 stays in RequestPhase::Prefill per scheduler.rs:3078-3079). The Prefill branch (:1735-1751) mirrors resolve_prefill_kind (scheduler.rs:976-1007) without the solo terminal_prefill_catalog lookup — correct, because B >= 2 graphs are not in that catalog (scheduler.rs:886-916, runtime.rs:846-877).

fill_finishing_lanes refactor (policy.rs:1621-1655) — behavior-preserving. The extracted helper now also skips slots already in *selected (:1638), which is equivalent to the old other_slot == slot check at both call sites: the promo call site passes selected = 1 << slot (:1146), and both guard remaining_capacity == 0 (:1632) exactly like the old if capacity > 1.

is_unmeasured_candidate interaction (policy.rs:563-566, cost.rs:878-880) — sound. packed_prefill_duration returns Some(0) for a declared but unmeasured packed graph, and observation(...).and_then(|(_, observed, _)| observed) (:565) is still None because observed = (nanos != 0).then_some(...), so candidates() correctly routes it to PlanOrigin::Discovery. cost.rs:581/:969/:606 now gate refresh_prefill_context_slopes/PrefillCostModel on && key.batch == 1, which is required — prefill_context_slopes is [_; 3] indexed by prefill kind only, so a B >= 2 prefill key would otherwise pollute the solo context-slope peers.

ScheduledStep::validate_mixed packed branch (scheduler.rs:436-463) — correct and non-tautological. Rejects empty/oversized lanes, tokens == 0, tokens > token_capacity, sum > packed_token_capacity (with checked_add), duplicate request slots, and re-validates geometry via valid_packed_prefill_geometry(.., REQUEST_LANES, None). commit additionally rejects lanes.len() > batch_capacity (scheduler.rs:2615-2617).

valid_packed_prefill_geometry (manifest.rs:449-467) — correct. All four call sites traced (manifest.rs:889 → request_capacity(), catalog.rs:277 → usize::MAX sentinel, selection.rs:295 → REQUEST_LANES, scheduler.rs:906 → limits.request_slots). The usize::MAX sentinel is safe because request_capacity() == max_active.next_power_of_two() and max_active <= REQUEST_LANES == 64 is enforced at manifest.rs:733. B >= 2 with P == 0 is unsatisfiable (width > 0 && width <= packed && packed >= 64, :456-457); B == 1 with P != 0 is rejected at manifest.rs:895-900. saturating_mul/is_multiple_of are overflow-free.

packing.rs buffer sizing & offsets — correct. The packed_token_capacity != 0 arm (:169-188) sits after the Mixed arm and before is_prefill(), so Mixed and B == 1 prefill and Speculative are all unaffected. packed_offset advances with checked_mul/checked_add (:549-574); every write is bounded by input.elements. The new guard runs before self.staging.clear() (packing.rs:440), so a rejection leaves no partially-written state; pack() clears unconstrained_masks on any error. Vision rejection covers all four sources (ImageFeatureSlot, ImageFeatureIndex, ImageLeftContext, ImageRightContext, :109-126).

selection.rs --max-concurrency filter (:366-387) — correct. active < 2 ⇒ limit 0 drops every B >= 2 packed graph while leaving B == 1 prefill (limit max_batch >= active >= 1) intact; ScoredPrefill/Vision untouched; locating the graph at :280-300 is O(1) per graph, no new O(N²).

Simulator accounting (scripts/scheduling_sim/simulator.py:64-98, scheduler.py:11-58, 70-74) — sound and lockstep with Rust. A packed cohort decrements remaining_prefill once per lane, emitted derives from remaining_prefill == 0, prefill_tokens = prompt_tokens - remaining_prefill — no double counting of lanes or tokens. _select_packed_prefill_lanes matches select_packed_prefill_cohort on: <2 offers → None, two orders (value and value/token), per-lane min(remaining, W_req), reject when total + work > P, cap at B, require >= 2, same (total_value, lane_count, total_work) key. Off-by-one checks (== B vs >= B, > vs >= on P) match. And scheduler.candidates:70-74 skips packed graphs on the decode path so a packed shape never contributes decode rows.


Audit limitations (stated, not claimed as findings)