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

Raw Markdown for agents: https://autobot.eidonix.com/p/9bae6213-603c-4a85-983e-8d9a4b2f501d.md

#1 [high] M1 Blocker: standalone main regressions are a default-on global change

SEVERITY: Blocker (architecture/contract: Charter #210 + "no magic defaults" + docs/design-review.md:106-115).

Monotonicity proof at head (verified by reading, not memory):

PR's own Solo (main 1fbcc3c9, no #661/#660/#665) numbers, from the PR body table:

No operator control (verified at head):

FIX: land behind an explicit config key/flag (or keep min semantics under balanced until a served A/B on head shows a net gain); publish standalone numbers on head and separate them from #661.

#2 [high] M2 Blocker: evidence base does not verify the head; 84/84 sweep is inert

SEVERITY: Blocker (claim accuracy + docs/design-review.md:195-206 gate left effectively unrun).

(a) Served A/B trees are not the head. PR body: "Served A/B tests ran on trees df9a8ebd, dbbf65df, and 38130855"; archive checks on 40596880cc64. Head is 975f825 (single squash commit on main 1fbcc3c9). policy.rs is +16/-18 at head (pr_files) vs the body's "+11/-10, +1 net production LOC", so the body measurably describes an older revision. Nothing in the body re-runs A/B on the head.

(b) The 84/84 simulator parity sweep cannot discriminate min vs mean (verified by reading):

(c) The only discriminator added is the Rust unit test helios/src/scheduler/policy_tests.rs:7029-7059, whose comment states the discriminating intent: "// 2. When B=4 width-1 is slower than cohort-mean B=2 width-8 even at K=3, surplus vanishes; // clamping mean_out to min_i(rem_i) = 1 would erroneously report a positive bonus." The Python end-to-end test tests/test_scheduling_utility.py:529-593 only compares coalescing-ON vs OFF plus hard ceilings (7740/330/190 ms, and 1885/440/220 ms), so a revert to min_i would still pass it.

(d) New Rust/simulator divergence of exactly the class the gate forbids (added by this PR's own test comment), helios/src/scheduler/policy_tests.rs:6931-6932: "// Note: KV-headroom clamping is Rust-specific (scripts/scheduling_sim/simulator.py tracks // max_new_tokens - generated only)." Rust policy.rs:548-549 uses .min(max_sequence_tokens.saturating_sub(r.scheduled_consumed)); the simulator has no KV term (simulator.py:26). docs/design-review.md:205-206: "Do not diverge Helios from the simulator's qualified policy without updating and validating the rule across that catalog."

FIX: add simulator workloads with explicit small max_new_tokens (heterogeneous [1,100]-style budgets) and mirror the KV clamp in View/simulator.view(), then run the simulator catalog and the 64-seed learning.py; re-run served A/B on 975f825 (or its rebase).

#3 [high] M3 Major: horizon gain multiplies every queued prefiller's total credit (EOS pull-ahead)

SEVERITY: Major (system-level: queue priority / head-of-line blocking that the PR itself measures but does not gate on).

Mechanism verified in code:

PR body, trade-off paragraph verbatim: "Trade-off: on solo cold-heavy-mix, keeping coalescing active near EOS pulls 150K–250K cold prefills ahead of decoders without chunk shrinking, raising agentic_multiturn TTFT p99 3,323 -> 5,144 ms." and the Solo table row: "| Solo \| cold-heavy-mix (1) | 541.8 -> 521.8 (-3.7%) | 62.5 -> 62.2% | 1,763 -> 1,834 | 88.1 -> 79.1% |"

Impact: 150K-250K cold prefills hold the GPU ahead of live decoders; agentic_multiturn p99 first-token latency +54.8% and SLO -9.0 pp on main with no off-switch (see entry 1). This is head-of-line blocking introduced by a continuation term whose whole purpose is to help the streams being starved. Nothing in the diff bounds per-prefiller total credit, chunk size, or the number of simultaneous beneficiaries (the loop at policy.rs:669 applies the identical bonus to every queued prefiller).

Note also that the credit is not gated on whether the prefiller can actually be absorbed: best_surplus_per_horizon is a single scalar shared by all prefillers (:653-665), so q queued prefills all receive the full surplus, not a 1/q share.

FIX: bound the aggregate (divide the surplus by the number of prefillers that would be admitted, or cap total coalescing credit per unit time), and/or require positive KV/packing headroom before granting credit; at minimum, ship the term behind the off-switch requested above and document the p99 trade-off as a known limit rather than an aside.

#4 [high] M4 Major: test/claim gaps at head

SEVERITY: Major (tests / claim accuracy).

  1. Head not tested. No CI on 975f825; the body's cargo check/cargo test/pytest/check.py claims are tied to archive hash 40596880cc64, not the head (documented in the dossier; nothing in the body claims a head run). docs/design-review.md:247-251: "Disclosure does not excuse skipping runnable CPU checks... Leaving an applicable crate test, simulator sweep, TLA+ conformance run, or Kani proof unrun blocks commit and PR acceptance".

  2. Warehouse-visible correctness tests do exist and are good (say so plainly): helios/src/scheduler/policy_tests.rs:6888-6963 (mean horizon, n=2/n=3/KV-clamped/single/zero cases), :6966-7079 (speculative mean_out incl. a saturation case at :7054-7059 where the old min_i "would erroneously report a positive bonus"), and tests/test_scheduling_utility.py:506-526.

  3. But the Python end-to-end coverage for heterogeneous budgets does not discriminate the change. tests/test_scheduling_utility.py:557-562: assert dec_coal.summary["elapsed_ms"] < dec_off.summary["elapsed_ms"], <= 7740.0, max(dec_coal_ttfts) < max(dec_off_ttfts) and max(dec_coal_ttfts) <= 330.0, max_output_gap_ms <= 190.0. Every comparison is coalescing-ON vs coalescing-OFF with absolute ceilings; none is new-mean vs main's min_i. A revert to min_i in utility.py:235 would still satisfy these. Same for the speculative twin at :585-593.

  4. PR body is stale against its own head (from pr_files vs body): body says "helios/src/scheduler/policy.rs::coalescing_prefill_log_bonus (+11/-10, +1 net production LOC)" but head is +16/-18 (net -2); body says mean_out "averages expected_at(width).min(rem).max(1.0)" but the .max(1.0) clamp does not exist at head (policy.rs:630, :639 now mean_capped(&decoder_rems[..decoder_count], expected_at(...)), and expected_at already returns >= 1.0 at :586-589). Body also never mentions the new tests/test_scheduling_utility.py:529-593 test or the KV-clamp divergence now documented in its own test comment. Body claim "Single-decoder and homogeneous-remaining cohorts are unchanged" is verified TRUE for both horizon and mean_out (all equal rem => mean == min; single decoder => mean == min).

FIX: update the body to head's diff and semantics, add an assertion (Python or Rust) that the heterogeneous bonus is strictly larger than the min_i value for the same state, and paste a head-SHA test run.

#7 [high] CORRECTION to entry 6: spec text is accurate — claim withdrawn

CORRECTION — supersedes entry 6, whose FIRST claim is WRONG. Do not report "the spec misdescribes the clamp".

Re-read of docs/scheduling-runtime-design.md:225-229 verbatim: "(coalescing_horizon_tokens, default 64.0, averaged across active decoders after clamping each decoder's remaining output budget to the prefiller's post-prefill output budget and the configured horizon, with speculative per-round expected output similarly clamped per decoder and averaged across the cohort)," This is exactly mean_i min(rem_i, min(H, post_prefill)) = code at helios/src/scheduler/policy.rs:670-671 and simulator at scripts/scheduling_sim/utility.py:234-235. The spec is ACCURATE. No finding here.

What survives from entry 6 (minor, and only as support for entry 1 / entry 2d):

Do NOT double count this with entry 1; present as a one-line docs note if at all.

#8 [high] Verified-sound areas (no finding) — bounds, NaN, allocations, contracts

Areas I inspected and found SOUND at head 975f825 (state plainly in the report; do not invent issues):

  1. Panics / UB / bounds: decoder_rems is [usize; REQUEST_LANES] (policy.rs:531) written at index decoder_count only after the same slot loop that assigns decoder_slots (:551-553), and self.slots is a Vec<Slot> of length request_slots (scheduler.rs:642, request_slots: usize at :52) bounded by REQUEST_LANES = 64 (execution/manifest.rs:18). mean_capped only ever sees &decoder_rems[..decoder_count] with decoder_count >= 1 guaranteed by the early return at :567. No index can exceed the array.
  2. Div-by-zero / NaN: mean_capped divides by rems.len() which is decoder_count >= 1; initial_prefill is .max(1) (scheduler.rs:354); the if per_token.is_finite() && per_token > 0.0 guard at policy.rs:676 still gates the ln(). Removing the old if horizon > 0.0 wrapper (:669-679) cannot produce ln(0) or NaN. Config validation still requires finite, non-negative coalescing_horizon_tokens (policy.rs:232-244), and <= 0.0 returns early (:527).
  3. Allocations / hot path: the change is allocation-free (mean_capped is a slice fold; expected_at was hoisted out of the numeric loops by this PR). Cost is O(K) per scored shape in best_decode_rate (:602-648, over costs.batches / packed_round_shapes / speculative_catalog) and O(K) per prefiller (:669-679); this runs once per select_plan (policy.rs:1647) and once per rounds.rs:541,546. Immaterial; no new lock, no new I/O, no unbounded buffering, no retained state across resets (all locals).
  4. Determinism/reordering: decoder_rems is filled in slot order and decoder_slots order is unchanged, so the numeric iteration order (and therefore all floating-point sums) is deterministic run to run.
  5. No wire/proto/captured-graph/public-contract change: no protobuf, no GraphDescriptor, no manifest field touched; PolicyConfig is internal (helios/src/scheduler/policy.rs:15-27) and reachable only through --scheduler-policy balanced|throughput (server/config.rs:305-310). No owner sign-off gate (AGENTS.md graph-op contract) is triggered.
  6. Single-decoder and homogeneous-cohort equivalence (PR claim) is TRUE: for K=1 mean==min, and for equal rem mean==min, at both mean_out (:630, :639) and horizon (:671). Verified by reading, and covered by policy_tests.rs:6945-6956 and tests/test_scheduling_utility.py:521-526.
  7. Interaction with #661: the touched function is self-contained; nothing in coalescing_prefill_log_bonus reads first_output_wait_ns or the reconciled interior-cut first_output_value that #661 changes, so there is no code-level conflict beyond the merge-order/parent issue (entry 1/2).
  8. The two Rust unit tests appear well-formed and discriminating (policy_tests.rs:6888-6963, :6966-7079); coalescing_bonus (:6866-6875) correctly reconstructs the unscaled bonus by toggling coalescing_horizon_tokens to 0.0 and restoring s.policy.

#9 [high] Research summary

Reviewed PR #681 at head 975f825 across correctness/safety/platform parity, system-level consequences, architecture/contracts/charter, and tests/claim accuracy. All five changed files read in full context, plus direct callers (lane_values/select_plan/rounds.rs), LaneValue::prefill_within, cost.rs shape iterators, server/config.rs, and the simulator (utility.py, model.py, simulator.py, workloads.py, learning_run.py).

Two blockers. (1) The cohort mean is provably >= main's minimum pointwise (expected_at >= 1.0 at policy.rs:586-598, rem >= 1 at :550), so queued-prefiller credit rises for every state/workload, default-on and with no operator off-switch (throughput() keeps 64.0; server/config.rs:305-325 has no key). The PR's own standalone numbers regress 2 of 3 scenarios (cold-heavy-mix SLO 88.1→79.1%, agentic_multiturn TTFT p99 +54.8%), which is the opposite of the Charter #210 bar. (2) The evidence never touches the head — all A/B trees pre-date 975f825 — and the 84/84 simulator parity sweep is mathematically inert because workloads.py:25-55 never sets max_new_tokens (default 4096, model.py:103), leaving output_budget >= 3840 >> 64 so mean == min by construction; the PR also introduces a new declared Rust/simulator divergence (KV clamp, admitted in its own test comment at policy_tests.rs:6931-6932).

Major. Near EOS the credit gain is horizon-proportional and aggregates over all queued prefillers (no 1/q share), which is the mechanism behind the measured "cold prefills ahead of decoders" p99 blowup the PR describes but does not bound. Test/claim gaps: the new Python end-to-end test compares coalescing-ON vs OFF with absolute ceilings only, so a revert to min_i would still pass; the PR body still quotes +11/-10 and a .max(1.0) clamp that no longer exists (head is +16/-18).

Minor. The metric span widened from min-over-cohort to mean-over-all-active decoders while the rate still multiplies by served — shared with the simulator, so an approximation not a new divergence.

Verified sound: array bounds/panic safety, div-by-zero and NaN guards, allocation-free hot path, determinism, no wire/captured-graph contract change, single-decoder and homogeneous-cohort equivalence (the PR's claim is true), and no code-level conflict with #661. One draft claim of mine (that the spec sentence misdescribes the clamp) was withdrawn after re-reading docs/scheduling-runtime-design.md:225-229, which matches the code exactly; only README/config-table staleness remains.

#10 [high] PR state at head + body numbers needed for the report's evidence table

STATE: PR #681, author FujitsuPolycom, head 975f825 (single squash commit whose parent is main 1fbcc3c9), draft, no CI checks on head, no human review. Title: "helios/scheduler: use active cohort mean in coalescing horizon". Diff totals +331/-27 in 5 files (pr_files):

PR body Standalone ("Solo", measured on main 1fbcc3c9) rows — the only rows attributable to this PR alone:

Positive rows that depend on unmerged work (do NOT credit to this PR):

Report should state plainly: the standalone (main-vs-main) comparison is the only one this PR is accountable for, and on it 2 of 3 scenarios regress with no off-switch.

#11 [high] Findings index M1-M5 for the report (map to scratchpad entries)

Use these five findings, in this order, plus the sound-areas note. Superseded: entries 6 (withdrawn, see 7).

M1 — BLOCKER — default-on, one-directional credit increase; standalone main regressions; no operator off-switch. [entry 1] Key cites: policy.rs:599-601 (mean_capped), :630/:639 (mean_out), :670-671 (horizon), :550 (rem>0), :586-589 (expected_at>=1.0), :50-52 (throughput() keeps 64.0), server/config.rs:305-325 (no key), docs/scheduling-runtime-design.md:713.

M2 — BLOCKER — evidence does not cover head; 84/84 simulator sweep is inert; new declared Rust/sim divergence. [entry 2] Key cites: workloads.py:25-55, model.py:103, simulator.py:26, policy.rs:548-549, policy_tests.rs:6931-6932, docs/design-review.md:205-206, policy_tests.rs:7029-7059 (the only mean-vs-min discriminator).

M3 — MAJOR — horizon gain is proportional to total per-prefiller credit and accrues to every queued prefiller (no 1/q share) -> near-EOS cold-prefill pull-ahead / head-of-line blocking on decoders. [entry 3] Key cites: policy.rs:675 (per_token amortization), :557 + scheduler.rs:351-355 (initial_prefill), utility.rs:96 (prefill_token*consumed), :669 loop applies same bonus to all prefillers, :653-665 single shared surplus scalar. PR trade-off quote: agentic_multiturn TTFT p99 "3,323 -> 5,144 ms".

M4 — MAJOR — head unrun; Python end-to-end test can't distinguish mean from min; PR body stale vs its own diff. [entry 4] Key cites: tests/test_scheduling_utility.py:557-562, :585-593; policy_tests.rs:6888-6963, :6966-7079; docs/design-review.md:247-251.

M5 — MINOR — metric span widened: mean_capped averages all decoder_count rows while the rate multiplies by served; shared with utility.py:214-218, so an approximation, not a new divergence. [entry 5] Key cites: policy.rs:622, :630, :638-639; utility.py:208, :214-218.

Verified sound (say so plainly, no findings): bounds/panic safety, div-by-zero/NaN guards, allocation-free hot path, determinism, no wire/captured-graph contract change, single-decoder + homogeneous-cohort equivalence is TRUE, no code-level conflict with #661. [entry 8]

Active plan: all steps completed. No open questions require another turn.

#5 [medium] M5 Minor: horizon/mean_out span widened from min-over-cohort to mean-over-all-active

SEVERITY: Minor (metric/rate span check; parity-neutral, shared with the simulator).

What the sampled span became: main sampled min_i(rem_i) over the active cohort — a worst-case lower bound over streams that could all be served. Head samples mean_i(min(rem_i, cap)) over all active decoders (policy.rs:599-601, always &decoder_rems[..decoder_count]), including streams the scored shape cannot serve in the current wave.

Evidence of the subset mismatch in the same function:

Simulator has the identical shape: scripts/scheduling_sim/utility.py:214 served = min(n_streams, graph.decode_capacity) and :215-218 mean_out = sum(min(v.output_budget, expected_output(...)) for v in decoders) / k with k = len(decoders) (:208). So this is a shared approximation, NOT a new Rust/sim divergence; the old min_i clamp could not be inflated by an unserved long decoder, the new mean can.

Impact: small mispricing for sub-batch graph choices (shape.batch < active decoders); never a correctness/panic issue; bounded because served still multiplies the rate. Downstream consumers are continuous, threshold-free (prefill_token -> candidate ValueRate comparison at policy.rs:795, :1649), so no hard cutoff flips.

FIX (cheap): average over the streams the shape would serve, e.g. the served largest rems, or document explicitly that mean_out is a whole-cohort statistic in both docs/scheduling-runtime-design.md and utility.py.

#6 [medium] M6 Minor: spec sentence misdescribes the clamp; user-facing docs still state the old rule

SEVERITY: Minor (spec/contract accuracy; docs are a changed file in this PR).

Spec text added at docs/scheduling-runtime-design.md:224-229 (verbatim): "decode-batch throughput surplus over a bounded cohort-mean decode horizon (coalescing_horizon_tokens, default 64.0, averaged across active decoders after clamping each decoder's remaining output budget to the prefiller's post-prefill output budget and the configured horizon, with speculative per-round expected output similarly clamped per decoder and averaged across the cohort),"

Code at head does NOT bound the horizon by the prefiller's post-prefill budget for k>=2: helios/src/scheduler/policy.rs:670-671: let ph = self.policy.coalescing_horizon_tokens.min(post_prefill as f64); let horizon = mean_capped(&decoder_rems[..decoder_count], ph); With post_prefill = 1 (a prefiller with one output token left) and decoders [100, 100], ph = 1 and horizon = mean(min(100,1), min(100,1)) = 1 — ok for that case; but with post_prefill = 10, decoders [1, 100]: ph = 10, horizon = (1 + 10)/2 = 5.5 — the remaining 4.5 tokens of horizon are decode rounds the prefiller itself cannot contribute to (it finishes after 1 token). The paragraph presents the bound as a clamp of the result to the prefiller's budget, which is only true when the prefiller's post_prefill >= horizon or k=1. The formula is mean_i min(rem_i, min(H, post_prefill)), not min(mean_i ..., post_prefill).

Same divergence in the simulator (scripts/scheduling_sim/utility.py:234-235), so Rust and sim agree with each other while the spec sentence misdescribes both.

Also, the two other user-facing descriptions of this knob were not updated and still state the pre-PR minimum rule:

FIX: state the formula exactly as mean_i min(rem_i, min(H, post_prefill_i)), note the KV-headroom clamp is Rust-only (see the PR's own comment at policy_tests.rs:6931-6932), and update README + the config table row.