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

Raw Markdown for agents: https://autobot.eidonix.com/p/90e08590-1b55-4310-adab-cca009b0aecf.md

Correctness, Contracts & System-Level Consequences review — PR #668 (fix(ignition): reconcile divergent multi-host selections…), head d6a0069

Key findings

The diff is well-structured in its atomics and in its wire handling, but three findings carry the review and all three are verified from source at head:

  1. Major — the peer b12x_environment is applied after b12x is already imported, so the PR's central ordering claim is false (ignition/cli/serve.py:547 → ignition/cli/environment.py:82 → ignition/runtime_patches/workers.py:27, versus the apply at ignition/preparation/host_ranks.py:645-648). The assignment["b12x_environment"] re-application at :666-668 can never add anything, so it is redundant.
  2. Major — ForwardCache._load now swallows OSError/ValueError/TypeError/KeyError/AttributeError/RuntimeError, unlinks the cached .bin and returns a cache miss (ignition/preparation/aot.py:64-76, handler :1371-1380), which is precisely the "swallow, skip or retry an unexplained error" pattern charter #397 forbids, and the unguarded unlink converts a read-only cache into a fatal error.
  3. Major system-level consequence — a divergent rank 1 now forces every job's re-preparation on all ranks via changed computed over all gathered ranks (ignition/preparation/collectives.py:436-440) while configs holds only locally divergent entries (:441-449), consumed by ignition/preparation/tuning.py:521-535; it multiplies the cost of the very retry loop (#651) the PR aims to end.

Lesser findings: the forward-cache key hashes ambient B12X_* while only the recipe mapping crosses to peers (hosts silently fork the cache; the exclusion list is a denylist so future knobs fork by default); reconcile keys on (name, variant, component_id) while agree_selections keys on bare name and reconcile is unscoped by operation group, contradicting its own docstring; HostRendezvous.prepare(..., b12x_environment=None) has no caller. Areas I verified as sound are listed at the end, plus a documentation gap against AGENTS.md:234.

I found no maintainer review, and no evidence that this diff ran on 2× GB10; the two hardware comments on the PR validate the diagnosis and the manual workarounds, not this head.


F1 — Major: peer b12x_environment is applied after b12x.preparation is imported; the description's ordering claim is factually wrong

Citations: ignition/cli/serve.py:547-555, ignition/cli/environment.py:5-11 and :82, ignition/runtime_patches/__init__.py:119, ignition/runtime_patches/workers.py:26-29, ignition/preparation/host_ranks.py:645-648, :666-668, :297, :313-326.

PR text (What changed → peer propagation): "HostRendezvous.prepare sends non-empty b12x_environment ahead of assignment unpickling (so import-time reads see it)".

ignition/cli/serve.py:547-555 (verbatim):

    environment.apply(configuration, (gpu,))
    identity = source_identity()
    control, executor = knock(args.rendezvous, args.rank, args.ranks, identity=identity,
                              topology=local_topology(gpu), report=progress)
    serve_peer(control, executor, args.rank, args.ranks, hub_cache=hub_cache, progress=progress,
               export_staging=configuration.directory("export_staging"), identity=identity,
               core_cache=configuration.directory("core_cache"),
               kernel_cache=configuration.directory("kernel_cache"),
               checkpoint_token_file=configuration.get("preparation.checkpoint_token_file").value)

environment.apply ends with runtime_patches.apply() (ignition/cli/environment.py:82), which calls workers.register_hooks() (ignition/runtime_patches/__init__.py:119), which does from b12x.preparation import register_worker_initializer (ignition/runtime_patches/workers.py:27). The peer env only arrives afterwards, inside serve_peer:

ignition/preparation/host_ranks.py:645-648
        command = receive_object(control)
        if isinstance(command, tuple) and command[0] == "b12x-environment":
            os.environ.update(_validate_b12x_environment(command[1]))
            command = receive_object(control)

The contract that makes this a defect is stated in ignition/cli/environment.py:5-11: "PyTorch, b12x, Triton, and the CuTe DSL read these variables when they are imported or first used. apply sets the environment before installing runtime patches." Rank zero gets its recipe env at ignition/cli/serve.py:211 (environment.apply(configuration, local, plan.recipe.b12x_environment)) before apply installs patches; a peer gets it after. Any B12X_* variable that b12x caches at import time therefore still differs between rank zero and peers — the exact asymmetry #668 claims to remove.

The accurate statement of what the code does: the peer env precedes the recipe/operator imports and preparation, because those happen later at host_ranks.py:665 (assignment = receive_object(control)) and :670 (prepare = assignment["prepare"]). That is sufficient for B12X_W4A16_A4_PREFILL, which is read from os.environ during preparation, and explains why the two 2× GB10 comments on the PR see the expected speedup. It is not sufficient for anything read at b12x import time.

Consequence: assignment["b12x_environment"] re-application at host_ranks.py:666-668 is dead weight — it can only re-set what the early frame already set (prepare sends exactly the same validated mapping at :345-347), so there is no second chance, just a redundant write.

Fix (the dropped #675 ordering): validate and reply with the mapping in _admit (host_ranks.py:276-299; the reply at :297 is currently send_json(sock, {"accepted": True, "session": self.session})), and in join run knock() first, then environment.apply(configuration, (gpu,), b12x_environment), then serve_peer. Failing that, correct the description and document the invariant "peer env is not visible to b12x.preparation's import" — no doc currently records it (search_code over docs/ for b12x_environment|reconcile_selections returns nothing).


F2 — Major: _CORRUPT_ARTIFACT_ERRORS swallows transient and genuine errors and deletes the artifact

Citations: ignition/preparation/aot.py:64-76, :1371-1380, :1377; test tests/preparation/test_forward_cache_sources.py:194-217.

aot.py:64-76
_CORRUPT_ARTIFACT_ERRORS = (
    EOFError,
    pickle.UnpicklingError,
    struct.error,
    zlib.error,
    zipfile.BadZipFile,
    OSError,
    ValueError,
    TypeError,
    KeyError,
    AttributeError,
    RuntimeError,
)
aot.py:1371-1380
    def _load(self, forward, path, *, required=False, before_run=None):
        try:
            with bind_device(self.device, freeze_tuning=self.options.get(
                    'triton.autotune_at_compile_time', False)), path.open('rb') as file:
                artifact = torch.compiler.load_compiled_function(file)
        except _CORRUPT_ARTIFACT_ERRORS as error:
            if required or isinstance(error, (MemoryError, torch.OutOfMemoryError)):
                raise
            Path(path).unlink(missing_ok=True)
            return None

Two concrete impacts:

Fix: narrow the tuple to true deserialization errors (EOFError, pickle.UnpicklingError, struct.error, zlib.error, zipfile.BadZipFile, a short allowlist of torch archive errors), log the swallowed exception at warning level with the path, and wrap the unlink (try: Path(path).unlink(missing_ok=True) except OSError: pass).

Also (Minor, claim accuracy): the MemoryError arm at :1377 is dead — MemoryError is a subclass of neither listed type (only torch.OutOfMemoryError subclasses RuntimeError). The appended test test_forward_cache_recovers_from_corrupt_cached_bin_on_restore (tests/preparation/test_forward_cache_sources.py:212-217) monkeypatches load_compiled_function to raise MemoryError and asserts it propagates, which it does trivially because MemoryError is outside _CORRUPT_ARTIFACT_ERRORS; the assertion does not exercise the :1377 branch it claims to cover. The description's "while still raising on … MemoryError / torch.OutOfMemoryError" therefore overstates what the code does for MemoryError (it raises by omission, not by design).


F3 — Major: widened mismatch detection makes every rank re-prepare every job, with an empty override map on the ranks that agreed

Citations: ignition/preparation/collectives.py:436-449, ignition/preparation/tuning.py:521-535, evidence in tests/preparation/test_tuning_shards.py:264-324.

collectives.py:436-449
        changed = any(
            (target := target_for(decl_key, name_key)) is not None and payload != target[0]
            for rank_entries in gathered
            for decl_key, name_key, payload, _ in rank_entries
        )
        configs = {}
        for plan, decl_key, name_key, payload, _ in entries:
            target = target_for(decl_key, name_key)
            if target is not None and payload != target[0]:
                target_payload, config = target
                if plan in configs and plan.contract.config_payload(configs[plan]) != target_payload:
                    raise ValueError("one plan has conflicting rank-shared configurations")
                configs[plan] = config
        return configs, changed
tuning.py:521-535
            if (self._coordinator is not None and len(self._coordinator.ranks) > 1
                    and (self.tuning_replica is None or self.tuning_replica.index == 0)):
                configs, changed = self._coordinator.reconcile_selections(requests)
                if changed:
                    if shard_ranks is not None:
                        self.configure_tuning_shard(0, (0,))
                    try:
                        for job in self._jobs(requests):
                            plans = {plan for request in job for plan in iter_plans(request)}
                            results.append(self._coordinator.prepare(self, job, progress=progress,
                                autotune=self.autotune,
                                selected_configs={plan: config for plan, config in configs.items() if plan in plans}))

changed is computed over all gathered ranks (so all ranks enter the pass in lockstep — that part is correct and deliberate), but configs only holds entries where this rank's payload differs from the target. In the exact #651 GLM-5.3 TP2 case the new 2-rank test in this PR asserts this asymmetry directly: rank 0 ends with configs == {} while rank 1 gets both entries. Rank 0 then re-runs prepare(..., autotune=self.autotune, selected_configs={}) for every job — i.e. it re-enters autotuning with no overrides, only to re-derive the selections it already had, while rank 1 re-prepares with the adopted config. The PR widens the trigger ((request.name, variant, component_id) matches now reconcile payloads that the old portable_declaration-only rule ignored — the dossier's 1,648 differing selections on the real hardware), so this wasteful full re-prepare fires on cases that previously did not reach the pass at all.

Fix: pass the rank's own already-agreed selection for each plan in configs for every plan in plans (from request.plan.selection), so the reconcile pass re-binds rather than re-races, and/or pass autotune=False on this second pass. At minimum, the description's "Expected result" should state that one divergent rank costs all ranks a full re-preparation pass, rather than implying convergence is cheap.


F4 — Minor: forward-cache identity hashes ambient B12X_*, but peers only receive the recipe-declared mapping

Citations: ignition/preparation/aot.py:79-87, :897-899, :47-62; ignition/preparation/host_ranks.py:201-209; ignition/cli/serve.py:193-197, :416-420.

aot.py:897-899
        key = hashlib.sha256(pickle.dumps((namespace, options, _b12x_forward_env(), torch_key(),
            runtime_patches.identity(), properties.name, properties.major, properties.minor,
            properties.multi_processor_count)))

_b12x_forward_env() (:79-87) reads os.environ on the local host. The peer side only ever receives the validated recipe mapping — _validate_b12x_environment rejects non-B12X_ names, B12X_COMPILE_CACHE_DIR and non-string values (host_ranks.py:205-208), and rank zero sends model.recipe.b12x_environment (serve.py:197, :420). So a B12X_* variable exported in rank zero's shell changes rank zero's ForwardCache.root and not the peers'.

Impact: the stated goal ("distinct hosts with different cache paths keep identical forward-cache root names") holds for filesystem paths, but the same divergence re-enters through the environment — heterogeneous hosts silently fork the forward cache, losing the peer transfer that _share_artifacts exists to provide, and each fork recompiles the catalog. The exclusion list _NON_EXECUTION_B12X_ENV (aot.py:47-62) is a denylist, so any future B12X_* diagnostic knob not added to it forks the cache by default (with a full one-time recompile as the failure mode — the description even accepts this for existing knobs).

Fix: hash the recipe's declared b12x_environment mapping (already transported to peers, so rank zero and peers agree by construction) instead of ambient os.environ; or make the exclusion list an allowlist of execution-relevant names.


F5 — Minor: reconcile keys differ from agree_selections keys and are unscoped by operation group

Citations: ignition/preparation/collectives.py:218, :377-392, :398-410, :429-434, docstring :399-406, error text :394-396.

_selected_plan_catalog now records (plan, decl_key, (name, variant, plan.component_id), payload, config) (:218), and target_for prefers the name key (:429-434); agree_selections compares bare names: local = {item["name"]: (item["component"], json.dumps(...)) (:377) scoped by self.operation_ranks (:381-392). Two consequences:

Fix: derive both keys from one function so reconcile and agree cannot disagree about "the same selection"; replace "rank zero" with "the operation's first rank" in the docstring and error text; scope the gather by self.operation_ranks like agree_selections does.


F6 — Minor: HostRendezvous.prepare(..., b12x_environment=None) has no caller

Citations: ignition/preparation/host_ranks.py:313-326; sole caller ignition/preparation/rank_group.py:278-290.

host_ranks.py:313-326
    def prepare(self, snapshot, config, prepare, *, checkpoint, progress=None, core_storage=None,
                b12x_environment=None):
        ...
        b12x_env = (self.b12x_environment if b12x_environment is None
                    else _validate_b12x_environment(b12x_environment))

rank_group.prepare_group calls ranks.prepare(snapshot, config, prepare, checkpoint=checkpoint, progress=progress, core_storage=core_storage) (rank_group.py:289) and never passes the new kwarg, so the override path is dead and the two env sources (constructor vs per-call) can silently diverge. The description's "wired from model.recipe.b12x_environment in _export_hosts and debug_serve" is true only via the constructor (serve.py:197, :420). Either drop the parameter or thread it from prepare_group.


Tests and claim accuracy

Verified sound (no finding)

Open questions

Not found: maintainer review or assignment; CI conclusion for d6a00698; any 2× GB10 run of this head; any doc/CHANGELOG entry for the peer env channel or peer-local kernel_cache remap; any coordination note on ordering with the open aot.py PRs #597/#678 and host_ranks.py/test PR #671.