Key findings
Verdict: the diff is lean on the axis that matters, and the five simplifications below are all deletions inside the new plumbing — none touch the scheduling policy itself. No new flags, unsafe, environment reads, GraphKind, model branches, CLI/PolicyConfig fields, wire/ABI changes, or dead code; interpolated_prefill_duration is one self-contained pure function and docs/README/check.py (not opened) move in the same change. What the PR does add is duplicated plumbing: an ad-hoc per-slot memo threaded through five signatures (S1), one 17-line interpolation block copied verbatim twice (S2), a catalog walked twice for one boolean (S3), a second kind→catalog switch (S4), and a peer-ordering rule written four times (S5).
- S1 (high) —
PrefillSlotPlan/prefill_slot_state/prefill_slot_nat_fit(policy.rs:79-86,:420-456) is an ad-hoc cache that duplicates one already in the tree, costs five signature changes, and is under-keyed (memoises onslot, ignoring thekindit is handed) — delete it rather than repair it. - S2 (high) — the
last_interpinterpolation block is copy-pasted verbatim, 17 lines × 2 (policy.rs:1006-1022,:1356-1372), differing only inrequest→randwidth→capacity; one helper removes both and the only place the two copies can drift. - S3 (medium-high) —
service_rateswalks the same prefill catalog twice for one flipped boolean (service.rs:224-231);scan_prefill(false)subsumesscan_prefill(true), so thetoken_rate == 0.0gate and the second full catalog walk both go. −9 lines, one fewer catalog walk per admission. - S4 (medium) —
prefill_catalog_for_terminal(policy.rs:350-358) re-implements the kind→catalog switchprefill_catalog(:342-348) already has; and it exists only to accept a pre-resolvedterminal_onlybool, which is what drags thenatural_fit_prefill_capacity→…_for_terminalrename through six call sites. - S5 (medium) —
interpolated_prefill_durationstates its peer-ordering rule four times (cost.rs:734-744skip form,:759-772accept form with abetter_at_same_capclosure defined for that copy only); thehi/lopre-filter is exactly the negation of the accept test, so one comparator and one pass replace both. −15 lines.
All line numbers at head 29f2b5b. Nothing below is a correctness bug; where a buggy workaround exists the recommendation is explicitly delete it.
S1 (high) — Delete PrefillSlotPlan, don't repair it
helios/src/scheduler/policy.rs:79-86:
#[derive(Clone, Copy, Default)]
struct PrefillSlotPlan {
ready: bool,
cut: Option<usize>,
terminal_only: bool,
nat_fit_ready: bool,
nat_fit: Option<usize>,
}
helios/src/scheduler/policy.rs:420-456:
fn prefill_slot_state(
&self,
slot_plans: &mut [PrefillSlotPlan; REQUEST_LANES],
slot: usize,
request: &LiveRequest,
age_price: f64,
) -> (Option<usize>, bool) {
let plan = &mut slot_plans[slot];
if !plan.ready {
plan.cut = self.estimated_checkpoint_cut(request);
plan.terminal_only =
self.prefill_requires_terminal_completion_for_age(request, plan.cut, age_price);
…and :437-456:
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(
What it costs and why it is redundant:
- Five signature changes. The type is a new trailing
&mut [PrefillSlotPlan; REQUEST_LANES]onadd_candidate(policy.rs:1323) andcontinuation_candidate(policy.rs:937), constructed at:1486and:1933, and then carried through every arm ofcandidates(), including the non-prefill ones —Vision:1524,Speculative:1530, default/batch:1536— where it only reaches the prefill branch insidecontinuation_candidate(:1460, used at:988/:1003). plan.cutis already cached.estimated_checkpoint_cutresolves throughcheckpoint_selection_cached, keyed on(RequestHandle, bool)inside thePlanningScopethat bothselect_plan(policy.rs:1642) andphase_plan(policy.rs:1909) install (checkpoints.rs:11-19,:410-428). The field re-implements a cache that exists one module away.age_priceis constant for a wholecandidates()call (lane_valuesreturns a single value), yetterminal_only— a pure function of(request, cut, age_price)— is baked into a cachedboolatpolicy.rs:430-431.next_progressalready gets the nat-fit dedupe for free fromnatural_fit.get_or_insert_with(policy.rs:756,:768-775) with no struct and no flag.- And the memo is under-keyed, so it should be deleted, not given a
kinddimension.prefill_slot_nat_fit(:437-456) memoises onslotalone and never re-reads itskindargument:
if !plan.nat_fit_ready {
let catalog = self.prefill_catalog_for_terminal(kind, plan.terminal_only);
candidates() walks Prefill, TerminalPrefill, ScoredPrefill, … (:1487-1497) against one shared prefill_plans (:1486), while the pre-existing inline form recomputed the fit per (kind, slot) over effective_prefill_catalog(…), which returns the scored catalog for ScoredPrefill unconditionally. Under terminal_only == true the shared value was computed over terminal_prefill_catalog, so the ScoredPrefill iteration is priced against a terminal-catalog natural fit — an unintended change the new tests do not cover (the nat-fit tests at policy_tests.rs:7432, :7530, :7830 exercise Prefill/TerminalPrefill only). Repairing that means adding a kind dimension to a cache whose whole purpose was to avoid a ≤12-entry loop.
Concrete simplification: delete the struct (:79-86) and both helpers (:420-456); remove the prefill_plans parameter from add_candidate (:1323) and continuation_candidate (:937) and the argument at eight call sites (:988, :1003, :1334, :1353, :1460, :1520, :1524, :1530, :1536, :1936, :1940); compute (cut, terminal_only) once at the top of candidates()/phase_plan() into a local array and the nat fit inside the existing if kind.is_prefill() arm (:1518-1521), where kind is already in hand. This removes ~40 lines, five signature edits, two _ready flags, and one invariant ("nat_fit is only valid after state()") that nothing enforces.
S2 (high) — One helper instead of a verbatim 17-line copy
helios/src/scheduler/policy.rs:1006-1022:
&& let Some(interp) = match last_interp {
Some((w, pos, res))
if w == work && pos == request.scheduled_consumed =>
{
res
}
_ => {
let res = self.costs.interpolated_prefill_duration(
following,
width,
work,
request.scheduled_consumed,
);
last_interp = Some((work, request.scheduled_consumed, res));
res
}
}
helios/src/scheduler/policy.rs:1356-1372 is byte-identical apart from request→r and width→capacity:
&& let Some(interp) = match last_interp {
Some((w, pos, res))
if w == work && pos == r.scheduled_consumed =>
{
res
}
_ => {
let res = self.costs.interpolated_prefill_duration(
kind,
capacity,
work,
r.scheduled_consumed,
);
last_interp = Some((work, r.scheduled_consumed, res));
res
}
}
The surrounding ns decision (interp → nat_fit == Some(width) → 0 → continue) is duplicated too: :999-1031 vs :1349-1381.
Concrete simplification: one method on RequestScheduler, e.g. fn unmeasured_prefill_ns(&self, kind: GraphKind, capacity: usize, work: usize, start: u64, nat_fit: Option<usize>, age_price: f64, last: &mut Option<(usize, u64, Option<u64>)>) -> Option<u64> returning Some(ns) / Some(0) / None, called from both sites as let Some(ns) = … else { continue };. −17 lines, and it removes the only place the two copies can drift (today one passes following/width, the other kind/capacity — the kind of asymmetry that silently diverges on the next edit). Bonus deletion: last_interp (:970, :1330) saves at most one O(entries) scan when two slots report the same (work, start), inside a loop that is already O(capacities × slots) and calls interpolated_prefill_duration per capacity — dropping it deletes 8 more lines and the w == work && pos == … guard entirely.
S3 (medium-high) — service_rates walks the same catalog twice
helios/src/scheduler/service.rs:224-231:
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(false) (:201-223) takes the max over all capacities in catalog, a strict superset of what scan_prefill(terminal_only) — which only adds the skip_nonterminal filter at :210-212 — considers. Inside this else if prefill branch token_rate starts at 0.0 (:166) and is set by nothing else, so the token_rate == 0.0 gate exists only to avoid re-paying a pass that need not have run.
Concrete simplification: replace all eight lines above with
let allow_nonterminal = terminal_only
&& self.has_active_age_priced_stream()
&& !self.prefill_must_complete_terminally_from(request, start, cut);
token_rate = token_rate.max(scan_prefill(terminal_only && !allow_nonterminal));
−9 lines and one full catalog walk per admission, with identical semantics.
S4 (medium) — prefill_catalog_for_terminal duplicates prefill_catalog, and the rename it caused
helios/src/scheduler/policy.rs:342-348 (pre-existing) and :350-358 (new):
fn prefill_catalog(&self, kind: GraphKind) -> &[usize] {
match kind {
GraphKind::ScoredPrefill => &self.scored_prefill_catalog,
GraphKind::TerminalPrefill => &self.terminal_prefill_catalog,
_ => &self.prefill_catalog,
}
}
fn prefill_catalog_for_terminal(&self, kind: GraphKind, terminal_only: bool) -> &[usize] {
if kind == GraphKind::ScoredPrefill {
&self.scored_prefill_catalog
} else if terminal_only {
&self.terminal_prefill_catalog
} else {
&self.prefill_catalog
}
}
Same three catalog fields, same switch, differing only in that the new one takes a pre-resolved terminal_only bool. Concrete simplification: 3 lines instead of 9, keeping the ScoredPrefill test first for precedence:
fn prefill_catalog_for_terminal(&self, kind: GraphKind, terminal_only: bool) -> &[usize] {
if kind == GraphKind::ScoredPrefill { &self.scored_prefill_catalog }
else if terminal_only { &self.terminal_prefill_catalog }
else { &self.prefill_catalog }
}
or, if the caller resolves the kind up front, self.prefill_catalog(if terminal_only { GraphKind::TerminalPrefill } else { kind }). Either way the point stands: removing the duplicate switch also removes the reason for the natural_fit_prefill_capacity → natural_fit_prefill_capacity_for_terminal rename, which exists solely to accept the extra terminal_only: bool (policy.rs:393-399) and churns six call sites (:446, :447, :755, :769, :1789, plus the next_progress closure). terminal_only is just kind == TerminalPrefill once resolved, so passing the resolved GraphKind deletes both _for_terminal suffixes.
S5 (medium) — One comparator, one pass
helios/src/scheduler/cost.rs:734-744 (skip form) and :759-772 (accept form) of interpolated_prefill_duration:
if key.tokens > capacity {
if hi.is_some_and(|(c, cur_same, _)| {
key.tokens > c || (key.tokens == c && cur_same && !same_kind)
}) {
continue;
}
} else if lo.is_some_and(|(c, cur_same, _)| {
key.tokens < c || (key.tokens == c && cur_same && !same_kind)
}) {
continue;
}
…then again at :762-772:
let better_at_same_cap = |cur_same: bool, cur_ns: u64| {
(same_kind && !cur_same) || (same_kind == cur_same && full_ns < cur_ns)
};
if key.tokens > capacity {
if hi.is_none_or(|(c, cur_same, cur_ns)| {
key.tokens < c || (key.tokens == c && better_at_same_cap(cur_same, cur_ns))
}) {
hi = Some((key.tokens, same_kind, full_ns));
}
} else if lo.is_none_or(|(c, cur_same, cur_ns)| {
key.tokens > c || (key.tokens == c && better_at_same_cap(cur_same, cur_ns))
}) {
lo = Some((key.tokens, same_kind, full_ns));
}
The is_some_and pre-filter at :734-744 is exactly the negation of the is_none_or accept test at :762-772 — the same ordering predicate written twice, in two spellings, plus a closure defined only for the second copy (and only after :749's predictor work, which the pre-filter exists to skip). 40 lines express "nearest strictly-larger measured peer, nearest measured smaller peer, preferring the same kind at equal capacity".
Concrete simplification: one local fn better(new_cap: usize, new_same: bool, cur: (usize, bool, u64), want_hi: bool) -> bool and a single pass that only calls it (dropping the pre-filter; if the predictor work is genuinely worth skipping, compute (capacity, same_kind, ns) pairs into a small local loop first and reduce with the two orderings). −15 lines, one comparator instead of four, and the two orderings become visibly symmetric.
Minor (noted, not flagged — unit-test scaffolding)
helios/src/scheduler/cost.rsadds three tests (:1280,:1355,:1474) that each re-declare the same ~25-linemake/step_for/timingclosure set already duplicated at:1092/:1107/:1121and:1212/:1226. Hoisting to module-level#[cfg(test)]helpers removes ~100 lines across five copies. Below the sparing threshold for this lens, but it is the largest single block of removable lines in the diff.helios/src/scheduler/policy_tests.rs:6975-7010hand-restates the SM120/GB10 duration tables that also live inscripts/scheduling_sim/workloads.py:58-91; a drift between them would be silent.
Checked and deliberately not flagged
terminal_prefill_window(scheduler.rs:657,:842-860) — keep. It is a hoist of an O(catalog) computation on theresolve_prefill_kind_fromhot path, i.e. exactly the optimisation requested in #538's review, not speculative state. One note only: both catalog setters must callrecompute_terminal_prefill_window, andscored_prefill_catalog(:818) correctly does not.has_active_age_priced_stream(scheduler.rs:989-998) — one predicate answering two questions (feedback barrier and interpolation gate), but both derive from the same documented condition; splitting it would add a name, not remove one.prefill_must_complete_terminally_from(scheduler.rs:957-987) — partly re-walks whatnatural_fit_prefill_capacity_for_terminal(…, terminal_only = true)walks. Worth a shared helper if the file grows further; a follow-up, not a blocker, and I am not raising it as a suggestion.interpolated_prefill_duration's clamp (cost.rs:779-781) and itsScoredPrefillisolation (:702-707) are the minimum needed to make the rule well-defined, not defensive generality.- No dead code: every new symbol (
PrefillSlotPlanaside) has a live caller, and theeffective_prefill_catalog→prefill_catalog_for_terminalrename left no shim behind.
Conventions (AGENTS.md, module structure)
No structural violation. The change adds no flag, env variable, config knob or extension point — the "one of three homes" rule is about where a new knob may live, and this adds none; whether an implicit change to the shipped balanced preset counts as a "magic default" is the design-fit lens's question, not a simplicity defect. Test placement follows the repo's convention of testing at real production entry points (phase_plan, plan_requires_feedback, candidates, service_rates). The two helper renames are unsolicited churn but are already subsumed by S4 rather than flagged separately.
Open questions / not found
- Does S1's deletion preserve the
phase_planpath?phase_plan(policy.rs:1933) constructs its ownprefill_plansfor a single request across the catalog loop; the eager per-slot computation I propose must still coverTerminalPrefill's promotion ofPrefill(:979-983,:1498-1502). I did not re-derive that path end to end. - Is
last_interpmeasurably useful? No profile in the PR, and the description's "hostplan()4.70×–8.65×faster" figure has no artifact behind it, so I cannot say whether keeping the memo is justified by measurement. Under the lens's rules the unmeasured memo loses to deletion. - S3's semantics under
prompt_logprobs.scan_prefillcloses overcatalog(service.rs:195-199), which selectsscored_prefill_catalogbeforeterminal_onlyis consulted; I did not trace whetherterminal_onlycan be true on that path, so my replacement keeps the boolean identical either way. - S5's pre-filter cost. I could not measure whether the
is_some_andpre-filter's purpose was to skip the predictor work at:745-755in a hot loop; if it was, thereduce-over-collected-pairs form is the safe rewrite rather than the single fused pass.