Correctness and contracts scratchpad · NVIDIA/hyperflare-inference #661

Raw Markdown for agents: https://autobot.eidonix.com/p/f66ead43-9df4-4bf7-8e7d-9a4d581f4358.md

#1 [high] Finding 1: resolve_prefill_kind widening to non-existent TerminalPrefill graphs (Major)

FILE: helios/src/scheduler.rs:899-907 (pr head 3d868f84)

let needs_terminal =
    end >= next_stop || (window > 0 && next_stop.saturating_sub(end) <= window);
if self.terminal_prefill_catalog.binary_search(&capacity).is_err() {
    return if request.deferred_prefill {          // <- was `&& needs_terminal`
        GraphKind::TerminalPrefill
    } else {
        GraphKind::Prefill
    };
}

needs_terminal is now computed and unused in that branch.

Consequences (all verified):

  1. On a subset core (PREFILL strict superset of TERMINAL_PREFILL — e.g. PREFILL 128..=16384, TERMINAL 256..=16384) every capacity absent from the terminal catalog (128 here) is classified TerminalPrefill while deferred_prefill is set. No such graph exists, so add_prefill_candidate (policy.rs:1433-1435 if work == 0 || self.resolve_prefill_kind(...) != kind { continue; }) drops the PREFILL(128) candidate, and costs.prefill_entry(TerminalPrefill,128) is None so no TerminalPrefill(128) candidate appears either. The complete-state small PREFILL graphs become unusable for the remaining chunks of a deferred prompt.
  2. helios/model-contract.md:182-186 says: "Helios derives the tail-protection window from the prepared catalog as the largest PREFILL capacity absent from the TERMINAL_PREFILL catalog; those smaller PREFILL graphs execute complete continuation state." Those graphs are contractually complete-state (safe to run, and to finish, while continuation state is deferred), so denying them is a contract-level change, not a scheduling detail.
  3. service.rs:302-319 prices a request from resolve_prefill_kind_from; for capacity 128 it now yields TerminalPrefill, prefill_duration returns None (cost.rs:654-667 -> self.entry(key)?), so the measured Prefill(128) contributes no token rate to ServicePrice, where previously it did. Service price feeds token_log/rebase fairness (policy.rs:786-797), so cross-request fairness normalizers change silently.
  4. Policy-independent: no policy field gates it, so --scheduler-policy throughput (PolicyConfig { delivery_fairness: 0.0, decode_age_price: 0.0, ..default } policy.rs:50-52) is not an escape hatch for (1)-(3).
  5. Only synthetic catalogs exercise it (policy_tests.rs:8268-8280, 8734-8820); verification/helios-lifecycle/check.py:527-535 now enshrines the widened rule as a mutation target.

Fix: keep needs_terminal in that branch, or exclude only capacities where the PREFILL graph is not complete-state (i.e. where a TerminalPrefill shape exists), and add a subset-catalog test (PREFILL 128..2048 / TERMINAL 256..2048) asserting the deferred tail still has a legal chunk.

#2 [high] Finding 2: interpolated estimate displaces natural-fit zero-duration discovery (Major risk)

FILE: helios/src/scheduler/policy.rs:518-543 (prefill_candidate_ns)

if age_price > 0.0 && plan.nat_fit.is_some_and(|nat| capacity <= nat) {
    let interp = match *last_interp { ... self.costs.interpolated_prefill_duration(kind, capacity, work, request.scheduled_consumed) ... };
    if let Some(ns) = interp { return Some(ns); }
}
(plan.nat_fit == Some(capacity)).then_some(0)

The interp branch is evaluated before the natural-fit Some(0) marker, and the condition capacity <= nat includes capacity == nat. Before this PR, when predictor was None the code required natural_fit_prefill_capacity(...) == Some(capacity), i.e. exactly the nat-fit capacity kept duration_ns == 0.

ValueRate::compare (utility.rs:167-172) ranks by (duration_ns == 0).cmp(&(other.duration_ns == 0)).then(score) — a zero-duration candidate strictly outranks every measured candidate. Returning a positive interpolated ns for the nat-fit capacity removes that precedence precisely in the situation this PR targets (age-priced streams active). Consequences:

Fix: test capacity == nat_fit first and keep Some(0) for it, interpolating only capacities strictly below nat-fit; or add a test that with an active age-priced decoder the nat-fit shape is still the first candidate executed (measured) within N planning passes.

#3 [high] Research summary

Reviewed PR #661 (head 3d868f84) through the correctness/contracts/system-consequences lens, opening every Rust production change (scheduler.rs, scheduler/cost.rs, scheduler/policy.rs, scheduler/service.rs) plus their direct callers (cost.rs lookup/observe paths, refresh.rs, checkpoints.rs cost/cut selection, utility.rs ValueRate/prefill_within), the new tests in policy_tests.rs and cost.rs, and the doc/contract files the change touches (docs/scheduling-runtime-design.md, docs/scheduling-theory.md, helios/README.md, helios/model-contract.md, verification/helios-lifecycle/check.py).

Two substantive findings, both saved to the scratchpad with verbatim quotes and line citations:

  1. resolve_prefill_kind_from widening (Major). scheduler.rs:899-907 now returns TerminalPrefill for every capacity absent from terminal_prefill_catalog whenever deferred_prefill is set (needs_terminal is computed and then unused in that branch). On any subset catalog this classifies complete-state small PREFILL shapes as a non-existent TerminalPrefill: add_prefill_candidate drops the legal candidate and service_rates (service.rs:302-319) drops that capacity's measured rate, silently shifting ServicePrice fairness normalizers. It contradicts helios/model-contract.md:182-186, is policy-independent (so --scheduler-policy throughput is not an escape hatch), is covered only by synthetic catalogs, and is now enshrined in check.py:527-535.

  2. Interpolated estimates displace natural-fit zero-duration discovery (Major risk). policy.rs:526-542 evaluates the interpolation branch before the nat_fit == capacity Some(0) marker and the guard is capacity <= nat, so exactly the nat-fit capacity loses the duration_ns == 0 precedence of ValueRate::compare (utility.rs:167-172) whenever age pricing is active — i.e. the case the PR targets. The graph may never be executed, so it never becomes measured, breaking #538's discovery invariant; combined with the new global prefill drain (scheduler.rs:1187-1190) a suboptimal Discovery plan now also cannot pipeline. The PR's own cost test only asserts the zero-age direction, and no policy test covers nat-fit precedence under age_price > 0.

Areas I checked and found sound: the u128 interpolation arithmetic and non-monotonic clamp (cost.rs:695-776), last_interp memo keying and per-capacity reset, is_unmeasured_candidate never mis-tagging a measured candidate as Discovery, the age-priced resize_prefill cap that can only shrink (policy.rs:1838-1853), the cached terminal_prefill_window (recomputed on both catalog setters, so no stale-state path), preserves_first_output_wait's new branches, and the reconciled interior-cut credit (guarded by end == prompt_tokens, deferred_prefill, positive first_output_value, and fits_single_prefill_from). Platform parity is a non-issue: the change is single-threaded scheduler math with no new unsafe, I/O, or OS-specific path.

#4 [medium] Areas verified sound in PR #661 (no finding)

Verified at head 3d868f84 and found sound (do not report as issues):

#5 [medium] Contracts/docs/tests touched by #661 (citations)

Citations the final report needs:

CONTRACT

CODE UNDER REVIEW

TESTS

DOCS