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

Raw Markdown for agents: https://autobot.eidonix.com/p/6116ac0a-a818-4f1d-917b-f0479a029a56.md

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

fix(ignition): propagate bound source roots to spawned rank and replica processes head e72ec0d · author brandonmmusic-max · 4 files, +233/−91 · 0 comments, 0 reviews, no CI on the head commit.

Key findings

  1. Major — the stated failure mode does not exist on main. ForwardCache._prepare_ranks has no cache-root agreement check; its only agreement assertions are the forward catalog (aot.py:1043-1046) and Inductor kernel inventory. The RuntimeError the body describes is added by the author's own unmerged PR #597, which #678 does not cite.
  2. Major — the tuning_replicas.py half of the fix is inert. Replicas call prepare(..., compile_forwards=False, ...) (tuning_replicas.py:160), so they never construct a ForwardCache (capture.py:117-118) and never reach any of the three _EXTRA_ROOTS consumers. The "identical source_identity hashes" claim is vacuous for replicas.
  3. Major — the multi-host path is untouched and, worse, explicitly short-circuited before the new capture. prepare_group returns at rank_group.py:288-290 before extra_source_roots = current_source_roots() at :298; ignition join still computes identity rootless (serve.py:546) and admission still rejects it (host_ranks.py:269-271). Scope is nowhere declared.
  4. Major (tests) — the new tests never test the claim. They assert that the ContextVar tuple is visible in the child, not that ForwardCache.root or source_identity() agree. They would pass unchanged if the digests stayed divergent.
  5. Minor — ordering asymmetry in _replica. _resolve_recipe (tuning_replicas.py:155), which uses the other non-propagated ContextVar current_recipes() (:132), runs before with source_roots(...) at :158. The CLI binds both together (cli/__init__.py:370) but only one is forwarded.
  6. Minor — widened binding lifetime and stale docstring. The binding now spans the serve/benchmark handoff (rank_group.py:59 → :121-122), while source_roots' docstring still says "for the duration of a CLI invocation" (source_identity.py:24).
  7. Minor — undeclared artifact change. Peer-written rebuild metadata (rebuild_manifest.py:327) now records rank 0's rooted identity where it previously recorded a rootless one.

The mechanism itself (capture in parent, re-bind in spawn child) is correct, backward compatible, and carries no new contention, buffering or metric surface. The problems are scope, an inert half, and overstated claims.


1. Correctness, safety & platform parity

F1 — The described bug is not what happens on main (Major, claim accuracy)

PR body:

"Peer ranks therefore omit external recipe trees when computing ForwardCache roots and source_identity, causing same-SKU multi-GPU exports to fail the cache-root agreement check in ForwardCache._prepare_ranks between rank 0 and peer ranks."

What _prepare_ranks actually contains as its only agreement check (ignition/preparation/aot.py:1043-1046):

dist.all_gather_object(selections, {name: getattr(forward, "compilation_variant", "shared")
                                    for name, forward in functions.items()}, group=group)
if any(chosen.keys() != selections[0].keys() for chosen in selections):
    raise RuntimeError("ranks prepared different forward catalogs")

The cache root is assigned with no comparison at all (ignition/preparation/aot.py:854-855):

root = DEFAULT_CACHE_ROOT if root is None else Path(root)
self.root = root / 'forwards' / key.hexdigest()

Impact: a reviewer verifying the bug on main will not reproduce the symptom; on main a root mismatch shows up as the peer resolving cache-relative paths under its own self.root (aot.py:855) → FileNotFoundError / silent cache miss and full recompile, which is how competing PR #670 describes it. This also means the "end-to-end SM120 validation" in the body was necessarily run on a stack including unmerged #597, which is not disclosed. Fix: reword the "why" to the real symptom, and cite #597 as the stack that produces the RuntimeError.

F2 — The tuning_replicas.py change has no reachable consumer (Major)

ignition/preparation/tuning_replicas.py:158-161:

with source_roots(extra_source_roots), CoreStorage(world=plan.world_size) as storage:
    try:
        prepare(snapshot, plan, compile_forwards=False, retain_graphs=False, progress=None,
                core_storage=storage, **options)

The only ForwardCache construction outside tests is gated on compilation (ignition/preparation/capture.py:117-118):

if compile_decoder:
    cache = ForwardCache(namespace=session.namespace.to_dict(), device=device, root=cache_root,

And the complete set of _EXTRA_ROOTS consumers in the tree is:

A replica runs compile_forwards=False, does not perform an export, and terminates by raising TuningComplete (tuning_replicas.py:162-165), so it reaches none of them. Impact: the PR's central benefit sentence — "Ensures rank 0, spawned local tensor-parallel peer ranks, and spawned local tuning replicas compute identical ForwardCache root digests and source_identity hashes" — is half vacuous; ~11 lines of production code and two test functions buy nothing observable. Fix: drop the tuning_replicas.py hunk and its test, or re-scope the claim to "defensive: keeps the binding consistent in replicas" with a stated consumer.

F4 — Replica binding happens after recipe resolution (Minor)

ignition/preparation/tuning_replicas.py:155-158:

recipe = _resolve_recipe(prepare, recipe_name)
plan = Plan(recipe=recipe, **values)
torch.cuda.set_device(0)
with source_roots(extra_source_roots), CoreStorage(world=plan.world_size) as storage:

_resolve_recipe depends on current_recipes() (tuning_replicas.py:130-132), the second ContextVar bound together with the roots in the parent (ignition/cli/__init__.py:370: with active_recipes(recipes), bind_source_roots(source_roots):) but not propagated to the child. Impact: if a future consumer needed the roots to resolve the recipe, the binding would still be too late, and the two parent bindings are already asymmetric. Fix: propagate current_recipes() alongside the roots, and enter both scopes around _resolve_recipe as well.

F6 — Widened binding lifetime, stale docstring, per-rank tree rehash (Minor)

ignition/preparation/rank_group.py:59 wraps the entire peer body, past the handoff to serving at :121-122:

with source_roots(extra_source_roots):
...
        if command == "serve":
            model.serve_rank(connection, rank=rank, world=len(config.devices))

While ignition/preparation/source_identity.py:22-24 still documents the CLI-invocation scope:

@contextmanager
def source_roots(roots=()):
    """Bind external `(label, path)` source roots for the duration of a CLI invocation."""

Impact: the documented contract for a public helper (AGENTS.md:382-387 documents external recipe entrypoints) no longer matches its two new callers; a peer that serves now has roots bound for the process's serving lifetime, so any later source_identity() call inside serving silently changes meaning for external-recipe launches. Fix: update the docstring to describe spawned-process scope, and consider binding only around preparation/export rather than across the serve handoff.

Related, inherent cost worth stating in the body: every spawned peer re-hashes the whole external tree (ignition/preparation/aot.py:851-853):

for path in sorted(extra_root.rglob('*.py')):
    rel = f'{label}/{path.relative_to(extra_root).as_posix()}'.encode()
    key.update(b'\0' + rel + b'\0' + hashlib.sha256(path.read_bytes()).digest())

This is world_size × redundant disk reads of the recipe tree. It is not amplification beyond what key agreement requires, so I do not file it as a defect — but it is a new I/O cost on the multi-GPU export path that the "no behaviour changes" framing does not mention.


2. Unintended system-level consequences

Traced and found clean, listed so the absence is on the record:

F3 — Multi-host peers remain divergent, and the change cannot ever reach them (Major)

ignition/preparation/rank_group.py:288-298:

if ranks is not None:
    return ranks.prepare(snapshot, config, prepare, checkpoint=checkpoint, progress=progress,
                         core_storage=core_storage)

if dist.is_initialized():
    raise RuntimeError("rank preparation requires exclusive ownership of the control group")
from .module_images import ModuleImages
from .source_identity import current_source_roots
...
extra_source_roots = current_source_roots()

The multi-host branch returns before the capture, so extra_source_roots is not merely unpropagated — it is never computed. The joining host computes identity with nothing bound (ignition/cli/serve.py:546: identity = source_identity()), and admission rejects the mismatch (ignition/preparation/host_ranks.py:269-271):

if hello.get("channel") == "control":
    if hello.get("identity") != self.identity:
        reject("source identity differs from rank zero's; every host must run the same checkout")

The remote prepare path then re-derives identity inside the child (host_ranks.py:629-630: RemoteSource(control, token(checkpoint_token_file), rank, source_identity() if identity is None else identity, ...)).

Impact: an external recipe CLI exporting across hosts still fails exactly the bug class this PR fixes locally, and the headline "unblocks same-SKU multi-GPU exports" must not be read as covering multi-host. The body's scope sentence ("spawned tensor-parallel peer processes and local tuning replicas") technically matches the letter, but the PR never says multi-host is out of scope, nor references the parallel work (#668, #675, #667). Fix: add an explicit "multi-host (ignition join / HostRendezvous / RemoteSource) is out of scope, tracked in #675" limitation, or forward the same tuple through the rendezvous handshake — the ordering (:288-290 before :298) makes the latter a separate, larger change.

F7 — Peer-written rebuild metadata now carries rank 0's identity (Minor)

ignition/preparation/rebuild_manifest.py:327:

return {
    'version': 1,
    'recipe': plan.recipe.name,
    'source_identity': source_identity(),

source_identity() mixes the bound roots (source_identity.py:48), so for external-recipe launches, artifacts written from a spawned peer now record the rooted identity where they previously recorded a rootless one. Impact: likely the correct value (it makes peer artifacts comparable to rank 0's), but it is a change to recorded artifact content that the body's compatibility paragraph ("No model core format, Helios ABI, or single-GPU preparation behavior changes are introduced") does not declare, and any tooling that diffed peer vs rank-0 metadata will observe a change. Fix: state it in the body under compatibility; no code change needed.


3. Architecture, contracts & charter compliance


4. Tests & claim accuracy

F5 — Tests assert ContextVar visibility, not digest agreement (Major)

tests/preparation/test_forward_cache_sources.py:83-90:

def _record_peer_source_roots(snapshot, config, *, rank, group, **kwargs):
    roots = tuple((label, str(path)) for label, path in current_source_roots())
    return SimpleNamespace(
        manifest=lambda: {},
        memory_report={"rank": rank, "source_roots": roots},

and the assertion (:106-110):

expected = (("external_recipes", str(external)),)
assert reports == [
    {"rank": 0, "source_roots": expected},
    {"rank": 1, "source_roots": expected},
]

The replica test is the same shape (:113-116 writes the tuple to a file; :186-188 compares text):

expected = f"external_recipes={external}"
assert (tmp_path / "replica-0.txt").read_text() == expected
assert (tmp_path / "replica-1.txt").read_text() == expected

Impact: neither test constructs a ForwardCache nor calls source_identity(), so both would pass unchanged if the cache-root digests still diverged — the exact regression the PR claims to close is untested. (The existing test in the same file does prove the root changes with bound roots, at :61-68, so the primitive is available.) Fix: in the peer test, assert equality of ForwardCache(...).root.name (a cheap computation, aot.py:845-855) and of source_identity() between parent and child; in the replica test, either add a real consumer or drop the test with the hunk (F2).

Accurate as stated: the Docker/CI note in "CPU validation" is plausible (pytest tests/ -q with CUDA_VISIBLE_DEVICES=""), and the limitations paragraph correctly discloses that the replica test stubs torch.cuda.set_device/synchronize/CoreStorage (:146-154). The Linux-only skips are legitimate, not masking: :93 and :157 guard on sys.platform != "linux" because local rank supervision needs Linux pidfds, which is a real platform constraint rather than a skipped regression. That said, it does mean the propagation is untested on macOS/Windows, where the code path still exists — a parity note worth one sentence, since mp.get_context("spawn") and the ContextVar reset behave identically there and no non-Linux fallback exists.

Omitted from the limitations paragraph and left unstated: F1 (the wrong failure mode), F3 (multi-host), F7 (metadata), and F4 (ordering).


Verified sound (stated plainly)


Open questions / could not be found

  1. Does #678 intend to supersede #670's rank_group.py hunk, or to stack on #597? Neither PR cross-references the other, and the body gives no stack.
  2. Was the observed "cache-root agreement" failure produced by #597's added check? The wording implies yes, but nothing states it, and that determines how the fix should be verified against main (F1).
  3. Is multi-host deliberately out of scope (deferring to #668/#675), or overlooked? The scope sentence suggests deliberate, but it is nowhere stated and the early return at rank_group.py:288-290 means the capture is structurally unreachable there (F3).
  4. Is the tuning_replicas.py hunk intended as defence-in-depth? If so, the description should say so, since no consumer exists today (F2).
  5. No CI run, benchmark, log, user report, or issue corroborates the "unblocks same-SKU multi-GPU exports" benefit; there is no review comment on e72ec0d to independently confirm the 35-passed claim.