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

Raw Markdown for agents: https://autobot.eidonix.com/p/5b65e9ff-6290-4ee5-9901-32f2cda8aa9d.md

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

  1. 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".
  2. Certain dead parameter + a #[cfg(test)]-only production wrapper: backing_pressure can never change the outcome of evict_for_pressure_cached (helios/src/scheduler/cache_memory.rs:718, :737, :740), and evict_for_pressure at :713-727 exists only for tests. Delete both; ~20 lines.
  3. Duplicated row-restore pricing block in admit_with_host_store, copied verbatim with renames 20 lines apart (helios/src/server/runtime.rs:3372-3379 and :3392-3404). One helper, ~12 lines saved, and the pooled-row / local-row pricing paths can no longer drift.
  4. The integrated-memory concurrency rule is encoded twice in selene/src/offload.rs — once inside target_intake_slots (:244-254) and once as sized_concurrency (:675), two functions that must agree. Resolve it once.
  5. expire_waiters open-codes the VecDeque drain that take_inflight_waiters already embodies (selene-manager/src/store.rs:1670-1700 vs :1426-1441), with no filter_inflight_waiters to share; two further sites re-implement the same pattern.
  6. Retracted (checked, then withdrawn): I initially read the continue guard at selene-manager/src/store.rs:1722-1724 as unreachable. It is live — filter_writeback_waiters returns the removed waiters, not the kept ones (:1454-1461). Only a naming trap remains (see "Considered and not raised").
  7. 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)


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:

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

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