#1 [high] Lens: magic default extra_source_roots=() in _peer/_replica
Both new parameters are defaulted to ():
- ignition/preparation/rank_group.py:44-45
def _peer(parent, snapshot, config, rank, rendezvous, connection, control, prepare, exporting, recording,\n extra_source_roots=()): - ignition/preparation/tuning_replicas.py:142
def _replica(parent, prepare, recipe_name, snapshot, values, gpu_uuids, options, extra_source_roots=()):
Both are module-private spawn entry points with exactly one production call site each (rank_group.py:309-312, tuning_replicas.py:190-194), and the PR body itself calls the default the backward-compat story. But the bug being fixed IS "a spawn site forgot to carry parent state", so an empty default silently restores the exact failure mode (peer hashes no external roots -> ForwardCache split) with no error. Charter, How We Work: "Be explicit and pin everything. No magic defaults" (read_charter).
Fix: drop =() in both signatures. Only one in-tree caller needs updating: tests/preparation/test_native_processes.py:228-229 passes 10 positional args to rank_group._peer; tests/preparation/test_model_core.py:92-101 forwards *args so it is unaffected.
#2 [high] Lens: _peer whole-body wrap re-indents 85 lines; scope can be prepare-only
rank_group.py:59 wraps the whole ~85-line peer body in with source_roots(extra_source_roots):, re-indenting everything (diff +91/−85 for a 3-line semantic change). The ContextVar is consumed only by ForwardCache.__init__ during preparation (ignition/preparation/aot.py:845-848) and by source_identity() (source_identity.py:48), whose only in-tree caller path is rebuild_manifest.from_plan (rebuild_manifest.py:327), reached only from ignition/cli/serve.py:237 and :338 — the parent process, never the peer. Inside _peer, nothing after prepare(...) reads it: model.manifest()/export_manifest() (execution.py:254-259), export_model (runtime_core.py:344-440), serve_rank, serve_peer do not call source_identity.
So the scope can be just the two model = prepare(...) calls (rank_group.py:69-77, plus the ModuleImages/CoreStorage wrappers must stay as-is):
with recorder if recording else contextlib.nullcontext():
torch.cuda.set_device(config.devices[rank])
storage = CoreStorage(rank=rank, world=len(config.devices), device=config.devices[rank])
with storage, source_roots(extra_source_roots):
model = prepare(snapshot, config, rank=rank, group=dist.group.WORLD, core_storage=storage)
else:
with source_roots(extra_source_roots):
model = prepare(snapshot, config, rank=rank, group=dist.group.WORLD)
That removes the 85-line re-indent → diff drops to ~6 added lines, and matches the charter's "look for the smallest footprint". Trade-off to state: a whole-body wrap is more future-proof; if the author keeps it, that's defensible but should be said in the body.
Secondary, same file: source_identity.py:24 docstring still says "for the duration of a CLI invocation" although callers now bind it inside spawned children.
#5 [high] Research summary
Lens complete: the diff is functionally lean (one 3-line accessor plus argument plumbing; no new flags, env knobs, fallbacks or dead code), but two of the three findings are real and cheap to fix. Findings are in the scratchpad (entries 1-4).
-
extra_source_roots=()magic default (high) —rank_group.py:44-45andtuning_replicas.py:142both default the new arg to()in module-private spawn entry points that have exactly one production call site each (rank_group.py:309-312,tuning_replicas.py:190-194). The bug being fixed is "a spawn site forgot to carry parent state", so an empty default silently restores the exact failure mode with no error, and the charter says "Be explicit and pin everything. No magic defaults". Drop=(); onlytests/preparation/test_native_processes.py:228-229(10 positional args) needs updating;test_model_core.py:92-101forwards*argsand is unaffected. -
85 lines of re-indentation for a 3-line semantic change (high) —
rank_group.py:59wraps the entire_peerbody inwith source_roots(extra_source_roots):. Nothing afterprepare(...)in the peer reads the ContextVar (onlyForwardCache.__init__ataot.py:845-848andsource_identity()do, and the latter's only in-tree path isrebuild_manifest.from_planreached from the parent atserve.py:237 (not opened)/338). Narrowing the scope to the twomodel = prepare(...)calls (rank_group.py:69-77) collapses the diff to ~6 added lines, per "look for the smallest footprint". -
Leftover private read (low) —
aot.py:845-848still doesfrom .source_identity import _EXTRA_ROOTS/_EXTRA_ROOTS.get(); it should use the newcurrent_source_roots(). Alsosource_identity.py:24's docstring ("for the duration of a CLI invocation") is now inaccurate.
Checked-clean: no copy_context-style helper exists to reuse; current_source_roots() has 5 callers and mirrors registry.current_recipes(); the test additions follow repo convention (no tests/conftest.py (not opened) exists, so inline recipe builders are the norm). Cross-PR note: the rank_group.py hunk duplicates open #670's identical edit, so part of this work is redundant rather than redundant code.
#6 [high] Lens: verbatim current code for the _peer scope narrowing (citation for finding 2)
Verbatim at head e72ec0d, ignition/preparation/rank_group.py:61-79 (note the extra 4-space indent on every line is itself the re-indentation finding):
if exporting:
from .module_images import ModuleImages
from .core_storage import CoreStorage
import torch
# Only an export needs module images; without one, a profiler may own CUPTI.
recorder = ModuleImages() if recording else None
with recorder if recording else contextlib.nullcontext():
torch.cuda.set_device(config.devices[rank])
storage = CoreStorage(rank=rank, world=len(config.devices), device=config.devices[rank])
with storage:
model = prepare(snapshot, config, rank=rank, group=dist.group.WORLD, core_storage=storage)
else:
model = prepare(snapshot, config, rank=rank, group=dist.group.WORLD)
On main this same block sits at 4 spaces less indent with no with source_roots(...) wrapper (rank_group.py:58-72 at base). The whole-body wrapper added at :59 is what produced the +91/−85 in the PR's stated file stats.
Replacement (keeps ModuleImages/CoreStorage nesting untouched, binds only around the two prepare calls):
with storage:→with storage, source_roots(extra_source_roots):else:branch →with source_roots(extra_source_roots):around the singlemodel = prepare(...)call- delete the outer
with source_roots(extra_source_roots):at :59 and de-indent the body back to the base indentation.
If the author prefers the whole-body wrap for future-proofing, the final report should say that is defensible but should be disclosed in the PR body, since it costs ~85 lines of churn for no behavioural difference today.
#3 [medium] Lens: leftover private _EXTRA_ROOTS read in aot.py; tests follow repo convention
current_source_roots() (source_identity.py:17-19) mirrors registry.current_recipes() (ignition/registry.py:29-31) — idiomatic, keep it. But the PR leaves the one remaining private reader in place: aot.py:845-848
from .source_identity import _EXTRA_ROOTS
for label, extra_root in _EXTRA_ROOTS.get():
should now be for label, extra_root in current_source_roots():, deleting the private-attribute import. One-line cleanup in the same subsystem; optional/low.
Also tests: test additions follow repo convention — no tests/conftest.py exists at all (list_files found none), so per-test recipe builders are the norm (tests/cli/test_recipe_injection.py:17-42 builds the same 22-line Recipe(...)), and the pytest.MonkeyPatch.context() stub in _cpu_replica_entry (test_forward_cache_sources.py:146-154) is the same pattern as tests/preparation/test_model_core.py:92-101. Do NOT flag those as bloat.
#4 [medium] Lens: not flagged / checked-clean list
Items I deliberately did NOT flag as bloat, after checking:
current_source_roots()(source_identity.py:17-19, 3 lines) is not speculative generality: it has two production callers (rank_group.py:298, tuning_replicas.py:176) and 3 test callers; it is the minimal accessor mirroring registry.py:29-31.- Rank_group.py diff +91/−85 is 90% re-indentation (see entry 2); no dead code left behind — the added arg is actually used at rank_group.py:59 and tuning_replicas.py:158.
- Test file growth (+129/−3) contains no duplicated helper: repo has no tests/conftest.py, so the inline
_REPLICA_TEST_RECIPE(test_forward_cache_sources.py:122-143) and thepytest.MonkeyPatch.context()stubs (:146-154) follow existing precedent (tests/cli/test_recipe_injection.py:17-42, tests/preparation/test_model_core.py:92-101). - No new flags/env knobs/fallback branches: only new API surface is the defaulted trailing kwarg covered in entry 1.
extra_source_rootspickling throughcontext.Process(args=...)is the only path available (spawn children start with an empty ContextVar — verified no copy_context/contextvars-inheritance helper exists anywhere: search for copy_context returned nothing), so no simpler existing abstraction is being duplicated.
Cross-PR note for the final report: #678's rank_group.py hunk duplicates open PR #670's identical prepare_group→_peer→source_roots edit (per dossier), so in merge-order terms part of this diff is redundant work rather than redundant code.