Re review report · NVIDIA/hyperflare-inference #668

Raw Markdown for agents: https://autobot.eidonix.com/p/65e8c07d-aeb6-4164-a047-5b8208873cdd.md

Recommendation: Changes Requested

PR #668 cleanly addresses three real multi-host preparation defects—request-name-first selection reconciliation, peer b12x_environment / local kernel_cache propagation, and ForwardCache B12X keying with atomic .bin persistence—and independent 2× GB10 SM121 reports from @nepenth and @Reederey87 corroborate both root causes. Head d6a0069 rebased cleanly onto main (resolving the prior #667 conflict in host_ranks.py:723-725), but the PR's own 8-file diff (+424 / −44) has not yet addressed two concrete safety/test-isolation bugs from Round 1: ForwardCache._load silently unlinking valid .bin artifacts on transient OSError / CUDA / _load_inductor errors, and the new serve_peer test permanently leaking B12X_* variables into process-global os.environ.

Merge Risk

Level: Medium

Walkthrough

Pre-merge Checks

Blockers

  1. Narrow _CORRUPT_ARTIFACT_ERRORS, log dropped artifacts, guard unlink, and test torch.OutOfMemoryError (ignition/preparation/aot.py:64-76, 103-144, 1371-1380; tests/preparation/test_forward_cache_sources.py:212-217):

    • ForwardCache._load(..., required=False) wraps both path.open('rb') and torch.compiler.load_compiled_function(file) in except _CORRUPT_ARTIFACT_ERRORS, which catches blanket OSError, RuntimeError, ValueError, TypeError, KeyError, and AttributeError. Inside load_compiled_function, _load_inductor (aot.py:103-144) writes Triton cubins to disk (_materialize_selected_cubin at :121), loads CUDA modules (deserialize_bundled_cache_entry at :123), and enforces internal invariants with ValueError (:111) and RuntimeError (:128).
    • Consequently, any transient OSError (ENOSPC writing Triton cubins, EMFILE, EIO), non-OOM CUDA driver RuntimeError, or _load_inductor contract failure silently deletes a potentially valid .bin artifact with zero warning/logging and forces a full recompile (charter #397). Additionally, Path(path).unlink(missing_ok=True) (:1379) is unguarded against PermissionError/OSError (e.g., sticky/read-only directory or locked file on Windows), turning a recoverable miss into an unhandled crash.
    • At aot.py:1377, MemoryError in isinstance(error, (MemoryError, torch.OutOfMemoryError)) is unreachable dead code because MemoryError is not a subclass of any member of _CORRUPT_ARTIFACT_ERRORS. The test at tests/preparation/test_forward_cache_sources.py:212-217 only raises MemoryError, so it never enters the except clause and leaves the torch.OutOfMemoryError (RuntimeError subclass) carve-out completely untested.
    • Fix: Move path.open('rb') outside the corrupt-archive try (or handle FileNotFoundError explicitly as a miss); narrow _CORRUPT_ARTIFACT_ERRORS to genuine archive/deserialization errors (EOFError, pickle.UnpicklingError, struct.error, zlib.error, zipfile.BadZipFile—not blanket OSError or RuntimeError, or if a specific RuntimeError/ValueError from truncated torch archives must be handled, place an explicit except (MemoryError, torch.OutOfMemoryError): raise ahead of it and do not swallow OSError or _load_inductor contract faults); log a warning naming path and error before unlinking; wrap Path(path).unlink(missing_ok=True) in try: ... except OSError: pass; and test torch.OutOfMemoryError in test_forward_cache_sources.py.
  2. Fix the process-global os.environ leak in test_serve_peer_applies_b12x_environment_and_remaps_kernel_cache (tests/preparation/test_host_ranks.py:361-362, 426-438):

    • monkeypatch.delenv("B12X_W4A16_A4_PREFILL", raising=False) and monkeypatch.delenv("B12X_W4A16_SMALL_M_HOST_BARRIER_RESET", raising=False) are no-ops when those keys start absent, so pytest registers no teardown restoration (compare tests/cli/test_environment.py:55-62 (not opened), which explicitly works around this pytest behavior). serve_peer then mutates os.environ directly via os.environ.update(...), leaving both B12X_* variables set for every subsequent test in the same worker—directly perturbing _b12x_forward_env() and ForwardCache.root introduced in this PR.
    • Fix: Register undo entries before calling serve_peer (e.g., monkeypatch.setenv(k, ""); monkeypatch.delenv(k) for each key, matching tests/cli/test_environment.py:57-62 (not opened), or restore os.environ in finally:).

Should Fix

  1. Address or document the peer b12x_environment import-order gap (ignition/cli/serve.py:547-555, ignition/cli/environment.py:7-9, 82, ignition/runtime_patches/__init__.py:119, ignition/runtime_patches/workers.py:26-29, ignition/preparation/host_ranks.py:297, 645-648):

    • In join(), environment.apply(configuration, (gpu,)) runs at serve.py:547 before knock() and serve_peer(). environment.apply calls runtime_patches.apply() (environment.py:82) → workers.register_hooks() (runtime_patches/__init__.py:119) → from b12x.preparation import register_worker_initializer (workers.py:27), so b12x and b12x.preparation are already imported before serve_peer receives ("b12x-environment", ...) at host_ranks.py:646-648.
    • For dynamically read flags like B12X_W4A16_A4_PREFILL, applying them before assignment = receive_object(control) (:665) works because recipe/operator modules import during unpickling. However, any future b12x_environment variable cached at b12x/b12x.preparation import time will still diverge between rank zero (serve.py:211, 438) and peers—contradicting ignition/cli/environment.py:7-9 and the PR description's unqualified "(so import-time reads see it)" claim (as @Reederey87 flagged after closing #675).
    • Fix: Either send b12x_environment in _admit's JSON reply (host_ranks.py:297) and call environment.apply(configuration, (gpu,), b12x_environment) in join() after knock() (note that source_identity(), local_topology(), and knock() do not require environment.apply—rank zero already runs all three before environment.apply at serve.py:193-211), which also eliminates the pickle-channel duplication below; or explicitly document in serve.py/host_ranks.py and the PR description that peer b12x_environment is applied after b12x.preparation import and only precedes recipe/operator imports.
  2. Do not auto-close #651 before confirming d6a0069 on live 2× GB10 hardware:

    • Independent 2× GB10 SM121 TP2 reports from @nepenth and @Reederey87 strongly validate both diagnosed root causes and manual workarounds, but neither ran this PR commit itself, and CI runs against pinned flashinfer (pyproject.toml:47) rather than paired flashinfer#199. Because #647 previously auto-closed #631 without resolving live 2× GB10 convergence, either verify this branch on 2× GB10 before merging or change Fixes #651 to Related: #651 until confirmed on hardware (and note the expected one-time ForwardCache re-key for recipes with b12x_environment).

Subtract / Simplify

  1. Collapse the duplicate b12x_environment wire channel and remove the unused prepare(..., b12x_environment=None) parameter (ignition/preparation/host_ranks.py:313-314, 325-326, 345-347, 376-377, 645-648, 665-668, ignition/preparation/rank_group.py:288-290, tests/preparation/test_host_ranks.py:400-412):

    • HostRendezvous.prepare sends the exact same b12x_env dict twice: once as ("b12x-environment", b12x_env) (:345-347) and again inside assignment["b12x_environment"] (:377), where serve_peer re-validates and re-applies it (:666-668). Because the early command is always sent whenever b12x_env is non-empty, the assignment copy can never add anything new (the test at test_host_ranks.py:400-412 only hits both paths by injecting two different dicts that HostRendezvous.prepare never produces).
    • Separately, prepare(..., b12x_environment=None) (:314, 325-326) has no caller (rank_group.py:288-290 never passes it; HostRendezvous.__init__ already validates and stores self.b12x_environment).
    • Fix: Keep a single channel (either _admit per Should Fix #1, or the early ("b12x-environment", ...) frame), remove "b12x_environment" from assignment and host_ranks.py:666-668, drop the unused b12x_environment=None parameter from HostRendezvous.prepare, and simplify test_host_ranks.py:400-412.
  2. Consolidate duplicated atomic-write blocks and fix the open-handle unlink in _share_artifacts (ignition/preparation/aot.py:90-100, 270-277, 868-878, 1185-1192; ignition/preparation/compile_pool.py:104, 115-123):

    • _save_compiled_function (aot.py:90-100) is identical to compile_pool._compile_forward (compile_pool.py:115-123, which already imports from .aot at :104), and aot.py maintains three additional inline NamedTemporaryFile + os.replace + unlink blocks (:270-277, :870-877, :1185-1192).
    • In the newly edited _share_artifacts block (aot.py:870-877), try: ... finally: temporary.unlink(missing_ok=True) is nested inside with tempfile.NamedTemporaryFile(...) as file:, so if file.write(payload[0]) fails before file.close(), unlink runs while the handle is still open (PermissionError on Windows, masking the write error).
    • Fix: Have compile_pool.py:115-123 call _save_compiled_function, and move try/finally outside the with block at aot.py:870-877 (or extract a single _atomic_write(path, writer) helper in aot.py).

Nits

Dropped on verification