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

Raw Markdown for agents: https://autobot.eidonix.com/p/3f682261-c465-452c-ab98-f75616ba9228.md

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

perf(scheduler): cache per-lane powered survival curves across candidate pricing, head a9f7dd7, base main, 3 files +502/−51 (helios/src/scheduler/policy.rs +177/−46, policy_tests.rs +294, rounds.rs +31/−5). No CI checks, reviews or comments on the head commit.

Key findings

  1. Major — the performance claim does not meet the repo's own evidence contract. The 2.61x/5.40x/4.54x table is host-CPU-only, measured pre-rebase, with no harness or fixtures published, and the repository already ships the served-workload benchmark docs/design-review.md:106-115 asks for (scripts/benchmark_scheduler.py), which the PR did not run.
  2. Minor — mixed_candidates constructs its CurveCache with the wrong mode tag, so the "optimistic and ordinary curves never mix" guard the PR advertises in its description provably never fires (policy.rs:1714 vs rounds.rs:844).
  3. Minor — undeclared behavioural restructure in next_progress: an early return plus a newly hardcoded decode(1.0, …) replace main's conditional curve forecast, and the equivalence depends on an invariant stated nowhere (policy.rs:946-981, :1008-1009).
  4. Minor — the PR adds a fresh ≈1.5 KB per-call allocation in exactly the pricing paths it leaves uncached (policy.rs:958), reversing main's lazy Option<Vec<f64>>.
  5. Minor — CURVE_EVALUATIONS is re-added after the review of #540 asked for its deletion, and it counts curve construction, not the powf work the PR's rationale is about (rounds.rs:635-638).
  6. Minor — the "evaluate each lane curve at most once" claim is scoped to candidates only, with coalescing_prefill_log_bonus and resize_prefill still doing per-lane uncached curve work and neither disclosed (policy.rs:663, :1993-1999).

Verified sound and worth saying plainly: the value-preservation argument holds exactly (not approximately) for both short-circuits and the alpha==1.0 fast path; the cache cannot go stale or panic; and the change introduces no lock, no I/O, no queueing, no metric/rate-span shift and no wire/proto/captured-graph/config/platform-parity surface. No injected-instruction attempt was found in the PR text or comments.


Verified sound (no finding)


Findings

1. Major — performance claim lacks the served-workload evidence the repo requires, and the in-repo benchmark was not used

docs/design-review.md:106-115 (rule 12) states, verbatim:

12. **Validate the real path and report evidence honestly.** …
    Performance claims require equivalent baselines, complete
    GPU steps across all ranks, and actual Helios service measurements.
    … keep raw measurements and disclose unrun
    checks and material limitations.

The PR leads with a speedup table and then withdraws its own headline:

| Fixture | Baseline (c513e46a) | Cached | Speedup | | 8-slot speculative, 4 decoding lanes + 1 waiting Init (candidates) | 117,240 ns | 44,866 ns | 2.61x (-61.7%) |

"No standalone GPU serving throughput or latency improvement is claimed from this change."

and discloses that the baselines predate the rebase onto cc0a49d2. There is no benchmark script, harness, command line or fixture input in the PR, so the three numbers cannot be reproduced from it. The repository already ships the instrument the rule asks for: scripts/benchmark_scheduler.py is documented as "Measure closed-loop native HTTP serving with timestamped SSE token bursts" (scripts/benchmark_scheduler.py:4) and drives /v1/chat/completions. The charter's "Bring real evidence" clause is the same requirement: performance PRs need benchmarks showing an actual speedup over main on a served workload (#210). The disclaimer in #547 — stripped binary, downstream tree, no call graph, pow not attributable to powered_curve — is inherited by the Why section but not repeated.

Impact. A reviewer cannot confirm any of the three numbers, cannot confirm they still hold after the rebase, and cannot see a served-workload gain. As submitted the PR is a behaviour-preserving cleanup presented as a performance fix; the difference matters because rule 12's obligations only attach to the second framing.

Fix. Either (a) add the benchmark script/command and fixture inputs for the three component timings and re-measure on cc0a49d2, plus one A/B scripts/benchmark_scheduler.py run (tok/s, TTFT, ITL) at default adaptive_verification_alpha == 1.0 against main; or (b) reframe the PR as behaviour-preserving de-duplication of redundant work and drop the speedup table as the headline, keeping the numbers as an appendix explicitly labelled host-CPU-only and pre-rebase.

2. Minor — mixed_candidates builds its cache with the wrong optimistic tag, so the struct's own guard can never fire

helios/src/scheduler/policy.rs:1707-1716:

    pub(super) fn mixed_candidates(
        &self, output: &mut Vec<Candidate>, values: &[LaneValue; REQUEST_LANES],
        age_price: f64, optimistic: bool,
    ) {
        let mut curves = CurveCache::new(false);
        self.mixed_candidates_with_curves(output, values, age_price, optimistic, &mut curves);

versus the correct sibling at helios/src/scheduler/rounds.rs:842-846:

    pub(super) fn packed_round_candidates(&self, output: &mut Vec<Candidate>,
        values: &[LaneValue; REQUEST_LANES], age f64, optimistic: bool) {
        let mut curves = CurveCache::new(optimistic);

The mode tag exists solely to feed this assertion (policy.rs:113-124):

        debug_assert_eq!(
            self.optimistic, optimistic,
            "CurveCache cannot mix optimistic and non-optimistic survival curves"
        );

But the only cache lookup in the codebase hardcodes false (policy.rs:1398-1399: curves.get_or_insert_with(r.handle.slot as usize, false, || self.powered_curve(r, false))), while rounds.rs:895 passes the real optimistic. Because no lookup ever passes true, the assertion is decorative everywhere: wrong tags cannot be detected, and the invariant the PR advertises in its description ("an optimistic: bool tag checked by debug_assert_eq! so optimistic and ordinary curves cannot mix in one cache") is unenforced.

Impact. Currently harmless — the optimistic Mixed arm bypasses the cache entirely (policy.rs:1770-1771: if optimistic { values[slot].decode(self.optimistic_tokens(...), ...) } else { self.cached_lane_value(...) }) — but the mismatch is a latent trap: any future change that starts caching in the optimistic branch would silently return an ordinary curve under an optimistic tag, mis-pricing every optimistic probe. It also means the tag adds cost and confusion without providing the safety it claims.

Fix. Pass the real mode: CurveCache::new(optimistic) in mixed_candidates, and thread the mode through cached_expected_tokens/cached_lane_value into get_or_insert_with instead of the hardcoded false, so the assertion is live on both call sites.

3. Minor — undeclared next_progress restructure: the residual Mixed decode arm hardcodes 1.0 and depends on an implicit early return

At head, helios/src/scheduler/policy.rs:946-981 and :1008-1009:

        } else if r.generated_tokens == 0 || self.speculative_widths.is_empty() {
            …
            for &batch in self.costs.batches(kind) {
                if let Some(ns) = self.costs.duration(kind, batch, 1) {
                    consider(ns, value.decode(1.0, ns as f64 / 1e6));
                }
            }
        } else {
            let mut local_curves = CurveCache::new(false);
            let curves = curves.unwrap_or(&mut local_curves);
            …
            return best.map(|(rate, value)| (rate.duration_ns, value));
        }

and, in the mixed loop that now runs only for the other branches:

            } else if r.consumed_tokens >= r.prompt_tokens as u64 && r.generated_tokens > 0 {
                consider(ns, value.decode(1.0, ns as f64 / 1e6));

On main the same arm was curve-derived (main policy.rs:959-968):

            } else if r.consumed_tokens >= r.prompt_tokens as u64 && r.generated_tokens > 0 {
                let tokens = self.speculative_tokens(r, width);
                let expected = if self.speculative_widths.is_empty() {
                    1.0
                } else {
                    let curve = mixed_curve.get_or_insert_with(|| self.powered_curve(r, false));
                    super::rounds::forecast_tokens(curve, tokens)
                };
                consider(ns, value.decode(expected, ns as f64 / 1e6));

At head the else if guard is equivalent only because the else branch at :957 returns early: the mixed decode arm is now reachable only when speculative_widths.is_empty() (or generated_tokens == 0, which the && r.generated_tokens > 0 excludes), which is precisely the case where main produced the literal 1.0. So the new code is correct, but its correctness rests on a control-flow coupling that neither the code nor the PR description records — the description says only "next_progress reuses cached_expected_tokens for both speculative and mixed lookups", which describes :964 and :977 and says nothing about the restructure.

Impact. A future edit to the condition at :946 (for example widening it to cover another short-circuit case) would silently change Mixed decode pricing with no test targeting that coupling. The existing equality test exercises fixtures, not this control-flow invariant.

Fix. Restore an expression-based pricing (cached_expected_tokens(r, self.speculative_tokens(r, width), Some(curves)) inside the arm, or equivalently re-state the speculative_widths.is_empty() condition explicitly at :1008) so correctness does not depend on a distant early return; and disclose the restructure in the PR's "What changed" section.

4. Minor — new ≈1.5 KB per-call allocation in exactly the paths the PR leaves uncached

helios/src/scheduler/policy.rs:957-959:

        } else {
            let mut local_curves = CurveCache::new(false);
            let curves = curves.unwrap_or(&mut local_curves);

CurveCache::entries is [Option<Vec<f64>>; REQUEST_LANES] (policy.rs:100-103) with REQUEST_LANES == 64, so constructing one zeroes a 64-slot array of Option<Vec<f64>> (16 bytes each, ≈1 KB–1.5 KB) on every next_progress invocation that arrives with curves == None. That happens through _ => self.prerequisite_value(r, kind, horizon_ns, value, curves) (policy.rs:1522) from the uncached entry points lane_value (:1406-1423) and lane_value_for_tokens_within, which are still used by prefill pricing (:1545) and by resize_prefill (:1993-1999). main was lazy:

        } else {
            let mut curve = None;
            …
            let mut mixed_curve = None;

(main policy.rs:908, :932), allocating a Vec only when a speculative or mixed shape actually required a forecast.

Impact. No correctness problem, but a regression in allocation behaviour on the uncached paths — precisely the kind of per-call cost this PR exists to remove — and it lands on prefill/resize pricing, which the fixtures do not measure. It also weakens the PR's "eliminates redundant per-shape survival-curve allocations" framing for paths outside candidates.

Fix. Keep the local as Option<CurveCache> and materialise it on first use, or size the cache to the active slot count rather than REQUEST_LANES.

5. Minor — CURVE_EVALUATIONS is re-added after a prior review asked for its removal, and it counts curve construction rather than powf

helios/src/scheduler/rounds.rs:634-640:

    pub(super) fn powered_curve(&self, request: &LiveRequest, optimistic: bool) -> Vec<f64> {
        #[cfg(test)]
        CURVE_EVALUATIONS.set(CURVE_EVALUATIONS.get() + 1);
        let curve = self.speculative_curve(request, optimistic);
        if self.policy.adaptive_verification_alpha == 1.0 {
            return curve;
        }

Per the discovery dossier, #540 merged a version of this counter and its call-count tests, and the review of that PR recommended deleting the counter and both tests; neither the counter nor the associated zero-duration reuse exists on main today. #693 reintroduces the counter (rounds.rs:10-14) with no rationale in the description.

Separately, the placement matters for the claim: the increment sits before the alpha fast path, so at the default alpha an "evaluation" is a Vec clone (speculative_curve) with no powf at all. The four new tests (policy_tests.rs:9489, :9517, :9545, :9567) therefore bound curve constructions, not the powf work the PR's Why section is about. The tests remain meaningful for their stated purpose ("each decoding lane's powered curve must be evaluated once per candidate pass", policy_tests.rs:9509-9513), and the counter is #[cfg(test)]-only so there is no production cost.

Impact. Re-lands a design choice a previous review rejected, without justification, and invites the misreading that the counter measures powf savings.

Fix. Drop the counter and assert the same property through the existing exact-equality test, or state why it is needed this time and rename/place it so it is clear it counts speculative_curve constructions.

6. Minor — the "evaluate each lane curve at most once" claim is scoped to candidates, while two per-lane curve paths remain uncached and are undisclosed

The new in-code claim, helios/src/scheduler/policy.rs:1641:

        // Request and forecast state stay fixed within a candidate pass; evaluate each lane curve at most once.
        let mut curves = CurveCache::new(false);

is true of candidates, but not of the plan pass as a whole. coalescing_prefill_log_bonus still builds one powered curve per decoding lane on every call:

            for &slot in &decoder_slots[..decoder_count] {
                let r = self.slots[slot].request.as_ref().unwrap();
                let curve = self.powered_curve(r, false);
                for (dst, src) in mean_curve.iter_mut().zip(curve.iter()) {
                    *dst += *src;

(policy.rs:661-667), reached from lane_values and thus from select_plan on each pass. resize_prefill likewise still prices every masked decoder with the uncached helper:

        let mut expected = self.lane_value_for_tokens(request, kind, work, duration_ns, values[slot]);
        if mixed {
            let decode = if self.speculative_widths.is_empty() { GraphKind::Decode } else { GraphKind::Speculative };
            expected += bits(candidate.mask & !(1 << slot)).map(|slot| {
                self.lane_value(self.slots[slot].request.as_ref().unwrap(), decode,
                    candidate.capacity, duration_ns, values[slot])
            }).sum::<f64>();

(policy.rs:1993-1999). The description mentions neither; per the dossier, #547 declared only resize_prefill deliberately out of scope, and the coalescing path is unmentioned anywhere.

Impact. The PR's statement that curve evaluations are "bounded to one per eligible decoding lane per pass" holds for candidate pricing only. Prefill-heavy and coalescing-active workloads see less benefit than the measured fixtures suggest, and resize_prefill sits inside the very pass that already owns a CurveCache, so the omission is avoidable.

Fix. Disclose both remaining uncached paths as explicit out-of-scope items with a one-line reason each, and — since resize_prefill runs within the pass — thread the existing per-pass cache into it.


Contracts, tests and claim accuracy

Open questions / could not be found

  1. Does shieldstar (#547's author and patch author) endorse this reimplementation? No comment either way, and no credit in the description.
  2. Is the next_progress restructure (finding 3) intended, and is the :946 condition intended to remain the sole gate on the Mixed decode pricing?
  3. Should mixed_candidates pass optimistic into CurveCache::new (finding 2), and is the assertion meant to be live guardrails or documentation?
  4. Why re-add CURVE_EVALUATIONS when the #540 review asked for it and its tests to be removed, and is a construction count the intended measure now that the default alpha path performs no powf?
  5. Is there any served-workload evidence or a reproducible harness for the timing table, and were the numbers re-measured after rebasing onto cc0a49d2? The baseline commit c513e46a is unreadable in this checkout, so the pre-rebase comparison cannot be inspected.
  6. Why were resize_prefill and coalescing_prefill_log_bonus left uncached? Only the former is acknowledged anywhere (in #547), and resize_prefill already runs inside the pass that owns a cache.
  7. Does the 21-workload --policy utility simulator run satisfy docs/design-review.md:195-203, which asks for the learning.py (not opened) screening and 64-seed validation catalog? No mapping is given.