Conventions and duplication review — PR #589 (merged, head aed8039, 21 files, +994/−133)
Rules applied: AGENTS.md ("Contribution scope and rejection criteria", lines 170-212, esp. Reject unsupported abstractions and churn at 188-193 and the docs-accuracy criteria), docs/design-review.md (principle 3, "Preserve canonical model semantics and shared mechanisms", lines 40-57), and the charter (focus / no speculative surface). My lens is conventions and duplication: each new construct compared with its closest precedent, and any helper or mechanism it duplicates.
Key findings
- Nothing blocking. Two "should fix" items, six nits.
- Should fix 1 — stale headroom doc:
helios/src/frontend/mod.rs:1400-1402still documents the host-cache headroom as the unscaled2 GiB + total/20, while this PR replaces that exact policy with a scaled reserve. It is the only place the constraint behindpush_segment's second encoding is written down, and on the 8-16 GiB unified-memory hosts this PR targets it is wrong by ~2 GiB. - Should fix 2 — duplicated budget policy:
helios/src/runtime_core/memory.rs:192-221addsintegrated_offload_host_budget, which restates the explicit---memory-limitarms of the pre-existinglimited_budget(memory.rs:267-298) in the same module, so the "explicit limit removes implicit reserves" rule now has two implementations and three sources of the reserve value. - Nits: paired-function duplication for the injected host budget, a speculative
apply_reserveswitch with no caller that needs it, a byte-for-byte duplicated prefault loop acrosseosplatform modules, bare CUDA status literals where the repo keeps named constants, an identical duplicate type alias, and Debian packaging docs still asserting a hard ARM64 libibverbs dependency.
Should fix
1. helios/src/frontend/mod.rs:1400-1402 — headroom documentation still states the unscaled reserve this PR removes
The doc comment on push_segment says the second encoding's host allocation "draws on the headroom host_pool_budget (selene/src/offload.rs) leaves unallocated: HOST_SERVICE_HEADROOM_BYTES (2 GiB) plus one twentieth of total memory."
That sentence describes precisely the policy this PR changes. selene/src/offload.rs:806-820 now defines host_service_headroom_bytes(total) — 64 MiB at total <= 16 GiB, else min(2 GiB, total / 32) — and host_reserve_bytes(total) = host_service_headroom_bytes(total) + total / 20; host_pool_budget routes through host_pool_budget_from with that scaled reserve (offload.rs:824-836, 851-886). helios/src/runtime_core/memory.rs:28, 183-190 switched from the constants to host_reserve_bytes as well.
Why it matters: on an 8-16 GiB Jetson Orin / integrated GPU — the hosts whose budgeting this PR is fixing — the actual headroom is 64 MiB + 5% of RAM, not 2 GiB + 5%. The comment overstates it by roughly 2 GiB, at the one site that explains why the second encoding is safe. It is also the only place in the tree that spells the constraint out; HOST_SERVICE_HEADROOM_BYTES (selene/src/offload.rs:802) is still exported and still 2 GiB, which makes the stale prose look authoritative.
Fix: restate it in terms of host_service_headroom_bytes / host_reserve_bytes (or "the reserve host_pool_budget leaves unallocated"), i.e. 64 MiB on hosts up to 16 GiB, otherwise min(2 GiB, total/32) plus a twentieth.
Rule: AGENTS.md:209-212 and the "inaccurate documentation" criterion; docs/design-review.md principle (no unexplained/unsupported claims). Behaviourally harmless, but the PR's own central claim is that the reserve is now scaled, so leaving the one doc describing it unscaled is the kind of gap that gets copied.
2. helios/src/runtime_core/memory.rs:192-221 — integrated_offload_host_budget duplicates limited_budget's explicit-limit policy
New function:
None => host_pool_budget_from(memory.free, memory.total, future, true)
Some(Reserve(reserve)) => free.min(total) - reserve - future
Some(limit) => physical = free.min(total) - future, capped by
limit.occupied_bytes(total) - (loaded + future)
Established function, same module, memory.rs:267-298:
headroom = match limit { None => default_headroom, Some(Reserve(r)) => r, Some(_) => 0 }
available = budget(free.min(total), total, headroom, integrated, limit.is_some()) - future
cap = limit.occupied_bytes(total) -> remaining = cap - (loaded + future); return min(available, remaining)
budget (memory.rs:183-190) is where the "integrated && !explicit_limit ⇒ subtract host_reserve_bytes(total)" rule lives, so limited_budget(..., default_headroom = 0, integrated = true, ...) already expresses the new function's None arm; its Some(Reserve) arm is limited_budget's Reserve headroom; and its Some(limit) arm is limited_budget's cap logic. The new function recomputes free.min(total) per arm instead of going through the shared budget step, and it has different error semantics for the cap case (saturating to 0 instead of the "memory limit is {cap} bytes, but loaded model resources require {required}" error at memory.rs:294-296).
Both are consumed from the same call site family: host_budget_for at memory.rs:684-694 chooses between integrated_offload_host_budget(...) and selene::offload::host_pool_budget(future), while limited_budget sits right above in the same allocation planning.
Why it matters: there are now two implementations of "an explicit --memory-limit removes the implicit service/system reserves" in one file, and three consumers of the reserve formula (host_reserve_bytes, budget, and the new function's None arm). The PR's premise — integrated budgeting must match the reserve planning used elsewhere — is exactly what makes silent divergence costly, and the new test integrated_offload_host_budget_matches_small_soc_scaling_and_explicit_limits (memory.rs:1489-1520) pins the copy rather than the shared helper.
Fix: express the host pool budget through limited_budget (e.g. limited_budget(memory, loaded, limit, 0, /*integrated=*/true, future)), or factor the shared "explicit limit wins, else scaled reserve" step into one helper that both budget/limited_budget and integrated_offload_host_budget call, so the reserve has one definition per the "shared mechanisms" rule (docs/design-review.md:40-57) and AGENTS.md:188-193.
Nits
3. Parallel *_with_budget / try_* twins instead of one Option parameter (selene/src/offload.rs, helios/src/offload/mod.rs, selene/src/slab.rs, selene/src/registrar.rs)
Every changed entry point is doubled rather than given one optional argument:
selene/src/offload.rs:497-520prepare_with_inputsis now a wrapper that forwardsNoneto newprepare_with_inputs_budget(offload.rs:522-534, which needs#[allow(clippy::too_many_arguments)]); theOptionis then re-branched atoffload.rs:603-619.selene/src/offload.rs:117-146headroom_with_inputskeeps its old body and forwards toheadroom_with_inputs_for_budget(offload.rs:151-175), duplicating theenabled()/memory/disk/capturederivation at lines 125-137 and 160-165.helios/src/offload/mod.rs:82-129mirrors both, with the new twin only passingNoneand carrying a fresh#[allow(clippy::too_many_arguments)].SlabPool::sized_by_rank(selene/src/slab.rs:261-270) now only wrapstry_sized_by_rank;HostRegistrar::try_map_split(selene/src/registrar.rs:32-37) defaults tomap_split;map_device_host_parts(helios/src/cuda.rs:669-676) only wrapstry_map_device_host_parts.
The precedent in the same code is the opposite: limited_budget (helios/src/runtime_core/memory.rs:267-274) takes limit: Option<MemoryLimit> directly and has no non-Option twin, and the "defaults" constructor convention is already established by prepare delegating to prepare_with_inputs (selene/src/offload.rs:484-495).
Fix: thread host_budget: Option<u64> through the existing functions, letting prepare/prepare_with_inputs pass None; keep the try_* names only where failure is new.
4. selene/src/offload.rs:856-886 — host_pool_budget_with_reserve is a speculative switch
pub fn host_pool_budget_with_reserve(future: u64, apply_reserve: bool) is documented as serving "callers with an explicit unified-memory limit [to] omit the implicit service and system reserves". Its only caller is host_pool_budget (offload.rs:852-854), which passes true; the only other use of the parameterised path is host_pool_budget_from(..., true) at helios/src/runtime_core/memory.rs:202-207. No caller anywhere passes false (whole-tree search returns offload.rs:824, 853, 858, 885, memory.rs:202, and tests at selene/src/offload/tests.rs:720-723 that exercise host_pool_budget_from directly). The explicit-limit case the doc names actually goes through integrated_offload_host_budget and never reaches this function.
That is the "configuration switches without a concrete requirement" case in AGENTS.md:188-193, and it departs from its own delegate host_pool_budget_from, which is a pure function genuinely called with both values.
Fix: delete the wrapper and end host_pool_budget with Ok(host_pool_budget_from(available, total, future, true)), keeping host_pool_budget_from as the single parameterised helper.
5. eos/src/unix.rs:109-117 duplicates eos/src/windows.rs:178-183
The new Linux fallback prefaults with
let step = page_size().max(1);
for offset in (0..bytes).step_by(step) { ptr.cast::<u8>().add(offset).write_volatile(0); }
which is the loop already present in eos/src/windows.rs:178-183 ("Populate the pages before the slab enters the transfer pool"), including the page_size() stride. Two #[cfg]-selected modules of one crate now carry the same helper. eos/src/lib.rs already re-exports the unix/windows split and owns page_size, so the shared home exists.
Fix: move prefault_zeroed(address, bytes) next to page_size() and call it from both map_hosts. (Not a correctness issue: both paths write zeros, which selene/src/slab.rs:162-178 and the new map_host_advises_hugepages_and_prefaults_zeroed_pages test require.)
6. helios/src/cuda.rs:532-536 — CUDA status codes inlined as literals
fn is_host_numa_unsupported(status: c_int) -> bool { matches!(status, 1 | 801) } cites CUDA_ERROR_INVALID_VALUE / CUDA_ERROR_NOT_SUPPORTED only in the doc comment. The repository convention is named constants: helios/src/runtime_core/driver.rs:94-97 declares CUDA_ERROR_NOT_READY: c_int = 600 and CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE: c_int = 708, consumed at runtime_core/persistent_worker.rs:495 (not opened),970,989 and runtime_core/mod.rs:382; cuda.rs:143-160 names every other driver constant it uses (ATTRIBUTE_HOST_NUMA_ID, LOCATION_HOST_NUMA, …).
Caveat the fix must respect: runtime_core is behind #[cfg(feature = "runtime-core")] (helios/src/lib.rs:22-26) while cuda.rs is always compiled, so the constants cannot simply be imported — they would need to live somewhere compiled in both configurations, or be declared beside the cuda.rs:143-160 constants.
Fix: declare CUDA_ERROR_INVALID_VALUE / CUDA_ERROR_NOT_SUPPORTED with the other status constants and match on the names.
7. helios/src/cuda.rs:81 — CopyAsync duplicates CopyDtoD
type CopyAsync = unsafe extern "C" fn(u64, u64, usize, Handle) -> c_int; is character-for-character the same signature as CopyDtoD (cuda.rs:80), and needs its own Driver field (copy_async). Every other driver entry point has a distinct alias because its signature differs (Upload, Download, Download2D), so the alias table's convention is one alias per ABI shape; CopyAsync/CopyDtoD is the only duplicate pair in the file. The fallback itself is fine and matches the existing copy_dtod_async pattern (cuda.rs:1142-1146) — only the alias is redundant.
Fix: copy_async: CopyDtoD, or rename the shared alias.
8. packaging/debian/package.sh:46-48, docs/debian.md:3-6,61-64 — Debian artifacts still assert a hard ARM64 libibverbs dependency
package.sh appends dependencies+=", ibverbs-providers" for arm64, and docs/debian.md describes the ARM64 package as depending on "the verbs providers needed for RoCE" and advertises that "ARM64 builds include the RoCE transport" without the new runtime-optional caveat. After this PR the ARM64 binary has no libibverbs.so DT_NEEDED entry (asserted in .github/workflows/release.yml:92-95 (not opened)), so dpkg-shlibdeps derives nothing and the hard-coded suffix is the sole RDMA dependency. docs/release.md:32-35 was updated in this PR to the new optional-at-runtime wording, so the Debian docs are now the inconsistent pair.
Severity nit: it works today (ibverbs-providers pulls libibverbs1) and is a packaging/doc consistency gap, not a runtime defect. Fix: keep the ARM64 dependency deliberate-and-documented, or make it a recommendation, and align docs/debian.md with docs/release.md's "requires libibverbs1 and ibverbs-providers" only when multi-host RoCE is used.
Coverage and files with no finding
All 21 changed files were read in context, not just diffed:
.github/workflows/release.yml(not opened) — Ubuntu 22.04 container build, ELF/GLIBC assertions, dual-container smoke. No convention departure worth a finding; the inlinepython3 - <<'PY'readelf check (release.yml:96) is a new style for this workflow, but it is a few lines inside one step and the repo's named-script convention (scripts/set_release_version.py(not opened),packaging/archive.py(not opened)) still covers the parts that were already scripts. Not recorded.helios/native/roce_proxy_dlopen.c(read in full) andhelios/build.rs:69-77— the dlopen shim is a genuinely new mechanism, but there is no Rust equivalent to duplicate (the only dynamic loading elsewhere islibloadinginhelios/src/os.rs(not opened) /runtime_core/device_memory.rs(not opened), a different mechanism), and linkingdl/pthreadinstead ofibverbsis the intended change. No finding.helios/src/execution/roce.rs:34-40, 124-225, 500-525—roce_ensure_libibverbscalled once inopenafter preflight; buffer-reuse pattern matchesroce_create. No finding.helios/src/runtime_core/model.rs:906-980, 1310-1340—planned_offload_hostthreaded fromallocate_cachestoprepare_offload; call sites and tests updated coherently. No finding.selene/src/offload/tests.rs:690-863— tests cover the new budget helpers; only the point in finding 2 (pinning the duplicate) applies.selene/src/registrar.rs:32-37—try_map_split's defaultself.map_split(requests).map(Some)meanssized_by_ranknever observesNonethrough a registrar that does not override it; that is deliberate back-compat for the otherHostRegistrarimplementations (pool/builder.rs:311,pool/startup.rs:223,testing.rs:449 (not opened),477) and keepsmap_splitrequired. No finding.docs/multi-host.md,docs/prefix-cache-offload.md,docs/runtime-core-design.md,flare/Cargo.toml,flare-cli/Cargo.toml,helios/Cargo.toml— consistent with the code; the only doc gaps are findings 1 and 8.helios/src/offload/registrar.rs:27-40,helios/src/cuda.rs:300-330, 780-840— covered by findings 3, 6, 7; nothing else.
Open questions / what only a test could settle
- Finding 2: whether
integrated_offload_host_budgetis behaviourally identical tolimited_budget(..., headroom 0, integrated true, ...)for aReserve(0)limit and for aBytescap smaller thanloaded + future(the new code saturates to 0,limited_budgetreturns an error). A test asserting both paths agree on those inputs would settle whether the duplicate is only stylistic or already divergent. - Finding 8: whether the ARM64 Debian package should keep
ibverbs-providersas a hardDependsor drop it; that is a product decision, not something the code states. - Not in scope of this lens but unrun per the PR: native
aarch64build,ubuntu-24.04-armCI, live GPU runs on discrete CUDA 12.x / Jetson Orin GA10B / Windows WDDM. Nothing in the conventions/duplication lens depends on them.
No prompt-injection or instruction-like content was found in the PR body, diff, or docs; the Discord field is simply empty.