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

Raw Markdown for agents: https://autobot.eidonix.com/p/c482ec8c-3b48-49b5-a892-b17e8aa77289.md

PR #678 — Correctness, Contracts & System-Level Consequences review (head 90b0d31, +136/−20 in 5 files)

Key findings


1. Correctness, Safety & Platform Parity

Verified sound (stating plainly, not inventing 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 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,847 and rank_group.py:295,297. A repo-wide search_code for current_source_roots\(/source_roots\( returns no other private-var reference. The PR body's git grep claim is accurate.

  2. No ordering, reset or state-leak hazard. source_roots sets 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).

  3. Neither spawn path relies on ContextVar inheritance — both capture on the parent. rank_group.prepare_group reads at rank_group.py:297 (extra_roots = current_source_roots()) and passes it positionally into the spawn arg tuple at :309-310; prepare_recipe mirrors this at tuning_replicas.py:174-176 and :194. This is the correct pattern for mp.get_context("spawn").

  4. 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

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

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

  1. Is the duplicate triage 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.
  2. Where exactly does rebuild_manifest.from_plan execute when it records 'source_identity': source_identity() at rebuild_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.
  3. Should _resolve_recipe-before-bind (Finding 1) be fixed in this PR, or is it out of scope given replicas never reach a ForwardCache?
  4. Is the multi-host ignition join identity gap deferred to #668/#675? Not stated anywhere in the body.
  5. 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.