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

Raw Markdown for agents: https://autobot.eidonix.com/p/3080651b-4f63-4f38-a410-5df3eca10bbc.md

Subtraction, Simplicity & Conventions review — PR #699

Key findings

The diff is lean. I read all five changed files plus the surrounding code (selene/src/pool/{budget,budget/tests,builder,conn,shm,startup,mod}.rs, selene/src/offload.rs:880-1010, eos/src/{lib,unix}.rs, selene-manager/src/local.rs, helios/src/offload/pool*.rs, selene/Cargo.toml) and AGENTS.md. No new flag, config key, environment variable, dependency, protobuf field, or dead code is introduced; libc was already a Selene dependency; Budget::costs' changed signature has all three call sites updated (budget.rs:45-48, builder.rs:239-245, tests). Nothing is left behind from the old shape.

Four simplifications are worth making, all local and none structural:

  1. conn.rs:774-780, conn.rs:854 (high) — the shared_backed: Option<(u64, u64)> threading carries an unreachable tuple-pattern arm and a never-taken unwrap_or((0, 0)); a plain (u64, u64) local removes both and ~5 lines.
  2. budget.rs:19 (high) — backed_bytes.min(bytes) inside bytes.saturating_sub(...) is a no-op; the clamp is already applied by backed_shm_bytes at conn.rs:697.
  3. budget/tests.rs (medium) — the identical plan.iter().map(|region| (region.bytes, region.backed_bytes)) closure is written out five times; one module-local helper collapses it.
  4. budget/tests.rs:133-141 (medium) — the host: Err("no memory observation") assertion is a verbatim repeat of the pre-existing one at budget/tests.rs:82-90 and cannot be affected by backed_bytes.

I explicitly considered and cleared two tempting findings: relocating backed_shm_bytes into flare-eos, and deleting the non-Linux stub. Reasons below.


1. (high) conn.rs — the Option threading of backed bytes has a dead arm and a dead default

selene/src/pool/conn.rs:773-780:

    let mut plan = Vec::new();
    let shared_backed = shared.map(|shared| {
        (
            backed_shm_bytes(&shared.arena_path, shared.arena_bytes),
            backed_shm_bytes(&shared.staging_path, shared.staging_bytes),
        )
    });
    if let (Some(shared), Some((arena_backed, staging_backed))) = (shared, shared_backed) {

and selene/src/pool/conn.rs:853-854:

    if let Some(regions) = &regions {
        let (arena_backed, staging_backed) = shared_backed.unwrap_or((0, 0));

shared_backed is Some exactly when shared is Some, because it is shared.map(...) and shared is Option<&T> (which is Copy, so both uses see the same value). So:

Replace the three pieces with one plain local, computed inside the if let that already builds the two PlannedRegions:

    let mut backed = (0u64, 0u64);
    if let Some(shared) = shared {
        backed = (
            backed_shm_bytes(&shared.arena_path, shared.arena_bytes),
            backed_shm_bytes(&shared.staging_path, shared.staging_bytes),
        );
        plan.extend([ /* the two PlannedRegion entries, unchanged, conn.rs:781-792 */ ]);
    }

and at conn.rs:854:

        let (arena_backed, staging_backed) = backed;

Net: removes one Option binding, one two-Some pattern, and one dead default; about five lines shorter, and the "backed values belong to the shared file pair" invariant stops being expressible in two shapes. Convention tie-in: AGENTS.md:188-193 rejects "fallback layers" and "unsupported abstractions… without a concrete requirement"; here the Option and its default are exactly a fallback that no input can reach.

2. (high) budget.rs:19 — the .min(bytes) clamp is redundant twice over

selene/src/pool/budget.rs:18-19:

        regions.try_fold((0u64, 0u64), |(host, device), (bytes, backed_bytes)| {
            let additional_host = bytes.saturating_sub(backed_bytes.min(bytes));

u64::saturating_sub already floors at zero, so backed_bytes.min(bytes) changes nothing:

The clamp is also already enforced at the only production producer, selene/src/pool/conn.rs:697:

        .map(|meta| meta.blocks().saturating_mul(512).min(declared_bytes))

Replace with:

            let additional_host = bytes.saturating_sub(backed_bytes);

One expression, one mechanism to reason about; the hostile-input case is still safe. Knock-on to fix at the same time — selene/src/pool/budget/tests.rs:155:

            bytes: 4 << 20,
            backed_bytes: 8 << 20, // clamped to region.bytes

The comment names a clamp that, after the simplification, is doing no work; retarget it at saturating_sub ("backed beyond the region still charges zero"). The assertion at budget/tests.rs:168 (assert_eq!(host, 6 << 20);) passes unchanged either way.

3. (medium) budget/tests.rs — the (bytes, backed_bytes) mapping is duplicated five times

The same four-line closure appears at selene/src/pool/budget/tests.rs:25, :48-52, :65, :109-113, :163-167. Two of the five, verbatim:

// tests.rs:25
    let (host, device) = Budget::costs(plan.iter().map(|region| (region.bytes, region.backed_bytes))).unwrap();
// tests.rs:109-113
    let (host, device) = Budget::costs(
        plan.iter()
            .map(|region| (region.bytes, region.backed_bytes)),
    )
    .unwrap();

Every test in the module wants (host, device) from a plan, so the mapping is a fixture concern, not test logic. Add one module-local helper next to plan() at tests.rs:7:

fn costs(plan: &[PlannedRegion]) -> std::result::Result<(u64, u64), String> {
    Budget::costs(plan.iter().map(|region| (region.bytes, region.backed_bytes)))
}

then let (host, device) = costs(&plan).unwrap(); at the four value sites and assert!(costs(&self::plan(u64::MAX, 1)).is_err()); at tests.rs:47-54. Saves roughly eight lines and, more importantly, keeps the pairing of bytes with backed_bytes in one place so a future field addition to PlannedRegion is a one-line test change rather than five.

Related formatting point, low priority: cargo fmt was not run on the head commit — tests.rs:25 is 106 columns and tests.rs:65 about 100, over rustfmt's 100-column width — and there is no CI check on 135633f to catch it. Trivial, but the reflow disappears for free with the helper.

4. (medium) budget/tests.rs:133-141 — duplicated host: Err assertion adds nothing

The tail of the new test, selene/src/pool/budget/tests.rs:133-141:

    assert!(
        Budget {
            host: Err("no memory observation".into()),
            devices: vec![(device, false)],
        }
        .approve(&plan)
        .unwrap_err()
        .contains("no memory observation")
    );

is a verbatim repeat of the pre-existing assertion at selene/src/pool/budget/tests.rs:82-90 (same host: Err, same message, same .contains). It also cannot be affected by this PR's variable: Budget::approve reads self.host and returns the error at budget.rs:49-52 before any cost comparison, so backed_bytes never enters. Delete the block (~9 lines). Keep the sibling assertion at tests.rs:124-132 (GPU shortfall with host: Ok(25 GiB) below the 40 GiB pool): that one is new information, because it proves the zeroed host charge let the device charge be reached at all.

Reviewer note, not a deletion (out of this lens): tests.rs:123 assert_eq!(budget.charges(host, device), vec![device, device]); only restates host == 0 through charges, but it does pin the integrated-device consequence of budget.rs:30-42 (host.div_ceil(integrated)); it should be read as a statement of intent for unified-memory hosts rather than as coverage of new logic.


Considered and deliberately not reported


Open questions