#1 [high] Research summary
Subtraction & Simplicity review — PR #674
I read the changed files in the four threads (helios cache/scheduler, selene offload/pool/store/disk, selene-manager store/arena, helios server runtime/metrics) against AGENTS.md and against the helpers that already existed on main. The diff is large but mostly additive test and mechanism code; five places carry duplication worth removing before merge. Nothing here duplicates the Correctness lens: each item is a delete-or-collapse, not a patch.
1. helios/src/cache.rs:680-709 — role-preserving predicate implemented three ways in one function
.filter_map(|node| {
let role_preserving = node.child_count != 0
&& (node.role == RetentionRole::Endpoint
|| single_child_role
.get(&node.id)
.is_some_and(|&child_role| child_role >= node.role));
let cost = match (below, protected_token_budget) {
(Some(rank), Some(budget)) => {
let tokens = if role_preserving {
0
} else if node.child_count != 0 {
self.age_discounted_protected_tokens(node, rank)
} else {
let tokens = self.protected_eviction_tokens(node, rank);
tokens
};
The if/else if/else restates protected_eviction_tokens (:635-644), which already returns 0 exactly when role_preserving, already routes child_count != 0 to age_discounted_protected_tokens, and already returns age_discounted_protected_tokens for leaves — so the whole block is if role_preserving { 0 } else { self.protected_eviction_tokens(node, rank) }. The let tokens = …; tokens rebind is dead. Second, is_role_preserving_compaction (:646-654) now exists only to serve protected_eviction_tokens while the caller-side copy at :681-685 re-implements it against single_child_role; two copies of one predicate, one of them pub(crate) with no external caller (search_code is_role_preserving_compaction returns hits in cache.rs only). Replace the match arm with the two-case form and make is_role_preserving_compaction private.
2. selene-manager/src/store.rs:1690-1776 — the rotating epoch scan keeps four fields and rewrites its cursor bookkeeping four times
if let Some(index) = ready {
let waiter = self.writeback_waiters.remove(index).unwrap();
self.writeback_wake_cursor = if self.writeback_waiters.is_empty() {
0
} else {
index % self.writeback_waiters.len()
};
self.writeback_wake_remaining = if advanced == len {
0
} else {
self.writeback_wake_remaining
.saturating_sub(checked)
.min(self.writeback_waiters.len())
};
The else arm at :1759-1769 is the same block with start + advanced instead of index, and the same fixup appears again in expire_waiters (:1851-1857) and twice in the wake paths (:1587-1593, :4163-4167, :4240-4242) — five copies of "keep writeback_wake_cursor in range modulo writeback_waiters.len() and clamp writeback_wake_remaining". writeback_wake_remaining plus per-waiter last_wake_epoch (:581) plus writeback_wake_epoch (:654) is a third state machine layered over a queue whose entries are already removed by woken/expired drains. Collapse: one fn take_writeback_waiter(&mut self, index) -> WritebackWaiter and one fn retain_writeback_waiters(&mut self) that own the cursor fixup, delete the duplicated arithmetic, and let scan_writeback_waiters_step become the single if advanced == len { 0 } else { … } site. The three tests at :11884, :11991, :12444 pin the cursor invariants, so the shrink is safe to verify.
3. selene/src/store.rs:433-444 — retired / retired_offered is a two-method trait where every implementor overrides both
fn retired(&mut self, _key: PrefixKey, _tier: PoolTier, _how: Retirement) {}
/// The move of a retiring record ended after offering `offered` to the manager.
/// The default ignores `offered` and delegates to [`TierStore::retired`].
fn retired_offered(
&mut self,
key: PrefixKey,
tier: PoolTier,
how: Retirement,
_offered: &[Retiring],
) {
self.retired(key, tier, how);
}
The delegation runs in three different directions across implementations: selene/src/memory.rs:1185-1187 has retired forward to retired_offered(&[]) (reversing the trait default), selene/src/memory.rs:3612-3626 forwards both, selene/src/pool/local.rs:122-137 forwards both, and selene/src/pool/local/tests.rs:61-77 (not opened) overrides both to record twice. Callers must know which to call — selene/src/pool/cascade.rs:415 (not opened) uses retired_offered, :250/:348 use retired. One method fn retired(&mut self, key, tier, how, offered: &[Retiring]) {} with an empty default deletes the forwarding layer; the ~30 existing retired(..) call sites pass &[]. Since TierStore is pub and implemented from helios/src/offload/mod.rs (not opened), land this as part of the same trait change rather than a follow-up.
4. helios/src/server/runtime.rs — the pool-lookup reset is copied five times, and worth_restore restates a selene helper
if !pending_pool_answer {
incoming.pool_lookup = None;
incoming.pool_lookup_started = None;
incoming.pool_lookup_reissued = false;
incoming.pool_plan = None;
}
The PR added lines to this shape at five sites (hunk offsets ≈ :1801, :2616, :3031, :3045, :3077), the latter two verbatim active.incoming.pool_lookup = None; … continue;. Incoming already owns these four fields; one fn forget_pool_lookup(&mut self) reduces each site to a single call and makes the new pool_lookup_reissued flag impossible to leave stale. Separately, worth_restore (:227-232) is a local re-implementation of the guard-and-half rule in selene/src/store.rs:463-472 (worth_transfer), and the old pricing path still calls worth_fetching(&hit, prefill_rate) at :3164 — so two profitability rules now coexist in one function. Either route all restores through estimated_prefill_saved_seconds and delete worth_fetching's caller, or keep one helper; do not ship both.
5. selene/src/disk.rs:352-390 — four DiskThread constructors for one optional callback
pub fn start(name: &str) -> Result<Self> {
Self::start_inner(
name,
None,
#[cfg(any(test, feature = "test-support"))]
Faults::default(),
)
}
plus start_with_wakeup, start_with_faults, start_with_faults_and_wakeup — four public/cfg(test) entry points that all forward to start_inner(name, on_reply, faults). Two are enough: pub fn start(name: &str, on_reply: Option<Arc<dyn Fn() + Send + Sync>>) and the existing #[cfg(any(test, feature = "test-support"))] start_with_faults(name, faults, on_reply). Collapsing them also answers the AGENTS.md "Reject unsupported abstractions and churn / callbacks, optional paths" concern about on_reply on its narrowest surface.
Minor, mentioned once
selene/src/levels.rs:119-127rates() -> [f64; 4]hard-codes[NeighbourGpu, HostDram, HostNvme, RemoteNvme], andhelios/src/server/metrics.rs:1408-1422repeats the same ordering as a string list indexed[0..3]. Two places must stay in sync for a silent mislabel; drive the metric loop fromLevelvariants instead of a positional array.selene/src/offload.rs:233-240capture_headroom_slotsneedsif retention_slots == 0 { return 0 }only to defeat its own.max(1);headroom(...).clamp(1, retention_slots.max(1))(ormin(retention_slots)aftermax(1)) states the intent in one expression.helios/src/scheduler/cache_memory.rs:206-241:victim_released_pageshas exactly one caller (page_pressure_victim_priority) and can be inlined; the routing block at:411-430is then duplicated a third time in the test simulator at:1230-1268, which is the pre-existing pattern rather than a new defect.
Where the diff is already lean
The intake-sizing change (selene/src/offload.rs:681-685) deletes a branch rather than adding one; the metric split reuses the existing StoreStats/render-table machinery instead of a new path; helios/src/scheduler.rs:1559-1563 replaces refresh_admission_plan cloning with an in-place recheck rather than adding a parallel API; the buddy/coalescing logic in selene-manager/src/arena.rs:154-198 is a single self-contained method with no flags. The new helios alias-plane and midpoint-placement code has no configuration switches and no model branches, and helios/src/runtime_core/memory/codec_layout_tests.rs (not opened) is a CPU-only fixture module with no runtime path. I found no dead code left behind by the removed branches (the old inline write_all_at path is now write_record_buffered, still reached by the unaligned-window case at selene/src/disk.rs:905-911), and no AGENTS.md structural violation beyond the callback-surface note in item 5.
#2 [high] #674 Subtraction lens — find 1: role-preserving predicate triplicated in helios/src/cache.rs
File: helios/src/cache.rs, lines 680-709 (PR head).
Verbatim:
.filter_map(|node| {
let role_preserving = node.child_count != 0
&& (node.role == RetentionRole::Endpoint
|| single_child_role
.get(&node.id)
.is_some_and(|&child_role| child_role >= node.role));
let cost = match (below, protected_token_budget) {
(Some(rank), Some(budget)) => {
let tokens = if role_preserving {
0
} else if node.child_count != 0 {
self.age_discounted_protected_tokens(node, rank)
} else {
let tokens = self.protected_eviction_tokens(node, rank);
tokens
};
if tokens > budget {
return None;
}
tokens
}
_ => 0,
};
Some((node, cost, role_preserving))
})
Why it is removable:
protected_eviction_tokens(helios/src/cache.rs:635-644) already returns 0 exactly when role_preserving:
fn protected_eviction_tokens(&self, node: &Checkpoint, rank: RetentionRank) -> u64 {
if node.child_count != 0 {
if self.is_role_preserving_compaction(node) {
return 0;
}
} else if node.role == RetentionRole::Endpoint && node.parent.is_some() {
return 0;
}
self.age_discounted_protected_tokens(node, rank)
}
so the three-branch ladder reduces to if role_preserving { 0 } else { self.protected_eviction_tokens(node, rank) }.
- The
let tokens = self.protected_eviction_tokens(node, rank); tokensrebind is dead (clippy-visible). is_role_preserving_compaction(helios/src/cache.rs:646-654) ispub(crate)but search_code over the whole repo shows hits only in helios/src/cache.rs:637 and :646 — no external caller. It exists only to serve protected_eviction_tokens while :681-685 re-implements the same predicate againstsingle_child_role. Make it private, keep one body.
Concrete simplification: replace the match arm's inner let tokens = ... ladder with the two-case form; make is_role_preserving_compaction private.
Note: this is a delete/collapse, NOT the correctness bug of value 0-vs-nonzero; the Correctness lens owns any semantic question. Say explicitly it is duplication, not a defect.
Also related: verification/helios-lifecycle/check.py:515-519 mutates the exact source line let tokens = self.protected_eviction_tokens(node, rank); — a TLA+/mutation check pins that string, so any edit must keep that literal line present or update check.py.