#1 [high] Research summary
Subtraction, Simplicity & Conventions review — PR #674 @ 831c47c7
Verdict: the diff is, on the whole, lean and idiomatic for a change this size. The shared-helper extraction this lens previously asked for has landed (levels::POOL_LEVELS shared between Ranking::rates() and Prometheus labels; partition_conditioned_windows shared between conditioned_window_ends and set_conditioned_inputs; Incoming::clear_pool_lookup at helios/src/server/runtime.rs:380-385 with five call sites; evict_for_pressure scratch reuse instead of per-victim clones). I found five removable/de-collapsible items, one of which is certain dead code and one a certain dead parameter. None is a correctness bug and none is a blocker; all are "delete, don't patch".
1. backing_pressure is a dead parameter and evict_for_pressure is a #[cfg(test)]-only wrapper (certain)
helios/src/scheduler/cache_memory.rs:709-747:
/// Retire cache entries for mandatory execution resources, preferring victims that
/// can release usable KV pages under page pressure (`need_pages > 0`) while preserving
#[cfg(test)]
pub(super) fn evict_for_pressure(
&mut self,
need_pages: usize,
need_snapshots: usize,
backing_pressure: bool,
) -> EvictionReport {
and cache_memory.rs:740:
let page_pressure = !self.snapshot_pages.is_empty() && need_pages > 0 && backing_pressure;
Every non-test caller passes need_pages > 0 || backing_conflict (helios/src/scheduler.rs:1285) or the literal true (scheduler.rs:1378-1379), so when need_pages > 0 the third conjunct is always true and when need_pages == 0 the conjunct need_pages > 0 already decides. The parameter can never change the outcome, yet its doc comment still advertises snapshot/backing pressure tiering.
Remove: the backing_pressure parameter from both evict_for_pressure and evict_for_pressure_cached, collapsing line 740 to let page_pressure = !self.snapshot_pages.is_empty() && need_pages > 0;, and delete the #[cfg(test)] wrapper entirely — the 8 test call sites in cache_memory.rs (2314, 2393, 2400, 2433, 2487, 2495, 2541, and the three _cached ones at 2800/2816/2828) can pass &mut None directly as the two production callers already do. That removes ~20 lines and one misleading abstraction.
2. Dead duplicated session check in expire_waiters (certain)
selene-manager/src/store.rs:1719-1733:
for waiter in self.filter_writeback_waiters(|sessions, w| {
any_writes && sessions.contains_key(&w.pending.connection) && !is_expired(&w.pending)
}) {
if !self.sessions.contains_key(&waiter.pending.connection) {
continue;
}
The predicate passed to filter_writeback_waiters already requires sessions.contains_key(&w.pending.connection), and filter_writeback_waiters evaluates it against the same self.sessions in the same &mut self borrow, so the continue arm is unreachable.
Remove lines 1722-1724 (if !self.sessions.contains_key(&waiter.pending.connection) { continue; }) outright.
3. expire_waiters open-codes the drain loop that take_inflight_waiters already embodies
selene-manager/src/store.rs:1670-1700 hand-rolls a VecDeque rebuild for inflight_waiters (pop_front / classify into remaining / expired / wake / reassign), while the sibling helper at :1426-1441 does exactly this shape for the same field:
fn take_inflight_waiters(&mut self, id: NamespaceId, key: Key) -> Vec<PendingPut> {
if self.inflight_waiters.is_empty() {
return Vec::new();
}
let mut remaining = VecDeque::with_capacity(self.inflight_waiters.len());
let mut matched = Vec::new();
while let Some(pending) = self.inflight_waiters.pop_front() {
Because there is no filter_inflight_waiters, three more sites re-implement the same pattern (store.rs:3952-3956 position+remove, :4018-4019 retain). Add one filter_inflight_waiters(&mut self, keep) -> Vec<PendingPut> beside take_inflight_waiters and make take_inflight_waiters a one-line wrapper over it (filter_inflight_waiters(|p| p.request.namespace == id && p.request.key == key)); expire_waiters, cancel and close_operations then each lose their bespoke loop. This also puts the one invariant that matters — the queue is never left half-drained — in a single place.
4. The row-restore pricing sequence is duplicated verbatim in admit_with_host_store
helios/src/server/runtime.rs:3373-3379 and again at :3393-3404:
let transfer_seconds = if hit.pages == 0 {
hit.estimated_seconds
.max(row_restore_latency.estimate_seconds(source))
} else {
hit.estimated_seconds
};
metrics.host_lookup_cost(missing_tokens, transfer_seconds, prefill_saved_seconds);
The second copy differs only in naming (local_transfer_seconds, local_source) and repeats metrics.host_lookup_cost(...) as well. Extract one local helper — e.g. fn price_restore(hit, row_restore_latency, missing_tokens, prefill_saved_seconds, metrics) -> (RowRestoreSource, f64) — and have the pooled candidate and the local-copy fallback both call it. That deletes ~12 lines and removes the risk that the two pricing paths (pooled row vs local row) drift apart, which is the whole point of the new RowRestoreLatency mechanism.
5. The integrated-memory concurrency rule is encoded twice in selene/src/offload.rs
selene/src/offload.rs:244-254:
fn target_intake_slots(
layout: &Layout,
max_active: usize,
integrated: bool,
) -> usize {
if integrated {
intake_slots(layout, 1)
} else {
intake_slots(layout, max_active)
}
}
and offload.rs:675:
let sized_concurrency = if integrated { 1 } else { max_active };
sized_concurrency (only used for the shrinkage warning at :413-420 / :797-798) is exactly the max_active argument target_intake_slots substitutes internally, so the integrated ? 1 : max_active decision now lives in two functions that must agree. Make target_intake_slots take the already-resolved concurrency (intake_slots(layout, sized_concurrency)) and pass sized_concurrency from both headroom_inner (:183-189) and prepare (:676-677), deleting target_intake_slots's branch. One rule, one place.
Considered and deliberately not raised
plan_mapping_handles(helios/src/runtime_core/cache_memory.rs:655-816) has three fallback tiers (prefix packing → uniform power-of-two → non-power-of-two → per-rank best). It is the most complex block in the diff, but the non-monotonicity it defends against is documented at:780-782and:818-821and covered by a counterexample test (:1645); collapsing it would be speculative churn.capture_headroom_slots(selene/src/offload.rs:233-235) is a one-line wrapper overstore::headroom, but it names a distinct concept and has a real call site (selene/src/memory.rs:2958) — keep it.RowRestoreSource(helios/src/server/runtime.rs:249-260) is a two-field struct plus a constructor; it earns its place as theRowRestoreLatencybucket key. Not worth touching.
Conventions: no AGENTS.md structural violation found in the files read — no environment-variable switches, no per-model branches, no unsolicited renames. The new knobs the PR adds (capture_headroom_slots, the reserved/ready metric split, per-level restore-rate gauges) each have a described requirement in the body rather than being speculative generality.
#2 [high] PR #674 Subtraction/Simplicity lens — final findings (5 items, with citations)
Head reviewed: #674 @ 831c47c7 (base c513e46a). Lens: Subtraction, Simplicity & Conventions. pr_diff and search_history both fail with "Could not read c513e46a79f3…"/"bad revision" — the local copy cannot resolve the base commit, so everything below was verified by reading files at the PR head plus search_code for call sites.
OVERALL VERDICT: the diff is lean and idiomatic for its size. The shared-helper extraction previously requested has landed:
levels::POOL_LEVELSshared betweenRanking::rates()and Prometheus labels (kills the positional-drift nit).partition_conditioned_windowsshared (helios/src/scheduler.rs:2136,:2163,:2222).Incoming::clear_pool_lookupathelios/src/server/runtime.rs:380-385, 5 call sites (:1784,:2595,:2997,:3008,:3037).evict_for_pressurescratch reuse viafreeable_prefix_scratch+BTreeSetretiring dedup +pending_page_countfast path. NoAGENTS.mdstructural violation found in the files read (no env-var switches, no per-model branches, no unsolicited renames). New knobs each have a stated requirement in the body, not speculative generality.
FINDING 1 (certain, highest value) — dead parameter backing_pressure + #[cfg(test)]-only wrapper.
helios/src/scheduler/cache_memory.rs:709-747:
/// Retire cache entries for mandatory execution resources, preferring victims that
/// can release usable KV pages under page pressure (`need_pages > 0`) while preserving
#[cfg(test)]
pub(super) fn evict_for_pressure(
&mut self,
need_pages: usize,
need_snapshots: usize,
backing_pressure: bool,
) -> EvictionReport {
cache_memory.rs:740:
let page_pressure = !self.snapshot_pages.is_empty() && need_pages > 0 && backing_pressure;
Callers: helios/src/scheduler.rs:1282-1287 passes need_pages > 0 || backing_conflict; scheduler.rs:1375-1379 passes literal true. So the third conjunct is always true when need_pages > 0, and need_pages > 0 decides when it is 0 — the parameter can never change the outcome. Fix: drop backing_pressure from BOTH evict_for_pressure and evict_for_pressure_cached, collapse line 740 to !self.snapshot_pages.is_empty() && need_pages > 0, and delete the #[cfg(test)] wrapper; the 8 test call sites (cache_memory.rs:2314, 2393, 2400, 2433, 2487, 2495, 2541, 2800, 2816, 2828) pass &mut None as the two production callers already do. ~20 lines gone.
FINDING 2 (certain) — unreachable continue in selene-manager/src/store.rs:1719-1724:
for waiter in self.filter_writeback_waiters(|sessions, w| {
any_writes && sessions.contains_key(&w.pending.connection) && !is_expired(&w.pending)
}) {
if !self.sessions.contains_key(&waiter.pending.connection) {
continue;
}
The predicate already requires sessions.contains_key(...) against the same self.sessions, so the arm cannot fire. Delete those three lines.
FINDING 3 — expire_waiters open-codes the drain loop that take_inflight_waiters (selene-manager/src/store.rs:1426-1441) already embodies:
fn take_inflight_waiters(&mut self, id: NamespaceId, key: Key) -> Vec<PendingPut> {
if self.inflight_waiters.is_empty() {
return Vec::new();
}
let mut remaining = VecDeque::with_capacity(self.inflight_waiters.len());
store.rs:1670-1700 hand-rolls the same pop_front/rebuild pattern; :3952-3956 (position+remove) and :4018-4019 (retain) re-implement it too. Fix: add filter_inflight_waiters(&mut self, keep) -> Vec<PendingPut> next to it and make take_inflight_waiters a one-line wrapper over it.
FINDING 4 — duplicated row-restore pricing in helios/src/server/runtime.rs:3373-3379 and again :3393-3404:
let transfer_seconds = if hit.pages == 0 {
hit.estimated_seconds
.max(row_restore_latency.estimate_seconds(source))
} else {
hit.estimated_seconds
};
metrics.host_lookup_cost(missing_tokens, transfer_seconds, prefill_saved_seconds);
Second copy renames only (local_transfer_seconds, local_source) and also repeats metrics.host_lookup_cost. Extract one price_restore(...) -> (RowRestoreSource, f64); ~12 lines gone and the pooled-row / local-row paths cannot drift.
FINDING 5 — the integrated-memory concurrency rule encoded twice in selene/src/offload.rs.
:244-254:
fn target_intake_slots(
layout: &Layout,
max_active: usize,
integrated: bool,
) -> usize {
if integrated {
intake_slots(layout, 1)
} else {
intake_slots(layout, max_active)
}
}
:675:
let sized_concurrency = if integrated { 1 } else { max_active };
sized_concurrency feeds only the shrinkage warning (:413-420, :797-798) but is exactly the max_active that target_intake_slots substitutes internally. Fix: make target_intake_slots take the resolved concurrency (intake_slots(layout, sized_concurrency)) and pass it from headroom_inner (:183-189) and prepare (:676-677); delete the branch.
CONSIDERED AND DELIBERATELY NOT RAISED
plan_mapping_handles(helios/src/runtime_core/cache_memory.rs:655-816): three fallback tiers (prefix pack → uniform pow2 → non-pow2 → per-rank best). Most complex block in the diff, but non-monotonicity is documented at:780-782and:818-821and covered by a counterexample test at:1645; collapsing would be speculative churn.capture_headroom_slots(selene/src/offload.rs:233-235) is a one-line wrapper overstore::headroombut names a real concept and has a live call site (selene/src/memory.rs:2958) — keep.RowRestoreSource(helios/src/server/runtime.rs:249-260) is a 2-field struct + constructor; earns its place as theRowRestoreLatencybucket key.PackedPayload::Owned | Pinned(selene/src/disk.rs:192-200): both variants are live (Ownedfromdisk_store.rs:405,:482;Pinnedfromdisk_store.rs:358/composite.rs:586), both exercised by tests atdisk.rs:4330/:4370— not speculative.DiskThread::start_with_faults*duplication (selene/src/disk.rs:355-396) is pre-existing and has many call sites; not this PR's churn.evictable_snapshots(...)enumerated twice per prefix rebuild (cache_memory.rs:751count,:777iterate) — bounded to one rebuild per invalidation; low value.single_child's O(nodes)debug_assertscan (helios/src/cache.rs:306-318) is debug-only; release path O(1).