Key findings
PR #668 is a three-defect fix and most of it is justified, but it leaves five concrete subtractions — one new helper added without retiring four pre-existing copies, one duplicated transmission channel, one duplicated validation, one speculative fallback branch, and one dead parameter plus one dead except arm.
- The new
_save_compiled_functionhelper duplicates four existing inline atomic-save blocks and retires none —aot.py:90-100,aot.py:270-278,aot.py:870-877(which this PR rewrote and left inline),aot.py:1185-1193,compile_pool.py:115-123(byte-identical to the new helper). - The peer
b12x_environmentis sent twice and applied twice, and the second copy can never carry anything new —host_ranks.py:344-347,host_ranks.py:377,host_ranks.py:666-668. The new test only passes because it fabricates a scenario the real sender never produces (tests/preparation/test_host_ranks.py:410-415). _validate_b12x_environmentre-implementsRecipe.__post_init__—host_ranks.py:201-209vsignition/declaration.py:251-253; the only genuinely new rule is theB12X_COMPILE_CACHE_DIRexclusion._remap_peer_config's non-dataclasssetattrbranch is unreachable —host_ranks.py:212-219; every preparation config is a frozen dataclass (ignition/preparation/bootstrap.py:25-37), sosetattrraisesFrozenInstanceError.- Dead parameter and dead exception arm —
b12x_environment=NoneonHostRendezvous.prepare(host_ranks.py:313-314,:325-326) has no caller (rank_group.py:286), andisinstance(error, (MemoryError, …))(aot.py:1377) can never be true becauseMemoryErroris not in_CORRUPT_ARTIFACT_ERRORS(aot.py:64-76).
Everything else is lean: the request-name-first reconcile_selections rewrite and the _selected_plan_catalog name key are compact and idiomatic, and the 2-rank Gloo test is a good unit test. No doc updates, but that is a documentation finding, not a subtraction one.
1. New helper duplicates four existing inline atomic-save blocks; the PR even grew one of them
Evidence — the new helper (ignition/preparation/aot.py:90-100):
def _save_compiled_function(artifact, path):
"""Write a compiled forward archive via a sibling temporary file and atomic rename."""
path = Path(path)
path.parent.mkdir(parents=True, exist_ok=True)
with tempfile.NamedTemporaryFile(dir=path.parent, suffix='.tmp', delete=False) as file:
temporary = Path(file.name)
try:
artifact.save_compiled_function(str(temporary))
os.replace(temporary, path)
finally:
temporary.unlink(missing_ok=True)
The same dance already exists in four places, all in code this PR either touches or sits next to:
ignition/preparation/compile_pool.py:115-123— byte-identical includingartifact.save_compiled_function:
This ispath = Path(path) path.parent.mkdir(parents=True, exist_ok=True) with tempfile.NamedTemporaryFile(dir=path.parent, suffix='.tmp', delete=False) as file: temporary = Path(file.name) try: artifact.save_compiled_function(str(temporary)) os.replace(temporary, path) finally: temporary.unlink(missing_ok=True)_save_compiled_functioncopied across a module boundary —compile_pool.pyalready imports from.aotat line 104, so it could call the helper today.ignition/preparation/aot.py:270-278(guard build, in the same file):with tempfile.NamedTemporaryFile(dir=root, suffix='.tmp', delete=False) as file: temporary = Path(file.name) try: pickle.dump(result, file) file.close() os.replace(temporary, path) finally: temporary.unlink(missing_ok=True)ignition/preparation/aot.py:1185-1193(lent jobs, same file):with tempfile.NamedTemporaryFile(dir=jobs, suffix='.tmp', delete=False) as file: temporary = Path(file.name) try: pickle.dump((dumps(forward), str(path)), file) file.close() os.replace(temporary, job) finally: temporary.unlink(missing_ok=True)ignition/preparation/aot.py:870-877— this PR edited this block to add temp cleanup instead of replacing it with the helper it added 780 lines above:with tempfile.NamedTemporaryFile(dir=target.parent, suffix=".tmp", delete=False) as file: temporary = Path(file.name) try: file.write(payload[0]) file.close() os.replace(temporary, target) finally: temporary.unlink(missing_ok=True)
What to remove: add one _write_atomic(path, write) in aot.py where the write step is a callback (artifact.save_compiled_function, pickle.dump, file.write all fit write(file_or_path)), then delete the four inline bodies above and have compile_pool.py:115-123 call it. The diff currently adds a fifth copy of a six-line pattern; a fix that claims to make .bin persistence atomic should make it atomic in one place.
2. The peer b12x env is transmitted twice and applied twice; the second copy is unreachable
Evidence — early send (ignition/preparation/host_ranks.py:344-347):
with phase(progress, "Admit checkpoint range readers"):
if b12x_env:
for control in controls:
send_object(control, ("b12x-environment", b12x_env))
Same dict repeated in the assignment (host_ranks.py:375-377):
assignment = {"store": (self.address[0], self.store.port), "config": config, "prepare": prepare,
"exporting": core_storage is not None, "b12x_environment": b12x_env}
And re-validated and re-applied by the peer (host_ranks.py:666-668):
b12x_env = _validate_b12x_environment(assignment.get("b12x_environment"))
if b12x_env:
os.environ.update(b12x_env)
The early send is unconditional whenever b12x_env is non-empty and happens before the assignment for every control, so the assignment key can never deliver a binding the peer does not already hold. It is a second protocol command, a second _validate_b12x_environment call per peer, and a second undocumented channel for one setting.
What to remove: drop "b12x_environment": b12x_env from assignment and the three lines at :666-668; the :646-648 arm becomes the single apply site.
The new test hides this. tests/preparation/test_host_ranks.py:405-415 feeds the peer different values on the two channels:
commands = iter((
("b12x-environment", {"B12X_W4A16_A4_PREFILL": "1"}),
("checkpoint-source", None),
assignment,
"close",
))
with assignment carrying {"B12X_W4A16_SMALL_M_HOST_BARRIER_RESET": "0"} (:392-398) and the test then asserting both landed (:427-433). HostRendezvous.prepare can never produce that input — it sends the same dict twice. Once the redundant arm is removed, the test should assert one channel, which is honest and shorter.
3. _validate_b12x_environment re-validates what Recipe already guarantees
Evidence (ignition/preparation/host_ranks.py:201-209):
def _validate_b12x_environment(environment):
if not environment:
return {}
resolved = dict(environment)
if any(not isinstance(name, str) or not name.startswith("B12X_")
or name == "B12X_COMPILE_CACHE_DIR" or not isinstance(value, str)
for name, value in resolved.items()):
raise ValueError("b12x environment settings must map non-cache B12X_ names to string values")
return resolved
Already enforced upstream (ignition/declaration.py:251-253):
if any(not name.startswith("B12X_") or not isinstance(value, str)
for name, value in self.b12x_environment.items()):
raise ValueError("b12x settings name B12X_ variables with string values")
The only inputs are model.recipe.b12x_environment (ignition/cli/serve.py:197, :420), so the prefix and type checks are dead. The one rule that is genuinely new is the B12X_COMPILE_CACHE_DIR exclusion, because environment.apply already points that variable at the peer-local cache (ignition/cli/environment.py:47: "B12X_COMPILE_CACHE_DIR": str(kernel_cache / "b12x")), so forwarding it would undo the peer-locality this PR is trying to establish.
What to remove: collapse the function to the single exclusion, drop both dict(environment) copies (the assignment pickles the same mapping anyway):
def _peer_b12x_environment(environment):
if "B12X_COMPILE_CACHE_DIR" in environment:
raise ValueError("peer b12x environment must not redirect B12X_COMPILE_CACHE_DIR")
return dict(environment)
Rejecting a non-string value at rendezvous time on data the recipe type-checked is not a new guarantee; AGENTS.md's ban on strengthening-by-duplication applies.
4. _remap_peer_config's non-dataclass branch is speculative and unreachable
Evidence (ignition/preparation/host_ranks.py:212-219):
def _remap_peer_config(config, *, kernel_cache):
if config is None or kernel_cache is None or not hasattr(config, "kernel_cache"):
return config
local_cache = Path(kernel_cache)
if is_dataclass(config) and not isinstance(config, type):
return replace(config, kernel_cache=local_cache)
setattr(config, "kernel_cache", local_cache)
return config
Every preparation config derives from BasePreparationConfig, a frozen dataclass (ignition/preparation/bootstrap.py:25-37):
@dataclass(frozen=True)
class BasePreparationConfig:
...
kernel_cache: Path | None = None
setattr on it raises FrozenInstanceError, so the fallback path is never reachable in production and is only kept alive by the is_dataclass/setattr imports this PR adds at host_ranks.py:35 (from dataclasses import dataclass, is_dataclass, replace). The test only exercises the dataclass path (test_host_ranks.py passes a real BasePreparationConfig).
What to replace it with:
def _remap_peer_config(config, *, kernel_cache):
if config is None or kernel_cache is None or not hasattr(config, "kernel_cache"):
return config
return replace(config, kernel_cache=Path(kernel_cache))
and reduce the import back to from dataclasses import dataclass, replace. A frozen-config fallback that cannot run is exactly the "speculative compatibility / fallback layer" AGENTS.md tells authors not to add.
5. Dead parameter and dead exception arm
(a) The b12x_environment override on prepare has no caller (host_ranks.py:313-314 and :325-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))
The only call site is ignition/preparation/rank_group.py:286:
return ranks.prepare(snapshot, config, prepare, checkpoint=checkpoint, progress=progress,
core_storage=core_storage)
Nothing anywhere passes b12x_environment= (grep confirms the only occurrences are host_ranks.py:314, :325-326 and the constructor). Remove the kwarg and use self.b12x_environment; the rendezvous already validated it in __init__ (:233), so the ternary and its second validation go with it.
(b) MemoryError in the corrupt-load guard can never be true (aot.py:1376-1377):
except _CORRUPT_ARTIFACT_ERRORS as error:
if required or isinstance(error, (MemoryError, torch.OutOfMemoryError)):
MemoryError is not a subclass of any member of _CORRUPT_ARTIFACT_ERRORS (aot.py:64-76: EOFError, pickle.UnpicklingError, struct.error, zlib.error, zipfile.BadZipFile, OSError, ValueError, TypeError, KeyError, AttributeError, RuntimeError), so an except _CORRUPT_ARTIFACT_ERRORS block can never bind a MemoryError. Only torch.OutOfMemoryError (a RuntimeError) is live here. Drop MemoryError from the tuple.
The subtraction point behind that guard: it exists only because RuntimeError/OSError/ValueError/TypeError/KeyError/AttributeError were added to the catch tuple, which makes the arm broad enough that OOMs have to be carved back out. The Correctness lens owns whether that breadth is safe; from a simplicity standpoint the tidier shape is a narrow tuple of genuine deserialization failures (EOFError, UnpicklingError, struct.error, zlib.error, BadZipFile, plus the OSError-on-truncated-read case if the author can justify it) and no ad-hoc isinstance re-narrowing at the call site.
Secondary (follow-up, not blocking): the b12x blacklist
_NON_EXECUTION_B12X_ENV (aot.py:47-62) is a 14-name frozenset plus a B12X_LOG_ prefix rule in _b12x_forward_env (aot.py:79-87), i.e. an opt-out list where every future b12x knob silently lands on the execution-relevant side and re-keys every host's forward cache. The recipe already declares exactly the settings it prepares with (ignition/declaration.py:231, documented at :205-207) and this PR now ships that declared set to peers, so keying ForwardCache on the declared bindings would delete the blacklist. Caveat: ForwardCache is constructed at ignition/preparation/capture.py:118 (not opened), which may not have the recipe in hand, so this is a design follow-up rather than a change to request in this PR.
What is already lean (no change requested)
- The request-name-first
reconcile_selections(ignition/preparation/collectives.py:398-449) and the_selected_plan_catalogname key (:209-224) are compact: onetarget_forclosure used by both thechangedflag and the returnedconfigs, which is the right shape for keeping ranks in lockstep. It computestarget_forin two traversals rather than one, but that is clearer than the alternative and not worth churn. - The 2-rank Gloo test (
tests/preparation/test_tuning_shards.py:262-325) is a legitimate multi-rank test of the reconcile contract. - The three
.binsave-site replacements and the_share_artifactscleanup are correct in intent; the only objection is that they should have been one shared helper (finding 1).
Open questions
- Whether the author intends the assignment copy of
b12x_environmentas protocol redundancy (a retry path if the early command is lost) — nothing in the code or description says so, and no reader can tell from the two apply sites which one is authoritative. - Whether
_remap_peer_config'ssetattrbranch was kept for a config type outsideignition/preparationthat prepares throughserve_peer; I found none in the repo, but the branch implies the author had one in mind. - Whether the broadened
_CORRUPT_ARTIFACT_ERRORS(includingOSError/RuntimeError/TypeError/KeyError/AttributeError) was required by an observed corrupt-cache failure mode or added defensively; the PR describes "truncated or corrupt.bin" but does not say which exception the truncation actually produced. - No AGENTS.md line numbers are cited above because the file was read during earlier research rather than in this pass; the rules referenced are the module's standing guidance against speculative compatibility/fallback layers and against duplicating validation.