#1 [high] Research summary
Subtraction, Simplicity & Conventions review of #674 (head 45fb3809) — five high-value simplifications, each with exact citations; the rest of the diff is genuinely lean.
What is already lean (no action). Several parts of this diff are consolidations rather than accumulations and should not be touched: Incoming::clear_pool_lookup (helios/src/server/runtime.rs:375-382) collapses four repeated 2–3 line resets; refresh_admission_plan_in_place (helios/src/scheduler.rs:1554-1558) removes a whole clone; Core::release_removed / update_clean_slots (selene/src/memory.rs:958-969, :939-945) replace five hand-maintained clean_slots adjustment sites; the host_cache_disk_* / host_cache_disk_reserved_* metric split is a real separation, and host_pool_rates_present (metrics.rs:312, :672-679) correctly suppresses absent gauges instead of emitting zeros.
S1 (highest value) — delete the cold-start prefill EMA instead of patching it. observe_prefill_rate (helios/src/server/runtime.rs:3052-3075) is unreachable: capacity = step.prefill_capacity() as u64; if !step.kind.is_prefill() || step.lanes.len() != 1 || capacity == 0 … while prefill_capacity() is mixed.as_ref().map_or(0, …) (scheduler.rs:465-467) and mixed is only legal on GraphKind::Mixed (scheduler.rs:437-462), which is_prefill() excludes (manifest.rs:85-87). The correctness lens will file "repair it to use token_capacity"; the subtraction answer is the opposite: remove the function, the prefill_rate: f64 field (runtime.rs:1251, :1288), the self.prefill_rate argument at :1646, the fallback_prefill_rate parameter and its tail let gained = candidate_tokens.saturating_sub(resident_tokens); gained as f64 / fallback_prefill_rate.max(1.0) (runtime.rs:3266-3268), and then the now-orphaned INITIAL_PREFILL_RATE (selene/src/store.rs:447) plus worth_fetching/worth_transfer (store.rs:457-470), whose only remaining callers after this PR are tests (selene/src/disk_store/coalesce/tests.rs (not opened), composite.rs:2920 (not opened)) — helios now calls worth_restore only (runtime.rs:238, :3362). Net: ~45 lines and one dead public API removed instead of one bug fixed.
S2 — RowRestoreLatency re-implements selene::levels::Rate. The new tracker (runtime.rs:261-332) is a copy of the existing 3-sample ring with the same 10 s half-life: bucket.samples[bucket.next] = seconds; bucket.next = (bucket.next + 1) % bucket.samples.len(); … let mut ordered = bucket.samples; ordered[..bucket.count].sort_by(f64::total_cmp); bucket.last_median = Some((ordered[bucket.count / 2], Instant::now())); versus self.samples[self.next] = bytes as f64 / elapsed.as_secs_f64(); … let mut values = self.samples; values[..self.count].sort_by(f64::total_cmp); self.median = values[self.count / 2]; with RECOVERY = 10 s (selene/src/levels.rs:34, 57-87). Also RowRestoreSource + the free row_restore_source constructor (runtime.rs:246-260) hand-roll a (pooled, tier) key that selene already models as a level. Recommendation: keep one ring type (generalise Rate to compare on latency, or add a Latency sibling next to it) and key the map on the existing tier/level type; ~90 new lines become a thin wrapper. Note the median-index inversion the correctness lens reports lives in exactly this duplicated block, so collapsing the copy fixes that too.
S3 — drop the priority_uses_role_preserving flag and the duplicated priority closure. select_eviction_candidate (cache.rs:732-792) takes a fifth parameter purely to decide whether to build the O(N) map: let track_role_preserving = priority_uses_role_preserving || (below.is_some() && protected_token_budget.is_some());, and that flag exists only because there are two public wrappers (cache.rs:794-811) over the same private function. The map is built at most once per selection pass, so always tracking is simpler than a boolean that two call sites hard-code to true/false (eviction_candidate_within_budget passes |_, _| ()). Collapse to a single select_eviction_candidate(below, immediate, budget, priority) with eviction_candidate_within_budget delegating via |_, _| (). Related: the same closure is written out three times — page_pressure_victim_priority(&self.snapshot_pages, &refs, node, role_preserving) at cache_memory.rs:394-406, at :627-638, and in the reference model at :1235-1248 — hoist one fn snapshot_page_priority(&self, refs, node, role_preserving) method and call it from both production sites (the test copy is an acceptable independent model).
S4 — remove plan_refreshed and the three-arm plan match. A bool is threaded from begin_pool_lookup (runtime.rs:1602-1613) through a nine-field HostAdmissionProbe (:3288) into 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 } … } (runtime.rs:3314-3323) solely to skip one refresh that begin_pool_lookup has already performed on incoming.pool_plan in place (:3194-3197, :3209-3212). Passing queued_plan: Option<&AdmissionPlan> and always plan.clone() (the clone is needed either way) deletes the flag, its field, and one of the three arms. begin_pool_lookup itself also has two near-identical "refresh in place, return false on error" blocks (:3194-3197 and :3209-3212) that collapse into one prologue.
S5 — conditioned_window_ends duplicates the window partition in set_conditioned_inputs, and conditioned_inputs_from_images is a redundant wrapper. The new estimator helper (scheduler.rs:2110-2142) re-derives exactly the boundaries set_conditioned_inputs already computes at :2183-2196: if !in_window || features + input.feature_range.len() > capacity { if in_window { ends.push(input.token_span.start); } in_window = true; features = 0; } features += input.feature_range.len(); versus if windows.is_empty() || features + input.feature_range.len() > capacity { if let Some(previous) = windows.back_mut() { previous.prefill_end = input.token_span.start; } … } features = 0;. Extract one partition_conditioned_inputs(inputs, capacity) -> Vec<usize> (boundary token per window) and build both windows and ends from it; this also removes the drift risk the docs now describe. Separately, fn conditioned_inputs_from_images(images: &[PreparedImageInput]) -> Vec<ConditionedInput> (runtime.rs:3271-3277) is a five-line free function that only calls the new PreparedImageInput::conditioned_input method (frontend/images/conditioned.rs:150-158); map at the two call sites (:1713, :3335) and delete the free function.
Minor (mention, not a blocker). assert_clean_slots_invariant is guarded at every call site with #[cfg(any(debug_assertions, test))] — ~15 repetitions in selene/src/memory.rs (e.g. :716-717, :781-782, :1111-1112, :1178, :1279, :1351-1352); a fn debug_check(&self) whose body is cfg-gated would keep call sites one line. And Core::evictable (memory.rs:910-916) duplicates the inline can_evict closure in allocate_slots (:738-745), though the borrow split there is a legitimate reason.
Conventions. No AGENTS.md violation found in scope: no environment-variable toggles, no model-identity switches, no new config knobs (the TierStore::retired/pending_pool_drain signature changes are declared in the PR body's public-API list), and the invariant/test additions follow the repository's "test the contract" rule. The one convention-adjacent concern is S1's dead-but-shipped fallback path, which the repository's "reject fallback layers … without a concrete requirement" rule covers.
#2 [high] PR #674 Subtraction/Simplicity lens — 5 high-value simplifications with citations
PR #674 (head 45fb3809), Subtraction / Simplicity & Conventions lens. All items verified in tree.
S1 (HIGHEST) — delete the cold-start prefill EMA rather than repair it.
- helios/src/server/runtime.rs:3052-3075
fn observe_prefill_rate(&mut self, step:&ScheduledStep, tokens:u64, timing). Guard:let capacity = step.prefill_capacity() as u64; if !step.kind.is_prefill() || step.lanes.len() != 1 || capacity == 0 || (step.lanes[0].tokens as u64).saturating_mul(2) < capacity { return; } - Unreachable: prefill_capacity() ==
self.mixed.as_ref().map_or(0, |m| m.prefill_capacity)(helios/src/scheduler.rs:465-467);mixedlegal only on GraphKind::Mixed (scheduler.rs:437-462); is_prefill() = Prefill|TerminalPrefill|ScoredPrefill only (helios/src/execution/manifest.rs:85-87). - Call site runtime.rs:1931. Field
prefill_rate: f64runtime.rs:1251, init :1288flare_selene::INITIAL_PREFILL_RATE. Passed to admit_with_host_store at runtime.rs:1646. - Fallback tail: runtime.rs:3266-3268
let gained = candidate_tokens.saturating_sub(resident_tokens); gained as f64 / fallback_prefill_rate.max(1.0). - Then-orphaned public API: selene/src/store.rs:447
pub const INITIAL_PREFILL_RATE: f64 = 8000.0;, store.rs:457-470worth_fetching/worth_transfer— after this PR helios calls onlyworth_restore(runtime.rs:238, :3362); remaining worth_fetching callers are tests (selene/src/disk_store/coalesce/tests.rs, selene/src/composite.rs:2920). - Contrast: main sampled every prefill by fence elapsed, no capacity gate.
S2 — RowRestoreLatency duplicates selene::levels::Rate.
- New tracker helios/src/server/runtime.rs:261-332 (
RowRestoreBucket:263-269,RowRestoreLatency:275-281,RECOVERY_SECONDS = 10.0:282, observe :308-320, estimate :322-332). - Verbatim copy of selene/src/levels.rs:57-76 (
observe: 3-sample ring,sort_by(f64::total_cmp),values[count/2],RECOVERY = Duration::from_secs(10)at levels.rs:34). Note median index inversion (correctness lens) lives in this duplicated block. - Also duplicated key:
RowRestoreSource { pooled, tier }+ free fnrow_restore_sourceruntime.rs:246-260 — selene already has Level/Tier model (selene/src/levels.rs:10-28, 109-114 POOL_LEVELS). - Fix: one latency ring type (generalise Rate or add sibling) + key on existing tier/level; ~90 new lines become a thin wrapper.
S3 — eviction selection flag + triplicated priority closure.
- helios/src/cache.rs:732-792
select_eviction_candidate<K: Ord>(below, immediate, protected_token_budget, priority_uses_role_preserving: bool, mut priority); line 740-741let track_role_preserving = priority_uses_role_preserving || (below.is_some() && protected_token_budget.is_some());. Map built once per pass (:744-753), so always-on is cheaper to reason about than a bool. - Wrappers cache.rs:794-802
eviction_candidate_with_priority(passes true) and :804-811eviction_candidate_within_budget(passes false,|_,_| ()). - Same closure written 3×: helios/src/scheduler/cache_memory.rs:394-406, :627-638 (evict_for_pressure), test model :1235-1248. Hoist
fn snapshot_page_priority(&self, refs, node, role_preserving) -> (bool,u64,bool)and call from both production sites.
S4 — plan_refreshed bool + 3-arm plan match.
- helios/src/server/runtime.rs:1602-1613 computes
let plan_refreshed = if let Some(store) = … { begin_pool_lookup(...) } else { false };; stored asplan_refreshed: boolin structHostAdmissionProbe(:3288, destructured :3311). - Match runtime.rs:3314-3323:
(Some(plan), true) => plan.clone(), (Some(plan), false) => { let mut plan = plan.clone(); scheduler.refresh_admission_plan_in_place(&mut plan)?; plan } (None,_) => …. The flag exists only because begin_pool_lookup already refreshed in place (:3194-3197, :3209-3212). Passqueued_plan: Option<&AdmissionPlan>, always clone, delete flag+field+arm. - begin_pool_lookup has two near-identical "refresh in place, return false" blocks (:3194-3197, :3209-3212) → one prologue.
S5 — conditioned-window partition duplicated; redundant free wrapper.
- New helios/src/scheduler.rs:2110-2142
conditioned_window_endsre-derives boundaries already computed inset_conditioned_inputsat scheduler.rs:2181-2196:if !in_window || features + input.feature_range.len() > capacity { if in_window { ends.push(input.token_span.start); } in_window = true; features = 0; } features += input.feature_range.len();vsif windows.is_empty() || features + input.feature_range.len() > capacity { if let Some(previous) = windows.back_mut() { previous.prefill_end = input.token_span.start; } … }. Extractpartition_conditioned_inputs(inputs, capacity) -> Vec<usize>; both consume it. Used at helios/src/scheduler/checkpoints.rs:466, :482. fn conditioned_inputs_from_imagesruntime.rs:3271-3277 is a 5-line wrapper over the new methodPreparedImageInput::conditioned_input(helios/src/frontend/images/conditioned.rs:150-158); map directly at :1713 and :3335, delete wrapper.
Minor (mention only): #[cfg(any(debug_assertions, test))] self.assert_clean_slots_invariant(); repeated ~15× in selene/src/memory.rs (:716-717, :781-782, :1026-1027, :1111-1112, :1149-1150, :1178, :1279, :1351-1352, :3211-3212, :3348 etc.) — a single fn debug_check(&self) with cfg-gated body keeps call sites one line. Core::evictable (memory.rs:910-916) duplicates inline can_evict closure in allocate_slots (:738-745) (borrow split is a legitimate reason).
Already lean / do NOT change: Incoming::clear_pool_lookup runtime.rs:375-382; refresh_admission_plan_in_place scheduler.rs:1554-1558 (removes a clone); Core::release_removed memory.rs:958-969 and update_clean_slots :939-945; metric split host_disk_records vs reserved + host_pool_rates_present gate (helios/src/server/metrics.rs:309-315, 656-679, 1409-1428) which correctly suppresses absent gauges; evict_for_pressure fallback to evict (cache_memory.rs:599-607) is a legitimate delegation, not speculative generality.
Conventions: no AGENTS.md violation found — no env-var toggles (AGENTS.md:452-455), no per-model flags/allowlists (:352-364), no new config knobs; Public API changes (TierStore::retired, pending_pool_drain, HostHit.pooled, StoreStats reserved/rate fields, worth_restore, levels::POOL_LEVELS) are declared in the PR body. The dead fallback of S1 falls under "reject fallback layers … without a concrete requirement" (AGENTS.md:188-193).