PR #678 — Correctness, Contracts & System-Level Consequences review (head 90b0d31, +136/−20 in 5 files)
Key findings
- No blocker. The diff is small and mechanical, and I verified it sound in every area of this lens.
_EXTRA_ROOTSreally is now encapsulated insidesource_identity.py, the new accessor is a pureContextVarread, and both spawn paths read the roots on the parent side and pass them as a pickled argument — nothing depends on spawn inheritance. - Minor — recipe is resolved before the roots are bound inside
_replica(tuning_replicas.py:155vs:158), so the body's "spawn-boundary parity withrank_group._peer" is overstated by one statement._resolve_recipecallsimportlib.import_module(prepare.__module__)(:135), so an external-recipe package importable only via a bound root still runs with empty roots. - Minor — the only test of
prepare_recipeanywhere is Linux-gated (test_forward_cache_sources.py:210-212), and nothing tests theranks is not Nonerejection (tuning_replicas.py:172-173) or the empty-tuning_gpusearly return (:170-171). The Windows spawn path added by this PR is untested; its pickling of the new(str, Path)tuple is proven only on Linux. - Informational — the replica propagation is defensive only, exactly as the body discloses:
_replicacallsprepare(..., compile_forwards=False)(:160) and exits atTuningComplete(:162-165), so no replica ever constructs aForwardCacheor callssource_identity()in-tree. Adjudication should not credit a live bug fix here. - Residual, pre-existing, outside this diff: the multi-host
ignition joinpath still computessource_identity()with no bound roots (serve.py:546) and peers are admitted only on exact identity match (host_ranks.py:270-271). Not a regression, but undeclared in the body. - Merge order: open PR #695 rewrites the same
tuning_replicas.pyneighbourhood for a different purpose (cross-rank tuning-selection sharing, and a different_prepare_ranksBindingMismatchroot cause). #678 is 2 lines at:190-194/:158; land it first.
1. Correctness, Safety & Platform Parity
Verified sound (stating plainly, not inventing issues)
-
Encapsulation is real and complete. After the diff,
_EXTRA_ROOTSis referenced only insideignition/preparation/source_identity.py— definition:12-14, accessor body:19, set:26, reset:30, andsource_identity()'s own read at:48:_EXTRA_ROOTS: contextvars.ContextVar[tuple[tuple[str, Path], ...]] = contextvars.ContextVar( "flare_source_identity_roots", default=() ) def current_source_roots() -> tuple[tuple[str, Path], ...]: """Return the bound external `(label, path)` source roots for this context.""" return _EXTRA_ROOTS.get()Both former importers now use the accessor:
aot.py:845,847andrank_group.py:295,297. A repo-widesearch_codeforcurrent_source_roots\(/source_roots\(returns no other private-var reference. The PR body'sgit grepclaim is accurate. -
No ordering, reset or state-leak hazard.
source_rootssets then resets a token (source_identity.py:26,30), and nesting behaves correctly; the new test proves it (test_forward_cache_sources.py:151-160). -
Neither spawn path relies on
ContextVarinheritance — both capture on the parent.rank_group.prepare_groupreads atrank_group.py:297(extra_roots = current_source_roots()) and passes it positionally into the spawn arg tuple at:309-310;prepare_recipemirrors this attuning_replicas.py:174-176and:194. This is the correct pattern formp.get_context("spawn"). -
No new silent-miss path.
ForwardCache.__init__keeps its pre-existing fail-loud check for a bound-but-missing root (aot.py:848-850):extra_root = Path(extra_root).resolve() if not extra_root.is_dir(): raise ValueError(f"bound source root {label!r} does not exist: {extra_root}")
Finding 1 — Minor: _replica resolves the recipe before binding the roots, so "spawn-boundary parity" is overstated
Citation: ignition/preparation/tuning_replicas.py:155 (resolution) vs :158 (bind); import at :135.
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:
try:
prepare(snapshot, plan, compile_forwards=False, retain_graphs=False, progress=None,
core_storage=storage, **options)
with
module = importlib.import_module(prepare.__module__)
Impact: any module-level import triggered by _resolve_recipe runs with an empty root context, one statement before the bind. The PR body claims the replica path gains "spawn-boundary parity with rank_group._peer"; in fact only the prepare(...) call is covered, not recipe resolution/import, so a recipe importable only through a bound external root would still fail inside a tuning replica. Unreachable today (the child is handed an already-resolved recipe name from a registry that the parent populated, and prepare_recipe spawns after the parent imported the recipe module), hence Minor, not Major.
Fix: move with source_roots(extra_source_roots): up to wrap _resolve_recipe(...) and Plan(...) (a three-line re-indent), or narrow the body's wording from "spawn-boundary parity" to "cache-root parity for replica preparation" next to the existing "defensive parity" caveat.
Finding 2 — Minor: platform-parity gap in test coverage of the new spawn argument
Citation: tests/preparation/test_forward_cache_sources.py:210-212.
@pytest.mark.skipif(sys.platform != "linux", reason="tuning replica supervision requires Linux pidfds")
def test_prepare_recipe_propagates_source_roots_to_spawned_tuning_replica(tmp_path, monkeypatch):
pytest.importorskip("flare_heliopause")
search_code shows prepare_recipe is called from three places in ignition/ (tuning_replicas.py:168 definition, serve.py:312, serve.py:456) and from exactly one place in tests/ (test_forward_cache_sources.py:237).
Impact: on Windows/macOS the propagation this PR adds is never executed by any test, and the new extra_source_roots tuple (which pickles Path objects) is unverified there. Additionally nothing exercises prepare_recipe's ranks is not None rejection (tuning_replicas.py:172-173), its empty-tuning_gpus early return (:170-171), or its non-zero-exitcode failure path (:198-202) — the _cpu_replica_entry shim (test_forward_cache_sources.py:199-207) also stubs CoreStorage and torch CUDA, which the body discloses.
Fix: add a non-spawn unit test asserting ValueError for options={"ranks": object()} and asserting the early return for plan.tuning_gpus == (); leave the pidfd gate to the real-spawn test.
2. Unintended System-Level Consequences
Verified sound
- No lock, mutex, queue or rendezvous added.
tuning_replicasalready usedmultiprocessing.get_context("spawn")before this change (pr_diff: thecontext = multiprocessing.get_context("spawn")line is unchanged context); the diff adds one positional argument to the existingargstuple and onewith-manager. - No memory amplification or retention.
extra_source_rootsis a tiny immutable tuple of(str, Path)per replica (one per replica process, at mostlen(plan.tuning_gpus)//plan.world_size − 1copies), garbage-collected whenprepare_recipereturns. - No failure-propagation blast-radius change. The replica failure path is untouched:
worker.join(timeout=60)thenif worker.exitcode != 0: prepared.close(); raise RuntimeError(...)(tuning_replicas.py:198-202). Binding aContextVarin the child cannot fail in a way that leaves the parent'spreparedmodel dangling — the child exits and the parent raises as before. - No metric/rate/admission-pricing span change. The diff touches no instrumentation; nothing sampling
inbound_rate/estimated_seconds/worth_fetching-class metrics, no rank-0-vs-all-shards scope change, and therefore no downstream threshold to re-check. - No hot-path regression. All reads are on the preparation path (
prepare_groupbefore spawn,prepare_recipebefore spawn,ForwardCache.__init__), never per-token or per-request.
Finding 3 — Informational: the replica propagation is defensive-only today (matches the body; recorded so adjudication does not over-credit it)
Citation: ignition/preparation/tuning_replicas.py:159-165.
try:
prepare(snapshot, plan, compile_forwards=False, retain_graphs=False, progress=None,
core_storage=storage, **options)
except TuningComplete:
torch.cuda.synchronize()
else:
raise RuntimeError("a tuning replica continued beyond kernel preparation")
With compile_forwards=False the replica never reaches the ForwardCache construction in aot.py:847, and never calls source_identity() in-tree; the child then exits, so there is no stale-state or cache-root-divergence risk from leaving the roots bound through the whole with block. The PR body states this ("defensive parity"), so the claim is honest — but the observable behavior of _replica is unchanged for every current recipe.
3. Architecture, Contracts & Charter Compliance
- No wire/proto/captured-graph/core-format/public-API change. The external entrypoint contract is byte-identical:
ignition/cli/__init__.py:364def main(argv=None, *, recipes=(), prog="ignition", source_roots=()), still bound at:370insidewith active_recipes(recipes), active_prog(prog), bind_source_roots(source_roots):. No new flag, no new default, no opt-in needed. - No
AGENTS.mdowner-sign-off trigger: nothing here adds a captured-graph op family. No Charter #210 served-workload A/B requirement: no performance claim is made. - Right layer: the change reuses the existing
source_rootscontext manager and the existing parent-capture/pass-as-arg spawn convention already merged in #670 (rank_group.py:297,309-310) rather than inventing a new mechanism — consistent with the charter's "smallest footprint in shared code" rule. - Merge-order note (Finding 5): open PR #695 (lukealonso, 2026-12-02 21:41, +526/−15) also edits
ignition/preparation/tuning_replicas.pyandignition/preparation/tuning.py. #678's footprint in that file is 2 lines (:158,:190-194); landing #678 first spares #695 a rebase. The two are semantically orthogonal, but both report aForwardCache._prepare_ranksfailure family — #695'sBindingMismatchondecoder.layers[*].attention.scratch_layoutcomes from divergent tuning selections, a different root cause than this PR's cache-root story. Reviewers must not conflate them.
4. Tests & Claim Accuracy
Claim-by-claim against the actual diff (all verified at head):
| Body claim | Verdict | Evidence |
|---|---|---|
Added current_source_roots() |
True | source_identity.py:17-19 |
Replaced direct _EXTRA_ROOTS imports |
True | aot.py:845,847; rank_group.py:295,297; no other references remain |
prepare_recipe captures roots and passes a required argument |
True | capture :174-176; required positional in signature :142; passed :194 |
_replica binds with source_roots(...), CoreStorage(...) around replica preparation |
True for prepare(...) only |
:158; see Finding 1 for resolution-before-bind |
| No core-format / Helios ABI / single-GPU behavior change | True | only ContextVar reads plus one spawn argument |
git diff --check clean, py_compile clean, git grep zero refs |
Consistent with what I see | encapsulation verified independently |
| "36 passed, 0 failed, 0 skipped" | Author-reported only | No CI run is visible on 90b0d31; the dossier records no check run and no post-rebase review |
| Tests are CPU-only with CUDA stubs | True and disclosed | _cpu_replica_entry :199-207 patches torch.cuda.set_device, torch.cuda.synchronize, core_storage.CoreStorage |
The new assertions are meaningful, not tautological: _stub_forward_cache_root() (test_forward_cache_sources.py:35-42) derives the root from a real aot.ForwardCache(...).root under a patched SM120/96-SM device, and both tests compare against an unbound baseline (:109, :216) with cache_root != baseline_root (:123, :245) plus rank-0/replica-0 agreement (:122, :244).
Residual and pre-existing (outside this diff, not a regression)
Citation: ignition/cli/serve.py:546 and ignition/preparation/host_ranks.py:270-271.
identity = source_identity()
control, executor = knock(args.rendezvous, args.rank, args.ranks, identity=identity,
if hello.get("identity") != self.identity:
reject("source identity differs from rank zero's; every host must run the same checkout")
The joining host computes source_identity() with no bound roots, so multi-host external-recipe parity still depends on the external entrypoint passing source_roots to the joining CLI as well. search_code confirms no source_roots reference anywhere under ignition/cli/ other than __init__.py:364-370. The PR body does not mention this. Separate but related: local tuning replicas and multi-host are mutually exclusive by construction (tuning_replicas.py:172-173 raises when ranks is set, and serve.py:451 sets ranks=rendezvous), so this PR's replica propagation never intersects the join path.
Open questions / not found
- Is the
duplicatetriage label stale now that #670 merged, or is it saying the remaining replica-parity half is not worth landing? No human comment or label change answers this. - Where exactly does
rebuild_manifest.from_planexecute when it records'source_identity': source_identity()atrebuild_manifest.py:329? If it runs inside a spawned preparation child, that artifact's recorded identity now includes rank 0's external roots because of this propagation — a recorded-artifact behavior change the body does not note. I did not locate its call site to confirm which process runs it. - Should
_resolve_recipe-before-bind (Finding 1) be fixed in this PR, or is it out of scope given replicas never reach aForwardCache? - Is the multi-host
ignition joinidentity gap deferred to #668/#675? Not stated anywhere in the body. - No CI run and no post-rebase review exist to independently confirm the 36-passed figure, and no issue, benchmark or user report corroborates the external-recipe multi-GPU benefit.