Subtraction and simplicity report · NVIDIA/hyperflare-inference #674

Raw Markdown for agents: https://autobot.eidonix.com/p/39b4912d-c901-4b84-bf46-b9e58c3ab8ff.md

Subtraction & Simplicity review — PR #674

Scope and method

I read the changed files across the four threads (helios cache/scheduler/server, selene offload/pool/store/disk, selene-manager store/arena) against the helpers that already exist on main and against AGENTS.md. The diff is ~+11.2k/−704 across 40 files, but the bulk is added mechanism plus tests; I found five places where duplication or an over-wide surface should be removed or collapsed before merge, plus three minor notes. None of these is a correctness finding — the Correctness & Contracts lens owns semantics; every item below is a delete-or-collapse, and where a workaround should be deleted rather than patched I say so.


1. helios/src/cache.rs:680-709 — one cost rule implemented three times, and a pub(crate) predicate with no external caller (highest value)

            .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))
            })

protected_eviction_tokens (helios/src/cache.rs:635-644, pre-existing) already encodes exactly this rule:

    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 whole three-arm ladder is if role_preserving { 0 } else { self.protected_eviction_tokens(node, rank) }. The let tokens = self.protected_eviction_tokens(node, rank); tokens rebind is dead (clippy-visible). Concretely: replace the inner let tokens = …; ladder with the two-case form.

Second half: the PR also made is_role_preserving_compaction (helios/src/cache.rs:646-654) pub(crate), but search_code is_role_preserving_compaction returns only helios/src/cache.rs:637 and :646 — no caller outside the file. It exists to serve protected_eviction_tokens while :681-685 re-implements the same predicate against the single_child_role map (a legitimate O(1) hoist). Make it private; the hoisted map copy stays, the public surface shrinks by one method.

This is duplication, not a defect: the values agree today, which is exactly what makes the second copy easy to drift.

Caveat for the author: an earlier research pass noted that verification/helios-lifecycle/check.py:515-519 mutates the literal line let tokens = self.protected_eviction_tokens(node, rank); — I did not re-verify that file this pass, but if true any edit must either keep that literal line or update check.py in the same commit.


2. selene/src/store.rs:433-444 — a two-method trait whose every implementor overrides both and forwards to the other

    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 both directions across implementations: the default sends retired_offered → retired, while selene/src/memory.rs:3612-3626 and selene/src/pool/local.rs:122-137 override both and forward the other way (retired → retired_offered(&[]) / tiers.retired_offered(...)). Callers must therefore know which method carries the information: selene/src/pool/cascade.rs:415 (not opened) uses retired_offered (with &entry.offered), while other sites use retired. Test doubles override both (selene/src/pool/local/tests.rs:61-77 (not opened), selene/src/pool/store/tests.rs:155-160 (not opened)) and assert on the pair.

Collapse to one method fn retired(&mut self, key: PrefixKey, tier: PoolTier, how: Retirement, offered: &[Retiring]) {} with an empty default; the handful of existing retired(..) call sites pass &[]. That deletes the forwarding layer, the doc comment explaining the forwarding, and the "which one do I call" ambiguity. TierStore is pub and also implemented from helios/src/offload/mod.rs (not opened), so land this in the same commit rather than as follow-up churn.


3. selene-manager/src/store.rs — the rotating writeback cursor fixup is copy-pasted six times, with three fields of bookkeeping

            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 same "keep writeback_wake_cursor in range modulo writeback_waiters.len() and clamp writeback_wake_remaining" arithmetic appears at selene-manager/src/store.rs:1586-1593 (key-match removal, which additionally does the removed_before_cursor computation at :1571-1583), :1743-1754 (found-waiter arm), :1759-1768 (scan-end arm — the same block with start + advanced instead of index), :1851-1857 (expire_waiters), :4163-4167, and :4240-4242.

The state itself is three fields (writeback_wake_cursor, writeback_wake_remaining, writeback_wake_epoch at :652-654) plus a per-waiter last_wake_epoch (:1458) layered over a queue whose entries are already drained by key or by expiry. Concretely: introduce one fn take_writeback_waiter(&mut self, index: usize) -> WritebackWaiter and one fn retain_writeback_waiters(&mut self, f: impl FnMut(&WritebackWaiter) -> bool) that own the cursor fixup; wake_writeback_waiters (:1690-1710), scan_writeback_waiters_step (:1712-1775), expire_waiters, and the two inline removals then each express only their own predicate. The existing cursor tests (:11884, :12000, :12444-12463, :12487) pin the invariants, so the shrink is verifiable. I am not asking for a redesign of the rotating scan — only that the fixup live in one function instead of six.


4. selene/src/disk.rs:355-390 — the PR turns two constructors into four for one optional callback

    pub fn start(name: &str) -> Result<Self> {
        Self::start_inner(
            name,
            None,
            #[cfg(any(test, feature = "test-support"))]
            Faults::default(),
        )
    }

    /// Spawn the thread under `name` and invoke `on_reply` after each job reply
    /// is queued so callers can wake an event loop without waiting for a poll tick.
    pub fn start_with_wakeup(

On main this was two entry points (start, start_with_faults — verified against main at selene/src/disk.rs:350-361). The PR adds start_with_wakeup (:366-376) and start_with_faults_and_wakeup (:384-390), all four forwarding to start_inner(name, on_reply, faults) (:392-396). Callers are exactly three: selene-manager/src/store.rs:927-929 (the fault and non-fault wakeup pair) and the test at selene/src/disk.rs:4884-4887.

Two entry points suffice: keep start(name) calling start_with_wakeup(name, None), and give the fault variant the Option<Arc<dyn Fn() + Send + Sync>> argument directly:

    pub fn start_with_wakeup(name: &str, on_reply: Option<Arc<dyn Fn() + Send + Sync>>) -> Result<Self>;
    #[cfg(any(test, feature = "test-support"))]
    pub fn start_with_faults_and_wakeup(name: &str, faults: Faults, on_reply: Option<Arc<dyn Fn() + Send + Sync>>) -> Result<Self>;

start_with_faults then disappears. This also answers the AGENTS.md:188-193 concern — "Reject unsupported abstractions and churn… Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement" — by keeping the new on_reply callback surface at its narrowest (see Open questions).


5. helios/src/server/runtime.rs — the four-field pool-lookup reset is written out five times

                active.incoming.pool_lookup = None;
                active.incoming.pool_lookup_started = None;
                active.incoming.pool_lookup_reissued = false;

(:3030-3032; verbatim variants at :1800-1802, :2614-2616, :3044-3046, :3076-3078, plus the bare self.pool_lookup_started = None at :402 and :3240.) Incoming already owns all four fields (pool_lookup_reissued is new in this PR, :211), so stale-reset is now a five-place invariant to keep. Add fn forget_pool_lookup(&mut self) on Incoming and call it at each site; the new pool_lookup_reissued flag then cannot be left stale by a future edit. The existing phase tests at helios/src/server/runtime/phase_tests.rs:3419 (not opened), 3445, 3534 already assert the reissue behaviour, so the refactor is covered.


Minor (worth one line each, not blocking)


Where the diff is already lean (no action)


Open questions

  1. Does the new on_reply callback surface need a maintainer decision? AGENTS.md:176-181 says "Flags, enums, callbacks, optional paths, and temporary implementations cannot be used to bypass" the architectural boundaries, and :188-193 rejects "extension points… fallback layers… without a concrete requirement". Item 4 above narrows the surface, but the callback itself (a wake signal plumbed from the disk thread into the manager event loop) should be justified explicitly in the description as a required mechanism rather than left implicit.
  2. Merge order with #665 (open, FujitsuPolycom) which rewrites eviction_candidate_within_budget in the same file and the same docs/prefix-cache-offload.md (not opened) sections. Item 1 touches exactly that function's neighbourhood, so whoever lands second should not also be carrying a dedup refactor.
  3. Not verified this pass: whether worth_fetching (selene/src/store.rs:454-460) still has a helios caller alongside the new worth_restore (helios/src/server/runtime.rs:225). A search of runtime.rs for worth_fetching returned no hits, so my earlier concern about two coexisting profitability rules in that file does not hold — but if a third site does call it, the two rules should be reduced to one helper.
  4. I did not open verification/helios-lifecycle/check.py this pass, so the mutation pin noted under item 1 rests on earlier research and should be confirmed by the author before editing that function.