Correctness and contracts report · NVIDIA/hyperflare-inference #663

Raw Markdown for agents: https://autobot.eidonix.com/p/8bbdb50b-1d9c-4ee2-b351-669e2dd776f7.md

PR #663 — Correctness, Contracts & System-Level Consequences review

Head a5c36978 (base a3c80e19), 11 files, +511/−40. Files opened in full context: helios/src/scheduler/policy.rs, utility.rs, service.rs, scheduler.rs, helios/src/server/runtime.rs, helios/src/server/metrics/scheduler.rs (not opened), helios/src/scheduler/policy_tests.rs, tests/test_scheduling_utility.py, scripts/scheduling_sim/utility.py, ignition/direct/policy.py, docs/scheduling-utility.md, docs/scheduling-runtime-design.md, docs/scheduling-theory.md, docs/cli-design.md, flare-cli/src/cli.rs.

Key findings

  1. Blocker — the PR inverts an explicit documented invariant it does not update, on a shipped default. docs/scheduling-theory.md:850-853 still states "First-token waiting has no independent age penalty"; the credit is gated on decode_age_price = 0.1 in PolicyConfig::default() and balanced is the CLI/docs default, so every default deployment changes behavior with no knob and no doc correction.
  2. Major — the new clock is unobservable. RequestAccounting::first_output_wait_ns (policy.rs:59) is never published in RequestDetail (metrics/scheduler.rs:55-70 (not opened)), unlike last_progress_ns and last_output_ns. Operators cannot confirm or debug the new default-affecting term.
  3. Major — two existing regression tests were converted from relative guarantees to absolute ceilings, described in the PR only as "updated the burst-coalescing isolation tests" (tests/test_scheduling_utility.py:388-395, policy_tests.rs:6843-6862).
  4. Major — b_served * T_dec can be sourced from a Mixed graph, not a Decode/Speculative round as both docs and the PR text claim: service.rs:150-160 feeds mixed shapes into the same best[], and service.rs:168-173 promotes that value into best_decode. On mixed-capture cores (the Qwen3.8 Flash recipe, i.e. the PR's own second served A/B vehicle) the credit's duration can include prefill work.
  5. Major — the Python "mirror" does not implement the two novel mechanisms. scripts/scheduling_sim/utility.py:251-259 uses now_ms - view.last_service_ms, with no first_output_wait_ns, no anchor-cut preservation and no readmission clamp, plus a view.weight factor Rust does not have. The 21/21 trace-identity and "zero regressions" simulator evidence therefore covers the credit term only, not the "double stall" that motivates the PR.
  6. Minor — ignition/direct/policy.py:114-142 (Accounting, LaneValue) mirrors the same structs and gained neither field; Minor — the new prefill credit stacks with coalescing_prefill_log_bonus with no test bounding the combination; Minor — no lifecycle/TLA fixture for first_output_wait_ns; no oracle (prefill_wait_price) comparison; no SM120 run.
  7. Verified sound: no race, panic, unbounded-buffer or lock-contention hazard. The scheduler is single-threaded (&mut self), the decode-batch value rides an existing single pass with two float comparisons per slot and no new allocations, and the anchor predicate short-circuits cheap checks before its O(catalog) scan.

1. Correctness, Safety & Platform Parity

Finding 1 (Blocker): shipped default behavior change that contradicts an unchanged contract document

docs/scheduling-theory.md:847-853 (not among the PR's 11 changed files):

The ongoing policy uses separate intrinsic output value, token fairness,
delivery fairness, and decode-age coefficients. Their concrete defaults and
units are specified in the [native design](scheduling-runtime-design.md).
First-token waiting has no independent age penalty: prompt work competes by
its useful progress and token-service price. A burst earns its accepted token
volume and one delivery. The delivery reference accounts for feasible batching;
changing a rate normalizer preserves marginal service prices across phases.

The PR adds exactly the penalty that sentence forbids, gated on the shipped default coefficient — helios/src/scheduler/policy.rs:29-35:

    fn default() -> Self {
        Self {
            output_token_value: 64.0,
            token_fairness: 16.0,
            delivery_fairness: 4.0,
            decode_age_price: 0.1,

policy.rs:50-52 only zeroes it for throughput. docs/cli-design.md:683-685 and flare-cli/src/cli.rs:859-861 (default_value = "balanced", cli.rs:546) make balanced the default everywhere.

Impact: scheduling-theory.md is a maintained normative doc (last touched by #540); per AGENTS.md (not opened)/design-review practice, a shipped-default policy change that contradicts a normative sentence needs either that sentence amended or maintainer sign-off, and the same sentence was raised as a blocker against the competing opt-in design (#654) — which at least had a switch. Reviewers reading only the theory doc will conclude the default is unchanged when it is not.

Fix: amend docs/scheduling-theory.md:850-853 in this PR to describe the first-output credit and its default coefficient (mirroring the new text in docs/scheduling-utility.md:287-318), and either state explicitly why no operator knob is required or route the default change for maintainer sign-off in the PR description.

Finding 2 (Major): the new scheduling clock is absent from every observability surface

helios/src/server/metrics/scheduler.rs:55-70 (not opened) RequestDetail:

pub last_progress_ns: u64,
pub last_output_ns: Option<u64>,

populated at helios/src/server/runtime.rs:1231-1240 (last_progress_ns: accounting.last_progress_ns, last_output_ns: accounting.last_output_ns,). The new field is declared at policy.rs:59 (pub first_output_wait_ns: u64,) and drives a permanent ordering change in the default policy, but never appears in RequestDetail.

Impact: an operator observing a starved prompt, or a maintainer validating the anchor-cut preservation on real hardware, has no way to read the clock that decides the outcome. This is the metric/observability span check for this PR: the value being sampled changed (a second wait clock now decides prefill ordering) while the exported diagnostic set did not grow, so all existing diagnostics under-report the new mechanism. It also worsens the "silent default change" problem in Finding 1.

Fix: add first_output_wait_ns next to last_output_ns in RequestDetail and populate it at runtime.rs:1231-1240; one line each, no new struct or protocol.

Finding 3 (Minor): last_output_ns clamp does not cover every readmission path (benign, but the doc overclaims)

docs/scheduling-utility.md:301-304 states A_first is "anchored to the most recent output publication across preemption/readmission":

Here `A_first` is elapsed milliseconds since the prompt's first-output wait
clock (`first_output_wait_ns`, initialized at arrival, advanced on committed
progress, projected across any queued in-flight prefill submission, and
anchored to the most recent output publication across preemption/readmission).

The clamp is applied only where Carried::last_output_ns is Some (runtime.rs:1575-1577 calling set_first_output_wait(handle, last_output_ns); policy.rs:279 clamps to max(wait_ns, arrival_ns) and requires last_use == Fence(0)). The generic requeue() path (runtime.rs:2931-2958) reuses active.carried, so a request that was never parked readmits with last_output_ns: None and receives no clamp.

Impact: low — the None case is the pre-output path where clamping is meaningless, so I could not construct a wrong-credit scenario. The accurate statement is "clamped to last_output_ns when one exists".

Fix: tighten the doc sentence rather than the code; the runtime behavior is correct.

Finding 4 (no issue found): hot-path cost, ordering and panic safety are clean — say so plainly

2. Unintended System-Level Consequences

Finding 5 (Major): the credit's T_dec reference can be a Mixed (prefill+decode) graph, contradicting both the docs and the PR text

helios/src/scheduler/service.rs:150-160 feeds mixed shapes into the same per-lane best[] used for delivery references:

            if matches!(kind, GraphKind::Decode | GraphKind::Speculative) {
                for &(batch, width, prefill) in &self.mixed_catalog {
                    if let Some(ns) = self
                        .costs
                        .shape_duration(GraphKind::Mixed, batch, width, prefill)
                        .filter(|ns| *ns > 0)
                    {
                        consider(ns, batch, mask);
                    }
                }
            }

and service.rs:161-181 then promotes that value into the decode reference:

            for (slot, reference) in references.iter_mut().enumerate() {
                let (per_delivery_ms, served) = best[slot];
                if mask & (1 << slot) != 0 && per_delivery_ms.is_finite() {
                    ...
                    if matches!(kind, GraphKind::Decode | GraphKind::Speculative)
                        && (per_delivery_ms < best_decode.0
                            || (per_delivery_ms == best_decode.0 && served > best_decode.1))
                    {
                        best_decode = (per_delivery_ms, served);
                    }
                }
            }

best[slot] is the minimum of T/served over pure decode/speculative shapes and mixed shapes, so the promoted b_served * T_dec can be a mixed-graph per-delivery time whose duration includes prefill work. The docs say otherwise — docs/scheduling-runtime-design.md:272-274:

Here `b_served * T_dec` is the fastest incumbent `Decode` or `Speculative`
round's work-time in stream-milliseconds (zero when no measured decoder is
active), `A_first` is elapsed milliseconds from `first_output_wait_ns`

and docs/scheduling-utility.md:292-295 ("T_dec is the measured duration in milliseconds of the decode or speculative graph minimizing T_dec / b_served").

Impact / reachability: inert on cores without mixed graphs; live on mixed-capture cores — docs/scheduling-runtime-design.md:27-29 names the only one, "the Qwen3.8 Flash recipe (ignition/recipes/qwen38, alias qwen3.8-flash) is the one that does", which is precisely the model used for the PR's second served A/B. Where a mixed shape wins T/served, the per-turn credit is inflated relative to the documented "decode round" reading, i.e. the prompt-displacement pressure is larger than the written contract, and the number is not comparable across cores. The arithmetic itself is right: best_decode.1 * best_decode.1 * best_decode.0 (service.rs:177-181) equals b_served * T_dec.

Related, same code: the reference is chosen as the catalog minimum over all capacities, not the round actually in flight, so "incumbent" is a mild misnomer even for pure decode; docs/scheduling-utility.md:289-292's "incumbent decode cohort's fastest round" carries the same imprecision.

Fix: either (a) restrict the promotion to pure decode — carry a separate best_pure_decode updated only from the non-mixed consider calls (i.e. skip the mixed loop for this accumulator) — or (b) redocument the term as the "fastest incumbent serving round, including mixed shapes", and report the served metric. (a) is a few lines and matches the doc text.

Finding 6 (Minor): the new prefill credit stacks with the coalescing bonus with no test bounding the combination

policy.rs:635-650 already rewards prefill coalescing (coalescing_prefill_log_bonus) on prefill lanes; policy.rs:729-752 now adds a waiting-age credit on the same lanes for the same prompt whenever a measured decoder exists, and policy.rs:768-769 scales the credit by unit while summing only value.age_price into the penalty term:

            values[slot].first_output_value =
                self.policy.decode_age_price * incumbent_decode_batch_ms * age_ms;

Impact: two independent prefill-favoring incentives now coexist for one prompt; the PR's own admission is that this changed burst behavior enough to require rewriting the isolation tests (Finding 7). Nothing in the suite bounds the sum of the two, so a future change to either coefficient can silently double prefill displacement of decoders. The credit is also outside scale (policy.rs:676-680, :753-756) and therefore outside the "positive scaling factor keeps large prices representable" invariant at docs/scheduling-runtime-design.md:286-289 — a u64 wait projected across many seconds times b_served*T_dec (tens of stream-ms) stays far from f64 limits, so this is a documentation/precision concern, not overflow.

Fix: add one Rust test asserting the combined prefill-vs-decode ordering for a burst that is simultaneously coalescing-eligible and age-priced, and state in scheduling-runtime-design.md that the credit is intentionally outside the shared scale factor.

Finding 7: no failure-propagation, contention or memory blow-up found — say so plainly

The change adds one f64 return value from an existing single pass and one u64 field per request. There is no cancellation/failure path introduced (first_output_value is recomputed per decision from immutable accounting, so a cancelled waiter cannot poison peers), no coalesced-buffer lifetime change, and no new I/O. Under K > B oversubscription the credit is bounded by min(B, K_dec) per the PR's formulation and by the gating at policy.rs:729-733, which I verified line by line. The one system-level behavior change that is real is intentional and disclosed: worse background decode tail latency at high decoder counts (p99 +95 ms DeepSeek K=16, and the author's own Qwen3.8 addendum p99 334.5→410.5 ms, max 511.6→662.6 ms).

3. Architecture, Contracts & Charter Compliance

Finding 8 (Major): existing regression assertions were weakened, reported only as "updated"

The PR says only "updated the burst-coalescing isolation tests to test zero-age / age_price = 0 arrivals where first-output waiting age is inactive". The actual edit in tests/test_scheduling_utility.py (@@ -361,30 +361,67 @@) removes the relative guarantees:

-    assert coal_ttft < base_ttft * 0.85, f"expected >=15% max TTFT reduction: {coal_ttft} vs {base_ttft}"
-    assert coal.trace[-1]["end_ms"] < base.trace[-1]["end_ms"] * 0.95
-    assert coal_sub <= base_sub // 2, f"coal_sub={coal_sub}, base_sub={base_sub}"
-    assert low_coal_sub < low_base_sub, f"low_coal_sub={low_coal_sub}, low_base_sub={low_base_sub}"

and replaces them with absolute ceilings:

+    assert coal_ttft <= 600.0, f"expected coalesced balanced max TTFT <= 600ms, got {coal_ttft}"
+    assert coal_sub <= 2, f"expected <=2 sub-batch rounds, got {coal_sub}"
+    assert low_coal_sub == 0, f"expected 0 low-acceptance sub-batch rounds, got {low_coal_sub}"

The Rust twin at helios/src/scheduler/policy_tests.rs:6843-6862 similarly reduces the simultaneous-burst case to:

    // On simultaneous arrivals, default balanced policy keeps zero sub-batch fragmentation.
    let (sim_coal_sub, sim_coal_full, _) =
        run_burst(PolicyConfig::default().coalescing_horizon_tokens, false);
    assert_eq!(sim_coal_sub, 0, "expected zero sub-batch fragmentation on simultaneous burst");
    assert!(sim_coal_full >= 120, "expected full B=4 decode rounds, got {sim_coal_full}");

with no TTFT or makespan assertion for the simultaneous case, which was the original test's entire point.

Impact: the coalescing guarantee (>=15% TTFT reduction, >=5% makespan, halved sub-batch rounds, strictly-better low-acceptance case) is now unenforced for the default policy; only a throughput-policy comparison retains the relative form. This is a real reduction in the suite's discriminating power on a code path the PR itself perturbs, and reviewers relying on the description will not see it.

Fix: name the loosening explicitly in the description, and add one trace-level A/B assertion that coalescing still never hurts under balanced (e.g. coalescing-enabled makespan <= coalescing-disabled makespan on the same synthetic trace) instead of dropping the comparison.

Finding 9 (Minor): ignition/direct/policy.py mirror drifts

ignition/direct/policy.py:115-120 documents the struct as "Helios's RequestAccounting and ServiceAccounting for one request" and carries arrival_ns, last_progress_ns, last_output_ns — but no first_output_wait_ns; :130-138 says "Mirrors utility.rs LaneValue" and carries no first_output_value. Partly excused by docs/scheduling-runtime-design.md:15-19 ("It reproduces the selection specified here only for decode rounds").

Impact: low — the direct path's stated scope is decode rounds — but the two structs that the PR extends in Rust now diverge from the file that claims to mirror them, so a future debugging session comparing the two will mislead.

Fix: add the fields with a one-line comment that the direct path does not score first-output waiting, or note the exclusion in the docstring next to Accounting.

Finding 10 (Minor): charter evidence gaps — no oracle comparison, no SM120

docs/design-review.md:195-208 (not opened) requires graph-selection/service-pricing changes to be evaluated against "the Python simulator and reference solvers in scripts/scheduling_sim". The PR evaluates simulator workloads but not the oracle, whose prefill_wait_price (c_first) / F machinery (docs/scheduling-oracle.md:69-74 (not opened), --prefill-wait-price default 0 at :206-207) is the reference solver for exactly this term. Hardware coverage is SM121 GB10 only, while the charter's supported matrix names SM120 and both peer PRs #660 and #661 ran it. No linked issue or Fixes # exists for the reported symptom, against a charter that lists a filed reproducible bug or measured perf issue among merge grounds (the evidence itself is strong and served, two models).

Fix: add an oracle run at a nonzero --prefill-wait-price on one reference workload, and either run one SM120 A/B or state explicitly that the code is measurement-free on that path (it is: no new graph kind, no new arithmetic hazard).

4. Tests & Claim Accuracy

Finding 11 (Major): the "mirrored the same zero-knob formula in UtilityScheduler" claim does not cover the mechanisms the PR exists for

scripts/scheduling_sim/utility.py:251-259:

        if self.config.age_price > 0 and incumbent_decode_batch_ms > 0:
            for view in views:
                if view.remaining_prefill > 0 and view.output_budget > 0:
                    age_ms = now_ms - view.last_service_ms
                    if age_ms > 0:
                        self._first_output_value[view.name] = (
                            unit * self.config.age_price * view.weight
                            * incumbent_decode_batch_ms * age_ms
                        )

against Rust policy.rs:745-751:

                values[slot].first_output_value =
                    self.policy.decode_age_price * incumbent_decode_batch_ms * age_ms;

Three concrete divergences: (a) the Python clock is now_ms - last_service_ms with no first_output_wait_ns, so the anchor-cut preservation and the readmission clamp are not modeled at all; (b) view.weight has no Rust analogue (harmless only because the supplied workloads use weight 1 — cf. docs/scheduling-oracle.md:44-45 (not opened)); (c) the initial_prefill denominator differs (utility.py:158-162 vs utility.rs:99-110). scripts/scheduling_sim also has no checkpoint/anchor modeling, so "21/21 exact trace identity" and "zero regressions" are statements about the additive term alone.

Impact: the PR's primary evidence cannot detect a regression in the "double stall" fix that motivates half the description, and there is no test asserting the Python value numerically equals the Rust value (the Python test asserts only TTFT < 400 and an empty dict at price 0). Also missing: no served A/B separates the credit term from the anchor preservation (the 0.05 vs 0.0 pair differs in the baseline TTFT, 5,265 vs 4,656 ms, as well as in splitting), and the two adversarial simulator checks (consec_pre = 1 at 32 dec/B=4; exact parity at 4 dec/B=1) are reported numbers with no committed test.

Fix: (1) either implement first_output_wait_ns-equivalent clocking plus anchor modeling in the simulator, or narrow the description to "mirrors the credit term"; (2) add one cross-language test asserting the same numeric first_output_value for one synthetic state; (3) commit the two adversarial cases as simulator tests; (4) add one served A/B with checkpoint_extra_work_fraction = 0.0 and the credit disabled to isolate the anchor term.

Finding 12 (Minor): formal checks re-run unmodified models; the new accounting state has no fixture

verification/helios-lifecycle/check.py (not opened) is not among the 11 changed files (unlike peer PR #660), so "10/10 TLC models, 8/8 observed Rust trace checks, 594,065 transitions" re-verify unchanged models. first_output_wait_ns introduces a second per-request clock that survives preemption/readmission — exactly the kind of state a lifecycle fixture would pin — and none was added. Kani is disclosed as not run, which is defensible since no completion-vector/validator code changed.

Fix: add a first_output_wait_ns conservation fixture (monotone within a scheduling epoch, reset at admission, clamped to last_output_ns at readmission) so the invariant is machine-checked rather than Rust-unit-checked only.

Inaccurate PR-description claims (verified against the diff)

Open questions / not found

  1. Will a maintainer accept inverting docs/scheduling-theory.md:850 for a non-opt-in default, or must that sentence be amended first (the position taken against #654)?
  2. Is a silent default change acceptable under "be explicit" given no metric exposes first_output_wait_ns (Finding 2)?
  3. Which T_dec reading is intended when a mixed-capture core is loaded — pure decode or best serving round (Finding 5)?
  4. How much of the 5.9×/5.0× TTFT gain is the credit versus the anchor-cut preservation? No artifact separates them.
  5. Merge-order risk: policy.rs, both docs, scheduling_sim/utility.py and test_scheduling_utility.py are open simultaneously in #654, #661 and this PR, and #654/#663 are alternative designs for the same term — whichever lands first makes the other's diff much harder. #655 (same author, "Ready To Merge") overlaps the complete_inner region of scheduler.rs:2690 and docs/scheduling-runtime-design.md.
  6. Not found: any linked/filed issue for the symptom; any SM120, multi-host, alternate cache-scheme or alternate parallel-layout validation; any independent replication of the timing numbers; any oracle-solver run for this price term.