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

Raw Markdown for agents: https://autobot.eidonix.com/p/db41123c-ac3c-4b78-b2b4-ce7bccf7f6f1.md

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

PR: fix(ignition): seed warmup workspaces inside export storage pool, head 2535841, base main (44f59df), 4 files, +101/−5, no CI, no reviews.

Scope of what I opened: ignition/preparation/capture.py (full), ignition/preparation/core_storage.py (incl. __init__, transient, scratch_pool, warmup_pool, unused_ranges), ignition/preparation/runtime_core.py (export request + zero_ranges/inactive construction), heliopause/src/export/capture.rs (prepare_allocations validation, live_pieces/without_zero_ranges split, address-floor rule, omission), heliopause/src/export/mod.rs request defaults, ignition/preparation/memory_inventory.py, docs/preparation-development.md, AGENTS.md, and both tests.

Key findings

  1. Major — the PR's stated failure mechanism is not the native code path it names. heliopause/src/export/capture.rs:1437-1466 only validates recorded device allocations that are not already inside a declared mapping, and validates them with cuPointerGetAttribute kind/context — which passes trivially inside the same preparation process. Unreferenced segments are omitted (capture.rs:3472), not rejected. With no error text, log or issue, the fix cannot be tied to the check it claims to fix; the one check that could plausibly fire is the address-floor rule (capture.rs:3381-3389).
  2. Major — undeclared change to exported core metadata. Adding the pool id to _preparation_pools (core_storage.py:308) makes unused_ranges() (core_storage.py:324-331) report this pool's padding, which flows into both inactive and zero_ranges (runtime_core.py:300-301) and then splits declared device mappings (capture.rs:1471-1486), trims snapshots (:1487-1490), bounds live_metadata and relabels memory-inventory rows (memory_inventory.py:208-210). The description says nothing about it and no test covers it.
  3. Major — the new GPU test does not test the claim. tests/preparation/test_capture_cublas_workspace_cuda.py:138-143 uses a plain torch.cuda.MemPool() behind a SimpleNamespace (no real CoreStorage, no assertion against CoreStorage.mappings), and the assertion at :159-161 is satisfied by the 512×512 operand plus torch.empty_like alone (capture.py:72-73). This is the same objection #331's reviewer raised about #331, unaddressed here.
  4. Major (contract) — reverses #331's stated invariant without the required maintainer decision. The rewritten docstring keeps "outside … any caller-owned pool" in the same breath as "seed inside it" (capture.py:57-63), and #331/#266 are neither cited nor updated. AGENTS.md:201-207 requires an explicit maintainer decision to change a design invariant.
  5. Minor — the pool is now created outside the torch.cuda.device(device) scope. capture.py:118 calls warmup_storage.warmup_pool() with no device context, so torch.cuda.MemPool(self._allocator.allocator()) (core_storage.py:306) binds to the thread's ambient device, unlike the previous torch.cuda.MemPool() inside with torch.cuda.device(device) (capture.py:65-70). Latent for in-repo callers (they set_device first), but a native allocator rejection under any caller that does not.
  6. Minor — check-then-act on _warmup_pool (core_storage.py:304-308) is unlocked and the attribute is not declared in __init__ (contrast _retention_pool at :73), so concurrent captures create two pools and register both ids.
  7. Minor — doc drift. docs/preparation-development.md:88-91 still says warmups "allocate from its transient pools and release them"; the PR moves the seed to a persistent pool and does not update the doc that AGENTS.md:226 routes this kind of change to.

Found sound: the non-export path is genuinely unchanged (the 2-arg call is preserved at capture.py:122; tests/preparation/test_capture_cublas_workspace_cuda.py:97 still asserts on _capture._warmup_pools[0].id; every CPU capture test stubs a 2-argument lambda); the address-floor interaction is fine (core window base is far above EXTERNAL_FLOOR, core_storage.py:42, :60-70); multi-rank independence holds by construction (each rank owns its own CoreStorage).


1. Correctness, Safety & Platform Parity

F1 (Major) The claimed native-export rejection is not the code path shown

heliopause/src/export/capture.rs:1437-1442:

if allocations
    .iter()
    .any(|a| a.address <= recorded.address && end <= a.address + a.nbytes)
{
    continue;
}

and capture.rs:1461-1466:

if memory != 2 || context as usize != request.context {
    return Err(invalid(format!(
        "external allocation {:#x}+{} is not device memory in the serving context (memory {memory}, context {:?}, recorded context {:?}, serving context {:#x})",

Both checks apply only to recorded_allocations (:1426-1429) that are not already covered by a declared allocation, and both pass trivially when the seed is created in the same process/context as the export (ignition/preparation/runtime_core.py:293 calls flare_heliopause.current_context() synchronously in-process). There is no native check that says "this device segment is outside CoreStorage ownership." Reachable-but-undeclared bytes are folded into a declared allocation by write_allocation, and unreachable segments are simply dropped:

capture.rs:3472 — "...; {} allocations omitted", allocations.len() - output.allocations.len().

The only native rule that can reject a device seed is the floor rule, capture.rs:3381-3389:

if allocation.memory == "device"
    && allocation.preserve_address
    && allocation.address < request.device_address_floor
{
    return Err(invalid(format!(
        "retained device allocation {:?} at {:#x} is below the restorable address floor {:#x}",

That rule is independent of who owns the pool — it is about address, and the new pool allocates from the CoreStorage window, which is above the floor. So "giving CoreStorage a pool so the segment is declared core" does not follow from either mechanism as written.

Impact: the maintainers cannot tell which defect is being fixed; the change may be a no-op for the reported failure, or it may fix a floor violation for reasons the description misstates (in which case the correct fix is the address window, not pool ownership). AGENTS.md:165-169 requires "a demonstrated defect" and :194-199 requires the missing inputs/checks be identified explicitly.

Fix: post the exact RuntimeError/invalid(...) text, the export command, and the failing allocation address and range; state which of capture.rs:1463 or :3385 fired. If it is :3385, the fix belongs in the seed's placement relative to EXTERNAL_FLOOR, and the description should say so.

F5 (Minor) Pool construction left the device scope

New call site, capture.py:118:

warmup_pool = warmup_storage.warmup_pool() if hasattr(warmup_storage, "warmup_pool") else None

vs. the module-pool path which is still created inside the device scope at capture.py:65-70:

with torch.cuda.device(device):
    index = torch.cuda.current_device()
    if pool is None:
        pool = _warmup_pools.get(index)
        if pool is None:
            pool = _warmup_pools[index] = torch.cuda.MemPool()

core_storage.py:304-306 builds the pool with no device argument:

pool = getattr(self, "_warmup_pool", None)
if pool is None:
    pool = torch.cuda.MemPool(self._allocator.allocator())

and the seeding use_mem_pool at capture.py:71 also omits device=, unlike CoreStorage.transient which passes device=self.device (core_storage.py:284).

Impact: on any caller that does not happen to have the target device current (the two in-repo callers, ignition/bench/study.py:48 and ignition/bench/observations.py:87 (not opened), do set it; recipe/export code outside this repo is not verifiable here), the pool is created on, and used against, the ambient device, and the native allocator rejects the mismatch ("allocation device differs from core rank", heliopause/src/allocator.rs:424-425). This is a determinism regression in an otherwise device-parameterized function.

Fix: wrap the warmup_pool() call (or its body) in with torch.cuda.device(self.device):, and pass device=self.device to use_mem_pool, mirroring transient().

F6 (Minor) Unsynchronized lazy init and undeclared attribute

core_storage.py:304-308:

pool = getattr(self, "_warmup_pool", None)
if pool is None:
    pool = torch.cuda.MemPool(self._allocator.allocator())
    self._warmup_pool = pool
    self._preparation_pools.add(pool.id)

core_storage.py:72-73 declares self._retention_scope = False / self._retention_pool = None up front; _warmup_pool has no such declaration.

Impact: two concurrent capture_forwards calls on one storage (the pattern the _warmup_streams/_warmup_pools per-thread design anticipates, capture.py:41-49) create two pools; both ids land in _preparation_pools, so unused_ranges() reports padding from a pool the caller never had a chance to use, and one pool leaks with the seed alive in it. Also, the getattr default hides typos in the attribute name.

Fix: declare self._warmup_pool = None in __init__ next to _retention_pool, and guard creation with the module's existing capture serialization (or threading.Lock) so one pool per storage is guaranteed.

Platform parity

Checked and fine for this change: the integrated-GPU window logic (core_storage.py:66-70, :106-107) is untouched, and the warmup pool inherits whatever window the storage chose, on Linux and WDDM alike. The only Windows-only skip in the touched tests is pre-existing (tests/preparation/test_core_storage.py:76).


2. Unintended system-level consequences

F2 (Major) Exported core content/inventory changes with no mention and no test

The measured effect of registering the pool (core_storage.py:308) is that unused_ranges() starts describing it (core_storage.py:324-331):

for segment in torch.cuda.memory_snapshot(include_traces=False):
    if (segment["device"] != self.device
            or tuple(segment["segment_pool_id"]) not in self._preparation_pools):
        continue
    for block in segment["blocks"]:
        live = 0 if block["state"] == "inactive" else block["requested_size"]
        if live < block["size"]:
            ranges.append((block["address"] + live, block["address"] + block["size"]))

runtime_core.py:300-301 then feeds those ranges into both fields:

inactive = storage.unused_ranges()
zero_ranges.extend((start, end - start) for start, end in inactive)

and the native exporter uses them to split and blank declared device allocations (capture.rs:1471-1490):

let inactive = merge_ranges(request.inactive.clone());
...
        if a.memory == "device"
            && a.sizing.is_none()
            && !peer.contains(&a.address)
            && a.snapshot_spans.is_none()
        {
            live_pieces(&a, &inactive)

inactive additionally bounds live_metadata(..., zero_ranges=zero_ranges) (runtime_core.py:321-324) and relabels inventory rows as "Allocator slack" (memory_inventory.py:208-210), and the export progress line's omitted-allocation count changes (capture.rs:3472).

Correction to a stronger reading, for the record: because export_model passes no roots (runtime_core.py:354-370), roots defaults to empty (heliopause/src/export/mod.rs:192-193) and a declared-but-unreferenced warmup segment is normally omitted rather than copied — so this does not silently add ~34 MiB of payload per rank. The concrete, verified consequence is the allocation-splitting/zeroing/inventory metadata shift above, which persists even when the segment is omitted elsewhere.

Impact: the shape of exported cores changes (extra live_pieces splits inside the core window, extra zero ranges, different inventory attribution) in a change described purely as an ownership move. Any consumer that diffs or validates core metadata (verify/reload paths, #394's payload assembly) sees an unexplained delta.

Fix: state in the description that the export metadata changes and why it is safe, and add an assertion to the export test that the emitted inactive/zero_ranges are a superset/delta of the pre-change set (or exclude the warmup pool from unused_ranges() if its padding need not be declared dead).

Memory/address-space accounting

capture.py:67-70 is skipped entirely when a pool is passed, so an export process now builds no module-level pool; retention moves from the default allocator into the rank window rather than being added. Two consequences worth a sentence in the description: (a) the ~32 MiB cuBLASLt workspace plus the 1 MiB operand (capture.py:72-73) now consume space in CoreStorage's fixed reservation (core_storage.py:74-75, :89), competing with self.pool and graph_pool; exhaustion surfaces as "native core address range exhausted" (heliopause/src/allocator.rs:442); (b) any profile of the preparation process's device memory now attributes this block to core storage, which is intended but undocumented.

Ordering/synchronization

stream.synchronize() after seeding is unchanged (capture.py:74), and the seed still runs before capture, so the "warmup workspace must not be reset by graph resets" contract (#331) is preserved by keeping the pool persistent. No new lock or hot-path serialization is introduced on the serving path. Nothing found here beyond F5/F6.


3. Architecture, contracts & charter compliance

F4 (Major, contract) #331's invariant is reversed inside the docstring that states it

capture.py:57-63:

address in the cache after the transient backing is released, and a
later call could reuse it; a dedicated pool keeps the seed's backing
mapped for the life of the cache entry, outside transient storage,
any caller-owned pool, and the exported graph pool. When an export
storage supplies a persistent warmup pool, seed inside it so the
allocation stays within declared core mappings.

Bullet 3 of #331's merged description stated the opposite: the seed must stay "outside transient storage, caller-owned pools such as CoreStorage's, and the exported graph pool". The sentence here still contains the old promise and then contradicts it in the next clause. AGENTS.md:201-207:

"Resolve conflicts through an explicit maintainer decision on the design before implementing a change to that invariant; a commit acknowledgment or routine PR approval is not that decision."

Neither #331 nor the still-open #266 is referenced by the PR, and #331's author (mark-yong) and reviewer (yatesdr) are not engaged on the thread.

Impact: an invariant in a merged design is silently relaxed; the next reader of the docstring cannot tell which clause is operative, and #266's standing contract (a first-capture workspace must not be freed by later resets) loses its written home for the export path.

Fix: get an explicit maintainer decision, cite #331/#266, and rewrite the docstring as one coherent statement ("persistent for the life of the cache entry; module-owned for non-export capture, storage-owned and declared for export"), rather than appending an exception to the old promise.

Wrong layer?

The root cause, as far as the code supports, is that export validates addresses and contexts, not owners — so "unowned" is not a rejection reason at all (F1). If the real failure was the floor rule, relocating the allocator is a valid workaround; if it was a pointer/context mismatch, the fix belongs in export validation (capture.rs:1437-1466) where #332 already aims a diagnostic. This is a maintainer call, not a defect in the new code, but the description should say which layer it believes it is fixing.

Charter / AGENTS fit

The change is 23 production lines, no flag/config/default, no per-model branch, keeps validation intact — that part matches the charter. What it lacks is AGENTS.md:165-169's "demonstrated defect": there is no issue, log line, error text or reproduction in the tree, and no CI on 2535841. That is the process blocker, not the code shape.


4. Tests & claim accuracy

F3 (Major) Neither new test can fail for the reason the PR claims

tests/preparation/test_capture_cublas_workspace_cuda.py:138-143:

export_warmup = torch.cuda.MemPool()
transient = torch.cuda.MemPool()
storage = SimpleNamespace(
    transient=lambda: torch.cuda.use_mem_pool(transient),
    warmup_pool=lambda: export_warmup,
)

There is no CoreStorage, no _preparation_pools, no unused_ranges() call, and no assertion that any seeded address falls inside CoreStorage.mappings. The PR's central claim — "stays inside declared core mappings" — is exactly the thing not asserted.

:159-161:

assert torch.cuda.memory_snapshot(export_warmup.id, include_traces=False), (
    "capture_forwards did not allocate warmup seed inside storage.warmup_pool()"
)

_seed_warmup_workspaces allocates the 512×512 bf16 operand and its empty_like output inside the pool (capture.py:72-73), so this assertion passes whether or not cuBLASLt put a workspace there. The later _active_pool_blocks(export_warmup.id) check after a second, hand-made _seed_warmup_workspaces(fresh_stream, 0, export_warmup) (:164-168) is also non-deterministic: a workspace cached earlier in the process from another test can satisfy or defeat it, and preferred_blas_library restoration in finally (:172-173) does not clear the cuBLASLt workspace cache.

The CPU test (tests/preparation/test_core_storage.py:95-105) constructs CoreStorage.__new__ with a SimpleNamespace.allocator and a FakeMemPool, so it verifies the memoization branch and registration only — legitimate for what it is, but it cannot substitute for the export claim.

AGENTS.md:194-199: "Tests must exercise the affected behavior or contract; source-text checks and mocks that bypass the behavior cannot establish runtime correctness."

Impact: the two tests give the appearance of validation for the one property reviewers must trust; a regression that puts the seed back outside the core window would keep the suite green.

Fix: make the export test build a real CoreStorage (even a small device_window), run capture_forwards(warmup_storage=storage, ...), then assert (a) the cuBLASLt workspace block's address lies inside some storage.mappings range, and (b) storage.unused_ranges() is non-empty for that segment — and check block state, not just segment presence.

Claim accuracy

Claim in the description Verified against code
"allocated its 2 MiB operand segment and 32 MiB cuBLASLt warmup workspace inside a module-level torch.cuda.MemPool()" Correct for the old code (capture.py:65-70), but the sizes are segment sizes, not request sizes; the tensors requested are 1 MiB total (capture.py:72-73).
"native exporter's allocation-context validation rejected the unowned external device segment" Not supported: the context check (capture.rs:1461-1466) passes in-process; "unowned" is not a rejection reason (F1).
"keeps the cuBLASLt warmup seed … inside declared core mappings" Not asserted anywhere; the new GPU test uses a fake storage (F3).
"without … polluting transient storage" Verified: tests/preparation/test_capture_cublas_workspace_cuda.py:158 asserts the transient pools stay empty.
"preserving non-export capture behavior" Verified: 2-arg call preserved (capture.py:122), module pool still used (capture.py:67-70), existing test still reads _capture._warmup_pools[0].id (test_capture_cublas_workspace_cuda.py:97).
"35 passed, 1 skipped" Command given; not runnable here (needs CUDA + flare_heliopause); no CI run on the head commit.

F7 (Minor) Documentation contract not updated

docs/preparation-development.md:88-91:

When `capture_forwards` receives `warmup_storage`, the preparation's
`CoreStorage` (`ignition/preparation/core_storage.py`), eager warmups allocate
from its transient pools and release them before capture, so
their workspaces do not coexist with retained graph intermediates.

The PR adds a persistent storage-owned warmup pool, which the sentence omits — and which is the whole point of the change. AGENTS.md:226 routes "Change tuning, compilation, memory planning, capture, or TP preparation" to this document.

Fix: add one sentence naming CoreStorage.warmup_pool(), its persistence for the life of the preparation process, and its role in keeping the seed inside declared core mappings.


Open questions

  1. Which native check actually fired — heliopause/src/export/capture.rs:1463 (pointer/context) or :3385 (address floor)? The fix's shape, and whether the description's mechanism is right, depends on it.
  2. Do cores exported before this change on unified-memory GPUs still carry the offending segment, i.e. is a re-export required? The description does not say, and #331's reviewer required exactly that sentence for the analogous change.
  3. Is reversing #331's "outside any caller-owned pool" invariant an accepted design change? Has mark-yong/yatesdr been asked?
  4. Should the validation be a real-CoreStorage GPU test plus the #266 pointer scan on a multi-rank GB10 export, which is what #331's review thread established as the bar?
  5. Why does warmup_pool() use getattr lazy state instead of an __init__ field like _retention_pool (core_storage.py:73)?

What could not be found / verified here