#1 [high] Lens review PR #661 — Subtraction/Simplicity findings (5 + minor)
PR #661 (FujitsuPolycom) subtraction/simplicity lens. All line numbers at head 29f2b5b.
VERDICT: the diff is unusually disciplined on the policy axis (0 flags, 0 unsafe, 0 env reads, 0 new GraphKind, 0 model branches, docs+README+check.py updated, no dead code, interpolated_prefill_duration is one self-contained pure fn). What it does add is duplicated plumbing: an ad-hoc per-slot memo struct threaded through 5 signatures, one 17-line interpolation block copied twice, and a second catalog-resolution loop. 5 suggestions, all deletions.
S1 (HIGH) — PrefillSlotPlan + prefill_slot_state + prefill_slot_nat_fit (policy.rs:79-86, :420-456) duplicate a cache that already exists, and cost 5 signature changes.
- 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> } - policy.rs:420-456
prefill_slot_state/prefill_slot_nat_fit= two lazy memos with two separate_readyflags. - Threaded as a new last parameter
prefill_plans: &mut [PrefillSlotPlan; REQUEST_LANES]intoadd_candidate(policy.rs:1314-1324),continuation_candidate(policy.rs:937), and constructed at 3 sites (policy.rs:1486, :1933) — half the call sites (Vision/Init/Restore/Snapshot/Resume/Decodearms at :1522-1538) pass it into a function that ignores it entirely. - The memo is redundant for two of three fields:
estimated_checkpoint_cutalready goes throughcheckpoint_selection_cachedkeyed on(RequestHandle, bool)inside thePlanningScopethat bothselect_plan(policy.rs:1642) andphase_plan(policy.rs:1909) install (checkpoints.rs:11-19, :410-428).prefill_requires_terminal_completion_for_ageandnatural_fit_prefill_capacity_for_terminalare pure functions of(request, cut, terminal_only, kind)andage_price/kind-set are constant for a wholecandidates()call, soready/nat_fit_readybuy only the O(capacities×slots)→O(slots) dedupe — whichnext_progressalready gets for free fromnatural_fit.get_or_insert_with(policy.rs:756, :768-775). - REPLACE: drop the struct and both helpers; compute
(cut, terminal_only, nat_fit)once per slot eagerly at the top ofcandidates()/phase_plan()into a local[(Option<usize>, bool, Option<usize>); REQUEST_LANES](nat_fit keyed by the 3 prefill kinds, or&mutrefreshed only whenkindchanges inside the existingif kind.is_prefill()arm), and pass&instead of&mut. Removes ~40 lines, 5 signature edits, 2 flags and one invariant ("nat_fit is only valid after state()") that nothing enforces. - Alternative if eager is unwanted: fold these two entries into
checkpoints::SelectionCache(already a per-request HashMap with aboolkey) instead of a second cache.
S2 (HIGH) — the last_interp interpolation block is copy-pasted verbatim, 17 lines × 2.
- policy.rs:1006-1022 and policy.rs:1356-1372 are byte-identical apart from
request→randwidth→capacity:&& 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 } }(second copy at :1363-1370 useskind, capacity, work, r.scheduled_consumed.) - REPLACE with one helper on
RequestScheduler: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>returningSome(ns)/Some(0)/None, called from both sites. −17 lines and removes the only place where the two call sites can drift. - Bonus deletion: the memo itself saves at most one O(entries) scan when two slots happen to report the same
(work, start), inside a loop that is already O(capacities × slots) and re-runsinterpolated_prefill_durationper capacity. Droppinglast_interpaltogether deletes 8 more lines and thew == work && pos == ...guard.
S3 (MEDIUM-HIGH) — service_rates scans the same catalog twice for one flipped boolean.
- 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)takes the max over a strict superset ofscan_prefill(true)'s candidates, so the second pass subsumes the first; thetoken_rate == 0.0guard exists only because the first pass was already paid for, and inside thiselse if prefillbranchtoken_rateis set by nothing else (it starts at 0.0 at :166).- REPLACE both calls 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));That is −9 lines: delete the second call, the== 0.0gate, and one full catalog walk per admission.
S4 (MEDIUM) — prefill_catalog_for_terminal is a near-duplicate of prefill_catalog.
- policy.rs:342-358:
prefill_catalogmatchesScoredPrefill→scored,TerminalPrefill→terminal,_→prefill;prefill_catalog_for_terminal(kind, terminal_only)matchesScoredPrefill→scored,terminal_only→terminal,_→prefill. - Exactly equivalent to
self.prefill_catalog(if terminal_only { GraphKind::TerminalPrefill } else { kind })(ScoredPrefill is matched first in both). - REPLACE the 9-line body with that one line and keep the old name at call sites; that also makes the
effective_prefill_catalog→prefill_catalog_for_terminalrename (6 call sites: policy.rs:446, :755, :1789 + the 3 diff hunks) and thenatural_fit_prefill_capacity→natural_fit_prefill_capacity_for_terminalrename (which only exists to accept the extraterminal_only: bool) unnecessary churn — delete them and pass the resolvedGraphKindinstead.
S5 (MEDIUM) — interpolated_prefill_duration implements its peer ordering rule four times.
- cost.rs:734-744 (skip form:
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(...) { continue; }) - cost.rs:759-772 (accept form: the same
key.tokens < c || (key.tokens == c && better_at_same_cap(...))/key.tokens > c || ...predicates again, with a closurebetter_at_same_capdefined for the second copy only). - The
hi/lopair plus the pre-filter is 40 lines for "nearest strictly-larger measured peer, nearest measured smaller peer, preferring the same kind at equal capacity". - REPLACE with one local
fn better(new_cap, new_same, cur: (usize, bool, u64), want_hi: bool) -> booland a single pass that only calls it (drop theis_some_andpre-filter, which is exactly the negation of the accept test) — or collect(capacity, same_kind, ns)andreducewith the two orderings. −15 lines, one comparator instead of four.
MINOR (noting only, per lens rules on unit tests) — cost.rs adds 3 tests (:1280, :1355, :1474) that each re-declare the same 25-line make/step_for/timing closures, on top of 2 pre-existing copies (:1092/:1107/:1121 and :1212/:1226). Hoisting them to module-level #[cfg(test)] helpers removes ~100 lines; the realistic_sm120_duration_ns/gb10 tables in policy_tests.rs:6975-7010 likewise restate scripts/scheduling_sim/workloads.py:58-91 by hand.
ALSO CHECKED, deliberately NOT flagged: terminal_prefill_window field (scheduler.rs:657, :842-860) is a hoist of an O(catalog) computation on the resolve_prefill_kind_from hot path — it is an optimisation requested in #538's review, keep it, though note both catalog setters must call recompute_terminal_prefill_window while scored_prefill_catalog (:818) correctly does not; has_active_age_priced_stream (scheduler.rs:989-998) is one predicate answering two questions (barrier + interpolation gate) but both derive from the same documented condition, so keep; prefill_must_complete_terminally_from (scheduler.rs:957-987) partly re-walks what natural_fit_prefill_capacity_for_terminal(…, terminal_only=true) walks, and the two catalogs could be resolved once by a shared helper — worth a follow-up if the file grows further, not a blocker.
#3 [high] S1 evidence — PrefillSlotPlan memo is under-keyed, delete not repair
Verification strengthening S1 (delete the memo rather than repair it). prefill_slot_nat_fit (policy.rs:437-456) memoises on slot alone and ignores its own kind argument on later calls:
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(request, catalog, plan.cut, plan.terminal_only);
plan.nat_fit_ready = true;
}
plan.nat_fit
candidates() (policy.rs:1487-1497) iterates Prefill, TerminalPrefill, ScoredPrefill, Vision, … in order, sharing one prefill_plans for the whole call but NOT across mixed_candidates/packed_round_candidates (constructed at :1486 after those). So:
- The pre-existing inline form recomputed per (kind, slot):
self.natural_fit_prefill_capacity(r, self.effective_prefill_catalog(request, following, cut), cut)(old policy.rs, removed at diff hunk @@ -937,23 +984,51) witheffective_prefill_catalogreturning the SCORED catalog for ScoredPrefill unconditionally. - The new memo computes nat_fit once for kind=Prefill. Under
terminal_only == falsethe catalogs coincide (bothprefill_catalog) so the ScoredPrefill reuse is harmless. Underterminal_only == truethe cached value was computed overterminal_prefill_catalog, so the ScoredPrefill iteration incandidates()and the ScoredPrefill path inadd_candidateare priced against a terminal-catalog natural fit instead of the scored one — a behaviour change the diff does not intend and the tests do not cover (the new-nat-fit tests at policy_tests.rs:7432, :7530, :7830 use Prefill/TerminalPrefill only). This is a reason to DELETE the slot memo (S1) rather than add akinddimension to its key: recomputing per (slot, kind) is what the pre-existing code did, is O(capacities) per kind, is already bounded by ≤12 catalog entries, and removes the stateful invariant entirely. Same argument coversplan.cut/plan.terminal_only, which additionally bakeage_priceinto a cachedbool(policy.rs:430-431) even thoughlane_valuesreturns a singleage_pricefor the wholecandidates()call.
#4 [high] Research summary
Subtraction/Simplicity lens on PR #661 — five deletions, all in the new plumbing, none touching the scheduling policy itself. Findings are saved in the scratchpad (entries 1–3) with verbatim quotes and file:line at head 29f2b5b.
The diff is lean on the axis that matters. No flags, unsafe, env reads, new GraphKind, model branches, CLI/PolicyConfig fields or wire changes; no dead code left behind; interpolated_prefill_duration is a single self-contained pure function; docs, README and the check.py (not opened) mutation anchor are updated in the same change; the terminal_prefill_window field is a legitimate hot-path hoist requested in #538's review, not speculative state. What the PR does add is duplicated plumbing.
S1 (high) — PrefillSlotPlan + prefill_slot_state + prefill_slot_nat_fit (policy.rs:79-86, :420-456) duplicate a cache that already exists and cost five signature changes. The struct is two lazy memos with two _ready flags, threaded as a new trailing &mut [PrefillSlotPlan; REQUEST_LANES] parameter into add_candidate (:1314-1324) and continuation_candidate (:937) and built at three sites (:1486, :1933) — while half the call sites (Vision/Init/Restore/Snapshot/Resume/Decode, :1522-1538) pass it to a function that ignores it. plan.cut is already cached for free: estimated_checkpoint_cut goes through checkpoint_selection_cached keyed on (RequestHandle, bool) inside the PlanningScope both select_plan (:1642) and phase_plan (:1909) install (checkpoints.rs:11-19, :410-428); age_price is constant for a whole candidates() call; and next_progress already gets the nat-fit dedupe from natural_fit.get_or_insert_with (:756, :768-775). Worse, the memo is keyed on slot alone and ignores the kind it is handed on later calls, so candidates()' shared array serves ScoredPrefill a nat fit computed over the terminal catalog when terminal_only is true — an unintended change the new tests don't cover. Delete the struct and both helpers; compute the triple per slot (or per slot×kind) inside the existing if kind.is_prefill() arm.
S2 (high) — the last_interp block is copy-pasted verbatim, 17 lines twice (policy.rs:1006-1022 and :1356-1372, differing only request→r, width→capacity). Extract one unmeasured_prefill_ns(...) helper returning Some(ns)/Some(0)/None; dropping last_interp entirely saves 8 more lines and its w == work && pos == … guard only ever saves one O(entries) scan inside an already O(capacities×slots) loop.
S3 (medium-high) — service_rates walks the same catalog twice for one boolean (service.rs:224-231): scan_prefill(false) takes the max over a strict superset of scan_prefill(true), and inside this branch token_rate starts at 0.0 from nothing else, so the == 0.0 gate only exists to avoid re-paying the first pass. Replace both calls with one scan_prefill(terminal_only && !allow_nonterminal).
S4 (medium) — prefill_catalog_for_terminal (policy.rs:350-358) near-duplicates prefill_catalog (:342-348) and exists only to take a pre-resolved terminal_only bool, which is what drags the natural_fit_prefill_capacity→…_for_terminal rename through six call sites. Three lines instead of nine; exact safe rewrite in scratchpad entry 2 (keep ScoredPrefill first for precedence).
S5 (medium) — interpolated_prefill_duration states its peer-ordering rule four times (cost.rs:734-744 skip form, :759-772 accept form with a closure defined for that copy only). One better(cap, same, cur) comparator and a single pass replaces the hi/lo pre-filter, which is exactly the negation of the accept test. −15 lines.
Minor, noted not flagged: the three new cost.rs tests re-declare the same 25-line make/step_for/timing closures on top of two pre-existing copies (~100 lines hoistable), and policy_tests.rs:6975-7010 restates workloads.py:58-91 by hand. has_active_age_priced_stream and prefill_must_complete_terminally_from are kept — the latter only partly re-walks what the nat-fit loop walks, and is worth a follow-up rather than a blocker.
#5 [high] Final report draft — Subtraction/Simplicity lens, PR #661
Subtraction, Simplicity & Conventions lens — PR #661, head 29f2b5b. Publish-ready report; details and verbatim quotes for each item are in entries 1 (S1–S5, minor, not-flagged), 2 (S4 exact rewrite) and 3 (S1 delete-not-repair evidence).
VERDICT PARAGRAPH (lead with this): The diff is lean on the axis that matters. No flags, unsafe, environment reads, new GraphKind, model branches, CLI or PolicyConfig fields, or wire/ABI changes; no dead code left behind; interpolated_prefill_duration is a single self-contained pure function; docs/scheduling-runtime-design.md, helios/README.md and the check.py mutation anchor are updated in the same change; and the cached terminal_prefill_window (scheduler.rs:657, :842-860) is a legitimate hot-path hoist of an O(catalog) computation on the resolve_prefill_kind_from path, requested in #538's review — keep it. Nothing here is a speculative-generality or config-knob finding. What the PR does add is duplicated plumbing: an ad-hoc per-slot memo threaded through five signatures, one interpolation block copied twice, a second catalog-resolution switch, and a catalog walked twice for one boolean.
S1 (high) — PrefillSlotPlan + prefill_slot_state + prefill_slot_nat_fit (policy.rs:79-86, :420-456) duplicate a cache that already exists and cost five signature changes. Two lazy memos, two _ready flags, threaded as a new trailing &mut [PrefillSlotPlan; REQUEST_LANES] into add_candidate (:1314-1324) and continuation_candidate (:937), built at :1486 and :1933 — while half the call sites (Vision/Init/Restore/Snapshot/Resume/Decode, :1522-1538) hand it to a function that ignores it. plan.cut is already cached: estimated_checkpoint_cut goes through checkpoint_selection_cached keyed on (RequestHandle, bool) inside the PlanningScope both select_plan (:1642) and phase_plan (:1909) install (checkpoints.rs:11-19, :410-428); age_price is constant for a whole candidates() call; next_progress already dedupes nat fit via natural_fit.get_or_insert_with (:756, :768-775). And the memo is keyed on slot alone while ignoring the kind it is handed on later calls, so the array shared across candidates()' Prefill→TerminalPrefill→ScoredPrefill walk serves ScoredPrefill a nat fit computed over the terminal catalog when terminal_only is true (unintended; new tests cover Prefill/TerminalPrefill only). So: delete the struct and both helpers rather than repair them — compute (cut, terminal_only, nat_fit) per slot (or per slot×kind) inside the existing if kind.is_prefill() arm. Removes ~40 lines, five signature edits, two flags, and one invariant ("nat_fit is only valid after state()") that nothing enforces.
S2 (high) — the last_interp block is copy-pasted verbatim, 17 lines twice: policy.rs:1006-1022 and :1356-1372, identical apart from request→r and width→capacity. Extract one unmeasured_prefill_ns(kind, capacity, work, start, nat_fit, age_price, last) -> Option<u64> returning Some(ns)/Some(0)/None, called from both sites; that also removes the only place the two copies can drift. Dropping the last_interp memo entirely saves 8 more lines: it only ever saves one O(entries) scan inside an already O(capacities×slots) loop.
S3 (medium-high) — service_rates walks the same catalog twice for one boolean (service.rs:224-231). scan_prefill(false) takes the max over a strict superset of scan_prefill(true)'s candidates, and inside this else if prefill branch token_rate starts at 0.0 with nothing else setting it (:166), so the token_rate == 0.0 gate exists only to avoid re-paying the first pass. Replace both calls with let allow_nonterminal = terminal_only && self.has_active_age_priced_stream() && !self.prefill_must_complete_terminally_from(request, start, cut); then token_rate = token_rate.max(scan_prefill(terminal_only && !allow_nonterminal)); — −9 lines and one full catalog walk per admission.
S4 (medium) — prefill_catalog_for_terminal (policy.rs:350-358) near-duplicates prefill_catalog (:342-348): same kind→catalog switch, differing only in that it takes a pre-resolved terminal_only bool. Three lines instead of nine (keep the ScoredPrefill test first for precedence; exact body in entry 2 — in practice prefill_requires_terminal_completion_from returns false early for prompt_logprobs at scheduler.rs:924, so the shorter form is behaviourally identical). Removing the duplicate switch also removes the reason for the natural_fit_prefill_capacity→…_for_terminal rename that churns six call sites (:446, :447, :755, :769, :1789 + next_progress).
S5 (medium) — interpolated_prefill_duration states its peer-ordering rule four times: the skip form at cost.rs:734-744 (key.tokens > c || (key.tokens == c && cur_same && !same_kind)) and the accept form at :759-772 with a better_at_same_cap closure defined only for the second copy. One better(cap, same, cur) -> bool comparator and a single pass replaces the hi/lo pre-filter, which is exactly the negation of the accept test. −15 lines, one comparator instead of four.
MINOR (below the sparing threshold, one line each in the report): the three new cost.rs tests (:1280, :1355, :1474) re-declare the same 25-line make/step_for/timing closures on top of two pre-existing copies (:1092/:1107/:1121, :1212/:1226) — ~100 hoistable lines; policy_tests.rs:6975-7010 hand-restates the tables in scripts/scheduling_sim/workloads.py:58-91.
DELIBERATELY NOT FLAGGED (state plainly, so the report doesn't read as a hunt): terminal_prefill_window (scheduler.rs:657, :842-860) — keep, it is the #538-review hoist; only note both catalog setters call recompute_terminal_prefill_window while scored_prefill_catalog (:818) correctly does not. has_active_age_priced_stream (scheduler.rs:989-998) — one predicate answering two questions, but both derive from the same documented condition. prefill_must_complete_terminally_from (scheduler.rs:957-987) — partly re-walks what natural_fit_prefill_capacity_for_terminal(…, true) walks and could share a helper, but that is a follow-up, not a blocker.
CONVENTIONS: nothing in AGENTS.md is violated structurally — no new flag or config knob that bypasses the "one of three homes" rule (the behaviour is implicit in the existing balanced preset, which is the documented reading question flagged by the design-fit lens, not a simplicity defect), no env variable, no speculative extension point, no unsolicited rename sweep beyond the two helper renames already covered by S4. Test placement follows the repo's "tests at real production entry points" convention (phase_plan, plan_requires_feedback, candidates, service_rates).
#2 [medium] S4 refinement — exact collapse of prefill_catalog_for_terminal
Correction/refinement to S4 in entry 1: the exact replacement must keep the ScoredPrefill test first, because prefill_catalog_for_terminal(ScoredPrefill, true) returns &self.scored_prefill_catalog while prefill_catalog(TerminalPrefill) would return the terminal catalog. So the 9-line body at policy.rs:350-358
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 }
}
collapses to the two-line body
fn prefill_catalog_for_terminal(&self, kind: GraphKind, terminal_only: bool) -> &[usize] {
self.prefill_catalog(if terminal_only { GraphKind::TerminalPrefill } else { kind })
}
only if the ScoredPrefill-first ordering is preserved, i.e. keep if kind == GraphKind::ScoredPrefill { &self.scored_prefill_catalog } else { self.prefill_catalog(if terminal_only { GraphKind::TerminalPrefill } else { kind }) }. In practice the two are mutually exclusive — prefill_requires_terminal_completion_from returns false early when request.prompt_logprobs is set (scheduler.rs:924) — so the shorter form is behaviourally identical today, but the two-branch form is the safe rewrite: 3 lines instead of 9, and it removes the duplicate kind→catalog switch that prefill_catalog already implements (policy.rs:342-348). The substantive point of S4 stands: the function exists only to take a pre-resolved terminal_only bool, and that is what drags the natural_fit_prefill_capacity→..._for_terminal rename through 6 call sites.