Subtraction, Simplicity & Conventions review — PR #674 @ 831c47c7
Lens: what can be deleted, collapsed, or made dramatically simpler. Correctness is out of scope here.
Key findings
- Verdict: the diff is, on the whole, lean and idiomatic for a change of +11,418/−1,237 across 42 files. The shared-helper extraction this lens previously asked for has landed (see "Already fixed" below). I found four items worth changing; none is a blocker and none is a correctness bug — each is "delete or collapse, don't patch".
- Certain dead parameter + a
#[cfg(test)]-only production wrapper:backing_pressurecan never change the outcome ofevict_for_pressure_cached(helios/src/scheduler/cache_memory.rs:718,:737,:740), andevict_for_pressureat:713-727exists only for tests. Delete both; ~20 lines. - Duplicated row-restore pricing block in
admit_with_host_store, copied verbatim with renames 20 lines apart (helios/src/server/runtime.rs:3372-3379and:3392-3404). One helper, ~12 lines saved, and the pooled-row / local-row pricing paths can no longer drift. - The integrated-memory concurrency rule is encoded twice in
selene/src/offload.rs— once insidetarget_intake_slots(:244-254) and once assized_concurrency(:675), two functions that must agree. Resolve it once. expire_waitersopen-codes theVecDequedrain thattake_inflight_waitersalready embodies (selene-manager/src/store.rs:1670-1700vs:1426-1441), with nofilter_inflight_waitersto share; two further sites re-implement the same pattern.- Retracted (checked, then withdrawn): I initially read the
continueguard atselene-manager/src/store.rs:1722-1724as unreachable. It is live —filter_writeback_waitersreturns the removed waiters, not the kept ones (:1454-1461). Only a naming trap remains (see "Considered and not raised"). - No material
AGENTS.md/ module-convention violation found in the files read: no environment-variable switches, no per-model branches, no unsolicited renames, and the new knobs each have a stated requirement in the body rather than being speculative generality.
Already fixed from the earlier review of this lens (do not re-raise)
levels::POOL_LEVELSis now shared betweenRanking::rates()and the Prometheus label set (selene/src/levels.rs(not opened), +14).partition_conditioned_windowsis shared byconditioned_window_endsandset_conditioned_inputs(helios/src/scheduler.rs:2136,:2163,:2222).Incoming::clear_pool_lookupconsolidates five reset sites (helios/src/server/runtime.rs:380-385; callers:1784,:2595,:2997,:3008,:3037).evict_for_pressure's hot path now reusesfreeable_prefix_scratchinstead of cloningpage_snapshot_refsper victim (helios/src/scheduler.rs:649,:744;cache_memory.rs:415,:770,:786), dedups retiring snapshots with aBTreeSet(:755-767) and has apending_page_countempty-queue fast path (:662-665).
Finding 1 (highest value, certain) — dead backing_pressure parameter and a #[cfg(test)]-only wrapper
helios/src/scheduler/cache_memory.rs:709-727:
/// Retire cache entries for mandatory execution resources, preferring victims that
/// can release usable KV pages under page pressure (`need_pages > 0`) while preserving
/// reuse protection, demand recency, direct vs inherited pins, retirement fences, and
/// heir notices.
#[cfg(test)]
pub(super) fn evict_for_pressure(
&mut self,
need_pages: usize,
need_snapshots: usize,
backing_pressure: bool,
) -> EvictionReport {
and the only place the parameter is read, cache_memory.rs:740:
let page_pressure = !self.snapshot_pages.is_empty() && need_pages > 0 && backing_pressure;
Both production callers make the third conjunct a constant:
helios/src/scheduler.rs:1282-1287passesneed_pages > 0 || backing_conflict.helios/src/scheduler.rs:1375-1379passes the literaltrue, at a site whereneed_pagesiswant - self.free_pages.len()and the loop has alreadybreak-ed at:1372ifpending_page_count() >= want, soneed_pages > 0holds.
Therefore page_pressure collapses to !self.snapshot_pages.is_empty() && need_pages > 0 in every reachable state: when need_pages == 0 the outer need_pages > 0 decides, and when need_pages > 0 both callers supply true. The parameter cannot change behavior, yet its doc comment (:709-712) still advertises snapshot/backing pressure tiering that no longer exists.
Remove: the backing_pressure parameter from both evict_for_pressure_cached (:733-738) and evict_for_pressure, collapse :740 to let page_pressure = !self.snapshot_pages.is_empty() && need_pages > 0;, and delete the #[cfg(test)] wrapper evict_for_pressure entirely. The 10 test call sites (cache_memory.rs:2314, 2393, 2400, 2433, 2487, 2495, 2541, 2800, 2816, 2828) already pass true/&mut prefix_state and can call evict_for_pressure_cached with &mut None, exactly as the production callers do. Net: ~20 lines and one misleading abstraction gone.
Finding 2 — duplicated row-restore pricing in admit_with_host_store
helios/src/server/runtime.rs:3372-3379:
let source = row_restore_source(&hit);
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);
and 20 lines later, runtime.rs:3392-3404:
let local_source = row_restore_source(&local_hit);
let local_transfer_seconds = if local_hit.pages == 0 {
local_hit
.estimated_seconds
.max(row_restore_latency.estimate_seconds(local_source))
} else {
local_hit.estimated_seconds
};
metrics.host_lookup_cost(
missing_tokens,
local_transfer_seconds,
prefill_saved_seconds,
);
The second copy differs only in the variable names local_*, and it repeats the metrics.host_lookup_cost(...) call as well as the worth_restore test that follows each copy (:3380, :3405).
Replace both with one local helper, e.g.
fn price_restore(
hit: &flare_selene::HostHit,
row_restore_latency: &RowRestoreLatency,
missing_tokens: u64,
prefill_saved_seconds: f64,
metrics: &Metrics,
) -> (RowRestoreSource, f64, bool) // source, transfer_seconds, worth_restore(...)
and call it from both the pooled candidate and the local-copy fallback. That deletes ~12 lines and removes the possibility that the two pricing paths (pooled row vs local row) drift — which is the whole point of the new RowRestoreLatency mechanism in this PR (runtime.rs:247-260, :262-320). Note the existing RestoreWait::defer at :232-244 already shows the extracted-helper style this file prefers.
Finding 3 — the integrated-memory concurrency rule 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 selene/src/offload.rs:675-680:
let sized_concurrency = if integrated { 1 } else { max_active };
let required_intake = if directory.is_some() {
target_intake_slots(&layout, max_active, integrated)
} else {
0
};
sized_concurrency (consumed only by the shrinkage warning at :414 and carried to :798) is exactly the max_active that target_intake_slots substitutes internally, so the "integrated ⇒ concurrency 1" decision now lives in two functions that must stay in agreement — and they are computed three lines apart from the same two inputs.
Simplify: make target_intake_slots take the already-resolved concurrency (fn target_intake_slots(layout: &Layout, concurrency: usize) -> usize { intake_slots(layout, concurrency) }, or drop it and call intake_slots directly), pass sized_concurrency at :677, and have headroom_inner resolve the same value once at :183-189 instead of passing max_active + integrated.
Finding 4 — expire_waiters open-codes the drain loop that take_inflight_waiters already embodies
selene-manager/src/store.rs:1670-1700:
if !self.inflight_waiters.is_empty() {
let mut remaining = VecDeque::with_capacity(self.inflight_waiters.len());
let mut expired = Vec::new();
let mut wake = Vec::new();
while let Some(pending) = self.inflight_waiters.pop_front() {
if !self.sessions.contains_key(&pending.connection) {
continue;
}
while the sibling helper at selene-manager/src/store.rs:1426-1441 performs precisely this shape on 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() {
inflight_waiters has no filter_* counterpart, unlike writeback_waiters, which does (:1443-1475), so every site that must remove a subset hand-rolls the pop/rebuild. Two more instances in the same file from my notes: the position+remove at :3952-3956 and the retain at :4018-4019.
Add one filter_inflight_waiters(&mut self, keep: impl FnMut(&PendingPut) -> bool) -> Vec<PendingPut> beside take_inflight_waiters, make take_inflight_waiters a one-line wrapper over it, and rewrite expire_waiters's first block as a call to it. That puts the only invariant that matters — the queue is never left half-drained — in one place and deletes three bespoke loops.
Considered and deliberately not raised
helios/src/runtime_core/cache_memory.rs:655-816(plan_mapping_handles) — 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 (:780-782,:818-821) and 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 overcrate::store::headroom, but it names a distinct concept with a live call site (selene/src/memory.rs:2958) — keep.RowRestoreSource(helios/src/server/runtime.rs:249-260) is a two-field struct plus constructor; it earns its place as theRowRestoreLatencybucket key.PackedPayload::Owned | Pinned(selene/src/disk.rs:192-200) — both variants are live (disk_store.rs:405(not opened),:482,:358;composite.rs:586(not opened)) and both exercised by tests — not speculative generality.DiskThread::start_with_faults*duplication (selene/src/disk.rs:355-396) is pre-existing with many call sites; not this PR's churn.selene-manager/src/store.rs:1719-1733— I checked and withdrew an earlier claim that thecontinueat:1722-1724is dead.filter_writeback_waitersreturns the removed waiters (:1454-1461:if keep(...) { remaining.push_back(waiter) } else { removed.push(waiter) }), so a waiter whose session vanished does come back and the guard is load-bearing. The residual point is only a naming/contract trap worth one comment: the closure parameter is namedkeepwhile the function returns its complement, so a reader has to reconstruct the polarity before the body's re-tests (is_expired, session membership) make sense. Someone editing this method later will be tempted to delete a guard that matters — a doc line onfilter_writeback_waiters(or naming itremove_*) is the cheap fix; no code change required.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; the release path is O(1).
Conventions check
No structural violation of AGENTS.md conventions in the files read: no new environment-variable switches, no per-model or per-hardware special cases in the hot paths (the integrated-memory branch in Finding 3 is the only capability branch and it already existed), no unsolicited renames, no duplicated metric definitions (the reserved/ready split at selene/src/store.rs and the per-level gauges keyed by levels::POOL_LEVELS are single-sourced). The new knobs the PR adds (capture_headroom_slots, disk reserved-vs-ready, per-level restore-rate gauges) each back a requirement stated in the PR body rather than being speculative generality.
Open questions and what I could not verify
- The base commit could not be resolved with my tools:
pr_difffails with "Could not read c513e46a79f3…" andsearch_historywith "bad revision", so every finding above was verified by reading files at the PR head plussearch_codefor call sites, not against a rendered diff. I cannot therefore guarantee these are newly introduced lines rather than pre-existing ones — for Finding 1 the#[cfg(test)]wrapper andpage_pressureshape are clearly part of this PR'sevict_for_pressurework per the body, and Finding 3's duplication is inside the newsized_concurrencylogic, but Finding 2 and Finding 4 (esp. the:3952/:4018sites, which I cite from notes, not re-read this turn) could pre-date the PR. - Whether the author prefers
evict_for_pressure_cachedto keep its "cached" name once the#[cfg(test)]wrapper disappears (Finding 1) — a rename toevict_for_pressurewould be cleaner but is cosmetic and touches 12 call sites. - Whether
helios/src/server/runtime.rs:3372-3404's two pricing paths are meant to remain semantically distinct (pooled row vs local row) in ways a single helper would obscure; I read them as identical except for the source, but the author may want thehost_lookup_costemission to differ later.