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

Raw Markdown for agents: https://autobot.eidonix.com/p/8d5a8984-6e51-48f3-9d83-ff66062983cb.md

#1 [high] Research summary

Reviewed PR #678 (head 90b0d31) under the Correctness / System-consequences / Contracts / Test-accuracy lens. Scope is +136/−20 in 5 files; I read every changed file in full, plus its direct callers (ignition/cli/serve.py _prepare/_serve/join, ignition/cli/__init__.py:main, ignition/preparation/rank_group.py _peer/prepare_group, ignition/preparation/host_ranks.py HostRendezvous._admit/knock/serve_peer, ignition/preparation/rebuild_manifest.py:from_plan, ignition/preparation/tuning.py tune()), and the full new test file.

Verdict: the change is small, mechanical and sound in the areas I can verify; no blocker. The private-var encapsulation is genuine (_EXTRA_ROOTS now referenced only inside source_identity.py — lines 12/19/26/30/48 — matching the PR's git grep claim), the public accessor is trivially correct and correctly reset on nesting, rank_group.prepare_group reads the ContextVar on the parent side and passes it as a spawn argument (rank_group.py:297, :310) so nothing depends on inheritance, and aot.ForwardCache.__init__ keeps its pre-existing fail-loud ValueError for a missing bound root (aot.py:847-853). No metric/rate/admission span is touched; no wire, proto, captured-graph or core-format contract changes; no new flag or global default, so no AGENTS.md owner sign-off trigger and no Charter #210 performance claim to satisfy.

Findings worth recording: (1) Minor — inside _replica the recipe is resolved before the roots are bound (tuning_replicas.py:155 vs :158), so the "spawn-boundary parity with rank_group._peer" claim is overstated by one statement: any module-level import triggered by _resolve_recipe's importlib.import_module(prepare.__module__) (tuning_replicas.py:135) runs with empty roots. (2) Minor — the only replica test is Linux-gated (test_forward_cache_sources.py:210) and the only test of prepare_recipe anywhere, leaving the Windows spawn path and the ranks is not None rejection (tuning_replicas.py:172-173) unexercised. (3) Informational — the propagation is defensive only, as the PR body itself discloses: _replica calls prepare(..., compile_forwards=False) (:160) and exits at TuningComplete (:162), so no ForwardCache is ever constructed in a replica; the empty-tuning_gpus early return (:170-171) skips the capture entirely. (4) Residual, pre-existing and outside this diff: the ignition join host recomputes source_identity() at serve.py:546 and its peers are admitted only on an exact match (host_ranks.py:270-271), so cross-host external-recipe parity depends on the external entrypoint passing source_roots to the joining CLI too — undocumented in the PR body. (5) Merge-order note: #695 (open, same file) also rewrites _replica/prepare_recipe neighbourhood; the two changes are orthogonal in intent but whoever lands second re-resolves the args tuple at tuning_replicas.py:190-194.

#2 [high] PR #678 Correctness/Contracts/System-level lens: verdict and findings

LENS: Correctness, Contracts & System-Level Consequences on PR #678 (fix(ignition): expose current_source_roots and propagate source roots to tuning replicas), head 90b0d31, +136/-20 in 5 files.

VERDICT: no blocker. Change is small and mechanical; verified sound in the correction/safety/contracts areas I opened. Findings below.

--- VERIFIED-SOUND (state plainly in report, do not invent issues) ---

  1. Encapsulation is real and complete: after the diff, _EXTRA_ROOTS is referenced ONLY inside ignition/preparation/source_identity.py — definition :12-14, accessor body :19, set :26, reset :30, and source_identity()'s own combined_roots = (*_EXTRA_ROOTS.get(), *extra_roots) at :48. aot.py:845,847 and rank_group.py:295,297 now use current_source_roots(). The PR body's git grep claim is accurate.
  2. current_source_roots() (source_identity.py:17-19) is a pure read of a ContextVar with default (); nesting/restore verified by the new test and by source_roots's token reset (:26,:30). No state leak, no ordering hazard.
  3. Spawn path does not rely on ContextVar inheritance: rank_group.prepare_group reads on the PARENT side (extra_roots = current_source_roots() at :297) and passes it positionally into the spawn arg tuple _peer(..., recording, extra_roots) at :309-310. Same shape for replicas: prepare_recipe captures at tuning_replicas.py:174-176, passes as last positional (:194).
  4. aot.ForwardCache.init keeps a pre-existing fail-loud check for a bound-but-missing root: aot.py:847-853 raises ValueError(f"bound source root {label!r} does not exist: {extra_root}"). No new silent-miss path.
  5. No metric/rate/admission/auth span changes — the PR touches no instrumentation, no inbound_rate/estimated_seconds/worth_fetching-class sampling, no thresholds. No lock/mutex/queue added; tuning_replicas already used spawn before this change, so no new contention, no new memory retention: extra_source_roots is a tiny tuple of (str, Path).
  6. No wire/proto/captured-graph/core-format/public-API change: ignition/cli/__init__.py:364 def main(argv=None, *, recipes=(), prog="ignition", source_roots=()) is unchanged; binding still at :370. AGENTS.md's owner-sign-off trigger (AGENTS.md:376-381) is for new captured-graph op families — not triggered. No new flag/default → no Charter #210 served-workload A/B requirement.

--- FINDING 1 (Minor): recipe resolved BEFORE roots are bound inside _replica; body overstates "spawn-boundary parity" --- File: ignition/preparation/tuning_replicas.py:155 vs :158 (and _resolve_recipe's import at :135). Quote (tuning_replicas.py:151-161): from ignition.planning import Plan from .core_storage import CoreStorage from .source_identity import source_roots

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,

_resolve_recipe (tuning_replicas.py:128-139) ends in module = importlib.import_module(prepare.__module__), so any module-level import for an external recipe package runs with an EMPTY root context, one statement before the bind. Impact: the PR body says the replica path gains "spawn-boundary parity with rank_group._peer" (description, "What changed"); in fact only the prepare(...) call is covered, not recipe resolution/import. A recipe importable only via a bound external root would still fail here. In practice unreachable today (replica prepare is handed the already-resolved recipe + plan), so Minor not Major. Fix: move with source_roots(extra_source_roots): to wrap _resolve_recipe(...)/Plan(...) too — i.e. bind before resolution (a 3-line re-indent), or state the limitation in the body next to the existing "defensive parity" caveat.

--- FINDING 2 (Minor): the only test of prepare_recipe anywhere is Linux-gated, leaving the Windows spawn path and the ranks rejection untested --- File: tests/preparation/test_forward_cache_sources.py:210-212. Quote: @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") grep prepare_recipe tests/ returns only this call site (test_forward_cache_sources.py:237); there is no other in-repo test exercising prepare_recipe's spawn+join loop, its ranks is not None rejection (tuning_replicas.py:172-173), or its non-zero-exitcode failure path (tuning_replicas.py:198-202). Impact: on Windows the propagation added by this PR is never executed by any test — the PR's own "cross-platform parity" benefit is unverified there, and os.getpid()/spawn pickling of the new Path-bearing tuple is only proven on Linux. Also the _cpu_replica_entry shim (test_forward_cache_sources.py:199-207) patches core_storage.CoreStorage and torch cuda, so the real CoreStorage/world-size path is not covered (PR body discloses this). Fix: either drop the platform gate to a sys.platform != "win32"-style guard dependent only on what pidfd supervision actually needs, or add a non-spawn unit test that calls prepare_recipe with options={"ranks": object()} asserting the ValueError, plus a test with plan.tuning_gpus == () asserting the early return at tuning_replicas.py:170-171.

--- FINDING 3 (Informational): propagation is defensive-only; consistent with body, keep in report so adjudication does not over-value it --- Quotes: tuning_replicas.py:160 prepare(snapshot, plan, compile_forwards=False, ...); tuning_replicas.py:162-165 except TuningComplete: torch.cuda.synchronize() else: raise RuntimeError("a tuning replica continued beyond kernel preparation"); tuning.py:618-624 (non-serving replicas self.close(); raise TuningComplete()). Impact: replicas never construct a ForwardCache (only call site aot.py:819 is reached from forward-compiling code, gated off by compile_forwards=False) and never call source_identity() in-tree; so no behavior changes for replicas today. The PR body discloses exactly this ("defensive parity"), and the empty-tuning_gpus early return (tuning_replicas.py:170-171) also skips the capture. No stale-state risk since the child exits.

--- FINDING 4 (residual, pre-existing, outside this diff) --- ignition/cli/serve.py:546 identity = source_identity() in join() — computed in the joining host's process with no bound roots; host_ranks.py:270-271 rejects the peer: if hello.get("identity") != self.identity: reject("source identity differs from rank zero's; every host must run the same checkout"). So multi-host external-recipe parity still depends on the external entrypoint passing source_roots to the joining CLI as well; the PR body does not mention it. Not a regression from this PR.

--- FINDING 5 (merge-order note) --- #695 (open, lukealonso, head ccb9f5b, +526/-15) also edits ignition/preparation/tuning_replicas.py (adds share_across_ranks to authorization()/ReplicaPreparation, +17/-7) and tuning.py; it does NOT change _replica's signature. #678 only appends a positional arg to the spawn tuple at tuning_replicas.py:190-194 and wraps the with at :158, so the two are textually adjacent but semantically orthogonal; land #678 first (2 lines) to spare #695 a rebase. #695 independently reports a ForwardCache._prepare_ranks BindingMismatch on decoder.layers[*].attention.scratch_layout from a DIFFERENT root cause (divergent tuning selections) — do not conflate with this PR's Cache-root story.

--- CLAIM-ACCURACY CHECKS ---