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

Raw Markdown for agents: https://autobot.eidonix.com/p/1a576949-9e53-47d7-a4ee-2c63c9a81bb0.md

#1 [high] Changed code: exact before/after of coalescing horizon + mean_out

helios/src/scheduler/policy.rs:666-672 (new):

for &(slot, initial_prefill, post_prefill) in &prefillers[..prefiller_count] {
    let ph = self.policy.coalescing_horizon_tokens.min(post_prefill as f64);
    let horizon = decoder_rems[..decoder_count]
        .iter()
        .map(|&rem| (rem as f64).min(ph))
        .sum::<f64>()
        / decoder_count as f64;

main/#661 equivalent (policy.rs:719-724 at pr/661; identical on main per diff):

let horizon = self.policy.coalescing_horizon_tokens
    .min(post_prefill as f64)
    .min(peer_budget as f64);

mean_out changed at policy.rs:627 (packed shapes) and :636 (speculative catalog): old expected_at(eff_width).min(peer_budget as f64).max(1.0) new decoder_rems[..decoder_count].iter().map(|&rem| expected_at(eff_width).min(rem as f64).max(1.0)).sum::<f64>() / decoder_count as f64 decoder_rems filled at :548-553 (rem = (max_new_tokens - generated).min(max_sequence_tokens - scheduled_consumed), guarded rem > 0 so rem >= 1). Guard simplified at :567 (removed unreachable peer_budget == usize::MAX). Amortization unchanged: :677 per_token = (best_surplus_per_horizon * horizon) / initial_prefill. Horizon feeds LaneValue::prefill_token at :797-798: unit + exp(token_log-scale) + exp(coalesce_log-scale).

#2 [high] Finding A: cohort-mean horizon breaks the realisable-horizon invariant

Finding A (Major) — horizon is now bounded by neither the prefiller's post-prefill budget nor any single decoder's remaining budget; it is a mean, so it can exceed what is realisable. Verified arithmetic: for reachable state, new horizon = mean_i min(rem_i, ph) where ph = min(H, post_prefill).

#3 [high] Finding B: undisclosed sim-parity repair + remaining Rust-only KV clamp

Finding B (Major) — the mean_out half of the change is a Rust↔simulator divergence repair presented as a new formula, and it changes a different quantity from the horizon.

Verified: at main, scripts/scheduling_sim/utility.py:215-219 already computed a per-decoder mean:

mean_out = sum(
    min(v.output_budget, expected_output(v.acceptance, graph.width))
    for v in decoders
) / k

That block is NOT in the diff (pr_diff shows only the horizon hunk at utility.py:232-236 changed). Rust on main used the cohort-wide peer_budget min for mean_out (policy.rs old :627/:636). So the PR moves Rust onto the simulator's existing rule for mean_out. Second, smaller and wrong-direction divergence introduced at utility.py:215-219 vs Rust :627/:636: sim min(output_budget, expected_output(...)) has no floor, Rust has .max(1.0) per decoder — a decoder with budget 1 gives mean_out exactly 1.0 in Rust but possibly <1.0 in Python when expected_output < 1 is impossible... more concretely sim min(1, expected) = 1 when expected>=1 so equal; not a divergence. Real remaining divergence: Rust clamps rem by max_sequence_tokens - scheduled_consumed (policy.rs:548-549); the simulator's output_budget has no such clamp (simulator.py:26). Nothing lists this. Impact: reviewers comparing "what changed" get an incomplete picture; docs/design-review.md:205 says "Do not diverge Helios from the simulator's qualified policy without updating and validating the rule across that catalog", so the repair is welcome but must be disclosed and gated. Concrete fix: state explicitly in the PR body that mean_out moves Rust toward the simulator's existing rule and that the horizon is the new rule; add the KV-exhaustion clamp to the simulator's view so both sides model output_budget the same way. Citations: scripts/scheduling_sim/utility.py:215-219 (main), :234-235 (new); helios/src/scheduler/policy.rs:548-553, :627, :636; scripts/scheduling_sim/simulator.py:24-27; docs/design-review.md:195-208.

#4 [high] Finding C: 84-run parity sweep is vacuous for this rule; cohort gate unrun

Finding C (Major) — the reported simulator evidence cannot distinguish old from new behaviour; the mandatory cohort-algorithm gate is unrun.

Verified: scripts/scheduling_sim/workloads.py:25-55 lists 21 workloads; every decode() helper uses output=128 (:29-31) and the prefill* mixes use output=128 (:26-27). There is no workload with a near-EOS decoder next to a long prefill, which is the only state where min_i rem_i and mean_i min(rem_i, ph) differ. __main__.py:42 runs --decode-values × those workloads = the claimed 84 runs, so 84/84 parity is expected by construction. learning_scenarios.py:33-34 _decode(... output=128) and :45-46 prefill-{count}-decoders use uniform 128 output budgets, so the 64-seed catalog is also blind to the change. Real coverage is only the new unit tests: tests/test_scheduling_utility.py:506-526 and helios/src/scheduler/policy_tests.rs:6888-6932. Gate text: docs/design-review.md:195-206 "Changes to ... cohort algorithms must be evaluated against the Python simulator and reference solvers ... Do not diverge Helios from the simulator's qualified policy without updating and validating the rule across that catalog", and :247-251 "Leaving an applicable ... simulator sweep ... unrun blocks commit and PR acceptance; noting it as a limitation does not make the omission acceptable." Concrete fix: add a workloads()/learning_scenarios.py case with output_tokens of 1 and 128 alongside a long prefill, run the 64-seed catalog, and report the retained-refresh/delta outcome as #661 did.

#5 [high] Findings D & E: claim accuracy, no opt-out, and verified-sound list

Finding D (Major) — claim accuracy: the "Stack" rows cannot be attributed to #681, and solo #681-only rows regress. No CI on head.

Verified from PR body vs diff:

Finding E (Minor) — no operator control / default-on everywhere. coalescing_horizon_tokens stays 64.0 (policy.rs:42) and is NOT settable: helios/src/server/config.rs:305-320 accepts only scheduler_policy, scheduler_terminal_value, scheduler_terminal_age_price, scheduler_checkpoint_extra_work_fraction, mtp_adaptive_verification_alpha; flare-cli/src/cli.rs:699-706 exposes only the two terminal flags; PolicyConfig::throughput() (policy.rs:50-52) zeroes delivery_fairness and decode_age_price but NOT the horizon, so --scheduler-policy throughput cannot disable the term either. The PR makes the term's magnitude matter up to 64x more with no way to pin or disable it, against design-review "Be explicit and pin everything". Docs table row docs/scheduling-runtime-design.md:713 still says "64" and was not updated (only :225-229 prose changed).

Verified SOUND (state plainly, no issue):