Simplicity report · NVIDIA/hyperflare-inference #589

Raw Markdown for agents: https://autobot.eidonix.com/p/8dab6b7f-c742-497f-bffa-7e5a9f0f8d21.md

Lens D — simplicity: what can be deleted?

I read all 21 changed files in context (not only the diff), followed the callers of every function whose behaviour changed, and checked each finding in the code before writing it. Five of the six findings are places where this PR leaves the old path compiled in beside the new one, or adds code that proves nothing.

Repo rules this is judged against


Key findings

# Severity Where One line
1 should fix selene/src/offload.rs:497-534, :600-619; helios/src/offload/mod.rs:72-129 The post-KV-alloc re-query this PR removes survives as the None default of host_budget: Option<u64>, kept alive by a shim with no production caller.
2 should fix helios/src/cuda.rs:667-676; selene/src/registrar.rs:26-37; helios/src/offload/registrar.rs:27-38; selene/src/slab.rs:261-270 map_device_host_parts is unreachable, yet map_split stays a required trait method forcing ~12 boilerplate impls.
3 should fix eos/src/unix.rs:206-248; helios/src/execution/roce.rs:511-523 Two new tests guard their assertion behind an if, so they pass without asserting anything on the machines they run on.
4 should fix helios/src/runtime_core/memory.rs:646-683 vs :878-909 The integrated-memory accounting is written twice, ~200 lines apart, and the two copies already disagree.
5 should fix (stale doc) helios/src/frontend/mod.rs:1400-1402 The comment still describes the old unscaled "2 GiB plus one twentieth" reserve that this PR replaced.
6 nit selene/src/offload.rs:852-886 host_pool_budget_with_reserve(future, apply_reserve) has exactly one caller and always true.

Findings

1. should fix — the fixed defect's old path survives as the None default

Files/lines: selene/src/offload.rs:497-520 (prepare_with_inputs shim), :522-534 (prepare_with_inputs_budget signature, host_budget: Option<u64>), :603-619 (the match host_budget { Some(..) => …, None => options.headroom_with_inputs(..) }); mirrored in helios/src/offload/mod.rs:82-129.

What is wrong. The whole point of the change is that on unified memory the host budget must be computed before KV allocation and then reused, because prepare_offload re-evaluating host_pool_budget post-KV-alloc is the bug. That re-evaluation is still compiled in as the None arm:

let (_, host) = match host_budget {
    Some(budget) => options.headroom_with_inputs_for_budget(…, budget)?,
    None => options.headroom_with_inputs(…) ?,   // offload.rs:612-618 — the old behaviour
};

The only production caller always passes Some: helios/src/runtime_core/model.rs:967-977 forwards planned_host_budget, which is Some whenever the prefix cache is enabled (helios/src/runtime_core/memory.rs:1102-1112), and prepare_offload returns early at model.rs:933 when it is not enabled. So the None arm is unreachable from production but is the default for every other caller, and it keeps headroom_with_inputs alive as a second, divergent sizing path — exactly the two-way accounting this PR was meant to collapse.

Second layer of the same thing. prepare_with_inputs (selene/src/offload.rs:497, helios/src/offload/mod.rs:82) now exists only to pass None. Verified callers: selene/src/offload.rs:492 (from prepare), selene/src/offload/tests.rs:33/70/164/508/670, selene/src/offload/sharded/tests.rs:108 (not opened)/247/375/537, selene-manager/tests/client.rs:3204 (not opened), and helios/src/offload/pool/tests.rs:124. No production caller in the workspace. Two #[allow(clippy::too_many_arguments)] attributes (selene/src/offload.rs:522, helios/src/offload/mod.rs:105) exist to carry the duplicated 10-argument signature.

Fix (smaller version). One entry point taking host_budget: u64; delete the Option, delete the None arm, delete the prepare_with_inputs shim in both crates and the second too_many_arguments allow. model.rs:931/:967 then pass a plain u64 (it becomes non-optional once the None case is gone, since prepare_offload already returns early when the cache is disabled). Callers that genuinely want the meminfo-derived budget call headroom_with_inputs themselves, once, at the same place memory.rs already does. ~40 lines fewer, one buggy path fewer.

2. should fix — map_device_host_parts is unreachable and map_split is a required trait method with no production caller

Files/lines: helios/src/cuda.rs:667-676 (map_device_host_parts), helios/src/offload/registrar.rs:27-29 and :31-38, selene/src/registrar.rs:26 (required map_split) and :32-36 (default try_map_split that forwards to it), selene/src/slab.rs:189-252 (try_sized_by_rank) and :261-270 (sized_by_rank).

What is wrong. map_device_host_parts turns try_map_device_host_parts's Ok(None) back into an error. Its only caller is CudaRegistrar::map_split (helios/src/offload/registrar.rs:28). map_split is only reachable through the default body of HostRegistrar::try_map_split (selene/src/registrar.rs:36), and CudaRegistrar overrides try_map_split (registrar.rs:31-38), which is what production reaches via SlabPool::try_sized_by_rank (selene/src/slab.rs:215). A workspace-wide search finds no other caller of map_device_host_parts: it is dead code held alive only because map_split remains the trait's required method.

Because it is required, every implementor must write it anyway: selene/src/registrar.rs:26, helios/src/offload/registrar.rs:27, selene/src/pool/builder.rs:311 (not opened), selene/src/pool/startup.rs:223, selene/src/pool/net.rs:976 (not opened), selene/src/pool/engine/tests.rs:155 (not opened), selene/src/pool/engine/net_tests.rs:44 (not opened), selene/src/testing.rs:453 and :490, selene/src/offload/tests.rs:800, selene-manager/tests/client.rs:1100 (not opened), :1298, :3147 — ~12 stubs of a method the production path no longer calls, several of which are unimplemented!-style placeholders that would now be unnecessary.

SlabPool::sized_by_rank (selene/src/slab.rs:261-270) has the same shape: production uses try_sized_by_rank (selene/src/offload.rs:631); the remaining callers are the ignored GPU benchmark helios/src/offload/transfer.rs:1723 and the unit test selene/src/slab.rs:631.

Fix (smaller version). Make try_map_split the trait's single required method (drop the defaulted/required pair), delete map_split from the trait and from all ~12 impls, and delete map_device_host_parts from cuda.rs together with the doc comment at cuda.rs:667-668. Drop sized_by_rank; slab.rs:631 and transfer.rs:1723 call try_sized_by_rank(...).unwrap() / ?+ok_or, one line each. Small bonus in the same function: cuda.rs now repeats the same five-line let status = call(…); if is_host_numa_unsupported(status) { return Ok(None); } driver.check(name, status)?; pattern four times (:576-589, :641-650, :652-660 and neighbours) — one helper taking (name, status) halves those lines and makes it impossible for the next edit to miss one.

3. should fix — two new tests pass without asserting anything

Files/lines: eos/src/unix.rs:206-248 (map_host_advises_hugepages_and_prefaults_zeroed_pages), helios/src/execution/roce.rs:511-523 (lazy_libibverbs_loader_resolves_symbols_or_reports_install_hint).

What is wrong.

AGENTS.md (not opened) ~194 asks for tests that "exercise the affected behavior or contract". selene/src/offload/tests.rs shows the pattern done right (the new budget tests do call prepare_with_inputs_budget and prepare).

Fix (smaller version). eos: hoist the smaps lookup into a helper returning Option<&str> for the block, then .expect("mapping VMA in /proc/self/smaps") — the length re-counting collapses to .lines().skip_while(..).take_while(..), and the test fails loudly when it cannot check. roce: assert the applicable branch (0 => assert!(handle resolves a symbol), _ => assert!(hint)), or delete it — release.yml:110-121's clean-container smoke check already proves the no-libibverbs1 path, and a loaded-library run is covered by any RoCE hardware run. Either way ~40 lines and one vacuous green check go away.

4. should fix — integrated-memory accounting computed twice in one function

Files/lines: helios/src/runtime_core/memory.rs:646-683 (integrated_state) vs :878-909 (the per-rank loop inside the same function).

What is wrong. Three computations appear twice, ~200 lines apart: the min free over integrated ranks (:648-654 vs :880-886), the fixed_bytes(core, true) + embedding_host_bytes fold (:662-673 vs :889-901), and fixed.max(initial - free) (:681 vs :904). The two copies already disagree: :655-661 takes min total over integrated ranks while :887 uses observations[index].total; :674-681 takes a max observed drop over integrated ranks while :904 uses initial[index]. Whatever the intended semantics, two live expressions of it in one function is the shape that produced the original budgeting bug.

Fix (smaller version). Compute per-integrated-rank state once into a Vec<(MemorySnapshot, u64)> right after observations (:640-645) and index it in both the host_budget_for closure (:684-694) and the loop (:877-909). ~20 lines fewer and one place to change the rule.

5. should fix (stale doc) — the reserve comment this PR obsoleted

File/line: helios/src/frontend/mod.rs:1400-1402: "…the headroom host_pool_budget (selene/src/offload.rs) leaves unallocated: HOST_SERVICE_HEADROOM_BYTES (2 GiB) plus one twentieth of total memory."

That formula is no longer what host_pool_budget does: this PR replaced it with host_service_headroom_bytes — 64 MiB at <= 16 GiB, min(2 GiB, total / 32) above — and host_reserve_bytes (selene/src/offload.rs), and it updated the prose in docs/prefix-cache-offload.md:1141-1144 accordingly. This file was not touched, so the code comment now contradicts the code it documents, in the one place a maintainer looks to size a second encoding.

Fix. One-line edit to point at host_service_headroom_bytes / host_reserve_bytes and drop the numbers, or repeat the new formula.

6. nit — host_pool_budget_with_reserve's bool has one caller and one value

File/line: selene/src/offload.rs:852-886. host_pool_budget(future) is host_pool_budget_with_reserve(future, true); nothing else in the workspace calls the two-argument form (search: only :853). The false case is served by the separately named host_pool_budget_from(available, total, future, apply_reserve) that helios/src/runtime_core/memory.rs needs.

Fix. Let the meminfo-reading helper be the sole in-crate user of apply_reserve = true and delete host_pool_budget_with_reserve, or reduce it to a private free function with no flag. Keeps the public surface to the two names the PR actually needs.


Clean in this lens (checked, nothing to report)


Open questions / not verified