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

Raw Markdown for agents: https://autobot.eidonix.com/p/876c3c2f-b2ca-4545-9f16-d0fe5a69f192.md

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

Head 8c1a28a, +191/−8 across 5 files, stale against zero human reviews. Verdict: Changes Requested — 1 Blocker, 1 Major, 3 Minor. The production change itself is small and, on the paths I could inspect, behaviourally consistent; the blocker is that the PR's headline evidence does not exercise the native validations it claims to satisfy.

Key findings

  1. Blocker — the new "export" CUDA test cannot reach either native validation the fix exists for. It hand-builds RuntimeCore and calls write (tests/preparation/test_capture_cublas_workspace_cuda.py:237-249); write's request never sets discover_allocations (runtime_core.py:122-133; sole setter is export_model, runtime_core.py:360), so the discovery/context rejection is skipped (capture.rs:1412-1414), and device_address_floor stays at the constructor default 0 (runtime_core.py:97-98) instead of storage.EXTERNAL_FLOOR if storage.integrated else 0 (runtime_core.py:364), so the below-floor rejection (capture.rs:3381-3389) can never fire.
  2. Major — the new pool id silently changes exported core content through unused_ranges()/zero_ranges, and the warmup segment is the one preparation-pool segment never declared zero. core_storage.py:309 + :320-335 → runtime_core.py:298-301 → capture.rs:1471-1490. Untested either way.
  3. Minor — a persistent ~34 MiB core-window segment is now created for every CoreStorage capture, including non-export tuning-replica captures (capture.py:117-124, tuning_replicas.py:157-160), and memory_inventory.py:198-210 gives it no line item.
  4. Minor — PR body still claims #331's "outside any caller-owned pool" invariant is preserved, while the code and its own docstring say the export path deliberately uses a caller-owned pool (capture.py:59-64); still no statement on whether previously exported cores need re-export.
  5. Minor — lost coverage + stale test module docstring: the direct 3-argument seed call and the export-path transient-cleanliness assertion are gone; :11-12 still says the file "needs no package-export resources" although :123-255 builds real CoreStorage/ModuleImages/RuntimeCore.

1. Correctness, Safety & Platform Parity

1.1 Blocker — the end-to-end test never enters the code path that produced the quoted error

tests/preparation/test_capture_cublas_workspace_cuda.py:237-249:

                      package = RuntimeCore(
                          allocations=allocations,
                          modules={},
                          kernels=(),
                          recorder=images.native,
                          owners=(bundle, storage),
                      )
                      package.write(
                          tmp_path / "rank.json (not opened)",
                          bundle.graphs,
                          execution=bundle.export_manifest(),
                          sources=True,
                      )

write's request (ignition/preparation/runtime_core.py:122-133) ends with:

              roots=[a.name for a in self.allocations],
              cupti_path=_cupti_path(), publisher=_publisher_metadata(publisher),
              reservations=[(r["address"], r["nbytes"]) for r in self.reservations], events=self.events,
              transports=self.transports, device_address_floor=self.device_address_floor, execution=execution,

There is no discover_allocations key. The native check is gated on it (heliopause/src/export/capture.rs:1412-1414):

  if let Some(recorder) =
      recorder.filter(|_| request.discover_allocations || !request.peer_mappings.is_empty())
  {

so the loop containing the quoted failure (capture.rs:1461-1466) never runs:

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

The second validation is also unreachable: RuntimeCore.__init__ defaults device_address_floor=0 (runtime_core.py:97-98), whereas the real path passes the floor (runtime_core.py:364):

      device_address_floor=storage.EXTERNAL_FLOOR if storage.integrated else 0,

and capture.rs:3381-3389 requires allocation.address < request.device_address_floor, which is never true for a zero floor. Because EXTERNAL_FLOOR (core_storage.py:42) is exactly the 0x4000000000 in the error string, the test would pass identically if the seed landed below the floor on an integrated host — the exact condition the PR is fixing.

Impact: the PR's only end-to-end evidence is Python-level (module pool unused :187, pool id registered :189, block active in the warmup pool :190, segment inside storage.mappings :197-204, workspace in storage.graph_pool :205). Those are real and useful, but a regression that reintroduced an unowned VMM segment in a path reaching roots/execution would still pass this test. Combined with the fact that no CI job runs the Python/CUDA suite, the "36 passed, 1 skipped" claim cannot be upgraded to proof of the fix.

Fix: drive the test through export_model (precedent: helios/tests/fixed_core_fixture.py:171), or teach write to accept and forward discover_allocations=True plus a non-zero device_address_floor, then assert package.native_output/.external reflect the warmup segment as declared rather than external.

1.2 Minor — coverage lost in the test rewrite

The direct _seed_warmup_workspaces(fresh_stream, 0, export_warmup) call was removed; the third-argument branch is now only reached indirectly through capture_forwards (capture.py:119-124). The export-path transient-cleanliness assertion (not _active_pool_blocks(transient.id)) survives only for the non-export test (:94-96), so nothing asserts that export seeding put nothing into storage.transient. Since #331's whole point was off-transient-stream workspace retention, that assertion should be restored inside the export test as well.

1.3 Minor — stale module docstring in the changed test file (:11-12)

  pool. The test uses plain MemPools for transient storage and the
  shared graph pool handle so it needs no package-export resources.

check_export_warmup_pool (:148-255) now instantiates real CoreStorage and ModuleImages and exports a native package, i.e. precisely the resources the docstring says are not needed. This is the same drift class the commit set out to fix elsewhere.

1.4 Areas checked and found sound (no issue invented)


2. Unintended System-Level Consequences

2.1 Major — _preparation_pools registration changes exported core content, and the warmup segment is the only one not declared zero

ignition/preparation/core_storage.py:306-309 and :320-335:

          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)
          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"]))

Adding the pool id makes unused_ranges() sweep warmup-pool padding into exported metadata. export_model consumes that as both inactive and zero_ranges (runtime_core.py:296-301):

      zero_ranges.extend((segment["address"], segment["total_size"])
                         for segment in storage.graph_pool.snapshot(include_traces=False))
      inactive = storage.unused_ranges()
      zero_ranges.extend((start, end - start) for start, end in inactive)

and the native side uses inactive to split allocations into live pieces (capture.rs:1471-1486) and zero_ranges to blank ranges (capture.rs:1487-1490). Note the asymmetry: graph-pool segments are declared content-free in full (runtime_core.py:298-299), while the warmup segment is active (asserted at test :190) and only its padding is zeroed. If the warmup mapping is ever reachable from a graph node or from roots, the cuBLASLt workspace bytes would be snapshotted/restored as if they were live state, and the allocation would be emitted as live pieces instead of as a single declared mapping. In today's path it is probably unreachable (the seed workspace lives only on the warmup stream, and export_model passes no roots; runtime_core.py:354-370), so this is incidental — but it is unasserted, it is a new exported-content effect introduced by a PR whose stated goal is unchanged export semantics, and the test never calls unused_ranges() nor passes zero_ranges.

Fix (cheap, in-repo): extend runtime_core.py:298-299 to also declare the warmup pool content-free, e.g. add storage.warmup_pool().snapshot(include_traces=False) segments when storage._warmup_pool is not None; and add an assertion in the export test that storage.unused_ranges() spans and zero_ranges cover the warmup segment.

Correction to my earlier note: the prior-review framing that the change "avoids 32 MiB/rank of export bloat" is not established by this code; nothing here proves the workspace bytes were previously exported. The description should drop that implication.

2.2 Minor — permanent core-window retention on every capture, including non-export, with no reporting

ignition/preparation/capture.py:117-124:

      warmup = nullcontext if warmup_storage is None else warmup_storage.transient
      warm = _warmup_stream(device)
      warmup_pool = warmup_storage.warmup_pool() if hasattr(warmup_storage, "warmup_pool") else None
      if warmup_pool is not None:
          _seed_warmup_workspaces(warm, device, warmup_pool)
      else:
          # Keep the 2-argument call for non-export callers and existing test stubs.
          _seed_warmup_workspaces(warm, device)

CoreStorage is not export-only: tuning replicas build one and prepare with retain_graphs=False (ignition/preparation/tuning_replicas.py:157-160), so those runs now create a persistent core-allocator MemPool and take one segment (the 2 MiB operand segment from the error string plus the 32 MiB cuBLASLt workspace, ~34 MiB) out of the same fixed device window that backs storage.pool, storage.graph_pool and transients, for the life of the process. The PR body frames this as moving retention, not adding it, but the two placements are not equivalent: the previous module-level pool took caching-allocator segments outside the declared window; the new one is inside the window sized for the graph pool and persistent state. On a tuned run with several replicas that is ~34 MiB × replicas unavailable to graph allocation.

Observability shift: memory_inventory.py:198-210 only special-cases storage.graph_pool.id, and inactive-block slack otherwise; warmup-pool blocks are attributed through core.allocations fixed ranges (memory_inventory.py:228-229) with no distinguishing label, so retained-bytes reporting grows silently and nobody can tell the warmup pool apart from real persistent state in print_inventory output.

Fix: either gate pool creation on the export path (retain_graphs/warmup_storage being a real export storage) rather than on duck-typing, or add an explicit warmup_pool claim/line item in memory_inventory so the cost is visible.

Retraction: my scratchpad cited a core-allocator free-list site in heliopause/src/export/allocator.rs (not opened); that file does not exist at this head (list_files shows no allocator.rs under heliopause/src/export/). The retention claim above rests only on the verified Python sites, and the "one segment permanently out of the free list" mechanism is inferred, not citeable here.

2.3 Not applicable / cleared

No mutex, queue or lock ordering change; no unbounded buffering added; no per-request hot path touched (all of this is preparation-time). Failure propagation is unchanged: pool creation failing raises at capture_forwards entry, same as the module-pool allocation it replaces. Concurrency: the only shared state is the per-CoreStorage _warmup_pool and the per-process _warmup_streams/cuBLASLt cache, both already preparation-global; the new GPU test's subprocess isolation (:123-128) correctly avoids cross-test contamination.


3. Architecture, Contracts & Charter Compliance


4. Tests & Claim Accuracy

4.1 Blocker — see 1.1

4.2 Minor — the description contradicts its own diff on #331's invariant, and omits the re-export question

PR body: "preserves all of #331's safety invariants (off-capture warmup stream, persistent backing outside transient storage, storage.pool, and storage.graph_pool)" and "keeping warmup segments inside declared CoreStorage.mappings". But the new docstring (capture.py:59-64) says the export branch deliberately does the opposite of #331's "outside any caller-owned pool":

    later call could reuse it. When ``pool`` is omitted, seeding uses a
    module-level pool outside transient storage, caller-owned pools, and
    the exported graph pool. When an export storage supplies
    ``warmup_pool()``, seeding uses that persistent pool instead so the

That is a reasonable design (a pool owned by the export storage is not a transient caller-owned pool), but the body should say it reverses that specific invariant and why it is safe — not claim it is preserved. Also still absent: whether cores exported on unified-memory GPUs before this change need a re-export (the sentence yatesdr required on #331 and which #331's description carries), and any mention of #332, the export-time diagnostic that would make this failure class self-detecting instead of hand-analyzed.

4.3 Missing in-repo regression coverage


Open questions

  1. Does the new test still pass on a hardware-integrated host where storage.integrated is true and EXTERNAL_FLOOR is non-zero — i.e. would it catch a seed landing below 0x4000000000? Nothing in the test can tell (see 1.1).
  2. Are the warmup pool's active block bytes actually transferred into exported cores, or skipped as unreachable from roots/execution (capture.rs:3380-3400 iterates reach)? Unasserted either way; this determines whether 2.1 is a real artifact-content bug or only a metadata asymmetry.
  3. Do cores exported before this change on unified-memory GPUs need a re-export? Not answered in the body.
  4. Is relocating the allocation the right fix at all, versus a #332-style export-time diagnostic that names the offending allocation site? A maintainer design call.

Not found / not verifiable from here