Review of PR #574 — Strip unguarded attributes from hyperflare_recipes objects in AOT guard serialization
Correctness lens. Head 16ffc6f, base main, 2 files, +54/−1 (ignition/preparation/forward_metadata.py, tests/preparation/test_guard_code.py). No reviews, no CI checks on the head commit. Author fordbmorris (Discord woooflet).
Key findings
- No blocking defect. The change is a one-token widening of an allowlist in
_uses_custom_object_state(ignition/preparation/forward_metadata.py:39-45). Objects underignition.*andb12x.*take exactly the same path before and after, so no existing guard-state format, core format, or persisted artifact changes. - Should fix: the fix is keyed to the literal string
'hyperflare_recipes.'even though external recipe repositories are a documented, supported configuration (AGENTS.md:379-384;ignition/cli/__init__.py:367(not opened),ignition/preparation/source_identity.py:12-25,43). Any other external recipe package still reproduces the exact failure this PR reports. - Should fix (conditional): the widened prefix applies an ignition-internal pickling contract (
object.__new__+vars(obj)) to classes owned by another repository, bypassing their__getstate__/__reduce__and any__slots__state (ignition/preparation/aot.py:98-99,157-165). - Nits: a sibling allowlist in
rebuild_manifest.py:365was not widened, leaving the two lists out of step; plus four small test-hygiene/coverage nits. - Positive checks worth recording: the new test genuinely fails without the fix; the core-boundary test cannot be violated by a string literal; and the guard-code cache cannot serve stale guards for the new payload shape.
What the change does (verified in context)
_uses_custom_object_state (ignition/preparation/forward_metadata.py:39-45) returns true only when the value has __dict__, its class __module__ starts with an allowed prefix, it is not a class, and it is not in _NON_OBJECT_NEW_TYPES (lines 33-36). The diff changes one prefix tuple on line 42:
and type(value).__module__.startswith(('ignition.', 'b12x.', 'hyperflare_recipes.'))
There are exactly two consumers of the predicate (grep over the tree):
_GuardPickler.reducer_override— ignition/preparation/aot.py:155-166:
withfrom .forward_metadata import _uses_custom_object_state if _uses_custom_object_state(obj): state = {key: value if id(value) in self.guard_tree_values else _Missing('unguarded attribute') for key, value in vars(obj).items()} ... return _guard_object, (type(obj),), state return super().reducer_override(obj)_guard_object(cls) = object.__new__(cls)at aot.py:98-99. Guarded values (those still reachable from the guard tree) are kept; every other attribute becomes_Missing, which is what removes the unpicklable Triton handle._ForwardPickler.reducer_override— forward_metadata.py:277-278, additionally gated onhasattr(type(value), '__getattr__'). A plain prepared recipe object has no instance-level__getattr__on its type, so for such objects the widened prefix changes nothing here. The PR description's claim that recipe objects "serialize and deserialize AOT guard states cleanly" holds for the guard-state path only; the forward-metadata path is not exercised by the new test.
Findings
Should fix — the fix is keyed to one package name, not to the supported configuration
ignition/preparation/forward_metadata.py:42
The allowlist enumerates the single literal prefix 'hyperflare_recipes.'. The repository documents arbitrary external recipe repositories as supported, not just the official one:
- AGENTS.md:379-384 — "Official model recipes live in
local-inference-lab/hyperflare-recipes(hyperflare_recipes/recipes/), and external recipe repositories can pass their ownRecipetuples directly toignition.cli.main(...)." ignition/cli/__init__.py:367(not opened) —def main(argv=None, *, recipes=(), prog="ignition", source_roots=()), binding arbitrary roots viasource_identity.source_roots(line 368-373).ignition/preparation/source_identity.py:12-25,43—_EXTRA_ROOTScontextvar andcombined_roots = (*_EXTRA_ROOTS.get(), *extra_roots), i.e. any labelled external source tree is mixed into the source identity by design.
Why it matters: for an external recipe package whose module name is not hyperflare_recipes, the precise defect in the PR's own "Why" still reproduces — PicklingError: Can't pickle <class 'triton.compiler.compiler.CompiledKernel'> during aot_forward guard serialization whenever a prepared non-nn.Module object retains a compiled handle. The bug class is narrowed to one package, not closed, and each new recipe repo would need a core-Ignition edit — against AGENTS.md's instruction to keep core small and model-agnostic (charter line 12; AGENTS.md:389-393).
Fix (either): (a) drive the predicate from the roots the CLI already receives — e.g. bind the external package prefixes/labels alongside source_roots (source_identity.py:12-25) and match against that set in _uses_custom_object_state; or (b) follow the repo's own convention for externally owned types, explicit registration as done for container/buffer declarations in rebuild_manifest.py:41-71 (declare_container_fields, weight_container, declare_module_buffers).
Should fix (conditional) — the widening imports an ignition-only pickling contract into externally owned classes
ignition/preparation/aot.py:157-165, with _guard_object at aot.py:98-99
For every matched object the guard pickler now emits (_guard_object, (type(obj),), state) where state is a vars(obj)-shaped dict, and _guard_object is object.__new__(cls). Consequences for hyperflare_recipes.* classes, none of which exist in this repository to check:
- A class with a custom
__reduce__/__getstate__is bypassed entirely; whatever transformation it relies on is skipped and its raw__dict__is pickled instead (values not inguard_tree_valuesbecome_Missing). - On load, pickle's BUILD step calls
obj.__setstate__when the class defines one. Becausestateis a plainvars()dict (with_Missingplaceholders), a recipe class whose__setstate__expects the shape produced by its own__getstate__will receive the wrong shape and can raise — turning a guard-serialization path into a load-time failure rather than a clean strip. - Slot-stored state is not covered at all:
_uses_custom_object_staterequireshasattr(value, '__dict__')(forward_metadata.py:41), so a slots-onlyhyperflare_recipes.*class holding a compiled handle still falls through to the default reducer and can still raise the originalPicklingError.
That contract (object.__new__ + vars()) holds for ignition./b12x. classes in this repository because they are written against it; it is not established for classes owned by another repo. Nothing in this repository demonstrates a current break — only a recipe-side class using __slots__, or pairing a custom __getstate__/__setstate__, would reveal it. Fix: document the required state contract for recipe classes in the docstring of _GuardPickler (aot.py:102-103) and, ideally, also match slot state (__slots__/__dict__ union) so the strip is complete; or coordinate a matching contract note with the hyperflare-recipes repo. A recipe-side unit test using a __slots__ + __setstate__ class would settle it.
Nit — the sibling allowlist was not widened, so the two lists disagree
ignition/preparation/rebuild_manifest.py:365
elif type(value).__module__.startswith(('b12x.', 'ignition.')) and hasattr(value, '__dict__'):
This is the second, independent copy of the same prefix knowledge (grep shows only these two sites: forward_metadata.py:42 and rebuild_manifest.py:365). It gates the weight-view walk that feeds rebuild_weights_metadata (rebuild_manifest.py:441-459), consumed from runtime_core.py:367-369. After this PR a hyperflare_recipes.* owner is guard-serializable but still invisible to that walk, so tensors owned by such objects are silently omitted from — or reported unavailable in — the rebuild catalog. Fix: extract the tuple into one shared constant/predicate and use it in both places, or confirm the documented WeightDeclaration path is the only supported one for recipe-owned weights and say so.
Nits — the new test (tests/preparation/test_guard_code.py:252-302)
- Line 283 mutates process-global class state.
_RecipeKernelOwner.__module__ = module_nameis a direct assignment; themonkeypatch.setitem(sys.modules, ...)on line 285 restores only the module entry, not__module__. After the test the class keeps ahyperflare_recipes.components._synthetic_guard_testmodule string whose module object is gone, which can confuse later pickling/repr in the same session. Usemonkeypatch.setattr(_RecipeKernelOwner, '__module__', module_name). (The class attribute at line 258,__module__ = "hyperflare_recipes.components.synthetic", is then immediately redundant with line 283 — the test never exercises that one.) - The fixture does not reproduce the reported error.
_UnpicklableHandle.__reduce__raisesTypeError(line 253-254), whereas the bug reported in the PR isPicklingErrorfromtriton.compiler.compiler.CompiledKernel. Raisingpickle.PicklingErrorwould make the regression test fail with the same signature as the field report. - Coverage is guard-states only. Only the
_GuardPicklerpath is exercised;_ForwardPickler(forward_metadata.py:277-278) is the second consumer and is additionally gated onhasattr(type(value), '__getattr__'), so the widened prefix cannot change its behaviour for a plain recipe object. Aforward_metadata.dumps/loadsround-trip on a recipe-like object would either close that gap or confirm it is a no-op and let the description say so. - Bool-identity assertions.
assert loaded.guard_check(forward) is True/is False(lines 298-302) assert identity, while the rest of the file asserts truthiness (lines 47-51, 248-249).guard_check's exact return type is not visible in this repo (call sites: aot.py:1160, tests/preparation/test_guard_code.py:50-51,248-249), sois Trueis a stricter claim than the surrounding tests make.
Verified positives (no action needed)
- Baseline behaviour unchanged. Only
hyperflare_recipes.*objects change path;ignition./b12x.objects produce byte-identical reductions, so existing guard states, core artifacts and persisted data are unaffected. The PR's "no runtime, core-format, or Helios behavior changes" claim is consistent with the diff. - The new test is discriminating. Without the added prefix,
_RecipeKernelOwnerfalls through toGuardsStatePickler.reducer_override, whose default reduction picklesvars(obj)including_UnpicklableHandle, whose__reduce__raises — so the test fails onmainand passes only with the fix. - Core boundary is intact.
tests/preparation/test_core_boundary.py:28-47walks AST imports only, so a new string literal cannot violate it, and core Ignition still never importshyperflare_recipes(AGENTS.md:389-393). - No stale-guard hazard from persisted state.
_guard_code_cache.buildkeys the on-disk binaries bysha256ofpickle.dumps((tuple(code_parts), closure_args))(aot.py:206-210) and writes atomically viaos.replace(aot.py:213-220). Changed pickled bytes for recipe objects therefore yield a cache miss and a new file, never a stale guard hit. - PR description has the four required parts (why / what changed / benefit / evidence) and honestly discloses that the unit-test run predated the rebase onto #509 ("Caveats / Limitations").
Open questions / not verifiable from this repository
- Rebased tip is unverified. The head commit has no CI checks, and the author's own caveat says
pytest tests/preparation/test_guard_code.py tests/preparation/test_core_boundary.pywas run before rebasing onto167f22c8, which moved_uses_custom_object_stateintoforward_metadata.py. Someone with a GPU runner (the evidence is ARM64 GB10 / Triton 3.8.0) should run both files on16ffc6f. I did not run them. - No
hyperflare_recipescode is in this repository, so I could not check whether any real recipe class (e.g. the citedPreparedResidualMixfor Inkling 2) uses__slots__, a custom__getstate__/__setstate__, or relies on object identity across a guard round-trip — which is exactly what decides whether the conditional should-fix above is live. ignition/cli/__init__.py:367(not opened) was read only through grep for the signature and thesource_rootsbinding; I did not audit the whole CLI path.- Beyond the diff, no callers of
_uses_custom_object_stateexist (grep: forward_metadata.py:42 definition, aot.py:155-157 and forward_metadata.py:277 use sites), so the blast radius of the change is fully covered above.