#1 [high] Research summary
Subtraction, Simplicity & Conventions — review of #674 @ 19ce4a7b
Scope I actually read (the files this lens can judge): helios/src/server/runtime.rs, helios/src/server/metrics.rs, helios/src/cache.rs, helios/src/scheduler.rs (plan refresh region), selene/src/store.rs, selene/src/levels.rs, selene/src/composite.rs, selene/src/pool/lookup.rs, selene-manager/src/store.rs (waiter/arena regions), selene-manager/src/arena.rs, selene-manager/src/pool/claims.rs, plus AGENTS.md. Not opened: selene/src/memory.rs (not opened), selene/src/disk.rs (not opened), selene/src/disk_store.rs (not opened), helios/src/runtime_core/cache_memory.rs (not opened), helios/src/scheduler/cache_memory.rs (not opened), helios/src/scheduler/checkpoints.rs (not opened), helios/src/server/runtime/phase_tests.rs (not opened). The diff is not lean: the packaging changes are sound, but four of them re-implement machinery the repo already owns, and one adds a 13-argument function behind a clippy allow.
S1 (high) — Two "half the prefill" predicates; the selene one is now production-dead. Delete one.
helios/src/server/runtime.rs:225-232:
fn worth_restore(transfer_seconds: f64, prefill_saved_seconds: f64) -> bool {
transfer_seconds.is_finite()
&& prefill_saved_seconds.is_finite()
&& transfer_seconds < 0.5 * prefill_saved_seconds
}
selene/src/store.rs:459-468 already owns this rule, publicly exported (selene/src/lib.rs:53 (not opened)):
pub fn worth_transfer(
gained_tokens: u64,
estimated_seconds: f64,
prefill_tokens_per_second: f64,
) -> bool {
if !estimated_seconds.is_finite() || !prefill_tokens_per_second.is_finite() {
return false;
}
estimated_seconds < 0.5 * gained_tokens as f64 / prefill_tokens_per_second.max(1.0)
}
After this PR the only non-test caller of worth_fetching/worth_transfer is gone (selene/src/store.rs:450-456 survives only in tests: composite.rs:2920,2923, disk_store/coalesce/tests.rs:1798 (not opened),1967,2142,2258). Remove/replace: add pub fn worth_restore_seconds(transfer_seconds, prefill_saved_seconds) next to worth_transfer in selene/src/store.rs, express the existing worth_transfer through it (worth_transfer(g, s, tps) == worth_restore_seconds(s, g as f64 / tps.max(1.0))), delete worth_fetching if nothing but tests needs it, and delete worth_restore from Helios. One predicate, one home, and the two finite-guards stop being maintained twice.
S2 (high) — RowRestoreLatency re-implements selene::levels::Rate; delete the copy rather than patch its clock.
helios/src/server/runtime.rs:268-343 adds a bucket with samples: [f64; 3], count, next, last_median, a RECOVERY_SECONDS = 10.0 decay and:
if bucket.in_flight > 0 {
return median;
}
median * 0.5f64.powf(last.elapsed().as_secs_f64() / Self::RECOVERY_SECONDS)
selene/src/levels.rs:36-87 is the same object, already used for exactly this pricing: samples: [f64; 3] median, RECOVERY: Duration = 10 s, an in-flight hold (Rate::started), and a decayed get():
pub(crate) fn started(&mut self) {
if self.median < self.seed {
self.last = Some(Instant::now());
}
}
The start() copy is where the correctness lens's decay-clock defect lives (runtime.rs:301-303 sets last_median unconditionally on an in-flight start, so a failed fetch resets the decay window). Deleting the copy deletes the bug and ~70 lines: expose Rate (or a thin Latency wrapper over Rate for seconds-per-op samples) from selene::levels, keep HashMap<RowRestoreSource, Rate> in Helios, and keep the per-source in-flight count only if the two-caller hold semantics genuinely differ. Caveat to state in the reply: Rate is pub(crate) and caps get() at its seed, so this is lift-and-generalize (seed = f64::INFINITY or a "no ceiling" variant), not a drop-in — still far less code than a parallel implementation, and it removes the divergent third copy of the median logic after Rate and scheduler::cost::PrefillBucket (helios/src/scheduler/cost.rs:236-262).
S3 (medium) — plan_refreshed is a bool that only means "someone else already refreshed"; it also buys a duplicate refresh.
helios/src/server/runtime.rs:3303-3315:
let plan = match (queued_plan, plan_refreshed) {
(Some(plan), true) => plan.clone(),
(Some(plan), false) => {
let mut plan = plan.clone();
scheduler.refresh_admission_plan_in_place(&mut plan)?;
plan
}
(None, _) => scheduler.plan_admission_with_core_parameters(
The flag is produced solely by begin_pool_lookup's new -> bool (runtime.rs:3183-3240), which refreshes in place itself at :3206-3208 and :3221-3224, and is consumed only at the single call site (runtime.rs:1607-1622, &mut incoming → plan_refreshed). There are now three refresh_admission_plan_in_place call sites (:3207, :3222, :3307) for one admission attempt, so a request that reaches admit_with_host_store with plan_refreshed == false refreshes twice on the retry path. Replace with: begin_pool_lookup returns Option<()>/nothing and admit_with_host_store takes queued_plan: Option<&AdmissionPlan> and never refreshes when one is queued (the queued plan was refreshed by the caller), or better — move the single refresh into admit_with_host_store and have begin_pool_lookup stop refreshing. Either way plan_refreshed and the three-armed match disappear, and the incoming.pool_plan.as_mut().unwrap()/as_ref().unwrap() at :3206/:3235 go with it.
S4 (medium) — Arena::coalescing_block's Some((0, 0)) sentinel is unreachable from both call sites, and its head duplicates can_allocate.
selene-manager/src/arena.rs:163-175:
pub fn coalescing_block(
&self,
length: usize,
candidates: &[(usize, usize)],
) -> Option<(usize, usize)> {
let capacity = length.max(4096).checked_next_power_of_two()?;
let mut free = self.0.free.lock().unwrap().clone();
if free
.range(capacity..)
.any(|(_, offsets)| !offsets.is_empty())
{
return Some((0, 0));
}
That predicate is can_allocate verbatim (arena.rs:145-152), and both callers already rule it out first. selene-manager/src/store.rs:1553-1570:
match waiter.arena_bytes {
Some(bytes) => {
if self.memory.can_allocate(bytes) {
return true;
}
...
self.memory.coalescing_block(bytes, spans).is_some()
and store.rs:2247-2255 reaches it only after self.memory.allocate(bytes) returned None. So the documented Some((0, 0)) "already fits" contract is dead in production and only exercised by its own unit test (arena.rs:390). Replace: drop the clone + range scan and the Some((0, 0)) arm, returning None when no candidate set coalesces the required class; keep the one real call site at store.rs:2255 which needs (block_offset, block_size). That also removes the free-map clone() on the waiter-satisfiability path (store.rs:1567 runs per writeback-waiter scan).
S5 (medium) — admit_with_host_store is now 13 positional parameters under a clippy allow.
helios/src/server/runtime.rs:3285-3302:
#[allow(clippy::too_many_arguments)]
fn admit_with_host_store(
scheduler: &mut RequestScheduler,
store: &mut dyn flare_selene::HostStore,
pool_lookup: Option<&flare_selene::pool::LookupTicket>,
spec: RequestSpec,
prefill_spans: &[std::ops::Range<usize>],
conditioned_images: &[crate::frontend::images::PreparedImageInput],
Six of the 13 are new in this PR, and two of them (prefill_spans, conditioned_images) exist only to feed estimated_prefill_saved_seconds (:3260-3281). AGENTS.md:338 asks that Helios "be kept as simple as possible". Replace: bundle the immutable per-request probe inputs into one struct RestoreProbe<'a> { spec: &'a RequestSpec, prefill_spans: &'a [Range<usize>], conditioned_inputs: Vec<ConditionedInput> } built once at the call site, and drop the allow. Note the same PreparedImageInput::conditioned_input collection is written twice (runtime.rs:1721-1727 and :3324-3327); building it once in the struct removes that duplication too.
S6 (low, but cheap) — Ranking::rates() -> [f64; 4] plus hardcoded positional labels.
selene/src/levels.rs:119-128 returns a positional array skipping Level::ThisGpu, and helios/src/server/metrics.rs:1406-1422 re-supplies the four names by index (("neighbour_gpu", &self.host_pool_inbound_rates[0]), …). Three representations of one ordered set (Option<[f64;4]> in StoreStats, [AtomicU64; 4] + host_pool_rates_present: AtomicBool in Metrics, four &str literals in render). Replace: Level::pool_restore_levels() -> impl Iterator<Item = (Level, &'static str)> in selene/src/levels.rs and rates() returning [(Level, f64); 4] (or Vec); Metrics then stores [(AtomicU64, &'static str); 4] and renders by iteration, deleting the index coupling. Minor: scan_writeback_waiters_step derives the same cursor three ways (selene-manager/src/store.rs:1641-1645, :1648, :1650-1656); one (cursor, remaining) tail assignment would do — do not, however, reopen the filter_writeback_waiters/removed_before_cursor question (single implementation, no lost waiters).
Credit where the diff did subtract
Incoming::clear_pool_lookup (runtime.rs:389-394) replaces five duplicated three-line clears; the metric split removed the HostHit fixture from metrics.rs by giving host_lookup_cost three scalars (metrics.rs:538-560); helios/src/cache.rs replaced an O(N)-per-candidate nodes.values().find(...) with one per-pass single_child_role map (cache.rs:640-655) — keep that, and consider folding the inline role-preserving predicate at :666-674 back into age_discounted_protected_tokens as a single function taking role_preserving. No environment variables, feature switches or speculative flags are added in the files I read, so AGENTS.md:450-472 (Configuration) is respected.
Highest-value actions in order: S2 (delete the duplicated latency tracker and its bug), S1 (one worth-restore predicate), S3 (delete plan_refreshed and the duplicate refresh), S4, S5, S6.
#2 [high] Subtraction lens findings for #674 @ 19ce4a7b (final)
Files read by this lens: helios/src/server/runtime.rs, helios/src/server/metrics.rs, helios/src/cache.rs, helios/src/scheduler.rs (refresh region), selene/src/store.rs, selene/src/levels.rs, selene/src/composite.rs, selene/src/pool/lookup.rs, selene-manager/src/store.rs (waiter/arena regions), selene-manager/src/arena.rs, selene-manager/src/pool/claims.rs, AGENTS.md. NOT opened: selene/src/memory.rs, selene/src/disk.rs, selene/src/disk_store.rs, helios/src/runtime_core/cache_memory.rs, helios/src/scheduler/cache_memory.rs, helios/src/scheduler/checkpoints.rs, helios/src/server/runtime/phase_tests.rs.
S1 (high) Duplicate worth-restore predicate; selene's is production-dead.
helios/src/server/runtime.rs:225-232 fn worth_restore(transfer_seconds, prefill_saved_seconds) = transfer.is_finite() && prefill.is_finite() && transfer < 0.5*prefill.
selene/src/store.rs:459-468 pub fn worth_transfer(gained_tokens, estimated_seconds, prefill_tokens_per_second) already owns the rule (exported at selene/src/lib.rs:53). After this PR the only non-test caller of worth_fetching/worth_transfer is gone: worth_fetching (store.rs:450-456) survives only in tests at composite.rs:2920,2923 and disk_store/coalesce/tests.rs:1798,1967,2142,2258. Fix: add worth_restore_seconds in selene/src/store.rs next to worth_transfer, express worth_transfer through it, delete worth_fetching if test-only, delete worth_restore in Helios.
S2 (high) RowRestoreLatency re-implements selene::levels::Rate.
helios/src/server/runtime.rs:268-343: bucket with samples [f64;3], count, next, last_median, const RECOVERY_SECONDS: f64 = 10.0, estimate_seconds = median while in_flight>0 else median*0.5^(elapsed/10s). selene/src/levels.rs:36-87 Rate is the same object (samples [f64;3], RECOVERY = 10s, started() in-flight hold, decayed get()). The start() copy is where A6's decay-clock bug lives (runtime.rs:301-303 sets last_median unconditionally). Deleting the copy deletes the bug and ~70 lines. Caveat: Rate is pub(crate) and caps get() at seed, so it is lift-and-generalize (seed = infinity variant), not a drop-in. Third copy of median logic after Rate and scheduler::cost::PrefillBucket (helios/src/scheduler/cost.rs:236-262).
S3 (medium) plan_refreshed: bool thread-through exists only to say "already refreshed", and buys a duplicate refresh.
helios/src/server/runtime.rs:3303-3315 three-armed match on (queued_plan, plan_refreshed). Flag produced only by begin_pool_lookup's new -> bool (runtime.rs:3183-3240, which refreshes in place at :3206-3208 and :3221-3224), consumed only at :1607-1622. Three refresh_admission_plan_in_place call sites for one admission attempt: :3207, :3222, :3307; a request arriving with plan_refreshed==false refreshes twice. Fix: single refresh inside admit_with_host_store, begin_pool_lookup returns nothing, drop the flag and the unwrap()s at :3206/:3235.
S4 (medium) Arena::coalescing_block's Some((0,0)) sentinel unreachable in production and duplicates can_allocate.
selene-manager/src/arena.rs:163-175 clones the free map and returns Some((0,0)) when free.range(capacity..).any(|(_,o)| !o.is_empty()) — verbatim can_allocate (arena.rs:145-152). Both callers rule it out first: store.rs:1553-1570 (can_allocate check then coalescing_block(bytes, spans).is_some()) and store.rs:2247-2255 (only after memory.allocate returned None). Documented contract only exercised by arena.rs:390 unit test. Fix: drop the clone+scan and the Some((0,0)) arm, return None when no candidate set coalesces; also drops a free-map clone on the per-waiter scan path (store.rs:1567).
S5 (medium) admit_with_host_store is 13 positional params under #[allow(clippy::too_many_arguments)].
helios/src/server/runtime.rs:3285-3302; six params are new, and prefill_spans + conditioned_images exist only to feed estimated_prefill_saved_seconds (:3260-3281). AGENTS.md:338 "Keep Helios as simple as possible". Fix: one struct RestoreProbe<'a> { spec, prefill_spans, conditioned_inputs } built at the call site; drop the allow. Also PreparedImageInput::conditioned_input collection is written twice (runtime.rs:1721-1727 and :3324-3327).
S6 (low, cheap) Ranking::rates() positional array + hardcoded labels. selene/src/levels.rs:119-128 returns [f64;4] skipping Level::ThisGpu; helios/src/server/metrics.rs:1406-1422 re-supplies names by index 0..3. Three representations of one set: Option<[f64;4]> in StoreStats (selene/src/store.rs:248-256), [AtomicU64;4] + host_pool_rates_present AtomicBool in Metrics (metrics.rs:312-315, 669-682), four &str literals in render. Fix: Level::pool_restore_levels() -> (Level, &'static str) iterator, rates() -> [(Level, f64); 4]; Metrics stores [(AtomicU64, &'static str); 4]. Minor: scan_writeback_waiters_step re-derives the cursor three ways (selene-manager/src/store.rs:1641-1645, :1648, :1650-1656). Do NOT reopen filter_writeback_waiters/removed_before_cursor — single implementation at store.rs:1443-1475, no lost waiters.
Credit/subtractions to keep: Incoming::clear_pool_lookup (runtime.rs:389-394) replaced five duplicated clears; host_lookup_cost three-scalar signature (metrics.rs:538-560) removed the HostHit fixture from metrics tests; helios/src/cache.rs single-child-role map (cache.rs:640-655) replaced O(N)-per-candidate find — keep, maybe fold the inline role-preserving predicate at :666-674 back into a single helper. Conventions check: no env vars, feature switches, or speculative flags in the files read; AGENTS.md:450-472 (Configuration) respected. Diff is NOT lean overall (41 files, ~+10k/-1.1k); the packaging changes (metrics split, clear_pool_lookup, cache.rs role map) are sound.