Code correctness report · NVIDIA/hyperflare-inference #715

Raw Markdown for agents: https://autobot.eidonix.com/p/ecf09b07-dd76-4b3e-9027-d08a30e1e74a.md

Deep Correctness Audit — PR #715 "additive packed multi-request prefill (Contract 3)" @ 49d5840

Partitioned per the >12-file / >900-LOC rule into three disjoint slices (helios contract+packing+selection; helios scheduler+cost+policy+checkpoints+server; ignition/Python). Every slice applied the full 4-part protocol; I then re-verified each reported finding myself against the files at pr/715 and discarded three sub-agent claims that did not survive verification (listed at the end). Verdict: no Blocker; one Major, five Minor.


F1 — Major — packed (batch >= 2) prefill lanes skip the authoritative checkpoint-cut recheck that solo prefill lanes get

Diff site helios/src/scheduler/policy.rs:2133-2136

if ((candidate.kind.is_prefill() && candidate.batch == 1)
    || candidate.prefill_slot.is_some())
    && matches!(origin, PlanOrigin::Ordinary | PlanOrigin::Discovery)
{
    let slot = candidate.prefill_slot.unwrap_or_else(|| bits(candidate.mask).next().unwrap());

Callee/materialization site helios/src/scheduler/policy.rs:2264-2266

tokens: if let Some(ref host) = lengths {
    host[slot]

The lane work those host_lengths were priced from — policy.rs:1340-1342 calls prefill_slot_state → helios/src/scheduler/policy.rs:518-525

if !plan.ready {
    plan.cut = self.estimated_checkpoint_cut(request);

estimated_checkpoint_cut = checkpoint_selection_cached(request, false) (helios/src/scheduler/checkpoints.rs:890-898) while the planner/committer use checkpoint_cut = checkpoint_selection_cached(request, true) (checkpoints.rs:900-908) — the two differ precisely in quote_storage, and plan_checkpoints matches a capture only on exact endpoint equality (checkpoints.rs:937-941: find(|cut| cut.endpoint == end && !deferred_after)).

Packed candidates are created with prefill_slot: None (policy.rs:1771) and host_lengths: Some(choice.lengths) (policy.rs:1763), so the guard above is false for them (both disjuncts fail) and they never reach the repair at policy.rs:2152-2163:

if actual_work != work || kind_changed {
    if let Some(resized) = self.resize_prefill(candidate, request, cut, values, age_price) {

which is the only place estimated vs authoritative divergence is reconciled (resize_prefill is itself solo-only, policy.rs:2194-2206).

Counterexample: prompt 1536 tokens, interior message-boundary cut at 1024 that is quotable only when snapshot rows are quoted for the whole packed step. estimated_checkpoint_cut (quote_storage=false) → Some(1024); authoritative checkpoint_cut → None (rows contended by the 3 other lanes of the same (TerminalPrefill,4,128,512) step). The cohort is priced with work = 1024, the lane runs 1024 tokens, and at commit plan_checkpoints finds no accounting cut with endpoint == 1024 → no capture, no reserve_guard, even though promote_request_anchor already armed the anchor guard for 1024 (checkpoints.rs:1001-1019). The anchor guard is then stuck until revoke_unused_anchor_guards. Symmetrically, estimated None / authoritative Some(1024) makes the lane run the full 1536 tokens past the armed anchor, so capture.endpoint == endpoint fails in completion (scheduler.rs:3106-3112) and the boundary is silently dropped — a warm-prefix cache miss that the feature's own purpose (warm-prefix turns) depends on.

Fix: extend the guard so packed candidates are rechecked too, e.g. if candidate.kind.is_prefill() && (candidate.batch == 1 || candidate.host_lengths.is_some()), and in the packed case recompute host_lengths[slot] = self.prefill_work_through(request, candidate.capacity, self.checkpoint_cut(request)) per lane, then re-validate sum(lengths) <= candidate.packed_token_capacity and bits(mask).count() <= candidate.batch; if either fails, drop the candidate. Add a policy_tests.rs case with quote_storage divergence forced between the two cut functions.


F2 — Minor — greedy packed cohort selection can reject a shape that has a valid cohort

helios/src/scheduler/policy.rs:1628-1654

for &idx in &order[..count] {
    if selected == batch { break; }
    if seeded == Some(idx) { continue; }
    let (slot, work, val, promoted) = offers[idx];
    if total_work + work > packed { continue; }
    ...
if selected < 2 { continue; }

The two passes (by_density in [false, true], policy.rs:1582) differ only in the primary key and are both single-seed forward greedy; an oversized high-value lane that fits alone blocks the pair that would fit, and neither pass recovers because both orderings rank it first.

Counterexample (realistic: width=64, packed=128): offers A(work 70, value 140), B(60, 100), C(60, 100).

Fix: seed the greedy once per candidate seed instead of once (for seed in order[..min(count,batch)], keep the best), or run the already-available best_two_stage_cohort-style fill (policy.rs:1261) with the packed packed budget. count <= REQUEST_LANES (16), so O(k·N log N) is free.


F3 — Minor — packed prefill replay duration is keyed by (kind,B,W,P) only, so the flat median pools cohorts from B to P rows, and the whole duration is charged to the cohort

Lookup helios/src/scheduler/cost.rs:644-659 → duration_key(Key { drafts: 0, kind, batch, tokens: width, prefill: 0, packed }). Observation path helios/src/scheduler/cost.rs:947-954 builds the same key from the committed step (packed: step.packed_token_capacity), then ReplayTimes::observe (cost.rs:492-511) takes a plain 9-sample median. Consumption helios/src/scheduler/policy.rs:1774

rate: ValueRate::new(duration_ns, choice.total_value, age_price),

and the PrefillCostModel (which predicts from work) is deliberately disabled for packed shapes (cost.rs:606-607: (key.kind.is_prefill() && key.batch == 1)).

Counterexample: shape (TerminalPrefill, 4, 128, 512) — the recipe runs it at 4 x 32 = 128 rows (~2 ms) and at 4 x 128 = 512 rows (~7 ms; the PR's own 3,947.3 µs vs 7,625.4 µs per layer shows the 2× range is real). Both samples land in the same ring, so a light 128-row cohort is priced at up to ~3.5× its true cost and a 512-row cohort at ~0.3×; because the rate is value/duration the light cohort is systematically starved and the heavy one over-promoted on every step. The amended docs/scheduling-runtime-design.md (Duration estimates, ~463-476) sanctions "the same flat nine-sample median as non-prefill graphs", but non-prefill keys have a fixed row count per key, so the sanction does not cover this new variability. Fix: add a work/rows dimension to Key for packed >= 1 (e.g. bucket total_work by 64), or attach an affine PrefillCostModel on choice.total_work for batch >= 2 and predict at policy.rs:1774.


F4 — Minor — the new --packed-verification guard is always satisfied for any recipe with a speculative graph

ignition/cli/serve.py:465-467 (changed by this PR)

if not any(
        signature.kind == "speculative" and signature.packed_token_capacity
        for signature in local_model.signatures.values()):

Callee that defeats it ignition/preparation/execution.py:102-106

packed = self.batch_capacity * self.token_capacity if not self.packed_token_capacity else self.packed_token_capacity
...
object.__setattr__(self, "packed_token_capacity", packed)

Every speculative signature has packed_token_capacity >= batch_capacity > 0 after __post_init__, so signature.packed_token_capacity is always truthy and the guard can never fire. Counterexample: a recipe with a single width-one speculative round GraphSignature("speculative", 4, 1, ("tokens",)) → packed_token_capacity becomes 4 → --packed-verification is accepted silently even though no packed round exists. Scoping to kind == "speculative" is itself correct (SpeculationParameters.packed_verification, ignition/parameters.py:783; shapes from packed_speculative_shapes, ignition/components/capacity.py:91-132) — no non-speculative kind needs it and no speculative case is newly rejected. Fix: signature.kind == "speculative" and (signature.token_capacity > 1 or signature.packed_token_capacity > signature.batch_capacity).


F5 — Minor — the Python geometry validator omits the batch <= request_capacity(max_active) bound that Helios enforces, so a recipe can prepare and export a core Helios refuses to load

ignition/preparation/execution.py:80-86

if self.kind in ("prefill", "terminal_prefill") and self.batch_capacity >= 2:
    if (not 2 <= self.batch_capacity <= MAX_CONCURRENCY
            or self.packed_token_capacity < 64
            ...

MAX_CONCURRENCY = 64 is a constant (ignition/components/capacity.py:11), while PreparedExecution.__init__ already computes the real bound at execution.py:300 (request_capacity(max_active), capacity.py:30-34). Rust enforces graph.batch_capacity > prepared.next_power_of_two() as u64 (helios/src/runtime_core/selection.rs:307) and passes self.request_capacity() into valid_packed_prefill_geometry (helios/src/execution/manifest.rs:889 → predicate (2..=max_batch) at manifest.rs:459). Counterexample: max_active=4, GraphSignature("terminal_prefill", 8, 128, ("tokens",), packed_token_capacity=256) → Python accepts, core exports; Helios core selection drops the graph and the process fails with "invalid or duplicate serving graph variant". (Minor rather than Major because the same pre-existing gap exists for mixed at execution.py:59 and speculative at :54.) Fix: or self.batch_capacity > request_capacity(max_active) in the packed-prefill arm.


F6 — Minor — P <= prefill_chunk_size is silently unenforced when the recipe omits server_config["prefill_chunk_size"], while Helios fails closed

ignition/preparation/model.py:32-43

prefill_chunk = self.server_config.get("prefill_chunk_size")
if prefill_chunk is not None:
    for name, signature in self.signatures.items():

No other Python layer checks the chunk bound (PreparedExecution.__init__, execution.py:255-372, has none). Helios defaults a missing key to 0, which rejects every B >= 2 graph: helios/src/runtime_core/selection.rs:281 let max_chunk = config["prefill_chunk_size"].as_u64().unwrap_or(0); feeding Some(chunk) at selection.rs:296 into max_chunk.is_none_or(|chunk| packed <= chunk) (manifest.rs:467). Counterexample: the tests' own fixture style, _execution(..., server_config={}, signatures={"tp": GraphSignature("terminal_prefill", 4, 256, ("tokens",), packed_token_capacity=1024)}) → accepted and exported, then rejected at Helios load. Fix: fail closed — treat a missing key as 0 (matching Helios) or default it to the same 4096 Helios uses in helios/src/server/config.rs:149 (not opened).


Verified sound — suspicions I opened and cleared (reported so they are not re-raised)

  1. pack_step packed guard is not a hole. helios/src/model/packing.rs:422-439: graph.packed_tokens is the descriptor's packed_token_capacity (packing.rs:276), and manifest validation requires packed >= 64 for B >= 2 (manifest.rs:464), so graph.packed_tokens != 0 at line 436 is a redundant, always-true conjunct — the check reduces to total_tokens > P, which is exactly the contract bound. It still rejects correct inputs. Zero-token lanes are impossible here because ScheduledStep::validate_mixed rejects lane.tokens == 0 (scheduler.rs:450) and pack_inputs calls it first (model/inputs.rs:35). Worth dropping the dead conjunct for clarity, but not a defect.
  2. promoted_limit is not capped at 1. policy.rs:1363 passes Some(capacity); capacity is continuation_candidate's second parameter (policy.rs:1060-1067), and the sole caller passes batch (policy.rs:1824: continuation_candidate(kind, batch, duration_ns, …)), consistent with the pre-existing capacity - 1 reservation at policy.rs:1152. Multi-lane promotion into a packed replay therefore works.
  3. The max_concurrency filter cannot silently drop all packed graphs. selection.rs:355-365: max_batch is min(batch_capacity of generation graphs with batch_capacity >= active), and .unwrap_or(active as u64) means an empty match yields active, so max_batch >= active always; with active >= 2 packed shapes up to active survive, and --max-concurrency 1 correctly yields limit = 0 (selection.rs:370-374). The new fixture at selection.rs:2102ff is not load-bearing for this.
  4. valid_packed_prefill_geometry is mutually satisfiable and matches the doc. manifest.rs:452-468: 2 <= B <= max_batch, 0 < W <= P, P >= B, P <= B*W, 64 | P, P <= i32::MAX, P <= max_chunk. B=2, W=1, P=64 is correctly rejected (packed <= B*W fails), minimal legal shape is B=2, W=32, P=64; all six recipe shapes satisfy it.
  5. Vision rejection on packed prefill is complete. model/packing.rs:113-126 rejects all four image bindings for is_prefill() && batch_capacity >= 2 while keeping them for batch == 1 (backward compatible); ScoredPrefill is a is_prefill() variant (manifest.rs:85-87) but is forced to batch_capacity == 1 at three layers (manifest.rs:951-956, catalog.rs:282-288, selection.rs:301-303), so it never reaches the packed branch.
  6. No NaN / div-by-zero / comparator panic in the new ranking code. select_packed_prefill_cohort uses total_cmp throughout (policy.rs:1590-1597, 1666-1670), density denominators are work > 0 (both builders skip work == 0: policy.rs:1343, 1741), ValueRate::new special-cases duration_ns == 0 (scheduler/utility.rs:154-165), and the candidate comparator ends on a total tie-break (total_value, selected, total_work, mask).
  7. ReplayTimes median direction is fine (cost.rs:498-510): len == 1 → ordered[0], even counts average the middle pair; no count/2 vs (count-1)/2 inversion, and a fresh single probe correctly resets the ring (if !fresh { self.ring.reset() }).
  8. is_non_terminal_prefill_step binary search is well-founded — scheduler.rs:897-899 sorts the packed catalog by (kind as u8, batch, width, packed) and scheduler.rs:950-953 searches exactly that key; validate_mixed (scheduler.rs:436-471) and commit (scheduler.rs:2576-2617) agree on the geometry they accept, and commit validates before any mutation.
  9. server/runtime.rs:846-900 catalog partitioning is disjoint: solo catalogs are filtered to batch_capacity == 1, packed to matches!(kind, Prefill | TerminalPrefill) && batch_capacity >= 2, so no shape is double-registered.
  10. Python/Rust predicate parity holds for all nine geometry predicates except the two noted in F5/F6; type(...) is not int at execution.py:78 correctly rejects True; the direct-mode key isolation in ignition/direct/scheduler.py:194-202 cannot double-register (B==1 → 3-tuple, B>=2 → 4-tuple, disjoint branches) and packed_shapes (scheduler.py:316-318, len(key) == 5) correctly keeps packed prefill keys out of Policy.packed_catalog.
  11. external_extents test-compile fix is complete — the field is new in this changeset (runtime_core/format.rs:24-36), so no pre-existing Core { … } literal could have been missed.

Sub-agent claims I discarded after verification

Notes