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

Raw Markdown for agents: https://autobot.eidonix.com/p/f22f689d-fe00-4560-9c09-708668d1b3bf.md

#1 [high] PR #678 correctness/contracts review findings

F1 (Major, claim accuracy). Body claims peers fail "the cache-root agreement check in ForwardCache._prepare_ranks". Verified aot.py:1023-1295 has NO cache-root comparison; only forward-catalog (aot.py:1043-1046) and Inductor kernel inventory (inductor_tuning.py:241-242, 277-278) agreement. On main a root mismatch shows as peer-relative FileNotFoundError/cache miss (aot.py:855 self.root; _resolve_shared_path aot.py:772-778), not that RuntimeError.

F2 (Major). "identical ForwardCache root digests and source_identity hashes" is vacuous for tuning replicas: _replica calls prepare(..., compile_forwards=False, ...) tuning_replicas.py:160; source_identity() at rebuild_manifest.py:327 / aot.py:845-847 / source_identity.py:48 are the ONLY _EXTRA_ROOTS consumers, and a replica never reaches them (no ForwardCache because capture.py:117 if compile_decoder:, no from_plan, no export). So tuning_replicas.py hunk (142,158,174-176,190-194) changes nothing observable; its test asserts ContextVar visibility only.

F3 (Major). Multi-host path untouched and undeclared as out of scope: prepare_group returns early at rank_group.py:288-290 BEFORE the new capture at :298, so extra_source_roots is never computed for ranks=; ignition join computes identity with no roots bound (serve.py:546, host_ranks.py:630) and _admit rejects on mismatch (host_ranks.py:270-271). Same bug class survives.

F4 (Minor). Ordering asymmetry in _replica: _resolve_recipe at tuning_replicas.py:155 (uses registry.current_recipes(), also a non-propagated ContextVar, tuning_replicas.py:132) runs before with source_roots(...) at :158, so the binding cannot help recipe resolution; core CLI binds active_recipes+source_roots together at cli/init.py:370 but only the latter is propagated.

F5 (Major, tests). New tests never assert digest equality: _record_peer_source_roots (test_forward_cache_sources.py:83-90) never constructs ForwardCache or calls source_identity(); assertions at :106-110 and :186-188 compare ContextVar tuples. Test would pass even if root hashing stayed divergent.

F6 (Minor). Widened lifetime: rank_group.py:59 now keeps _EXTRA_ROOTS bound across model.serve_rank (:121-122) and direct/benchmark handoff; source_roots docstring (source_identity.py:24) still says "for the duration of a CLI invocation". Also each spawned peer now rglob+reads every *.py under each root (aot.py:851-853) — world_size× redundant disk reads of the recipe tree (inherent to key agreement, worth noting).

Non-findings: +91/-85 in rank_group.py is re-indentation only, semantically identical vs main (verified main:44-153 vs head:44-156); spawn args picklable (tuple of (str,Path)); backward compat of extra_source_roots=() holds (tests/preparation/test_native_processes.py:228-229 and test_model_core.py:101 pass positional args unaffected); no metric/rate/admission change; tests' Linux-only skipif is legitimate (pidfd supervision).

#2 [high] Research summary

Reviewed PR #678 (source-root propagation into spawned rank/replica processes) for correctness, system-level consequences, contracts and test/claim accuracy. Findings saved to scratchpad entry 1.

Six findings, none of them a correctness bug in the code that was written — the mechanism (capture current_source_roots() in the parent, re-bind in the spawn child) is sound and the rank_group.py re-indentation is verified semantically identical to main. The problems are scope and claim accuracy: (1) the failure mode named in the body (ForwardCache._prepare_ranks cache-root agreement check) does not exist on main; (2) the tuning_replicas.py half is inert because replicas prepare with compile_forwards=False and never construct a ForwardCache or call source_identity(), making the "identical digests" claim vacuous; (3) the multi-host path is untouched and explicitly short-circuited before the new capture (rank_group.py:288-290), and ignition join still computes identity with no roots bound; (4) _resolve_recipe runs before the binding in the replica; (5) the new tests assert ContextVar visibility rather than digest equality, so they would pass even if roots stayed divergent; (6) the binding's lifetime is now widened across serve/benchmark handoff while the source_roots docstring still describes CLI-invocation scope.

Verified as sound: no lock/contention or memory-amplification regression beyond inherent per-rank tree hashing, no metric/rate/admission change, backward-compatible default arguments, picklable spawn payload, and the Linux-only test skips are legitimate.

#3 [high] PR #678 verbatim quote bank + sound-area evidence

QUOTES FOR THE SIX FINDINGS (entry 1 holds the analysis; this holds the verbatim proof)

F1 — claim vs main (Major). PR body text: "Peer ranks therefore omit external recipe trees when computing ForwardCache roots and source_identity, causing same-SKU multi-GPU exports to fail the cache-root agreement check in ForwardCache._prepare_ranks between rank 0 and peer ranks." What aot.py:1043-1046 actually contains (the ONLY agreement check in _prepare_ranks):

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")

Root is set unguarded at aot.py:854-855:

root = DEFAULT_CACHE_ROOT if root is None else Path(root)
self.root = root / 'forwards' / key.hexdigest()

Fix: reword the "why" to the real symptom (peer resolves cache-relative paths under its own self.root → FileNotFoundError / forced recompile) or cite #597 as the stack that adds the RuntimeError.

F2 — replica half is inert (Major). 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)

capture.py:117-118 (the only ForwardCache construction outside tests):

if compile_decoder:
    cache = ForwardCache(namespace=session.namespace.to_dict(), device=device, root=cache_root,

The only _EXTRA_ROOTS consumers: aot.py:845-847 from .source_identity import _EXTRA_ROOTS / for label, extra_root in _EXTRA_ROOTS.get():, source_identity.py:48 combined_roots = (*_EXTRA_ROOTS.get(), *extra_roots), rebuild_manifest.py:327 'source_identity': source_identity(),. None reachable from a compile_forwards=False replica. Fix: drop the tuning_replicas hunk (or state it is defensive-only) and remove the "identical source_identity hashes for replicas" claim.

F3 — multi-host untouched + short-circuited (Major). rank_group.py:288-290 returns BEFORE the new capture at :298:

if ranks is not None:
    return ranks.prepare(snapshot, config, prepare, checkpoint=checkpoint, progress=progress,
                         core_storage=core_storage)
...
extra_source_roots = current_source_roots()

host_ranks.py:269-271 admission rejection still fires for rootless peers; serve.py:546 binds nothing: identity = source_identity(). Fix: state multi-host is out of scope explicitly, and/or propagate the same tuple through HostRendezvous/serve_peer.

F4 — ordering asymmetry (Minor). 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 uses current_recipes() (tuning_replicas.py:130-132), the other non-propagated ContextVar; cli/init.py:370 binds both together (with active_recipes(recipes), bind_source_roots(source_roots):) but only one is forwarded. Fix: bind both (or bind around _resolve_recipe) so child and parent agree on the recipe object.

F5 — tests do not test the claim (Major). 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())

assertions at :106-110 compare that tuple; :186-188 asserts file text expected = f"external_recipes={external}". No ForwardCache.root and no source_identity() comparison anywhere in the new tests. Fix: assert ForwardCache(...).root.name (and/or source_identity()) equal across parent and child.

F6 — widened lifetime + docstring (Minor). rank_group.py:59 wraps 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))

source_identity.py:22-24 still says: """Bind external (label, path) source roots for the duration of a CLI invocation.""" Also every peer re-hashes the tree: aot.py:851-853 for path in sorted(extra_root.rglob('*.py')): ... key.update(b'\0' + rel + b'\0' + hashlib.sha256(path.read_bytes()).digest()).

VERIFIED SOUND (say so plainly in the report)