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
- 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-115asks for (scripts/benchmark_scheduler.py), which the PR did not run. - Minor —
mixed_candidatesconstructs itsCurveCachewith the wrong mode tag, so the "optimistic and ordinary curves never mix" guard the PR advertises in its description provably never fires (policy.rs:1714vsrounds.rs:844). - Minor — undeclared behavioural restructure in
next_progress: an earlyreturnplus a newly hardcodeddecode(1.0, …)replacemain's conditional curve forecast, and the equivalence depends on an invariant stated nowhere (policy.rs:946-981,:1008-1009). - Minor — the PR adds a fresh ≈1.5 KB per-call allocation in exactly the pricing paths it leaves uncached (
policy.rs:958), reversingmain's lazyOption<Vec<f64>>. - Minor —
CURVE_EVALUATIONSis re-added after the review of #540 asked for its deletion, and it counts curve construction, not thepowfwork the PR's rationale is about (rounds.rs:635-638). - Minor — the "evaluate each lane curve at most once" claim is scoped to
candidatesonly, withcoalescing_prefill_log_bonusandresize_prefillstill 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)
- Both short-circuits are exact, not approximate.
forecast_tokensisf64::from(width != 0) + powered[..width.saturating_sub(1)].iter().sum::<f64>()(helios/src/scheduler/rounds.rs:1017-1019), so forwidth == 0it is0.0and forwidth == 1it is1.0regardless of the curve. Thereforeproposal_forecast_tokens's early return
(fn proposal_forecast_tokens(&self, request: &LiveRequest, width: usize, optimistic: bool) -> f64 { if width <= 1 { return f64::from(width != 0); }rounds.rs:626-629) andcached_expected_tokens'sif tokens <= 1 { return f64::from(tokens != 0); }(policy.rs:1393-1395) return bit-identical values to the uncached path.GraphKind::Decodelanes arelane_tokens == 1, so the non-speculative Decode skip is sound. - The alpha==1.0 fast path is bit-identical.
if self.policy.adaptive_verification_alpha == 1.0 { return curve; }before thep.powf(alpha)map (rounds.rs:638-644) relies onpowf(p, 1.0) == p, which holds for everypproduced by a survival curve (finite in[0.0, 1.0]). The PR's own equality test covers alpha 1.0 and 0.6 againstspeculative_curve+powf(policy_tests.rs:9589,:9622-9629). - The packed
limit <= 1 { continue; }skip (rounds.rs:892-894) drops no ranking entry: the skipped body isfor position in 0..limit.saturating_sub(1)(:897), i.e. zero iterations atlimit <= 1, andgains,slot_pricesandranksare all derived from the samescoresvector (:905-910). - Cache safety.
candidatesis&selfand does not mutate slots, forecasts oracceptanceduring pricing, so a per-pass cache cannot go stale.CurveCache::entriesis indexed byr.handle.slot as usize(policy.rs:1399) withrequest_slots <= REQUEST_LANESenforced inRequestScheduler::new, so the fixed-size array access cannot panic. The production callers ofmixed_candidates/packed_round_candidatesare only the two insidecandidates;phase_planis#[cfg(test)]. - No system-level blast radius. No locks, no I/O, no channels, no shared state and no retries are added; work moves from per-shape to per-lane inside one already-serial
candidatespass, so there is no new contention, head-of-line blocking, failure propagation or unbounded retention.expected_speculative_tokens(the submitted-length accounting path) is untouched, so no metric or rate-span shrinks.
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 waitingInit(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
- No owner-sign-off surface. The diff touches no wire/protobuf schema, no captured-graph contract, no exported core format, no dependency pin, no config/default value and no CLI surface.
adaptive_verification_alphakeeps its default of1.0(policy.rs:41), which makes the new fast path the default path rather than an opt-in behaviour change. No Unix-vs-Windows parity surface is involved (pure scheduler arithmetic). This is correctly placed in the model-agnostic Helios scheduling layer the charter protects, with no per-model branch. - Tests added (
policy_tests.rs:9489,:9517,:9545,:9567): three are call-count assertions driven byCURVE_EVALUATIONS; the fourth,cached_lane_pricing_matches_uncached_for_unit_and_fractional_alpha, is the strongest evidence in the PR — it compares full candidate keys includingc.rate.score.to_bits()(policy_tests.rs:9575-9588) at alpha 1.0 and 0.6 across widths 0/1/2/4/8, a 1-remaining-token lane, waitingInit,Mixedand packedSpeculative, deterministic tie-breaking, optimistic probe paths and the selectedplan()winner. It is still a fixture-level equality test, not a differential run over production traces (contrast #188's ~210k-plan byte-identical trace check), and per the dossier no CI check has run on the head commit, so none of the reported suites has third-party confirmation. - Description accuracy. The "Why", "What changed" and "Limitations" sections are unusually honest and match the diff, with the exceptions recorded above: the
next_progressrestructure (finding 3) is not described, the "evaluate each lane curve at most once" statement (finding 6) is over-broad, and thepow@@GLIBC_2.29figure is inherited from #547 without that issue's own caveat that the profile cannot attributepowtopowered_curve. - Process note. The dossier records that #547, filed by shieldstar, contains a complete ready-to-apply patch implementing the same design, that #693 says only "Fixes #547" and does not credit shieldstar, and that #547 is still open — merging #693 would leave it open unless explicitly closed. This is a "Respect contributors" matter rather than a code defect, and there is no recorded endorsement or objection from the original author.
Open questions / could not be found
- Does shieldstar (#547's author and patch author) endorse this reimplementation? No comment either way, and no credit in the description.
- Is the
next_progressrestructure (finding 3) intended, and is the:946condition intended to remain the sole gate on the Mixed decode pricing? - Should
mixed_candidatespassoptimisticintoCurveCache::new(finding 2), and is the assertion meant to be live guardrails or documentation? - Why re-add
CURVE_EVALUATIONSwhen 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 nopowf? - 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 commitc513e46ais unreadable in this checkout, so the pre-rebase comparison cannot be inspected. - Why were
resize_prefillandcoalescing_prefill_log_bonusleft uncached? Only the former is acknowledged anywhere (in #547), andresize_prefillalready runs inside the pass that owns a cache. - Does the 21-workload
--policy utilitysimulator run satisfydocs/design-review.md:195-203, which asks for thelearning.py(not opened) screening and 64-seed validation catalog? No mapping is given.