Correctness, Contracts & System-Level Consequences review — PR #661 (helios/scheduler: explore smaller prefill chunks under active age-priced streams)
Head c588d61 on main 1fbcc3c9; +1,949/−106 in 11 files, production +397/−78 in 4 files (scheduler.rs +86/−10, scheduler/cost.rs +400, scheduler/policy.rs +196/−54, scheduler/service.rs +29/−17). All findings below were verified against the head by reading the files directly; quotes are verbatim.
Key findings
- Blocker — undeclared model-contract reversal.
scheduler.rs:901-906maps every capacity absent fromterminal_prefill_catalogtoTerminalPrefillwheneverrequest.deferred_prefill, dropping theneeds_terminalcondition.helios/model-contract.md:182-186still promises the opposite fallback toPREFILL, and the PR does not touch that file. The lifecycle mutation guard was updated to enforce the new rule (verification/helios-lifecycle/check.py:527-535). - Major — the two-frame prefill pipeline is switched off by any terminal-cleanup stream.
scheduler.rs:1187-1190returnstruefromprefill_step_requires_feedbackunconditionally whenhas_active_age_priced_stream(), and that predicate countsterminal_cleanuprequests underterminal_age_price(scheduler.rs:998-999), whichPolicyConfig::throughput()leaves at 1.0 (policy.rs:37,:50-52). The PR body's "(throughputpipelines)" claim is therefore false, and the PR's own test asserts the opposite of the body. - Major — prefill service-rate scope flips on a zero-rate edge case.
service.rs:321-328rescans non-terminal prefills only whentoken_rate == 0.0, i.e. only while no terminal shape is measured, although post-#661 non-terminal chunks are selectable at any time; the resulting rate feedsServicePrice::rebase(service.rs:475-483), so the stored prefill price steps discontinuously, contradictingdocs/scheduling-runtime-design.md:240-251. - Major —
interpolated_prefill_durationis systematically optimistic.cost.rs:720-777takes the minimum decode-step cost over any batch as the capacity-0 rung and interpolates absolute nanoseconds with no KV-context term, while peers get one (cost.rs:750-755). Against the PR's own GB10 catalog the estimate is 15–31% low for the chunk sizes this PR is meant to prefer. - Major — cross-kind natural-fit cache aliasing.
PrefillSlotPlanhas a singlenat_fitfield with nokindkey (policy.rs:89-96), butprefill_slot_nat_fitcomputes it fromkind(policy.rs:526-535) and the same plan array is reused across thePrefillandTerminalPrefillcandidate passes (policy.rs:1599-1634). - Major — evidence remains head-stale and the mandatory simulator gate is unrun. The body's Limits section dates every A/B before the guards and the rebase; the 64-seed validation preset is not among the presets claimed.
- Minor — theory doc still asserts prefill has no cadence or size preference (
docs/scheduling-theory.md:74-76,:93-97) while the new paragraph at:558-565only admits the simulator divergence.
1. Correctness, Safety & Platform Parity
F5 (Major) — nat_fit is cached per slot without a kind, so the terminal exploration gate is evaluated against the wrong catalog
policy.rs:89-96:
#[derive(Clone, Copy, Default)]
struct PrefillSlotPlan {
ready: bool,
cut: Option<usize>,
terminal_only: bool,
nat_fit_ready: bool,
nat_fit: Option<usize>,
}
policy.rs:518-537:
fn prefill_slot_nat_fit(
&self,
slot_plans: &mut [PrefillSlotPlan; REQUEST_LANES],
slot: usize,
request: &LiveRequest,
kind: GraphKind,
) -> Option<usize> {
let plan = &mut slot_plans[slot];
if !plan.nat_fit_ready {
let catalog = self.prefill_catalog_for_terminal(kind, plan.terminal_only);
plan.nat_fit = self.natural_fit_prefill_capacity_for_terminal(
The cached value depends on kind (prefill_catalog_for_terminal(kind, ...)), but the guard only tests plan.nat_fit_ready. One array is allocated and shared across both prefill kinds — policy.rs:1599 (let mut prefill_plans = [PrefillSlotPlan::default(); REQUEST_LANES];), the kind loop at :1600-1634, with the mask for TerminalPrefill built from requests whose expected kind is Prefill:
let expected = if kind == GraphKind::TerminalPrefill {
GraphKind::Prefill
} else {
kind
};
Same aliasing in the continuation path, where both kinds match promoted_kind == Prefill (policy.rs:1090-1114).
Impact: whichever prefill kind is scored first in the loop (Prefill, per :1601) writes nat_fit from prefill_catalog; the TerminalPrefill pass then reuses it. The new exploration gate is capacity <= nat_fit (policy.rs:1115-1116, and the add_candidate twin the notes track at :1467-1468). With the shipped catalogs (PREFILL from 128, TERMINAL_PREFILL from 256) the terminal pass inherits gate 128, so the true terminal natural fit 256 is never explored as unmeasured — the mechanism silently does nothing on TERMINAL_PREFILL cores, which the PR body itself calls out as the problem surface ("256..=16384 + PREFILL 128..=16384"). With a model whose terminal catalog starts below its prefill catalog the reverse happens: oversized terminal shapes pass the gate and are priced as legal chunks.
Fix: key the cache by kind (two fields, e.g. nat_fit_prefill/nat_fit_terminal, or set nat_fit_ready = false whenever kind changes), or allocate one plan array per kind as continuation_candidate effectively does.
Verified sound (not issues)
- The scheduler remains single-threaded; this PR adds no lock, no channel, no
unsafe, no spawn. terminal_prefill_windowcaching (scheduler.rs:660, recomputed at:847-858from bothprefill_graphsandterminal_prefill_graphs) is correct — both setters invalidate.- The
u128interpolation cannot underflow:hiis strictly greater thancapacity(cost.rs:734,:762-767) andlois<= capacityor the(0, floor)fallback (:775-778), socapacity - c_loandc_hi - c_loare non-negative. The non-monotonic clampif t_hi <= t_lo { return Some(t_hi.max(1)) }(:779-781) fails safe. resize_prefill's age-priced cap (policy.rs:1912-1916) fails safe: when the catalog lookup is unavailable it returnsNonerather than an oversized candidate.- Interpolated candidates still commit as
PlanOrigin::Discoveryand still require a drain through!costs.is_fresh(...); the notes verifiedpolicy.rs:1784-1792and theplan_requires_feedbackpath atscheduler.rs:1222, so the discovery origin cannot leak into the acceptance/staleness machinery.
2. Unintended system-level consequences
F2 (Major) — plan-agnostic drain reverses #645's two-frame prefill pipeline for throughput, and for prefills that are not age-priced at all
scheduler.rs:1187-1190:
fn prefill_step_requires_feedback(&self, plan: &ScheduledPlan) -> bool {
if self.has_active_age_priced_stream() {
return true;
}
scheduler.rs:996-1005:
pub(super) fn has_active_age_priced_stream(&self) -> bool {
self.slots.iter().filter_map(|s| s.request.as_ref()).any(|r| {
if policy::terminal_cleanup(r) {
self.policy.terminal_age_price > 0.0
} else {
self.policy.decode_age_price > 0.0
&& matches!(r.phase, RequestPhase::Decode | RequestPhase::Resume)
}
})
}
policy.rs:37 and policy.rs:50-52:
terminal_age_price: 1.0,
pub fn throughput() -> Self {
Self { delivery_fairness: 0.0, decode_age_price: 0.0, ..Self::default() }
}
Three consequences:
- The PR body's claim is false. The description says the change "drains active-stream non-terminal
Prefill(throughputpipelines)".throughput()zeroesdecode_age_pricebut notterminal_age_price, and:998-999counts terminal-cleanup streams against the terminal coefficient. So underthroughputa single resident checkpoint/completion-barrier request drains every prefill step. The PR's own test documents this:policy_tests.rs:8311-8314asserts "nonterminal Prefill must drain when a terminal-cleanup stream is age-priced", and:8316-8318restores pipelining only after zeroingterminal_age_priceexplicitly. - The drain is plan-agnostic and cross-request.
prefill_step_requires_feedbackreceivesplanbut never inspects it: one age-priced decoder — or one terminal-cleanup request — forces an extra feedback round-trip on every subsequent prefill submission, including prefills for cold prompts that share nothing with that stream.submission_window_availablegates the next submission onrequires_feedback(policy.rs:539-544), so each such step costs a full host round trip. This is the mechanism behind the body's ownT_50Crow, which reports+1.8%makespan while claiming a gap win. - "Age-priced" has two definitions in the same PR.
has_active_age_priced_stream(scheduler.rs:996-1005) compares the raw policy coefficients, whileprefill_requires_terminal_completion_for_ageandresize_prefilluse the scaled aggregateage_price(the notes verifiedpolicy.rs:1849-1865,:1906-1907against:834-848, whereage_priceisexp(-scale)-based). The two can disagree — a positive coefficient with a scale that makes the effective price numerically ~0 still drains.
Impact: a throughput-policy user with one checkpointing request loses the two-frame pipeline merged the day before in #645 (e85019b9), with no flag and no opt-out, and pays a drain per cold-prompt chunk. #661's stated purpose is to reduce decoder stalls, so a hard regression on the throughput path is the opposite of the intent.
Fix: make the predicate plan-aware — require that at least one masked, non-terminal request in this plan is itself age-priced (and gate terminal-cleanup streams on whether they share the plan), or add an explicit prefill_pipelining policy field so throughput() keeps the #645 pipeline. Then correct the PR description.
F3 (Major) — the non-terminal prefill rescan fires only at token_rate == 0.0, so the priced feasible set changes without the plan changing
service.rs:321-328:
token_rate = token_rate.max(scan_prefill(terminal_only));
if token_rate == 0.0
&& terminal_only
&& self.has_active_age_priced_stream()
&& !self.prefill_must_complete_terminally_from(request, start, cut)
{
token_rate = token_rate.max(scan_prefill(false));
}
scan_prefill(skip_nonterminal) (service.rs:298-320) keeps only the kinds it is told to keep; skip_nonterminal = terminal_only means the first pass skips GraphKind::Prefill entirely. The fallback pass — the only one that prices non-terminal chunks — is reachable only while no terminal shape for this request yields a duration.
That price is not cosmetic: service.rs:475-483 rebases the stored price from it, and the doc contract it implements is docs/scheduling-runtime-design.md:240-251:
"Individually feasible prefill service rates price each request from the prefill catalog and operation it can execute (
PREFILL,TERMINAL_PREFILL, orSCORED_PREFILL), excludingMIXEDdurations …"
Impact: terminal_only is a property of (request, cut, age_price) — the rate is a property of the feasible set, and after #661 the feasible set includes Prefill (policy.rs:1110-1141, :1462-1492). But the rate only reflects that when zero terminal shapes are measured. As soon as one TerminalPrefill capacity gets a GPU measurement — or as the last age-priced stream leaves and has_active_age_priced_stream() flips false — the computed rate jumps from the mixed-kind maximum to the terminal-only maximum or vice versa. ServicePrice::rebase(previous, rate) rescales the stored price by that ratio, so an unrelated event (a graph measurement landing, or another request finishing) rescales this request's prefill priority mid-prompt. The existing test only covers the token_rate == 0.0 branch (policy_tests.rs:8240-8243, "measured Prefill(2048) must provide fallback token_rate when TerminalPrefill is unmeasured"), so the discontinuity is untested.
Fix: when terminal_only && has_active_age_priced_stream() && !prefill_must_complete_terminally_from(...), always scan_prefill(false) — the zero-rate guard should exist only to avoid a full rescan when the terminal scan already covered the feasible set (i.e. !terminal_only). Add a test that measures one terminal shape and asserts the rate equals the non-terminal-inclusive maximum.
F4 (Major) — the interpolated estimate is optimistic, and the bias is largest exactly where the PR steers traffic
cost.rs:695-786. The relevant rungs:
if matches!(
key.kind,
GraphKind::Decode | GraphKind::Speculative | GraphKind::Resume
) {
decode_floor = Some(decode_floor.map_or(estimate.nanos, |f| f.min(estimate.nanos)));
continue;
}
if key.batch != 1 || key.tokens == capacity {
continue;
}
let (c_hi, _, t_hi) = hi?;
let (c_lo, t_lo) = match lo {
Some((c, _, t)) => (c, t),
None => (0, decode_floor?.min(t_hi)),
};
let span = (c_hi - c_lo) as u128;
let offset = (capacity - c_lo) as u128;
let interp = u128::from(t_lo) + (u128::from(t_hi - t_lo) * offset) / span;
Three concrete defects:
- The floor is taken before the batch filter. The
Decode | Speculative | Resumebranch (:720-725)continues beforeif key.batch != 1(:727), so an entry measured at any batch — including a large-batch decode that is cheap per step only because it wastes rows — sets the floor, and the loop takes the minimum over all such entries. - The floor becomes the capacity-0 rung with no KV-context term. Peers get context pricing:
pred.predict(key.tokens, start_position)pluswith_borrowed_context_slope(:750-755). The floor rung (:777) reuses a raw decodenanoswith no such term. Interpolating absolute nanoseconds from a decode step to a prefill peer assumes both graphs share the same fixed intercept, which they do not (peers fittheta0 + theta1*uperPrefillPredictor). - No per-token normalization and no freshness check. Interpolation is between two peers' absolute times, so the result is exact only if the constant term matches at both capacities — it does not for widely separated peers (128 vs 16384). Unlike the borrowed-slope/stale-key path,
interpolated_prefill_durationaccepts arbitrarily old measurements (estimate.nanos != 0is the only test at:717), so one old large-prefill measurement keeps every smaller shape "measured" indefinitely for ValueRate competition.
Quantified against the PR's own GB10 catalog (policy_tests.rs:7488-7505 prefill table; :7507-7518 decode, batch 1 = 28 ms), interpolating from the decode floor to Prefill(16384) = 1302 ms:
| capacity | estimate | measured | error |
|---|---|---|---|
| 128 | 38.0 ms | 45 ms | −15.7% |
| 256 | 47.9 ms | 65 ms | −26.3% |
| 512 | 67.8 ms | 98 ms | −30.8% |
| 1024 | 107.6 ms | 150 ms | −28.2% |
| 4096 | 346.5 ms | 380 ms | −8.8% |
The new unit test encodes the same arithmetic as ground truth — cost.rs test: let expected_4k = 18_000_000 + (1_302_000_000 - 18_000_000) / 4; (18 ms floor, 1302 ms peer) — so the test pins the optimistic formula rather than catching it.
Impact: this value is the ValueRate denominator for unmeasured candidates and it gates them by capacity <= nat_fit (policy.rs:1115-1116). Understating the smallest chunk's cost by ~30% means the exploration rule prefers the smallest unmeasured chunk by ~30% beyond what measured cost justifies: more chunks per prompt, therefore more drain barriers per prompt (F2) and more decoder stalls per prompt, at the same time the PR claims to reduce them. The body's own +1.8% makespan is consistent with this.
Fix: interpolate per-token time (or add the peers' fitted theta0) instead of absolute nanos; do not use an arbitrary decode step as the c = 0 rung unless it shares the fitted intercept with the peers — or require lo to be a measured prefill peer and return None otherwise; apply the same start_position context term to the floor rung; and enforce estimate_ttl-style freshness on candidates. Re-anchor the unit test to the measured table instead of the closed-form formula.
3. Architecture, contracts & charter compliance
F6 (Blocker) — the deferred_prefill kind resolution contradicts the published model contract, and the mutation guard now enforces the contradiction
scheduler.rs:895-910:
let window = self.terminal_prefill_window();
let needs_terminal =
end >= next_stop || (window > 0 && next_stop.saturating_sub(end) <= window);
if self.terminal_prefill_catalog.binary_search(&capacity).is_err() {
return if request.deferred_prefill {
GraphKind::TerminalPrefill
} else {
GraphKind::Prefill
};
}
needs_terminal is computed and then ignored on that branch. Before this PR the guard additionally required needs_terminal, so a non-terminal-catalog capacity with a deferred request still ran as Prefill unless it was at a completion boundary.
The contract it overrides — helios/model-contract.md:182-186:
"Helios derives the tail-protection window from the prepared catalog as the largest
PREFILLcapacity absent from theTERMINAL_PREFILLcatalog; those smallerPREFILLgraphs execute complete continuation state. When a model declares noTERMINAL_PREFILLgraphs, or omits a capacity from the terminal catalog, Helios falls back toPREFILLwith no contract version change."
helios/model-contract.md is not in the changed-file list.
Impact: for any model that omits capacities from the terminal catalog, a request holding deferred prefill state can no longer use the smallest complete-state PREFILL graph. On the shipped catalog (PREFILL from 128, TERMINAL_PREFILL from 256) the minimum chunk quantum during deferred prefill doubles to 256 and every mid-prompt chunk pays full terminal-state rebuild cost instead of the cheaper continuation path — the opposite of "smaller prefill chunks". This is a captured-graph selection contract per the charter's "captured-graph op contracts … requires owner approval" rule, and the PR declares neither the change nor a version bump.
Enshrined in the mutation guard: verification/helios-lifecycle/check.py:527-535 changed the expected source for the "deferred prefill small cut bypass" mutation from the old if request.deferred_prefill && needs_terminal { to the new if request.deferred_prefill {, so the lifecycle check now protects the new rule and will not flag a regression against the documented fallback.
Fix: restore needs_terminal in the condition (or, if the widening is intended, state it as a contract change: update helios/model-contract.md:182-186, bump the contract version, get owner sign-off, and describe the reach in the PR body — the description only alludes to it as "excludes non-terminal-catalog shapes under deferred_prefill"), and update the mutation guard to assert the intended rule plus a regression case for the documented fallback.
F1 (Blocker) — the evidence does not describe the mergeable head, and one behavioural claim is false
PR body, Limits:
"SM120 A/B ran on
fdb10bb5/82f68ea8beforeresize_prefill/Discoveryguards and1fbcc3c9rebase; template tests &kaniunrun."
Every headline row in the body's Result table (the post-#663 mixed-c32 p99 −29.0% / >250 ms −78.9%, the T_50C peak-gap −21.6%, the 215 → 78 row, the 4x GB10 >1s stall 24 → 0) therefore predates the guards and the rebase onto 1fbcc3c9. Only the archive-tree claim (5bb2aff2, tree 74625efe6837 == c588d610) ties the head to any verification, and it is an author claim with no readable CI run.
Second claim, PR body "Chunking & drain":
"drains active-stream non-terminal
Prefill(throughputpipelines)"
False per F2 (policy.rs:37, :50-52; scheduler.rs:998-999, :1187-1190).
Third, the gate: docs/design-review.md:195-208 requires "the screening and 64-seed validation catalog". The body claims learning.py (not opened) smoke+screen, whose presets use TRAINING_SEEDS = range(16) (scripts/scheduling_sim/learning_analysis.py:13); the held-out 64 seeds HELDOUT_SEEDS = range(10_000, 10_064) (learning_analysis.py:12) are only used by --preset validate. And the simulator's Graph carries only prefill_capacity/decode_capacity/width (scripts/scheduling_sim/model.py:24-36 (not opened)) — no TERMINAL_PREFILL splitting, no two-frame pipelining — so it cannot model either mechanism this PR changes even if run.
Impact: charter #210 requires served-workload evidence for a performance PR; the performance story here is on code that no longer exists, on a mechanism the simulator cannot represent. The throughput claim is a factual error about behaviour this PR introduces.
Fix: re-run the served A/B on c588d610 and report it; correct the throughput sentence (or make it true, per F2); run --preset validate or state explicitly that the simulator cannot model the changed mechanisms and add the capability first.
F7 (Minor) — the theory doc still contradicts the new behaviour; it only admits the simulator divergence
docs/scheduling-theory.md:93-96:
"All pure prefill, pure decode, and available mixed graphs compete on this score. No duration ceiling, prefill size preference, or breadth-before-depth rule precedes it."
docs/scheduling-theory.md:74-76: "Prefill has no externally visible per-chunk cadence."
The new paragraph at :558-565 concedes that the simulator's initial_discovery = "native" bootstraps unmeasured prefill shapes "without TERMINAL_PREFILL splitting or two-frame pipelining, whereas native Helios restricts solo (age_price == 0) cold discovery to natural fit and prices smaller unmeasured prefill capacities via GPU-measured interpolation" — but the earlier statements, which are the ones a reader uses for the contract, are unchanged. helios/README.md:285-287 and :426-431 now match the new behaviour, so the residual defect is theory-only.
Fix: amend :74-76, :93-97 and :119-120 to state the age-priced size preference and the drain cadence, in the same terms as the :558-565 paragraph, and note the service.rs feasible-set scope next to docs/scheduling-runtime-design.md:247-251.
4. Tests & claim accuracy
- Missing regression tests for the new pricing path (Major, tied to F3): the only service-rate test exercises the
token_rate == 0.0branch (policy_tests.rs:8240-8243); no test measures a terminal shape and asserts the rate does not jump, which is the case that will occur in steady state. - One new test cannot fail for the reason it is named after (Minor):
policy_tests.rs:7728-7810(continuation_candidate_excludes_oversized_padded_unmeasured_prefill) scores only anInitcontinuation (phase_plan(GraphKind::Init, ...),:7798-7800), while the oversized-sibling guard it names lives in the prefill branches (policy.rs:1110-1140; the dossier adds:1465-1492). The Autobot review reports the same blind spot atpolicy_tests.rs:7738-7741. The other six isolated scheduler tests are unaffected. - No test for the
nat_fitkind aliasing (F5), and no test asserts thedeferred_prefillrule againsthelios/model-contract.md:182-186(F6) — the only artifact touching the latter is the mutation guard, which was updated to match. - Accurate and checked: the drain-under-terminal-cleanup behaviour is documented by the PR's own test (
policy_tests.rs:8291-8333), and the GB10 catalog/decode tables used for the F4 arithmetic are in-tree fixtures (:7488-7518).
Open questions
- Is the
deferred_prefill→TerminalPrefillwidening (F6) intentional? Nothing in the PR body declares a model-contract change, and the contract file is untouched — if it is intentional the dossier's item A6 and the contract need to be reconciled by the author, not by a reviewer. - Is the
terminal_age_price = 1.0survival inthroughput()(F2) a deliberate decision to keep checkpoint barriers synchronous, or an oversight from #645? Either way the PR body's claim needs correcting. - Is the potentially-optimistic interpolation (F4) load-bearing for the reported win, or would requiring a measured
lopeer (no decode floor) still reproduce it? This is the cheapest experiment to settle the finding. - Does any served A/B exist for
c588d610itself? None is reported and no CI run is readable for that commit.
What I could not verify
No CI result is readable for c588d610; the only verification tying the head to a result is the author's local archive claim (5bb2aff2, tree 74625efe6837). The Autobot Changes-Requested review targets 29f2b5b, pushed before the head, so its findings are not evidence about c588d610. The 15.3 s GB10 TTFT figure in the #538/#550 history comes from #550's description, not from a run I could inspect. kani and template tests are admittedly unrun.