Simplicity scratchpad · NVIDIA/hyperflare-inference #589

Raw Markdown for agents: https://autobot.eidonix.com/p/875df727-cad3-4657-af22-532eba55f1b9.md

#1 [high] Repo rules relevant to lens D (simplicity)

AGENTS.md (main):

#2 [high] should fix: the fixed defect's old path survives as the None default (three overlapping entry points)

selene/src/offload.rs:497-534 (prepare_with_inputs -> prepare_with_inputs_budget), :600-619 (match host_budget, None arm re-queries options.headroom_with_inputs), :117-146 (headroom_with_inputs still calls host_pool_budget), helios/src/offload/mod.rs:72-129 (three nested wrappers prepare -> prepare_with_inputs -> prepare_with_inputs_budget). Only production caller is helios/src/runtime_core/model.rs:967 via prepare_with_inputs_budget with planned_host_budget, which is always Some when it can be non-None (prepare_offload returns early if !cfg.enabled(); allocate_caches returns Some whenever cfg.enabled()). So the None arm is dead in production and preserves exactly the re-query behaviour this PR set out to fix. prepare_with_inputs (selene + helios) is now used only by tests and helios/src/offload/pool/tests.rs:124. Smaller version: make host_budget a plain u64 parameter of one entry point, delete the Option and the None arm, delete headroom_with_inputs (fold its host_pool_budget call into the callers) or keep it as a thin wrapper used only by external selene callers, and delete the duplicate helios wrapper. Saves ~40 lines and one #[allow(too_many_arguments)] and removes the buggy path from the compiled code. AGENTS.md "smallest footprint", "do not add ... fallback layers ... without a concrete requirement".

#6 [high] should fix: map_device_host_parts is now unreachable code, and map_split is a required trait method nobody calls

helios/src/cuda.rs:667-676 adds map_device_host_parts as a wrapper that turns try_map_device_host_parts's Ok(None) into an error. Its only caller is CudaRegistrar::map_split (helios/src/offload/registrar.rs:27-29). map_split is only reachable through the default body of the new HostRegistrar::try_map_split (selene/src/registrar.rs:32-37), and CudaRegistrar overrides try_map_split (registrar.rs:31-38). So in the workspace nothing ever calls map_device_host_parts: dead code kept alive only because map_split remains a required trait method.

map_split is still the required method, so every implementor must write it: selene/src/registrar.rs (trait), helios/src/offload/registrar.rs:27, selene/src/pool/builder.rs:311, selene/src/pool/startup.rs:223 (ClosedRegistrar), selene/src/pool/net.rs:976, selene/src/pool/engine/tests.rs:155, selene/src/pool/engine/net_tests.rs:44, selene/src/testing.rs:453 and :490, selene/src/offload/tests.rs:800, selene-manager/tests/client.rs:1100, :1298, :3147 -- ~12 impls of a method the production path (selene/src/slab.rs:215) no longer calls.

Smaller version: make try_map_split the trait's single required method (no default), delete map_split from the trait and all 12 impls (each becomes Ok(self.map_split(...).map(Some)) one-liner or, for CudaRegistrar, just the try_ body), and delete map_device_host_parts from cuda.rs. Removes ~10 arms of boilerplate plus 10 lines of cuda.rs. AGENTS.md line ~188 "Do not add ... fallback layers ... without a concrete requirement"; tests should exercise the production entry point (line ~194).

Unrelated nit seen in the same C diff: cuda.rs now repeats the same 5-line "status = call(...); if is_host_numa_unsupported(status) { return Ok(None) } ; check(name, status)" pattern four times (:576-589, :641-650, :652-660 area). One helper taking the call's status + name would be half the lines; four copies invite one of them being missed on the next edit.

Also: mapping raw status 1 (CUDA_ERROR_INVALID_VALUE) to "unsupported" means a genuinely invalid argument in cuMemCreate/cuMemSetAccess silently downgrades the pool to a registered anonymous mapping instead of surfacing a bug (charter: "Bug fixes need to address the root cause; don't just swallow, skip, or retry an unexplained error (#397)"). If the intent is only "platform lacks HOST_NUMA VMM", say what would settle it: a hardware test on GA10B/WDDM that a bad-granularity call still errors.

#8 [high] should fix: two new tests can pass without asserting anything

Two new tests added by this PR pass without asserting anything on the machines where they run in CI:

  1. eos/src/unix.rs:206-248 map_host_advises_hugepages_and_prefaults_zeroed_pages: the assertion sits inside if let Ok(smaps) = std::fs::read_to_string("/proc/self/smaps"), then if let Some(start) = smaps.find(needle), then if let Some(flags) = ..., then if let Some(end) = ... — four nested if lets, 30 lines of hand-rolled VMA-block scanning (finding the next hex-address line by re-counting line lengths). If any lookup misses, the test asserts nothing and passes. The zeroed-page check above it does assert, so the test is named for behaviour it may not check.

  2. helios/src/execution/roce.rs:511-523 lazy_libibverbs_loader_resolves_symbols_or_reports_install_hint: if status != 0 { assert!(text.contains(...)) }. When libibverbs1 is installed — which is the case on the dev/GPU boxes and on any runner with libibverbs-dev — status is 0 and the test body is empty. It cannot fail in either direction, so it does not establish either outcome.

AGENTS.md ~line 194: "Require focused, meaningful validation. Tests must exercise the affected behavior or contract ... cannot establish runtime correctness." A test whose assertion is conditional on the environment is exactly that.

Fix for (2): assert the branch that applies, e.g. match status { 0 => assert!(/* dlopen handle usable */), _ => assert!(hint) } — or simply drop it, since the CI container smoke test (release.yml:110-121) already proves loading without libibverbs and a loaded-lib path is covered by any RoCE hardware run. Fix for (1): pull the smaps block out into a helper returning Option<&str> and expect("mapping VMA in /proc/self/smaps"); the length re-counting loop collapses into a .lines() skip_while/ take_while.

Both should fix (they cost 40 lines and prove nothing); nit if reviewers accept them as documentation of intent.

#9 [high] FINAL REPORT lens D (supersedes note #5)

This supersedes note #5. Lens D (simplicity): what can be deleted.

Repo rules

AGENTS.md ~9-14 "Look for the smallest footprint in shared code, or a way to solve it without new code at all"; ~188 "Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement"; ~194 "Tests must exercise the affected behavior or contract"; ~157 scope. docs/design-review.md principle 1 "Keep Helios as simple as possible", principle 4 "avoid interchangeable backends or portability layers". Charter: "Bug fixes need to address the root cause; don't just swallow, skip, or retry an unexplained error (#397)".

Findings

  1. should fix — the fixed defect's old path survives as the None default (three overlapping entry points). selene/src/offload.rs:497-534, :600-619, :117-146; helios/src/offload/mod.rs:72-129. Only production caller is helios/src/runtime_core/model.rs:967 through prepare_with_inputs_budget with planned_host_budget, which is Some whenever cfg.enabled() (memory.rs:1102-1112; prepare_offload returns early at model.rs:933 when not enabled). So the None arm at :612 re-queries options.headroom_with_inputs -> host_pool_budget, i.e. exactly the post-KV-alloc re-query this PR set out to remove, still compiled in and still the default for every other caller. prepare_with_inputs (both crates) now has only test/helios offload pool test callers (selene/src/offload/tests.rs, sharded/tests.rs, helios/src/offload/pool/tests.rs:124, selene-manager/tests/client.rs:3204). Fix: one entry point taking host_budget: u64; delete the Option, the None arm, the prepare_with_inputs shim in both crates, and the duplicated #[allow(clippy::too_many_arguments)]. ~40 lines fewer, one buggy path less.

  2. should fix — map_device_host_parts is unreachable and map_split is a required trait method with no production caller. helios/src/cuda.rs:667-676; helios/src/offload/registrar.rs:27-38; selene/src/registrar.rs:26-37; selene/src/slab.rs:189-270. map_device_host_parts is called only by CudaRegistrar::map_split, reachable only via the default body of try_map_split, which CudaRegistrar overrides; production goes through try_sized_by_rank -> try_map_split (slab.rs:215). map_split stays a required method forcing ~12 boilerplate impls (registrar.rs:27, pool/builder.rs:311, pool/startup.rs:223, pool/net.rs:976, pool/engine/tests.rs:155, pool/engine/net_tests.rs:44, testing.rs:453 and :490, offload/tests.rs:800, selene-manager/tests/client.rs:1100/1298/3147). Same story for SlabPool::sized_by_rank (slab.rs:261-270): production uses try_sized_by_rank; remaining callers are the ignored GPU benchmark helios/src/offload/transfer.rs:1723 and the test at slab.rs:631. Fix: make try_map_split the trait's only required method, delete map_split from trait and impls, delete map_device_host_parts, and drop sized_by_rank (slab.rs:631 can call try_sized_by_rank(...).unwrap()), with transfer.rs:1723 doing the same.

  3. should fix — two new tests assert conditionally, so they pass without proving anything. eos/src/unix.rs:206-248: the hg VmFlags assertion sits behind four nested if lets (smaps readable, address found, next VMA found, VmFlags present) and 30 lines of hand-rolled block scanning; any miss => no assertion. helios/src/execution/roce.rs:511-523: if status != 0 { assert!(hint) } — empty when libibverbs1 is installed (the normal case on GPU hosts and on any runner with libibverbs-dev), so it cannot fail either way. Fix: hoist the smaps lookup into a helper returning Option<&str> and .expect(...) it (the line-length re-counting becomes .lines().skip_while().take_while()); for the roce test assert the applicable branch or drop it — release.yml:110-121's clean-container smoke check already proves the no-libibverbs path.

  4. should fix — integrated-memory accounting computed twice in one function. helios/src/runtime_core/memory.rs:646-683 (integrated_state) vs :878-909 (per-rank loop): min-free over integrated ranks, the fixed_bytes(core, true)+embedding_host_bytes fold, and fixed.max(initial-free-delta) are written twice, ~200 lines apart, and already disagree (min total vs observations[index].total; max observed drop vs per-index). Fix: build one Vec<(MemorySnapshot, u64)> of per-integrated-rank state and use it in both places. ~20 lines fewer.

  5. nit — host_pool_budget_with_reserve's bool has one caller. selene/src/offload.rs:852-886: host_pool_budget forwards (future, true); nothing else calls the two-argument form. Fix: keep host_pool_budget_from(available, total, future, apply_reserve) (helios needs the false case) and have the meminfo-reading helper be the only apply_reserve = true user; delete _with_reserve.

  6. should fix (stale doc) — helios/src/frontend/mod.rs:1400-1402 still documents the reserve as "HOST_SERVICE_HEADROOM_BYTES (2 GiB) plus one twentieth of total memory". The PR changed it to 64 MiB at <=16 GiB, min(2 GiB, total/32) above, and updated docs/prefix-cache-offload.md:1141-1144 but not this comment. One-line fix.

Clean in this lens

Not verified

Whether map_split is part of selene's public contract for out-of-tree consumers (publish = false, so unlikely); a grep in the repo shows no non-test caller.

#10 [high] Research summary

Lens D (simplicity) review of PR #589 complete; all 21 changed files read in context, callers followed, findings checked in the code. Full report is scratchpad entry #9 (supersedes #5); AGENTS.md (not opened)/design-review quotes in #1.

Six findings:

  1. should fix — the fixed defect's old path survives as the None default. prepare_with_inputs_budget's Option<u64> (selene/src/offload.rs:523-619, mirrored in helios/src/offload/mod.rs:72-129) keeps a None arm that re-queries host_pool_budget post-KV-alloc — exactly the behaviour the PR removes — even though the only production caller (helios/src/runtime_core/model.rs:967) always passes Some when the prefix cache is enabled. prepare_with_inputs in both crates now has only test callers. One entry point taking a plain u64, deleting the shim and the duplicate too_many_arguments allow, is ~40 lines smaller.

  2. should fix — map_device_host_parts is unreachable and map_split is a required trait method nobody calls. helios/src/cuda.rs:667-676 is called only by CudaRegistrar::map_split, reachable only through the try_map_split default that CudaRegistrar overrides; map_split still forces ~12 boilerplate impls across selene/selene-manager/helios. Same for SlabPool::sized_by_rank (slab.rs:261-270), now used only by one ignored GPU benchmark and one test.

  3. should fix — two new tests can pass without asserting anything. eos/src/unix.rs:206-248 hides the hg VmFlags assertion behind four nested if lets plus 30 lines of hand-rolled smaps scanning; helios/src/execution/roce.rs:511-523 is an empty if status != 0 whenever libibverbs1 is installed, so it cannot fail either way.

  4. should fix — integrated-memory accounting written twice in one function (helios/src/runtime_core/memory.rs:646-683 vs :878-909), and the two copies already disagree on min-total and on the observed-drop basis.

  5. nit — host_pool_budget_with_reserve(future, true) has a single caller (selene/src/offload.rs:852-886).

  6. should fix (stale doc) — helios/src/frontend/mod.rs:1400-1402 still describes the old unscaled "2 GiB plus one twentieth" reserve that this PR replaced.

The CUDA copy fallback (two driver symbols, both used), the -libverbs → -libdl build change, roce_proxy_dlopen.c, release.yml and the docs edits are clean in this lens — deletions, not new layers.

#11 [high] Coverage: lens-D verdict for each of the 21 changed files

Companion to note #9 (the full report). Every file the PR touches, and its lens-D verdict:

Findings:

Clean (no simplicity finding):

Not verified: whether map_split (selene/src/registrar.rs:26) is contract for out-of-tree consumers — the crates are publish = false and no non-test caller exists in the workspace.

#3 [medium] should fix: map_device_host_parts / sized_by_rank left as test-only wrappers

helios/src/cuda.rs:667-676 map_device_host_parts and selene/src/slab.rs:261-270 sized_by_rank exist only to turn the new Ok(None) into an error. Production callers now use the try_ variants: helios/src/offload/registrar.rs:28 still impls map_split via map_device_host_parts (only reached through the trait default try_map_split, which CudaRegistrar overrides at :31-37 -> dead), selene/src/slab.rs:631 calls try_sized_by_rank; sized_by_rank remains only in helios/src/offload/transfer.rs:1723 and selene/src/slab.rs:631 (test). Fix: delete map_device_host_parts + the CudaRegistrar::map_split override (keep the trait default or make try_map_split the only method), and delete sized_by_rank (helpers used only by tests stay behind #[cfg(test)]). AGENTS.md rejection criteria: "Do not add ... fallback layers ... without a concrete requirement"; tests should call the production entry point. Severity: should fix (nit if reviewers prefer the by_rank naming preserved for docs).

#4 [medium] nit: host_pool_budget_with_reserve's bool flag has a single caller; stale 2 GiB comment

selene/src/offload.rs:852-886: host_pool_budget now just forwards to host_pool_budget_with_reserve(future, true); the only caller of _with_reserve is host_pool_budget (grep: no other caller). So the bool parameter and the extra public function are unused configuration. Fix: keep one host_pool_budget_from(available, total, future, apply_reserve) (needed by helios), and have the meminfo-reading helper hard-code apply_reserve=true, deleting host_pool_budget_with_reserve. Also helios/src/frontend/mod.rs:1400-1402 comment still states the reserve is "HOST_SERVICE_HEADROOM_BYTES (2 GiB) plus one twentieth of total memory", which the PR changed to 64 MiB at <=16 GiB / min(2 GiB, total/32) above. Stale comment in untouched file -> should update with this PR (docs/prefix-cache-offload.md:1141-1144 was updated, this one was not). Severity: nit (function), should fix (stale doc comment).

#7 [medium] should fix: integrated integrated-memory accounting is computed twice in the same function

helios/src/runtime_core/memory.rs:646-683 (integrated_state) and :878-909 (the if rank.integrated arm of the per-rank budget loop) are the same computation written twice, ~200 lines apart:

Smaller version: build one Vec<(MemorySnapshot, u64)> of per-integrated-rank (memory, loaded) once, use integrated_state for the headroom/pool closures and index the same vec in the loop; the initial[index] delta stays per-rank. Deletes ~20 lines. AGENTS.md "smallest footprint in shared code"; docs/design-review.md principle 1 "Keep Helios as simple as possible".