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
- Major — the stated failure mode does not exist on
main.ForwardCache._prepare_rankshas no cache-root agreement check; its only agreement assertions are the forward catalog (aot.py:1043-1046) and Inductor kernel inventory. TheRuntimeErrorthe body describes is added by the author's own unmerged PR #597, which #678 does not cite. - Major — the
tuning_replicas.pyhalf of the fix is inert. Replicas callprepare(..., compile_forwards=False, ...)(tuning_replicas.py:160), so they never construct aForwardCache(capture.py:117-118) and never reach any of the three_EXTRA_ROOTSconsumers. The "identicalsource_identityhashes" claim is vacuous for replicas. - Major — the multi-host path is untouched and, worse, explicitly short-circuited before the new capture.
prepare_groupreturns atrank_group.py:288-290beforeextra_source_roots = current_source_roots()at:298;ignition joinstill computes identity rootless (serve.py:546) and admission still rejects it (host_ranks.py:269-271). Scope is nowhere declared. - Major (tests) — the new tests never test the claim. They assert that the
ContextVartuple is visible in the child, not thatForwardCache.rootorsource_identity()agree. They would pass unchanged if the digests stayed divergent. - Minor — ordering asymmetry in
_replica._resolve_recipe(tuning_replicas.py:155), which uses the other non-propagatedContextVarcurrent_recipes()(:132), runs beforewith source_roots(...)at:158. The CLI binds both together (cli/__init__.py:370) but only one is forwarded. - Minor — widened binding lifetime and stale docstring. The binding now spans the serve/benchmark handoff (
rank_group.py:59→:121-122), whilesource_roots' docstring still says "for the duration of a CLI invocation" (source_identity.py:24). - 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
ForwardCacheroots andsource_identity, causing same-SKU multi-GPU exports to fail the cache-root agreement check inForwardCache._prepare_ranksbetween 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:
ignition/preparation/aot.py:845-851(for label, extra_root in _EXTRA_ROOTS.get():insideForwardCache.__init__)ignition/preparation/source_identity.py:48(combined_roots = (*_EXTRA_ROOTS.get(), *extra_roots))- transitively
ignition/preparation/rebuild_manifest.py:327('source_identity': source_identity(),)
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:
- No new lock/mutex/queue or head-of-line blocking. The diff adds one
ContextVar.setand a trailing argument at each spawn site (rank_group.py:309-311,tuning_replicas.py:190-194). Nestedsource_rootsscopes reset correctly (source_identity.py:25-30, exercised attest_forward_cache_sources.py:71-80), so no token leakage across the peer'sdist.destroy_process_group. - No memory amplification or unbounded retention. The captured payload is a tuple of
(str, Path); measured as picklable by construction at both spawn sites. No buffers added. - No metric/rate/admission-pricing span change. The span check finds nothing: no sampling site in
inbound_rate/estimated_seconds/worth_fetching-style code is touched, andForwardCache.rootis a cache key, not a measured interval. The only "scope" shift is hashing scope (rootless → rooted), which is the intended fix. - Failure-propagation blast radius unchanged. The
withblock adds no new exception path;source_rootsonly normalizes and resets (source_identity.py:25-30). A peer whose bound root later vanishes still hits the pre-existingValueErrorataot.py:849-850, now reachable in peers too — a strict improvement in diagnosability. - Partial-failure behaviour unchanged. Peer failure/
RankSupervisorhandling (rank_group.py:319) is untouched by the re-indentation.
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
- Right layer. The fix corrects a non-propagated
ContextVarat the twospawnboundaries instead of relaxing the hash or adding an env-var/flag escape hatch. That is the "smallest footprint in shared code" the charter asks for, and it adds no model branch, no CLI flag, no plugin discovery, and nohyperflare_recipesimport (ignition/cli/__init__.py:364-370binds; coreignitionstays external-recipe-agnostic perAGENTS.md:382-396). - No public/wire/captured-graph contract change requiring owner sign-off. No proto, ABI, captured-graph kind, or core format touched; all edits are inside
ignition/preparationplus one test file. - Backward compatibility verified. The new parameter is trailing and defaulted in both
_peer(rank_group.py:44-45) and_replica(tuning_replicas.py:142); existing positional callers are unaffected. In-tree callers ofprepare_group/prepare_recipenever bind roots today, so their cache keys are byte-identical before and after. - Charter's "Bring real evidence" (#397 / #210). This is a bug fix, not a performance PR, so no A/B is required — but the evidence is author-report-only: no CI run on
e72ec0d, no logs or artifacts for the SM120 2-GPU/4-GPU runs, and the same rig appears in #597's evidence. That, combined with F1, leaves the symptom unverified againstmain. - Overlap with a priority contributor's PR (#670,
lukealonso, open). #670 contains the identicalrank_group.pyhunk; #670's Autobot review asked for a CPU test for peer_EXTRA_ROOTSpropagation and suggested splitting that fix into its own PR, which #678 effectively is — yet #678 cites neither #670 nor the review. Merge order decides duplication, and the person most likely to review this PR has already written its core hunk elsewhere. Fix: cite #670 and #597 in the body, and state which PR owns therank_group.pyhunk.
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)
rank_group.py+91/−85 is pure re-indentation. The executable statement sequence of_peeris identical tomain; the only inserts are thesource_rootsimport (:53), thewithat:59, and the trailing argument (:309-311). No semantic change hides in the diff size.- Spawn payload is picklable at both sites — a tuple of
(str, Path). - Backward compatibility holds for all in-tree positional callers (e.g.
tests/preparation/test_native_processes.py:228-229; patched*argscallers elsewhere). - No metric, rate, or admission-pricing sampling change anywhere in the diff.
- No new lock, queue, buffering, or retention path; the only added cost is inherent per-rank tree hashing.
- Charter fit on placement, footprint, and PR-description structure (all four parts present, plus an explicit limitations paragraph — above the bar, notwithstanding its omissions).
Open questions / could not be found
- Does #678 intend to supersede #670's
rank_group.pyhunk, or to stack on #597? Neither PR cross-references the other, and the body gives no stack. - 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). - 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
returnatrank_group.py:288-290means the capture is structurally unreachable there (F3). - Is the
tuning_replicas.pyhunk intended as defence-in-depth? If so, the description should say so, since no consumer exists today (F2). - No CI run, benchmark, log, user report, or issue corroborates the "unblocks same-SKU multi-GPU exports" benefit; there is no review comment on
e72ec0dto independently confirm the 35-passed claim.