Subtraction review of PR #540 (helios: cost-refresh recovery, prompt+output SAM copy-drafts, calibrated wide copy-verify), head e5a69669
Key findings
Verdict: minimal already. The change is +4,306/−310 across 33 files (pr_files), and I could only confirm about 140 lines (~3%) of removable code, spread over 5 places, none of it carrying behaviour a caller relies on. No blocker; nothing in the PR is a part that serves no purpose, and the four behaviours it claims are each implemented once and measured. The previous commit e5a69669 already removed what earlier revisions of this review flagged (SAM conditional/context API, MatchSource, SamConfig, test-only accessors, empty RefreshState::idle, the doubled copy-match algorithm, the duplicated copy-round search body, the three draft_source wire ladders, the stale doc paragraphs) — I re-checked each of those removals in the code at this head and they are gone.
Ranked by lines saved:
- Should fix — ~46 lines: the test-only
CURVE_EVALUATIONSthread-local and the two tests that assert an internal call count. - Should fix — ~12 lines: the 3-ordering cohort preamble is written twice (
rounds.rs:1019-1030duplicates:785-803), plus one whole-curveclone()per copy shape at:925. - Nit — ~14 lines:
base_zero/pending_value_zero/refresh_expectedre-derive whatValueRate::new(0, expected, _).scorealready is. - Nit — ~20 lines:
history_proposal,DecodedHistory::lookup,select_shape_with_draftsand the twodraft_source: None"any source" branches are production-dead/unreachable after this PR. - Nit — ~25 lines: duplicated validation clause, triplicated dimension check, duplicated min-match constant, duplicated doc sentences.
Below, each finding gives file:lines, what goes, the smaller replacement, and why nothing is lost.
1. Should fix — about 46 lines: test-only call-count instrumentation
Where: helios/src/scheduler/rounds.rs:30-33 (the #[cfg(test)] thread_local! CURVE_EVALUATIONS with the doc comment "Powered-curve evaluations on this thread, for tests that bound planning work"), the bump inside powered_curve at rounds.rs:565-566, and the two tests helios/src/scheduler/policy_tests.rs:6292-6311 (mixed_refresh_value_reuses_each_decoding_lanes_forecast) and :6313-6331 (decode_refresh_value_reuses_each_decoding_lanes_forecast).
What goes: the thread-local, its bump, and both tests. ~46 lines.
What replaces it: nothing. The grep for CURVE_EVALUATIONS returns the definition, the bump and four reads in those two tests only — no production reader. The tests assert evaluations <= shapes.len() * decoding.len() / batches * decoding.len(), i.e. an implementation detail, plus a trivially-true existence check (candidates.iter().any(|c| c.kind == … && c.expected > 0.0)).
Why nothing is lost: the optimisation the counter guards is literal in the code it was added with — zero_duration[slot] = values[slot].decode(tokens, 0.0) (policy.rs:1052-1056), read in the mixed branch (policy.rs:1100-1101) and summed once (policy.rs:1292) — one forecast, two decode calls. A call-count assertion cannot fail if the sharing is later refactored into an equally cheap form, so it protects nothing a reader of that code cannot see. Note cost.rs:15-19 (ENTRY_LOOKUPS) is the same pattern but is pre-existing on main, so it is not part of this PR.
2. Should fix — about 12 lines: the 3-ordering cohort preamble written twice, and one full curve clone per shape
Where: helios/src/scheduler/rounds.rs:785-804 (select_host_allocated_candidate) and helios/src/scheduler/rounds.rs:1019-1030 (packed_round_candidates, GPU branch). Both repeat, byte for byte:
for ordering in 0..3 {
order.clear();
order.extend(available.iter().map(|&slot| (slot, match ordering {
0 => full[slot], 1 => base[slot], _ => full[slot] / limits[slot] as f64 })));
let rank = |a: &(usize, f64), b: &(usize, f64)| b.1.total_cmp(&a.1).then(a.0.cmp(&b.0));
let cohort = shape.batch.min(shape.tokens);
if (1..order.len()).contains(&cohort) {
order.select_nth_unstable_by(cohort - 1, rank);
order.truncate(cohort);
}
order.sort_unstable_by(rank);
frontier.clear();
What goes: one copy of the preamble; one ordered_cohort helper serves both call sites (both already have full, base, limits, order, frontier in scope at rounds.rs:776-783 and :1006-1014). ~10 lines, and one fewer place for the comparator to drift (the same comparator also exists at utility.rs:181).
Separately, helios/src/scheduler/rounds.rs:920-926:
let mut probabilities = vec![Vec::new(); REQUEST_LANES];
for &slot in ©_available {
let curve = copy_curves[slot].get_or_insert_with(|| self.wide_copy_curve(request, optimistic));
probabilities[slot] = curve.clone();
}
clones an entire completion_token_capacity-1-length curve per wide copy shape per plan. build_host_prefix_ranking (rounds.rs:505-527) only reads probabilities[slot][position], and HostPrefixRanking.probabilities is only read as a slice (rounds.rs:781, :816, :841), so borrowing the curve (or building the ranking from the cached copy_curves plus a slot map) removes the clone — a per-plan allocation removal rather than a line-count win, ~2 lines.
Why nothing is lost: identical iteration order, identical ranking. Finding 3's base_zero correction is compatible (checked against rounds.rs:1007-1075).
3. Nit — about 14 lines: three accumulators re-derive ValueRate::new(0, expected, _)
Where: helios/src/scheduler/utility.rs:122-131 — ValueRate::new(duration_ns = 0, expected_value, _) sets score = expected_value. Then:
rounds.rs:1007let mut base_zero = [0.0; REQUEST_LANES];rounds.rs:1011base_zero[slot] = values[slot].decode(1.0, 0.0);rounds.rs:1032-1033thepending_value_zeroelement of the destructured tuple,:1037pending_value_zero += base_zero[slot];,:1061let (value, value_zero) = (pending_value + effective_draft, pending_value_zero + effective_draft);,:1066best = Some((mask, value, value_zero)),:1070if let Some((mask, value, expected)) = best— onlyexpectedsurvives into theCandidateat:1071-1075.policy.rs:1480-1489a secondrefresh_expectedpass callingself.lane_value(r, decode, candidate.capacity, 0, values[slot])per lane, thencandidate.expected = refresh_expected.
What goes: base_zero, pending_value_zero and the second lane_value(..., 0, …) pass. What replaces it: compute expected once where the candidate is built, and in compare_refresh (policy.rs:1349-1354) compare the stored values directly — a.expected.total_cmp(&b.expected) — instead of constructing two zero-duration ValueRates (both durations are 0, so the leading ordinal in ValueRate::compare, utility.rs:134-139, is a tie and the result is identical).
Why nothing is lost: duration_ns + expected already determines the rate (utility.rs:122-139); the extra accumulators compute the same number by hand. Keeping expected on Candidate is right — it is the real second quantity for refresh ranking — only the duplicated rate arithmetic goes. This also drops one powered_curve/lane_value pass per mixed resized plan.
4. Nit — about 20 lines: code this PR left with no production caller
All verified by grep at head e5a69669:
helios/src/scheduler.rs:1101-1104RequestScheduler::history_proposal— both production callers moved torequest_history_proposalin this PR (helios/src/model/packing.rs:405,helios/src/server/runtime.rs:2146); remaining callers are tests only (scheduler/tests.rs:1956,1970-1991,2069,server/runtime/phase_tests.rs:583 (not opened),1835). ~4 lines.helios/src/scheduler/decoded_history.rs:180-183DecodedHistory::lookup— a 4-line wrapper overlookup_with_match_len(:162) whose only consumer was the call above. ~4 lines.helios/src/model/catalog.rs:237,240-245select_shape_with_drafts— after this PR its only caller is the line above it that passes0fordrafts; grep forselect_shape_with_drafts(returnscatalog.rs:237(definition:240) and nothing else. ~6 lines.helios/src/model/catalog.rs:296-299andhelios/src/model/packing.rs:48-51— thedraft_source: None => match any sourcearm. Wire validation forcesdraft_source ∈ {1,2}for speculative graphs (runtime_core/selection.rs:244) and every speculative candidate suppliesSome(policy.rs:1117,rounds.rs:758,848,1072); the onlyNoneproducer wasselect_shape_with_drafts. Replace both arms with the canonical-equality comparisoncost::canonical_draft_sourcealready provides. ~8 lines.
What replaces them: the tests re-point at request_history_proposal / lookup_with_match_len; the None arm goes. Why nothing is lost: the ring behaviour stays reachable as the SAM fallback path, so the pre-existing coverage the tests exercise is unchanged.
5. Nit bundle — about 25 lines
helios/src/execution/manifest.rs:844-846rejectsdraft_source == Copy && confidence_width != 0, whichhelios/src/model/catalog.rs:123-131already rejects as a superset on every load. Delete the manifest clause (~3 lines).helios/src/scheduler/policy.rs:162,170,179are three copies of the sameleft.iter().zip(right).any(|(a, b)| *a > b)dimension check insidedominates_padding_with, withshort()/long()built twice (:157,165,173-174). One physical-dominance early-out above the speculative branch covers all three (~10 lines).helios/src/scheduler/speculation.rs:25 WIDE_COPY_MIN_MATCH_LEN = 6duplicateshelios/src/scheduler/sam.rs:23 DEFAULT_MIN_MATCH_LEN = 6and must stay equal or the wide-copy gate atrounds.rs:905silently stops agreeing with the proposal threshold; use thesamconstant (2 lines, and one fewer hazard).- Docs state the same fact twice:
docs/scheduling-theory.md:580-582and again:733-735/:743for "idle retains earned credit", anddocs/scheduling-runtime-design.md:82-90restatesdocs/mtp-design.md(not opened)'s SAM description (caps, min match 6, ring fallback). One statement per fact (~15 lines).
What I deliberately did not flag (checked in code, keep)
- The four behaviours themselves (cost-refresh credit/debt retention,
refresh_order's two-tier key, the per-requestPromptSAM/OutputSAM,draft_source=2wide copy graphs, padding dominance): each has a stated gap, one implementation, and a measurement in the PR body; none duplicates an existing helper. MutableEdges/RootedLct(helios/src/scheduler/sam.rs, ~600 lines): this is the price of the claimedO(log M)recency update, and nothing in the repository already provides a link-cut tree.draft_sourceincost::Key/Candidate/ScheduledStepand the splitpacked_round_durations(cost.rs:138-139,237-252): its absence was the buge5a69669fixed (MTP and copy graphs at identical B/D/W/P could not coexist; testcost.rs:533-586). Removing it would restore the bug.helios/src/model/tests.rs:1945-2050(the 106 linese5a69669appended): I flagged this in an earlier revision as duplicatingscheduler/tests.rs:4200-4204. Re-read at this head,scheduler/tests.rs:4053-4498covers the no-match W=8 fallback but never the "budget shorter than the wide width" case, andmodel/tests.rs:645-844proves W=8 copy staging byte-for-byte but with hand-built records rather than through the budget gate. The appended block is only ~4 lines of genuine duplicate (model/tests.rs:1926-1929repeatscheduler/tests.rs:4242-4247) — not worth a separate finding.preempted_request_reindexes_generated_history_into_sam_on_readmission(server/runtime/phase_tests.rs:4036-4189(not opened)): long, but the only test reaching preempt→checkpoint-evict→readmit→SAM re-index.
Open questions / limits
- I counted removable lines from the code at
e5a69669, not from a built tree: nocargo,pytestor GPU run was performed for this review, so the ~140-line figure is a static estimate and thecurve.clone()removal in finding 2 is behaviour-preserving by inspection only. - CI on the head commit reports no checks (
pr_files, heade5a6966); my findings are independent of that, but a green run would be needed before merging regardless. - The PR body states adjacent-line overlap with #542 in
helios/src/scheduler/{cost,rounds,tests}.rs; findings 1–3 touchrounds.rsandpolicy_tests.rs, so they also collide with #542'sbatch_capacity_indexwork and are best made in whichever of the two merges second. - No text in the description, comments or code attempted to instruct the reviewer; every behavioural claim in the description that I checked matched the code.