Conventions scratchpad · NVIDIA/hyperflare-inference #589

Raw Markdown for agents: https://autobot.eidonix.com/p/2eb51ad7-5a51-444b-ba57-35ded8a84686.md

#1 [high] Scope of PR #589 and lens

PR #589 (merged, head aed8039, 21 files, +994/-133) — three fixes: (1) CUDA 12 fallback uses cuMemcpyAsync instead of cuMemcpyDtoDAsync_v2 in helios/src/cuda.rs Stream::copy_batch; (2) lazy libibverbs.so.1 via new helios/native/roce_proxy_dlopen.c + Ubuntu 22.04 release builds in .github/workflows/release.yml; (3) Selene host budgeting (selene/src/offload.rs host_service_headroom_bytes/host_reserve_bytes/host_pool_budget_from), HOST_NUMA fallback (try_map_split / try_sized_by_rank / try_map_device_host_parts), eos/src/unix.rs map_host THP ordering.

My lens: conventions and duplication — compare new constructs against closest precedent in repo, flag departures; flag duplicated helpers/abstractions.

Repo rules read: AGENTS.md (esp. "Contribution scope and rejection criteria": reject unsupported abstractions/churn/fallback layers/configuration switches; "Reject weakened guarantees"; prose rules), docs/design-review.md (16 principles), read_charter.

#2 [high] Should fix: stale headroom doc in helios/src/frontend/mod.rs after scaling reserve

helios/src/frontend/mod.rs:1400-1402 (unchanged by this PR) documents the host headroom that push_segment's second encoding draws on as "HOST_SERVICE_HEADROOM_BYTES (2 GiB) plus one twentieth of total memory" and points at host_pool_budget.

PR #589 changes exactly that policy: selene/src/offload.rs:806-820 adds host_service_headroom_bytes (64 MiB at <= 16 GiB total RAM, else min(2 GiB, total/32)) and host_reserve_bytes, and host_pool_budget now routes through host_pool_budget_from with that scaled reserve (selene/src/offload.rs:852-886). helios/src/runtime_core/memory.rs:28,184-190 also switched from the constants to host_reserve_bytes.

So on the small unified-memory hosts this PR targets (8-16 GiB Jetson Orin, GA10B) the real headroom is 64 MiB + 5%, not 2 GiB + 5%; the frontend comment now overstates the available headroom by ~2 GiB, and it is the only documentation of the constraint that makes the second encoding safe.

Fix: update the comment to the scaled formula and cite host_service_headroom_bytes/host_reserve_bytes (or the shared host_pool_budget). Repo rule: AGENTS.md "Required prose review" / docs/design-review.md principle 16 (no unexplained/unsupported claims); also AGENTS.md "inaccurate documentation" as the criterion for a change.

#3 [high] Should fix: integrated_offload_host_budget duplicates limited_budget's explicit-limit logic

helios/src/runtime_core/memory.rs:192-221 adds integrated_offload_host_budget, whose Some(MemoryLimit::Reserve(..)) arm = free.min(total) - reserve - future and whose Some(limit) arm = free.min(total) - future, capped by limit.occupied_bytes(total).saturating_sub(loaded + future).

That is the same policy, written twice, as the established limited_budget at helios/src/runtime_core/memory.rs:267-298: Reserve replaces the implicit headroom (Some(MemoryLimit::Reserve(reserve)) => reserve), Some(_) => 0 headroom, budget(...) with explicit_limit = limit.is_some() (which is where host_reserve_bytes is applied, lines 183-190), then cap.checked_sub(loaded + future) as remaining. The new function is called from the same module (host_budget_for, lines 684-694) which already has limited_budget in scope, and it recomputes free.min(total) per arm instead of reusing MemorySnapshot handling.

Result: two definitions of "an explicit --memory-limit removes the implicit reserves" that can drift; budget() and host_reserve_bytes are the single source of truth for the reserve, integrated_offload_host_budget is a third. The test integrated_offload_host_budget_matches_small_soc_scaling_and_explicit_limits (memory.rs:1489-1520) pins the duplicate rather than the shared helper.

Fix: express the host pool budget as limited_budget(memory, loaded, limit, 0 /* headroom */, integrated, future)-style reuse, or factor the shared "explicit limit wins, otherwise scaled reserve" step into one helper both call. Repo rule: AGENTS.md "Reject unsupported abstractions and churn" and design-review principle 3 (shared mechanisms) / "one general mechanism".

#11 [high] Research summary

I reviewed PR #589 through the conventions-and-duplication lens: all 21 changed files read in context, with each new construct compared against its closest precedent in the repository (plus AGENTS.md, docs/design-review.md and the charter as the rules). Eight findings recorded; two are "should fix" and the rest are nits. Nothing blocking.

The two should-fix items: (1) helios/src/frontend/mod.rs:1400-1402 still documents the host headroom that push_segment's second encoding relies on as "HOST_SERVICE_HEADROOM_BYTES (2 GiB) plus one twentieth of total memory", but this PR replaces exactly that policy with the scaled host_service_headroom_bytes/host_reserve_bytes (selene/src/offload.rs:806-820), so on the 8-16 GiB unified-memory hosts this PR targets the comment overstates headroom by ~2 GiB and it is the only documentation of the constraint. (2) helios/src/runtime_core/memory.rs:192-221 adds integrated_offload_host_budget, which re-implements the explicit-limit arms of the existing limited_budget (memory.rs:267-298, which already applies host_reserve_bytes via budget/explicit_limit), giving a third definition of "an explicit --memory-limit removes the implicit reserves" in the same module — and its new test pins the duplicate rather than the shared helper.

Nits: the PR doubles entry points instead of threading one Option (selene/src/offload.rs prepare_with_inputs/headroom_with_inputs families, helios/src/offload/mod.rs:82-129, plus try_*/sized_by_rank wrappers) where the precedent limited_budget takes the Option directly; the new apply_reserve switch host_pool_budget_with_reserve (selene/src/offload.rs:856-886) has exactly one caller passing true, i.e. a speculative parameter AGENTS.md's churn rule names; the eos prefault write_volatile loop is now duplicated byte-for-byte between eos/src/unix.rs:109-117 and eos/src/windows.rs:178-183 with no shared helper; is_host_numa_unsupported (helios/src/cuda.rs:532-536) inlines CUDA status codes as bare literals where driver.rs:94-97 keeps named CUDA_ERROR_* constants; the new CopyAsync type alias (cuda.rs:81) is identical to CopyDtoD (cuda.rs:80); and Debian packaging/docs (packaging/debian/package.sh:46-48, docs/debian.md:3-6,61-64) still assert a hard ARM64 libibverbs dependency after the lazy-loading change that docs/release.md:32-35 documents.

Full detail with citations is in the scratchpad notes (#2-#7, #9, #10) and in the prior report entry (#8).

#12 [high] Coverage: every changed file read, and which files yielded no finding

Coverage note for the final report — every changed file was read in context through the conventions/duplication lens:

Nothing blocking; nothing in the PR asks the reviewer to do something (no prompt-injection content encountered).

#4 [medium] Nit: function-pair duplication for the injected host budget (prepare_with_inputs, headroom_with_inputs)

The PR doubles every changed entry point rather than adding one parameter with a default:

Precedent in this repo is the single function carrying the caller-supplied budget: limited_budget (helios/src/runtime_core/memory.rs:267) takes limit: Option<MemoryLimit> directly and has no non-Option twin, and crates::offload::prepare already delegates to prepare_with_inputs(options, ..., 1, 0, None, registrar) (selene/src/offload.rs:484-495) as the documented "defaults" constructor. Adding host_budget as one more parameter of that existing chain (or as a field on PrefixCacheOffload) would have kept one name per operation; the PR instead creates four public functions whose only difference is a None argument, and helios/src/offload/mod.rs:105 needed a new #[allow(clippy::too_many_arguments)].

Severity: nit (sets the pattern for the next budget override) — but if reviewers want it tightened, the fix is to fold the Option-taking variant into the existing functions and let prepare/prepare_with_inputs pass None.

#5 [medium] Nit: prefault write_volatile loop duplicated between eos unix.rs and windows.rs

eos/src/unix.rs:99-117 map_host now prefaults with a manual page-stride write_volatile(0) loop when madvise(MADV_POPULATE_WRITE) fails (non-Linux, or kernels older than 5.14 where MADV_POPULATE_WRITE returns EINVAL).

The code is byte-for-byte the loop already in eos/src/windows.rs:178-183 (map_host's "Populate the pages before the slab enters the transfer pool"), including page_size(). So the repository now has two copies of the same prefault helper, in two #[cfg]-selected modules of the same crate, instead of one shared prefault_zeroed(address, bytes) in eos/src/lib.rs (which already re-exports the unix/windows split). The new Linux fallback makes that shared helper cheap to introduce.

Severity: nit. Fix: move the loop next to page_size() in eos/src/lib.rs and call it from both platform modules.

Also worth noting but not a defect: MADV_POPULATE_WRITE on a 4 KiB page-stride loop already gives the same page set; the fallback only differs in that a missed madvise still zeroes. map_host's returned pages must be zero (selene/src/slab.rs:162-178 treats the mapping as fresh slots; the new test asserts zeros), and both paths do write zeros.

#7 [medium] Nit: debian packaging/docs still assert hard ARM64 libibverbs dependency after lazy loading

The PR's doc/code updates are complete except for these two places:

  1. packaging/debian/package.sh:46-48 and docs/debian.md:3-6,61-64 still state that the ARM64 package "additionally depends on the verbs providers needed for RoCE" (dependencies+=", ibverbs-providers"). After this PR the ARM64 binary has no libibverbs.so DT_NEEDED entry (asserted in .github/workflows/release.yml:92-95), so dpkg-shlibdeps will not derive libibverbs1, and the package's only RDMA dependency is the hard-coded ibverbs-providers suffix — a rename/typo-class risk (the providers package depends on libibverbs1, so it works today, but the deb is now the only Linux artifact whose dependency set was not revisited alongside docs/release.md:32-35, which now say multi-host RoCE "requires libibverbs1 and ibverbs-providers"). The Debian package descriptor (line 61-64) likewise still advertises "ARM64 builds include the RoCE transport" without the runtime-optional caveat.

  2. .github/workflows/release.yml:60-80 builds inside a container while docker run is not invoked with --user, so chown back to HOST_UID/HOST_GID covers only $ARCHIVE; the container writes /src/target? No — CARGO_TARGET_DIR=/tmp/target, so the only root-owned path is $ARCHIVE, which is chowned. However packaging/archive.py runs inside Ubuntu 22.04 against a checkout whose flare-cli/Cargo.lock was written by the 1.94.1 toolchain — fine. Note scripts/set_release_version.py "$VERSION" still runs on the ubuntu-24.04-arm/ubuntu-24.04 host (line 56-57) before the container, so the version rewrite is unaffected.

Both are consistency notes, and (1) is the one I would raise: it is the remaining release artifact that still claims a hard libibverbs dependency after this PR's central claim removed it. Severity: nit (documentation/dependency consistency, not a runtime defect).

#9 [medium] Nit: host_pool_budget_with_reserve is speculative API with no caller

selene/src/offload.rs:856-886 adds pub fn host_pool_budget_with_reserve(future: u64, apply_reserve: bool) -> Result<u64>, documented as existing "for callers with an explicit unified-memory limit to omit the implicit service and system reserves".

Verified: its only caller is host_pool_budget at selene/src/offload.rs:852-854, which passes true. No caller anywhere passes false (search for host_pool_budget_with_reserve returns only those two sites; host_pool_budget_from(..., apply_reserve) at non-test call sites is called with literal true at helios/src/runtime_core/memory.rs:202-207). The explicit-limit path in fact goes through integrated_offload_host_budget (memory.rs:195-221), which bypasses this function entirely. Tests cover host_pool_budget_from directly (selene/src/offload/tests.rs:706-724), not this wrapper.

So the apply_reserve parameter is a configuration switch with no concrete requirement — the case AGENTS.md "Reject unsupported abstractions and churn" ("Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement") names, and the departure from the precedent set by its own delegate host_pool_budget_from, which is called with both values (memory.rs:202 and the reserve path) and is a pure function with no hidden system read.

Fix: drop host_pool_budget_with_reserve and inline host_pool_budget_from(available, total, future, true) at the end of host_pool_budget, keeping host_pool_budget_from as the single parameterised helper. Severity: nit.

#6 [low] Nit: CopyAsync type alias duplicates CopyDtoD in helios/src/cuda.rs

helios/src/cuda.rs:919-931 comment says the fallback exists for CUDA < 13 drivers (JetPack 6 / CUDA 12.6, discrete CUDA 12.x) and that cuMemcpyAsync "accepts device addresses, registered host aliases, and raw cuMemHostAlloc(..., flags=0) pointers".

Repository precedent for the same fallback is copy_dtod_async (helios/src/cuda.rs:1142-1146), which still resolves cuMemcpyDtoDAsync_v2 through driver.copy_dtod. The PR adds a second type alias (CopyAsync, line 81) that is identical in signature to CopyDtoD (unsafe extern "C" fn(u64, u64, usize, Handle) -> c_int, line 80) and a second Driver field copy_async (line 225), rather than reusing the alias. In this file every other driver entry point has a distinct named type because its signature differs (Upload, Download, Download2D), so the intent of the alias table is one alias per ABI shape; CopyAsync/CopyDtoD is the only duplicate pair.

Severity: nit. Fix: declare copy_async: CopyDtoD (or rename the shared alias to CopyAsync and use it for both), which keeps one alias per signature, matching Upload/Download grouping.

Verified: both are (u64, u64, usize, Handle) -> c_int, so the reuse type-checks.

#10 [low] Nit: is_host_numa_unsupported spells CUDA status codes as bare literals

helios/src/cuda.rs:532-536 adds

fn is_host_numa_unsupported(status: c_int) -> bool { matches!(status, 1 | 801) }

citing the codes only in the doc comment. The repository's precedent for CUDA status codes is named constants in helios/src/runtime_core/driver.rs:94-97 (pub const CUDA_ERROR_NOT_READY: c_int = 600;, pub const CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE: c_int = 708;), consumed by helios/src/runtime_core/persistent_worker.rs:495,970,989 and runtime_core/mod.rs:382. helios/src/cuda.rs itself names every other driver constant it uses (SOURCE_ORDER_STREAM, ATTRIBUTE_HOST_NUMA_ID, LOCATION_HOST_NUMA, ... at cuda.rs:143-160) with a doc comment giving the CUDA name.

Note the precedent does not transfer for free: 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 have to move to a module compiled in both configurations, or be declared next to the other constants in cuda.rs.

Fix: declare const CUDA_ERROR_INVALID_VALUE: c_int = 1; and const CUDA_ERROR_NOT_SUPPORTED: c_int = 801; alongside cuda.rs:143-160 and match on those names, or move them next to the existing CUDA_ERROR_* constants so there is one home for status codes. Severity: nit (readability/convention only); the doc comment currently carries the meaning.