#1 [high] Research summary
Subtraction / Simplicity review — PR #645
The diff is dense but mostly load-bearing; I found 6 concrete subtractions/collapses, ranked. (Correctness issues left to the other lens.)
1. Newly added dead code: Candidate::feedback is written and then unconditionally overwritten. materialize sets it and immediately replaces it:
// policy.rs:1793-1797
requires_feedback: candidate.feedback,
},
};
plan.checkpoint_plans = self.plan_checkpoints(&plan.step);
plan.step.requires_feedback = self.plan_requires_feedback(&plan);
The sole read of candidate.feedback is that line 1793. This PR adds two more writes to it plus a misleading comment:
// policy.rs:1287-1290
let selected = 1u64 << slot;
// `materialize` computes the authoritative `plan_requires_feedback` after
// checkpoint cuts and any prefill resizing are resolved.
let feedback = !matches!(kind, GraphKind::Decode | GraphKind::Speculative | GraphKind::Prefill);
and
// policy.rs:1705-1711
candidate.duration_ns = duration_ns;
candidate.feedback =
!matches!(kind, GraphKind::Decode | GraphKind::Speculative | GraphKind::Prefill);
Delete both new assignments and the 1288-1289 comment (or delete the feedback field from Candidate, policy.rs:92, and the feedback: false/true literals in rounds.rs:714,876 and policy.rs:1540). This removes 7 added lines that cannot affect behaviour.
2. ActionCosts::prefill_duration re-implements prefill_entry, including the duplicated Key literal. cost.rs:529-557 builds Key{drafts:0,kind,batch:1,tokens:capacity,prefill:0,packed:0}, and cost.rs:559-583 builds the identical literal. The 29-line body collapses to two lines on top of the existing single-lookup accessor with identical semantics (unmeasured → Some(0), no predictor → raw estimate.nanos):
// replace cost.rs:544-556 with
self.prefill_entry(kind, capacity)
.map(|predictor| predictor.map_or(0, |p| p.predict(work, start_position)))
prefill_predictor (585-587) then stays as prefill_entry(..).flatten(). One entry() per call is preserved, so the ENTRY_LOOKUPS budget (cost.rs:673-677) is unaffected.
3. PrefillBucket re-implements the 9-sample ring + median already in the same file as ReplayTimes. cost.rs:126-169 duplicates cost.rs:389-413, including the identical ring arithmetic and the identical middle-pair average:
// PrefillBucket::median, cost.rs:160-163
let lo = ordered[mid - 1];
let hi = ordered[mid];
let nanos = ((u128::from(lo.nanos) + u128::from(hi.nanos) + 1) / 2) as f64;
Some((nanos, 0.5 * (lo.u + hi.u), 0.5 * (lo.h (not opened) + hi.h (not opened))))
vs ReplayTimes::observe, cost.rs:407-409 ((u128::from(ordered[middle-1]) + u128::from(ordered[middle]) + 1) / 2) as u64. Collapse to one generic ring: make ReplayTimes generic over the sample type (PrefillSample is Copy + Ord-able already, ordering provided at 152-157) or keep ReplayTimes and hold u/h in parallel arrays. Saves ~25 lines and leaves one median definition.
4. Unreachable guard plus a redundant second slot scan in the coalescing path. scheduler.rs:1109-1112:
fn prefill_step_requires_feedback(&self, plan: &ScheduledPlan) -> bool {
if plan.kind != GraphKind::Prefill {
return true;
}
is dead: the only call site is scheduler.rs:1137, guarded by plan.kind == GraphKind::Prefill. Delete the guard and express the kind dispatch once (scheduler.rs:1135-1137) as match plan.kind { Decode | Speculative => false, Prefill => self.prefill_step_requires_feedback(plan), _ => true }. Separately, coalescing_prefill_log_bonus scans every slot twice with overlapping filters — policy.rs:453-482 counts prefillers and recomputes post_prefill, then policy.rs:592-619 re-scans the same slots with !r.prompt_logprobs && r.scheduled_consumed < r.prompt_tokens as u64 and recomputes the identical post_prefill (475-477 vs 605-607). Record (slot, post_prefill) in the first pass ([(usize, f64); REQUEST_LANES], REQUEST_LANES-bounded) and reuse it; ~15 lines gone and one scan of the slot table.
5. One predicate copied into eight places, and the copies already disagree. The widened non-barrier kind list now appears at transport.rs:968 and 1021, threaded.rs:876, parallel.rs:263, threaded/protocol.rs:35, scheduler.rs:1136, policy.rs:1290 and policy.rs:1711 — while policy.rs:1338 still carries the old two-kind list:
// policy.rs:1335-1338
let feedback = !self.costs.is_fresh(cost::Key { drafts,
kind, batch, tokens: capacity, prefill: 0, packed,
})
|| !matches!(kind, GraphKind::Decode | GraphKind::Speculative)
manifest.rs:84-101 is already the home for exactly this kind of predicate (is_prefill, samples). Add pub fn pipelines(self) -> bool { matches!(self, Self::Decode | Self::Speculative | Self::Prefill) } and use it at all six sites; the drift at policy.rs:1338 then cannot happen.
6. resize_prefill hand-rolls the new effective_prefill_catalog, with a guard that is already inside the callee. policy.rs:1688-1694:
let catalog = if !request.prompt_logprobs
&& self.prefill_requires_terminal_completion(request, cut)
{
&self.terminal_prefill_catalog
} else {
self.prefill_catalog(request.prefill_kind())
};
The !request.prompt_logprobs test is redundant — scheduler.rs:909-911 returns false for prompt_logprobs — so this is exactly self.effective_prefill_catalog(request, request.prefill_kind(), cut), the helper added at policy.rs:341-354. Replace the 6 lines with the one call; policy.rs:1089 and 1424 are candidates for the same treatment.
Minor: scripts/scheduling_sim/workloads.py:52-53 adds burst_four_low/burst_eight_low, which no test or script references (only burst_eight is used, tests/test_scheduling_utility.py:339) — either assert on them or drop them. And PolicyConfig::coalescing_horizon_tokens (policy.rs:26/42) is a new always-on coefficient with no --scheduler-* flag and no server-config key while every sibling has one (AGENTS.md:188-193, "no configuration switches without a concrete requirement"): either wire it through flare-cli/server/config.rs (not opened) like its siblings, or make it a module const. Docs were updated in three places, which is above the repo's norm; no AGENTS.md structural violations beyond the above.
#2 [high] PR #645 subtraction/simplicity review — 6 findings with citations
Lens: Subtraction, Simplicity & Conventions. PR #645, head 05cccb6, 20 files +1417/-127. Verdict: dense but mostly load-bearing; 6 real subtractions found.
F1 (dead code, added by this PR). Candidate::feedback (policy.rs:92) is written and then unconditionally overwritten — its only read is policy.rs:1793.
policy.rs:1793-1797: requires_feedback: candidate.feedback, / }, / }; / plan.checkpoint_plans = self.plan_checkpoints(&plan.step); / plan.step.requires_feedback = self.plan_requires_feedback(&plan);
This PR adds two more writes + a misleading comment:
policy.rs:1287-1290: let selected = 1u64 << slot; / // \materialize` computes the authoritative `plan_requires_feedback` after/// checkpoint cuts and any prefill resizing are resolved./let feedback = !matches!(kind, GraphKind::Decode | GraphKind::Speculative | GraphKind::Prefill);policy.rs:1705-1711:candidate.duration_ns = duration_ns;/candidate.feedback =/ !matches!(kind, GraphKind::Decode | GraphKind::Speculative | GraphKind::Prefill);Fix: delete both new assignments + comment; or delete the field entirely (also rounds.rs:714feedback: false, rounds.rs:876 feedback: false, policy.rs:1540 feedback: true`). Removes ~7 added lines.
F2 (duplication inside cost.rs). ActionCosts::prefill_duration (cost.rs:529-557) re-derives the exact Key literal that prefill_entry (cost.rs:559-583) already builds: Key { drafts: 0, kind, batch: 1, tokens: capacity, prefill: 0, packed: 0 } at cost.rs:536-543 and again 564-571.
Replace body (cost.rs:544-556) with:
self.prefill_entry(kind, capacity) / .map(|predictor| predictor.map_or(0, |p| p.predict(work, start_position)))
Same semantics (missing entry -> None; nanos==0 -> Some(0) -> 0; no predictor -> raw estimate.nanos). One entry() call preserved so ENTRY_LOOKUPS budget (cost.rs:673-677) unchanged. prefill_predictor (585-587) stays as prefill_entry(..).flatten().
F3 (duplication in cost.rs). New PrefillBucket (cost.rs:126-169) duplicates existing ReplayTimes (cost.rs:389-413) — same 9-slot ring (self.samples[self.next] = sample; self.next = (self.next+1)%self.samples.len(); self.len = (self.len+1).min(self.samples.len());) and same middle-pair average:
cost.rs:160-163: let lo = ordered[mid - 1]; / let hi = ordered[mid]; / let nanos = ((u128::from(lo.nanos) + u128::from(hi.nanos) + 1) / 2) as f64; / Some((nanos, 0.5 * (lo.u + hi.u), 0.5 * (lo.h + hi.h)))
vs cost.rs:407-409: ((u128::from(ordered[middle - 1]) + u128::from(ordered[middle]) + 1) / 2) as u64
Fix: make ReplayTimes generic over the sample type (ordering policy passed in / PrefillSample ordering already at cost.rs:152-157), or keep one ring and hold u/h in parallel arrays. Saves ~25 lines, one median definition.
F4 (dead guard + duplicate slot scan). scheduler.rs:1109-1112:
fn prefill_step_requires_feedback(&self, plan: &ScheduledPlan) -> bool { / if plan.kind != GraphKind::Prefill { / return true; / }
Guard is unreachable: only call site scheduler.rs:1137 is || (plan.kind == GraphKind::Prefill && self.prefill_step_requires_feedback(plan)). Folding: replace scheduler.rs:1135-1137 with a match plan.kind { Decode | Speculative => false, Prefill => self.prefill_step_requires_feedback(plan), _ => true }.
Also coalescing_prefill_log_bonus scans all slots twice with overlapping filters: policy.rs:453-482 computes post_prefill at 475-477 (let post_prefill = (r.max_new_tokens as usize).min(self.limits.max_sequence_tokens.saturating_sub(r.prompt_tokens)).saturating_sub(1);) and policy.rs:592-619 recomputes the identical expression at 605-607 under the same !r.prompt_logprobs && r.scheduled_consumed < r.prompt_tokens as u64. Record (slot, post_prefill) in pass 1 in a [(usize, f64); REQUEST_LANES]. ~15 lines saved.
F5 (conventions/drift: predicate copied 8x, copies already disagree). Widened non-barrier list GraphKind::Decode | GraphKind::Speculative | GraphKind::Prefill at transport.rs:968, transport.rs:1021, threaded.rs:876, parallel.rs:263, threaded/protocol.rs:35, scheduler.rs:1136, policy.rs:1290, policy.rs:1711 — but policy.rs:1335-1338 still has the OLD two-kind list:
let feedback = !self.costs.is_fresh(cost::Key { drafts, / kind, batch, tokens: capacity, prefill: 0, packed, / }) / || !matches!(kind, GraphKind::Decode | GraphKind::Speculative)
manifest.rs:84-101 is the existing home (is_prefill 85-87, samples 89-100). Add pub fn pipelines(self) -> bool { matches!(self, Self::Decode | Self::Speculative | Self::Prefill) } and use at all six+ sites.
F6 (helper not used where it applies). policy.rs:1688-1694 in resize_prefill:
let catalog = if !request.prompt_logprobs / && self.prefill_requires_terminal_completion(request, cut) / { / &self.terminal_prefill_catalog / } else { / self.prefill_catalog(request.prefill_kind()) / };
The !request.prompt_logprobs test is redundant — scheduler.rs:909-911 already returns false for prompt_logprobs — so this is exactly the new helper effective_prefill_catalog (policy.rs:341-354). Replace with one call. policy.rs:1089 (self.prefill_catalog(request.prefill_kind())) and policy.rs:1424 (for &capacity in self.prefill_catalog(kind)) are the same candidates.
Minor. (a) scripts/scheduling_sim/workloads.py:52-53 adds burst_four_low/burst_eight_low; no test or script references them (only burst_eight, tests/test_scheduling_utility.py:339) — drop or assert. (b) PolicyConfig::coalescing_horizon_tokens (policy.rs:26, default policy.rs:42 = 64.0, validated policy.rs:225-230) is a new always-on coefficient with no --scheduler-* flag and no server-config key while every sibling has one (AGENTS.md:188-193 forbids configuration switches without a concrete requirement, and the defaults table docs/scheduling-runtime-design.md:651-661 is untouched) — either wire it like its siblings or make it a const.
Docs were updated in three places (docs/scheduling-runtime-design.md:198-207, 403-423, 567-577), above repo norm; no other AGENTS.md structural violations. Pure correctness issues (policy.rs:812-820 mixed branch guard, checkpoints.rs stride loss at :225) deliberately left to the Correctness lens.