Review of PR #574 — lens D (simplicity): "Strip unguarded attributes from hyperflare_recipes objects in AOT guard serialization"
Key findings
The production change is genuinely minimal: one character-level addition to one predicate, no imports, no option, no fallback (ignition/preparation/forward_metadata.py:42). In this lens the production side is clean. The problems are (a) the same module-prefix allowlist already exists a second time in core ignition and this PR leaves it diverged (ignition/preparation/rebuild_manifest.py:365), (b) the hardcoded package list is the wrong shape for a project that officially supports third-party recipe repositories (AGENTS.md:379-393), and (c) the new 53-line test does not assert the stripping it is named for and re-tests behaviour an existing test already covers (tests/preparation/test_guard_code.py:277-302 vs :124 and :232-249). Two nits in the same test (dead class attribute plus a leaked class mutation, an avoidable wrapper class).
Nothing to report for other simplicity concerns: the diff adds no configuration switch, no compatibility layer, no parallel execution path, and no comment bloat. It also keeps the core boundary intact — the predicate matches on the __module__ string only, so ignition still never imports hyperflare_recipes (tests/preparation/test_core_boundary.py:39-47), and the new test uses a synthetic sys.modules entry rather than a real import (:281-285), satisfying :50-58.
No prompt-injection attempt or instruction-shaped content was found in the PR description, title, or comments.
Findings
1. Should fix — the module-prefix allowlist now exists twice in core ignition and has already diverged
ignition/preparation/forward_metadata.py:42 (changed) vs ignition/preparation/rebuild_manifest.py:365 (untouched)
weight_views walks prepared weight owners and has its own independent copy of the same predicate:
# ignition/preparation/rebuild_manifest.py:362-369
elif is_dataclass(value) and not isinstance(value, type):
...
elif type(value).__module__.startswith(('b12x.', 'ignition.')) and hasattr(value, '__dict__'):
owner = f'{type(value).__module__}.{type(value).__qualname__}'
children = ((f'.{key}', child) for key, child in vars(value).items())
else:
return
This PR updates only forward_metadata.py, so after the merge the tuple reads ('ignition.', 'b12x.', 'hyperflare_recipes.') in one file and ('b12x.', 'ignition.') in the other. A hyperflare_recipes.* weight holder that is not an nn.Module or a dataclass falls into the else: return branch at :368-369 and is silently skipped — no tensor views yielded, so rebuild_weights_metadata (:441-459) produces no entries for it, and the catalog built at runtime_core.py:130 / :368 omits those weights.
Why it matters for this lens: the divergence is the defect, not just the omission. The identical bug that motivated this PR (a package move out of ignition. silently defeating a prefix check) is still live in a second call site, and neither call site gives a maintainer any hint that a second list exists. The next package move repeats this exactly.
Fix (smaller version): hoist one module-level constant, e.g.
OWNED_MODULE_PREFIXES = ('ignition.', 'b12x.', 'hyperflare_recipes.')
in one module and import it at both sites. The change then lives on one line of one file, the two sites cannot drift, and whether weight_views should traverse recipe objects becomes a visible, reviewable decision rather than an omission.
Note in the PR's favour: rebuild_weights_metadata returns _declared_metadata(roots) for a WeightDeclaration (:445-446), and declare_weights (:86-106) is the declared path. If every real recipe reaches the catalog through declare_weights, then rebuild_manifest.py:365 does not need extending at all — in which case say so and share the constant anyway, so the asymmetry is deliberate and documented. That distinction is only settleable by a test with an undeclared hyperflare_recipes.* root.
2. Should fix — a hardcoded package list is the wrong shape for a project whose stated contract includes external recipe repositories
ignition/preparation/forward_metadata.py:42
AGENTS.md:379-384 states: "Official model recipes live in local-inference-lab/hyperflare-recipes (hyperflare_recipes/recipes/), and external recipe repositories can pass their own Recipe tuples directly to ignition.cli.main(...)." ignition/cli/__init__.py:367-374 implements exactly that, accepting recipes and source_roots; tests/cli/test_recipe_injection.py:95 exercises it with source_roots=(("external_recipes", pkg),).
So a prepared non-nn.Module object under external_recipes.* (or any other injected package) will still raise the very PicklingError: Can't pickle <class 'triton.compiler.compiler.CompiledKernel'> this PR exists to fix, and each new package name needs another one-line PR to this tuple. That is a growing allowlist, which AGENTS.md:188-193 treats as churn ("Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement") — here the concrete requirement is already documented at :381-382.
Smallest general version, needing no import and no plugin discovery (which AGENTS.md:392-393 forbids): key on structure rather than on a package name. _uses_custom_object_state already checks hasattr(value, '__dict__'), not inspect.isclass(value) and not isinstance(value, _NON_OBJECT_NEW_TYPES) (:41-44); dropping the module-prefix clause keeps every one of those guards, and the stripping itself is bounded downstream because _GuardPickler.reducer_override turns every attribute not in guard_tree_values into _Missing('unguarded attribute') (ignition/preparation/aot.py:157-160), and unguarded tensors already become _Missing at aot.py:126-128. So widening does not weaken guard checks; it only changes which objects get their unguarded attributes dropped instead of being handed to super().reducer_override.
If widening the predicate is judged too risky for this PR, the minimum acceptable version of this finding is: keep one constant (finding 1) and state in the code why third-party recipe modules are excluded — right now the tuple reads as if hyperflare_recipes. were the last package that will ever hold prepared objects. Only a test can settle this; adding a recipe-injected prefix case (a synthetic external_recipes.* module, exactly the technique already used at :281-285) to test_guard_code.py would settle it.
3. Should fix — the new test does not assert the stripping it is named for and duplicates an existing round-trip test
tests/preparation/test_guard_code.py:277-302
The test is named test_guard_pickler_strips_unguarded_attributes_from_recipe_objects, but it never asserts that the unguarded handle was stripped. _RecipeKernelOwner carries compiled_handle = _UnpicklableHandle() (:262), whose __reduce__ raises (:252-254) — yet the test only asserts output parity (:297) and guard invalidation True -> False -> True (:298-302). It would pass even if compiled_handle were restored as a live _UnpicklableHandle; it only proves the pickler did not crash, not that the attribute became _Missing. Contrast the existing test at :124, which does assert it: assert isinstance(restored.unguarded, _Missing).
The rest of the body is redundant. test_guard_serialization_roundtrips_tensor_user_attributes (:232-249) already covers exactly torch.compile + aot_compile + serialize + deserialize + torch.testing.assert_close + guard-invalidation, against a different owner type. So 53 added lines buy only the prefix match.
Smaller and stronger version (~12 lines), using the helper already in the file (:91-100):
def test_guard_pickler_strips_unguarded_attributes_from_recipe_objects(monkeypatch):
module = types.ModuleType("hyperflare_recipes.components._synthetic_guard_test")
module._RecipeKernelOwner = _RecipeKernelOwner
monkeypatch.setitem(sys.modules, module.__name__, module)
monkeypatch.setattr(_RecipeKernelOwner, "__module__", module.__name__)
owner = _RecipeKernelOwner(3)
restored = _roundtrip_guard(owner, guard_tree_values={id(owner): owner})
assert restored.scale == 3
assert isinstance(restored.compiled_handle, _Missing)
This drives _GuardPickler.reducer_override → _uses_custom_object_state (aot.py:155-165) directly, so it fails against the pre-fix predicate (the object falls through to super().reducer_override and the unpicklable handle propagates), it asserts the behaviour in the test's own name, and it drops a second torch.compile graph from the suite. AGENTS.md:194-196 requires tests that "exercise the affected behavior or contract"; asserting _Missing is what does that here.
4. Nit — dead class attribute and a leaked class mutation in the new test
tests/preparation/test_guard_code.py:258 and :281-285
__module__ = "hyperflare_recipes.components.synthetic" in the class body (:258) is overwritten at :283 with "hyperflare_recipes.components._synthetic_guard_test", so the body value is dead as soon as the test runs — and after it runs once, the value a reader sees at :258 is not the one in play.
Worse, :283 is a plain assignment on the class object, and monkeypatch does not undo it: monkeypatch.setitem(sys.modules, ...) (:285) restores only the sys.modules entry, so _RecipeKernelOwner.__module__ keeps pointing at a module that no longer exists for the remainder of the session. Any later test that pickles that class would fail in a confusing, order-dependent way.
Fix: delete :258 and use monkeypatch.setattr(_RecipeKernelOwner, "__module__", module_name). Separately, import types at :278 is a local re-import (the same style appears at :205), but types belongs with io/pickle/subprocess/sys at :6-9; a module-level import is one line instead of two.
5. Nit — the _RecipeForward wrapper is padding
tests/preparation/test_guard_code.py:268-274
_RecipeForward exists only to hold one tensor and the owner:
class _RecipeForward:
def __init__(self, scale):
self.value = torch.ones(2)
self.owner = _RecipeKernelOwner(scale)
def __call__(self):
return self.owner.apply(self.value)
Compiling against the owner directly — the pattern already used at :222-249, where _AnnotatedTensorForward is both the compiled subject and the thing whose attributes matter — removes a class and puts the reason the test exists (the owner's module prefix) in the first line a reader sees. This nit disappears entirely if finding 3's _roundtrip_guard version is taken.
What is clean in this lens
- The production diff adds no option, flag, fallback, compatibility shim, or parallel path; it does not import
hyperflare_recipesand does not touch_ForwardPickler's other behaviour (forward_metadata.py:277reuses the same predicate and needs no separate change — a single predicate call site pair, not a duplicated rule). - Core-boundary compliance holds:
tests/preparation/test_core_boundary.py:39-47inspects actual imports only, and the match here is a string comparison;:50-58is satisfied because the test creates a synthetic module (:281-285) instead of importing one. - The description is accurate and scoped ("No runtime, core-format, or Helios behavior changes"), and the stated caveat (the unit-test run predating the rebase onto
167f22c8) is honest; CI has no checks on the head commit16ffc6f, so the caveat is unresolved.
Open questions / not verified
- Whether any real
hyperflare_recipes.*weight holder reachesweight_viewswithout aWeightDeclaration(finding 1's "does:365need extending at all" branch) can only be settled by a test; the local copy has no such case. - I did not run the test suite; all behavioural claims about the new test are read from the code (
:252-302) against the pickler (aot.py:118-166). Runningpytest tests/preparation/test_guard_code.py tests/preparation/test_core_boundary.pyon the rebased tip would confirm the PR's own caveat and would show whether finding 3's replacement test passes.