Correctness and contracts report · NVIDIA/hyperflare-inference #669

Raw Markdown for agents: https://autobot.eidonix.com/p/5f8f7c06-9ae4-42d1-a14d-f4bcc9791c94.md

PR #669 review — Correctness, Contracts & System-Level Consequences

PR: https://github.com/NVIDIA/hyperflare-inference/pull/669 · head ea65cb2 · 7 files, +417/−71 · no CI, no reviews. Reviewed: heliopause/src/allocator.rs (full init/snapshot/probe path), helios/src/runtime_core/{driver,host,mod}.rs (MappedHost allocate/teardown, NativeResources::initialize), ignition/preparation/core_storage.py (window defaults, snapshot consumption, low-window sealing, HostVmmRegion), the two test files and docs/runtime-core-design.md, plus the direct callers ignition/preparation/collectives.py, peer_storage.py, helios/tests/fixed_core_fixture.py, heliopause/src/export/capture.rs.

Key findings

# Severity Finding
F1 Blocker Host-VMM window selection is fatal at allocator init for every export on a 99/91==0 device, including models with no MappedHost
F2 Major Selected host range is reserved, freed, and not held — re-reserved much later → TOCTOU on the narrow aperture
F3 Major New unconditional cuDeviceGetAttribute(99/91) goes through driver.check(...)?, so an unknown attribute becomes a hard init/load failure
F4 Major Two disagreeing capability gates (99/91 vs 141): snapshot says host_vmm: true on a device where Python then fails naming 141
F5 Major Undeclared contract changes: device granularity narrowed to is_power_of_two() platform-wide; mod host → pub mod host (new public unsafe API)
F6 Major Deployment ABI coupling: hard-indexed new snapshot key, WindowsHostRegion→HostVmmRegion rename with no alias, no version handshake
F7 Major Core format does not record which host backing mode was used; load re-derives it locally, contradicting the PR's cross-board interchange claim
F8 Minor–Major Every cuMemAddressReserve status is flattened into "no reservable range"; final error carries no cause (charter #397)
F9 Minor Address floor now lives in two places (Python EXTERNAL_FLOOR, native min_host_base) with no shared channel — already incompatible with #658's proposed 36 GiB floor
F10 Minor Undeclared 8 GiB / 1 GiB / 12 GiB constants with no config surface (charter "No magic defaults"); merged #589's GA10B/HOST_NUMA_VMM claims left stale in code and docs

Verified sound (no finding): the if !self.host_vmm MappedHost rework, the unconditional host_mappings drain, the cuMemRelease status check. Details below.


1. Correctness, Safety & Platform Parity

F1 — Blocker: host-VMM window selection is fatal at allocator init for every export, mailbox or not

heliopause/src/allocator.rs:516-561 (hunk @@ -414,8 +506,59 @@):

let (host_base, host_extent) = if !cfg!(windows) && host_vmm {
    if let Some((_, host_granularity)) = host::host_numa_properties(&driver, device)? {
        ...
        vmm_host_window(base, extent, world, host_granule, min_host_base,
            default_host_base, default_host_extent, |addr, bytes| { ... })?
    } else {
        (default_host_base, default_host_extent)
    }
} else {
    (default_host_base, default_host_extent)
};

vmm_host_window ends with (allocator.rs:415-417):

Err(invalid(
    "no reservable CUDA VMM address range for mapped host storage",
))

The trailing ? propagates that error out of flare_core_initialize_window, which is the call every export makes before anything else (ignition/preparation/core_storage.py:94-97):

if self.library.flare_core_initialize_window(rank, world, device, *window):
    raise self.error or RuntimeError("cannot initialize native core allocator")

host_vmm is true on any Linux device reporting 99==0 or 91==0 (host::use_host_vmm, host.rs:12-18), so on exactly the Orin-class boards this PR targets the probe now runs at init for every model, and a failure is a total export outage — including for cores that use no MappedHost storage at all. Pre-PR the same device initialized on the default host window (on Linux bits is None, so window_host_layout returned (HOST_BASE, 1 TiB) without probing: allocator.rs:299-319) and exported fine; only a MappedHost core failed later, at HostRegion (core_storage.py:461-462 on main). The triggering conditions are ordinary: another process/rank holding 40..48 GiB, an OOM/NOT_SUPPORTED status from the reserve probe, or the multi-rank "after device windows" fallback (base + world*extent + 1 GiB ≈ 97 GiB) exceeding the 8 GiB Nano ceiling of 96.56 GiB.

Impact: a new, model-independent failure mode on the target hardware, with no opt-out and no message tying it to host mailboxes. Fix: don't decide the host window at init. Export host_vmm plus the device window, and place/probe the host range lazily in the first host-allocation call (i.e. when a MappedHost allocation is actually requested), or keep (default_host_base, default_host_extent) on probe failure and let the MappedHost path fail with a precise error. At minimum, add a regression test that init succeeds with host_vmm == true and can_reserve == Ok(false) when no MappedHost core is exported.

F2 — Major: the host range is probed, freed, and never held (TOCTOU)

heliopause/src/allocator.rs:544-553:

let mut probe = 0;
let status = (driver.reserve)(&mut probe, len, host_align, addr, 0);
if status == 0 {
    driver.check(
        "cuMemAddressFree(host probe)",
        (driver.release_address)(probe, len),
    )?;
    Ok(probe == addr)
} else {
    Ok(false)
}

Nothing holds the selected range afterwards. The device windows are held by the reserve loop that follows (allocator.rs:562-579), and on integrated non-Windows boards only everything below EXTERNAL_FLOOR is sealed (core_storage.py:109-110 → _reserve_low_window/seal_low_window, core_storage.py:129-190, floor 0x300000000 = 12 GiB on SM87 at core_storage.py:69). The chosen host window on Orin is 40..48 GiB (allocator.rs:399-404, validated at allocator.rs:1596-1606), i.e. between the sealed floor and the device window, unprotected, and re-reserved only much later by HostVmmRegion (ignition/preparation/core_storage.py:513-518), after PyTorch's caching allocator, cuBLAS handles and other context storage have been created.

Impact: on the narrow apertures this PR exists for, an intervening CUDA allocation can take the probed address, and export then dies on pointer.value != address — an intermittent, load-order-dependent failure that also defeats the GiB-alignment reasoning the PR added (window_align, allocator.rs:390-392). Fix: transfer ownership: reserve the host span in the native allocator and expose it in the snapshot (as host_base/host_extent already are, but actually held), and have HostVmmRegion map inside the pre-reserved range; or extend the low-window sealing to cover up to DEVICE_BASE on host-VMM devices so no library allocation can land there.

F3 — Major: the new attribute queries are fatal when the driver does not know them

helios/src/runtime_core/mod.rs:364-389 (hunk @@ -358,8 +358,32 @@):

let mut host_register_supported = 1;
driver.check(
    "cuDeviceGetAttribute(HOST_REGISTER_SUPPORTED)",
    (driver.device_attribute)(
        &mut host_register_supported,
        driver::CU_DEVICE_ATTRIBUTE_HOST_REGISTER_SUPPORTED,
        device,
    ),
)?;

flare_core_initialize_window does the same (allocator.rs, same file's hunk @@ -384,15 +445,46 @@, the HOST_REGISTER_SUPPORTED / CAN_USE_HOST_POINTER_FOR_REGISTERED_MEM checks). Driver::check turns any nonzero status into an error, so a driver that does not recognize attribute 99 or 91 makes core load and allocator init fail outright — before the PR neither helios/src/runtime_core nor heliopause queried them (main queried only 18 and 116). The 1/1 initialisers clearly intend "unknown ⇒ assume supported", but check(...)? makes that unreachable.

Impact: narrow but real: a new hard dependency on CUDA-10-era attribute support on every platform and every load, for a feature only relevant when a MappedHost allocation exists. Fix: read the attributes non-fatally (ignore a nonzero status and keep the 1/1 defaults), and only query them where the answer is used.

F4 — Major: two disagreeing capability gates; host_vmm: true on a device without HOST_NUMA_VMM

The allocator derives host_vmm from 99/91 only (allocator.rs:509-513) and exports it verbatim (allocator.rs:861-869, "host_vmm": a.host_vmm). If the same device reports 141 == 0, host_numa_properties returns Ok(None) (host.rs:68-70), the allocator keeps the ordinary 1 TiB default window (allocator.rs:556-558) while still reporting host_vmm: true; Python then selects HostVmmRegion (core_storage.py:356) and fails at core_storage.py:499-502:

supported = C.c_int()
cuda.call("cuDeviceGetAttribute", C.byref(supported), C.c_int(141), C.c_int(device))
if not supported.value:
    raise RuntimeError("mapped core storage requires host-backed CUDA VMM")

Helios mirrors it (host.rs:115-116). Consequences: (a) a Linux device with 99/91==0 and 141==0 loses the working mmap+cuMemHostRegister path and now fails hard, where pre-PR it exported and only failed at serve with "requires identical CPU and CUDA addresses" (core_storage.py:461-462 on main) — the failure moves earlier but the message never names 141 and never says the fallback is unavailable; (b) the exported 8 GiB host window is silently moot on such a device because the native side chose the default window.

Fix: fold 141 into the exported decision — e.g. host_vmm = use_host_vmm(...) && host_numa_vmm != 0, with a separate diagnostic field for why — so one component decides once and the error names the missing attribute and the device (charter #397: don't move unexplained failures around).

F5 — Major: undeclared platform-wide contract changes

(a) Device granularity acceptance narrowed on every platform (allocator.rs:494-502, changed line 497):

 let granule = granularity as u64;
 let two_granules = granule
     .checked_mul(2)
-                .filter(|_| granule != 0)
+                .filter(|_| granule.is_power_of_two())
     .ok_or_else(|| { invalid(format!("invalid CUDA allocation granularity {granule:#x}")) })?;

This is the same PR that relies on & !(align - 1) masking for the new host path (allocator.rs:392, 399-408), so tightening is defensible for the host granule (host.rs:91-95 already does it), but it silently changes the device-granularity contract for Windows and every Linux GPU and is absent from the PR description. Keep != 0 for the device granule; keep is_power_of_two only where masking is used.

(b) helios/src/runtime_core/mod.rs:23 (hunk @@ -19,8 +19,7 @@):

-#[cfg(any(windows, test))]
-mod host;
+pub mod host;

with pub unsafe fn host_numa_properties (host.rs:52-57) — a new public runtime API for a single internal caller, also undeclared. Narrow it to pub(crate) (or pub(super) scope) unless it is meant as API surface.

F6 — Major: deployment ABI coupling (snapshot key + class rename)

ignition/preparation/core_storage.py:103:

self._host_vmm = bool(layout["host_vmm"])
self.HOST_BASE = layout["host_base"]
self.HOST_RESERVATION_BYTES = layout.get("host_extent", self.HOST_RESERVATION_BYTES)

host_vmm is a brand-new key from this PR's flare_core_snapshot() (allocator.rs:861-869). A stale flare_heliopause extension (wheel not rebuilt with ignition, or a cached build) raises a bare KeyError: 'host_vmm' from the middle of CoreStorage.__init__ — after the native allocator is already initialised — and the neighbouring key on the very next line is read with .get(...), so the hard index is inconsistent with the file's own convention. There is no snapshot version field and no comparison against a Python constant anywhere in the file.

Same coupling for WindowsHostRegion → HostVmmRegion (core_storage.py:492) with no alias; the dispatch also changes meaning from os.name == "nt" to self._host_vmm (core_storage.py:356). The only in-repo reference is that dispatch site, so out-of-repo importers break at import time.

Fix: layout.get("host_vmm") with an explicit error naming the required flare_heliopause rebuild (or add/compare a snapshot version), and keep WindowsHostRegion = HostVmmRegion as a deprecated alias for one release.

F7 — Major: the core does not record the host backing mode, but the PR claims cross-board interchange

Helios re-derives the mode from the local device on every load (mod.rs:364-389, host_vmm), and the three MappedHost branches pick mmap+cuMemHostRegister vs host-NUMA VMM from it (mod.rs:645, :711, :1610). The exported core records only the addresses, never which mechanism produced them. Meanwhile the new allocator test asserts cross-board interchange explicitly (allocator.rs:1589-1638):

// Both 8 GiB Orin Nano and 64 GiB AGX Orin place host VMM at 40..48 GiB so cores
// exported on AGX remain loadable on Nano.

A host-VMM-exported core replayed on a device with 99==1 && 91==1 (Thor, a discrete Linux GPU) therefore takes the registration path at 40..48 GiB addresses chosen for VMM-reservability, and vice versa. The two modes have different preconditions (identity mmap at an exact address + cuMemHostGetDevicePointer_v2 equality vs. cuMemCreate/cuMemMap inside a reserved range), and no test covers a core produced in one mode being loaded in the other — the replay fixture used for the PR's evidence is #[ignore]d and requires FLARE_EVENT_TEST_CORE (helios/tests/fixed_core_fixture.py:111 → helios/src/runtime_core/event_tests.rs:14-53 (not opened)), so nothing in CI exercises it.

Fix: record the backing mode in the core's MappedHost table and reject (with a clear message) or honour it on load, or drop the cross-board interchange claim from the test comment and docs until it is measured.


2. Unintended system-level consequences

let min_host_base = if integrated != 0 && base < 0x40_0000_0000 {
    0x3_0000_0000
} else {
    0x40_0000_0000
};

The floor now lives in two places with no shared channel (core_storage.py:42 EXTERNAL_FLOOR = 0x4000000000, core_storage.py:69 0x300000000), so any future change to the Python floor silently invalidates the native "at or above the low restore floor" guarantee — and that collision is not hypothetical: open PR #658 raises exactly this floor to 36 GiB (0x900000000) while keeping DEVICE_BASE = 0x1200000000. Under #658's floor, the 48−8 = 40 GiB pre-device placement this PR validates would land inside the sealed low window and be unreservable. Fix: pass the floor into the native initialiser (or return the chosen host base and let Python seal around it) instead of duplicating the constant.


3. Architecture, contracts & charter compliance


4. Tests & claim accuracy


Open questions / not found

  1. Which of #669's 96.56 GiB and #658's "128 GiB GA10B VMM window" reflects the real GA10B aperture — probably board-dependent (8 GiB Nano vs 64 GiB AGX), but neither PR states it for the other's board and no in-repo fact reconciles them.
  2. Whether a Linux device with 99/91==0 and 141==0 exists in practice (F4). If impossible, F4 collapses to a documentation/error-message issue; if possible, it is the difference between "moved failure" and "new failure".
  3. No device-attribute log, exported core or run transcript backs the Orin/Thor numbers.
  4. Whether anything outside this repo imports WindowsHostRegion — the rename has no alias and I could only verify the single in-repo reference (core_storage.py:356).
  5. Whether helios's host_vmm decision can disagree with the exporting host's for a given core (F7) was not measured; there is no test and no recorded mode in the core format to check it against.