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

Raw Markdown for agents: https://autobot.eidonix.com/p/0fac4f1d-03fb-483e-a478-692bd60aaf4f.md

#1 [high] Research summary

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

I inspected the three changed files at head (helios/src/scheduler/policy.rs, policy_tests.rs, rounds.rs), their callers (candidates, select_plan, phase_plan, add_candidate, continuation_candidate, prerequisite_value, next_progress, mixed_candidates, packed_round_candidates, lane_values/coalescing_prefill_log_bonus, resize_prefill, materialize), the main side of next_progress, and the contract docs (AGENTS.md, docs/design-review.md, scripts/benchmark_scheduler.py).

Verified sound (no finding)

Findings

1. mixed_candidates builds its per-call cache with the wrong mode tag — the struct's own guard cannot fire (Minor) helios/src/scheduler/policy.rs:1714 vs helios/src/scheduler/rounds.rs:844.

    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);          // policy.rs:1714
        self.mixed_candidates_with_curves(output, values, age_price, optimistic, &mut curves);

packed_round_candidates correctly does let mut curves = CurveCache::new(optimistic); (rounds.rs:844). Since CurveCache::get_or_insert_with hardcodes optimistic = false at the call site (policy.rs:1399) and rounds.rs:895 passes the real optimistic, the debug_assert_eq!(self.optimistic, optimistic, "CurveCache cannot mix …") (policy.rs:117-122) is decorative: the tag is never set to true anywhere a lookup happens, so the guard the PR advertises in its description provably never triggers. Today this is harmless because the optimistic Mixed arm bypasses the cache (if optimistic { values[slot].decode(self.optimistic_tokens(…)) } else { … cached_lane_value(…) }, policy.rs:1770-1771), but the tag is wrong and the "cannot mix" invariant is unenforced. Fix: CurveCache::new(optimistic) in mixed_candidates, and pass the mode through cached_expected_tokens instead of the hardcoded false.

2. Undeclared restructure in next_progress: the residual Mixed decode arm now hardcodes 1.0 and depends on an implicit early-return invariant (Minor, correctness-fragile) helios/src/scheduler/policy.rs:957-981 and 1008-1009.

        } else {
            let mut local_curves = CurveCache::new(false);
            let curves = curves.unwrap_or(&mut local_curves);
            …
            for &(batch, width, prefill) in &self.mixed_catalog { … cached_expected_tokens(r, tokens, Some(curves)) … }
            return best.map(|(rate, value)| (rate.duration_ns, value));
        }
        …
            } 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 Mixed loop ran unconditionally after the if/else and priced its decode arm as if self.speculative_widths.is_empty() { 1.0 } else { forecast_tokens(mixed_curve, tokens) } (policy.rs at main, lines 959-968). The new residual arm is only reachable with speculative_widths.is_empty() (the non-empty, generated_tokens > 0, post-prompt case now returns at :980), which is exactly why 1.0 is correct — but that reasoning is nowhere in the code or the description ("next_progress reuses cached_expected_tokens for both speculative and mixed lookups" covers only :964/:977). A future change to the :946 condition silently changes Mixed decode pricing. Fix: keep a cached_expected_tokens(r, self.speculative_tokens(r, width), Some(curves))-style expression, or add a comment stating the invariant; and disclose the restructure in the "What changed" section.

3. next_progress allocates a 1.5 KB CurveCache on every uncached call, where main allocated two Option<Vec<f64>> lazily (Minor) helios/src/scheduler/policy.rs:958.

            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 (helios/src/execution/manifest.rs:18 (not opened)), so this is a 64-slot array (≈1.5 KB) zero-initialized per next_progress invocation reached through prerequisite_value → cached_lane_value_for_tokens_within (_ => self.prerequisite_value(…, curves), policy.rs:1522) with curves == None, i.e. via lane_value/lane_value_for_tokens_within (policy.rs:1406-1423, 1469-1479) — the uncached entry points still used by prefill pricing (policy.rs:1545) and resize_prefill (policy.rs:1993-1999). main used let mut curve = None; / let mut mixed_curve = None; and only allocated a Vec on demand. This is exactly the kind of per-call cost the PR is trying to remove, in the paths the PR leaves uncached. Fix: keep the local as Option<CurveCache> and build it on first use, or make the cache a SmallVec/Vec sized to the active slot count rather than REQUEST_LANES.

4. CURVE_EVALUATIONS is re-added after a prior review asked for its removal, and it counts curve construction, not powf (Minor) 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, the review of #540 asked for this counter and its two tests to be deleted, and neither exists on main. Additionally, the counter is incremented before the alpha fast path, so at the default alpha an "evaluation" is a Vec clone with no powf at all — the four new tests (policy_tests.rs:9489/9517/9545/9567) bound constructions, not the powf work the PR's "Why" is about (the justification for decode_only_candidate_pass_builds_no_forecast_curve still holds). No production cost (#[cfg(test)] thread-local). Recommend dropping the counter and asserting the behaviour through the existing exact-equality test, or stating why it is needed this time.

5. Charter / design-review evidence gap: the speedup claim is host-CPU only, and the in-repo served-workload benchmark was not used (Major, process/contract) docs/design-review.md:106-115:

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 2.61x/5.40x/4.54x table and states "No standalone GPU serving throughput or latency improvement is claimed from this change", with baselines collected before the rebase. The repository already ships the measurement the rule asks for — scripts/benchmark_scheduler.py:4 ("Measure closed-loop native HTTP serving with timestamped SSE token bursts", driven at :24-45 over /v1/chat/completions) — and the PR does not run it, publish a harness for the table, or map its 21-workload simulator run to the learning.py (not opened)/64-seed evaluation docs/design-review.md asks for. Impact: the headline numbers are not reproducible from the PR and do not establish a served-workload gain (#210). Fix: add the benchmark script/command and fixture inputs for the three component timings, re-measure on cc0a49d2, and add one A/B scripts/benchmark_scheduler.py run (tok/s and TTFT/ITL) at default adaptive_verification_alpha == 1.0 against main, or explicitly frame the change as behaviour-preserving cleanup rather than a performance claim.

6. Claim-scope gap: the new "evaluate each lane curve at most once" comment is true only for candidates, and two per-lane curve paths remain uncached and are not disclosed (Minor) helios/src/scheduler/policy.rs:1641 and :663.

        // Request and forecast state stay fixed within a candidate pass; evaluate each lane curve at most once.
        let mut curves = CurveCache::new(false);
            for &slot in &decoder_slots[..decoder_count] {
                let r = self.slots[slot].request.as_ref().unwrap();
                let curve = self.powered_curve(r, false);

coalescing_prefill_log_bonus still builds one powered_curve per decoding lane on every lane_values call (policy.rs:658-667, reached from lane_values at :781, called from select_plan at :1826), and resize_prefill still prices every masked decoder with the uncached lane_value (policy.rs:1993-1999). Neither is mentioned in the description (the dossier notes #547 declared only resize_prefill out of scope). Impact: the "curve evaluations bounded to one per eligible lane per pass" statement in the description/table is scoped to candidate pricing and does not hold for the whole plan pass; prefill-heavy and coalescing-active workloads see less than the fixtures suggest. Fix: state the remaining uncached paths and why they are out of scope, or thread the cache through resize_prefill (it is already inside the pass that owns one).

No wire/protobuf, captured-graph, exported-core, dependency, config/default, or platform-parity (Unix vs Windows) surface is touched, so no owner sign-off question arises on those axes. AGENTS.md:165-169 (a demonstrated, measured cost is an acceptable justification) is satisfied by #547's profile only insofar as that issue itself disclaims attribution of pow to this path; the PR inherits that caveat without repeating it.

#2 [high] PR #693 correctness/system review — findings with citations

PR #693 head a9f7dd7, base main. Files: helios/src/scheduler/policy.rs (+177/−46), policy_tests.rs (+294), rounds.rs (+31/−5). REQUEST_LANES = 64 (helios/src/execution/manifest.rs:18). Default adaptive_verification_alpha = 1.0 (policy.rs:41).

VERIFIED SOUND (report should say so plainly):

FINDING 1 (Minor) — mixed_candidates uses wrong cache mode tag; its own debug_assert can never fire. policy.rs:1714 vs rounds.rs:844. pub(super) fn mixed_candidates(&self, output, values, age_price: f64, optimistic: bool) { let mut curves = CurveCache::new(false); // policy.rs:1714 self.mixed_candidates_with_curves(output, values, age_price, optimistic, &mut curves); rounds.rs:844 correct: let mut curves = CurveCache::new(optimistic);. The only cache lookup hardcodes false (policy.rs:1399: get_or_insert_with(slot, false, || self.powered_curve(r,false))) and rounds.rs:895 passes real optimistic, so debug_assert_eq!(self.optimistic, optimistic, "CurveCache cannot mix optimistic and non-optimistic survival curves") (policy.rs:117-122) never fires. Harmless today: optimistic Mixed arm bypasses cache at policy.rs:1770-1771 (if optimistic { values[slot].decode(self.optimistic_tokens(...)) } else { cached_lane_value(...) }). Fix: CurveCache::new(optimistic) and thread mode through cached_expected_tokens instead of hardcoded false.

FINDING 2 (Minor) — undeclared next_progress restructure; residual Mixed decode arm hardcodes 1.0 and relies on implicit early return. policy.rs:957-981 (else { let mut local_curves…; return best.map(...); }) and policy.rs:1008-1009 (} 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 Mixed loop ran unconditionally after if/else and priced if self.speculative_widths.is_empty() { 1.0 } else { forecast_tokens(mixed_curve, tokens) } (main policy.rs:932-968, quoted at main lines 959-968). New residual arm only reachable when speculative_widths.is_empty() (the non-empty + generated>0 + post-prompt case returns at :980), which is exactly why 1.0 is right — but that reasoning is absent from code and from the PR text, which only says "next_progress reuses cached_expected_tokens for both speculative and mixed lookups". Fix: keep expression-based pricing or add an invariant comment + disclose restructure.

FINDING 3 (Minor) — new per-call [Option<Vec>; 64] allocation in the paths the PR leaves uncached. policy.rs:958: let mut local_curves = CurveCache::new(false); let curves = curves.unwrap_or(&mut local_curves); CurveCache.entries is [Option<Vec>; REQUEST_LANES] (policy.rs:100-103), REQUEST_LANES=64 => ~1.5 KB zeroed per next_progress invocation reached via prerequisite_value with curves==None (policy.rs:1522 _ => self.prerequisite_value(r, kind, horizon_ns, value, curves)), i.e. through lane_value / lane_value_for_tokens_within (policy.rs:1406-1423, 1469-1479), still used by prefill pricing (policy.rs:1545) and resize_prefill (policy.rs:1993-1999). main used let mut curve = None; / let mut mixed_curve = None; (main policy.rs:908, 932) with lazy Vec. Fix: Option built on first use, or size to active slot count.

FINDING 4 (Minor) — CURVE_EVALUATIONS re-added after #540 review asked its removal; counts curve construction, not powf. rounds.rs:634-640: counter incremented before the alpha==1.0 return, so at default alpha an "evaluation" is a Vec clone with no powf. Dossier: #540 merged a version of this counter and the Autobot review recommended deleting it; neither counter nor the zero-duration reuse exists on main. Tests at policy_tests.rs:9489, 9517, 9545, 9567. #[cfg(test)] only, no production cost.

FINDING 5 (Major, process/contract) — perf claim is host-CPU only; in-repo served benchmark exists but was not run. docs/design-review.md:106-115 rule 12 verbatim: "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." PR: 2.61x/5.40x/4.54x table, baselines from pre-rebase c513e46a, no harness/command/fixtures; "No standalone GPU serving throughput or latency improvement is claimed." scripts/benchmark_scheduler.py:4 = "Measure closed-loop native HTTP serving with timestamped SSE token bursts"; driver at :19-45 posts /v1/chat/completions. PR did not use it. 21-workload --policy utility sim run not mapped to the learning.py/64-seed evaluation that docs/design-review.md:195-203 asks for. Docs quote for charter: AGENTS.md:165-169 (measured performance problem acceptable justification); AGENTS.md:72-113 four-part PR description contract (satisfied, aside from the inherited pow attribution caveat from #547).

FINDING 6 (Minor) — "evaluate each lane curve at most once" comment is scoped to candidates() only; two per-lane curve paths stay uncached and are undisclosed. policy.rs:1641 comment + policy.rs:663: let curve = self.powered_curve(r, false); inside coalescing_prefill_log_bonus decoder loop (policy.rs:658-667), reached from lane_values (policy.rs:781) -> select_plan (policy.rs:1826). resize_prefill still uses uncached lane_value per masked decoder (policy.rs:1993-1999). Dossier: #547 declared only resize_prefill out of scope; the coalescing path is mentioned nowhere. Fix: disclose, or thread the pass cache into resize_prefill (already inside the pass that owns one).

Tests inspected: four new tests policy_tests.rs:9489 (waiting Init prices curve once), 9517 (mixed_candidates once per call), 9545 (decode-only builds none), 9567 (cached vs uncached equality at alpha 1.0/0.6, widths 0/1/2/4/8, 1-remaining-token lane, waiting Init, Mixed + packed Speculative keys incl. c.rate.score.to_bits(), optimistic probe, plan() winner, tie-breaking). Strongest evidence in the PR; fixture-level only, no differential run over production traces (contrast #188's ~210k-plan byte-identical trace check). Dossier: no CI checks on head; no comments/reviews.

No injected-instruction attempt found in PR text or comments.