Review of PR #574 — lens D (simplicity): "Strip unguarded attributes from hyperflare_recipes objects in AOT guard serialization"
Head reviewed: 16ffc6f. Base main. 2 files, +54/−1.
Key findings
Verdict: should-fix issues only (no blockers in this lens).
The production diff is genuinely minimal by this lens and has nothing to subtract: ignition/preparation/forward_metadata.py:42 adds one string to an existing tuple. No option, flag, fallback, compatibility shim, parallel path, import or comment is added; _ForwardPickler (forward_metadata.py:277) reuses the same predicate rather than duplicating the rule, so one rule still has one owner. Core-boundary compliance holds — the check is a __module__ string comparison, so ignition still never imports hyperflare_recipes, per AGENTS.md:392-393 and tests/preparation/test_core_boundary.py:39-47.
What the lens does find is in the neighbourhood of the change and in the 53-line test:
- Should fix — the module-prefix allowlist now exists twice in core
ignition, and this PR has already diverged the two copies (forward_metadata.py:42vsrebuild_manifest.py:365). - Should fix — a hardcoded package list is the wrong shape for a contract that explicitly includes third-party recipe repositories (AGENTS.md:379-384), so
external_recipes.*still raises the samePicklingError. - Should fix — the new test never asserts the stripping it is named for, and re-tests what
test_guard_serialization_roundtrips_tensor_user_attributes(test_guard_code.py:232-249) already covers; ~12 lines do the job. - Nits ×3 — a dead class attribute plus a leaked class mutation, a local
import types, and an avoidable_RecipeForwardwrapper.
Findings
1. Should fix — the same module-prefix allowlist exists twice in core ignition, and this PR has diverged them
ignition/preparation/forward_metadata.py:42 (changed) vs ignition/preparation/rebuild_manifest.py:365 (untouched).
After this merge, forward_metadata.py:42 reads ('ignition.', 'b12x.', 'hyperflare_recipes.'), while weight_views keeps its own copy:
# ignition/preparation/rebuild_manifest.py:362-369
elif is_dataclass(value) and not isinstance(value, type):
owner = f'{type(value).__module__}.{type(value).__qualname__}'
children = ...
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
A hyperflare_recipes.* weight holder that is neither an nn.Module (:358) nor a dataclass (:362) falls into the anonymous else: return at :368-369 and yields no tensor views, so rebuild_weights_metadata (:441-459, iterating weight_views at :449) has no entries for it. That path is reached from ignition/preparation/runtime_core.py:112,130 and :286,368.
Why it matters: the exact class of bug that motivated this PR — a package move silently defeating a prefix check — is live in a second call site, and neither site tells a reader a second list exists. AGENTS.md:188-193 asks refactors to "remove a demonstrated source of defects".
Fix (smaller version): hoist one constant, e.g. OWNED_MODULE_PREFIXES = ('ignition.', 'b12x.', 'hyperflare_recipes.'), and import it in both modules; the change then lives in one line of one file and extending (or deliberately not extending) weight_views becomes a visible decision instead of an omission. If every real recipe weight object is reached through declare_weights (rebuild_manifest.py:86-106) and _declared_metadata (:445-446), :365 may not need extending at all — but say so, and share the constant anyway.
Settleable only by a test with an undeclared hyperflare_recipes.* root; the local copy has no real example to point at.
2. Should fix — a hardcoded package list is the wrong shape for a contract that includes third-party recipe repositories
ignition/preparation/forward_metadata.py:42.
AGENTS.md:379-384: official 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(...)". That is implemented: ignition/cli/__init__.py:367-375 accepts recipes and source_roots, and tests/cli/test_recipe_injection.py:78-98 exercises source_roots=(("external_recipes", pkg),) (:95).
Why it matters: a prepared non-nn.Module object under external_recipes.* still raises the very PicklingError this PR fixes, and every new injected package needs another one-line PR plus another test. AGENTS.md:188-193 rejects growing configuration/extension machinery without a concrete requirement; here the requirement is already documented at :381-382.
Fix, smallest general form (no import, no plugin discovery — which AGENTS.md:392-393 forbids): drop the module-prefix clause and keep the structural guards already present — hasattr(value, '__dict__'), not inspect.isclass(value), not isinstance(value, _NON_OBJECT_NEW_TYPES) (:41-44). Stripping stays bounded 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. If widening is judged too risky in this PR, the minimum is: one shared constant (finding 1) plus a comment in _uses_custom_object_state saying why third-party recipe modules are excluded.
Settleable by adding an external_recipes.* case to test_guard_code.py using the synthetic-sys.modules technique already in the file (:212-214).
3. Should fix — the new test does not assert the stripping in its own name, and duplicates an existing test
tests/preparation/test_guard_code.py:277-302 (the whole 53-line addition).
The name promises "strips unguarded attributes", yet nothing asserts that compiled_handle came back as _Missing; the test would pass if the handle were restored live and would only fail if pickling crashed. Contrast the in-file pattern at :124 (assert isinstance(restored.unguarded, _Missing)). The serialize → deserialize → output-parity → True → False → True guard block (:287-302) duplicates test_guard_serialization_roundtrips_tensor_user_attributes (:232-249) against a different owner type, so the 53 lines buy only the prefix match. AGENTS.md:194-196 requires tests that "exercise the affected behavior or contract"; asserting _Missing is what does that.
Smaller and stronger (~12 lines), replacing :268-302 and keeping _RecipeKernelOwner (:257-265):
def test_guard_pickler_strips_unguarded_attributes_from_recipe_objects(monkeypatch):
module_name = "hyperflare_recipes.components._synthetic_guard_test"
synthetic = types.ModuleType(module_name)
synthetic._RecipeKernelOwner = _RecipeKernelOwner
monkeypatch.setitem(sys.modules, module_name, synthetic)
monkeypatch.setattr(_RecipeKernelOwner, "__module__", module_name)
owner = _RecipeKernelOwner(3)
restored = _roundtrip_guard(
owner, guard_tree_values={id(owner): owner, id(owner.scale): owner.scale}
)
assert restored.scale == 3
assert isinstance(restored.compiled_handle, _Missing)
Two details make this correct: (a) owner.scale must be in guard_tree_values, otherwise it too is stripped to _Missing by aot.py:157-160 and restored.scale == 3 fails; (b) synthetic._RecipeKernelOwner = _RecipeKernelOwner is required because the class is serialized by reference (_guard_object, (type(obj),), aot.py:165) and pickle rejects a reference that sys.modules[module_name] does not resolve. It still fails against the pre-fix predicate: the object falls to super().reducer_override (aot.py:166), default state pickling reaches _UnpicklableHandle.__reduce__ (test_guard_code.py:252-254) and raises. It also avoids a second torch.compile graph in the suite.
4. Nit — dead class attribute and a leaked class mutation
tests/preparation/test_guard_code.py:258 and :283.
__module__ = "hyperflare_recipes.components.synthetic" in the class body (:258) is dead: :283 immediately overwrites it with ..._synthetic_guard_test, so the value a reader sees is never the one in play. Worse, :283 is a plain assignment that monkeypatch does not revert (monkeypatch.setitem at :285 restores only the sys.modules entry), so after the test _RecipeKernelOwner.__module__ points at a module that no longer exists — an order-dependent failure waiting for the next test that pickles this class.
Fix: delete :258 and use monkeypatch.setattr(_RecipeKernelOwner, "__module__", module_name) (as in the snippet above).
5. Nit — import types placement
tests/preparation/test_guard_code.py:278. A local re-import of a stdlib module used by two tests in this file; types belongs with io/pickle/subprocess/sys at :6-9 — one module-level line instead of a per-test import. (:205 does the same local import, so this is style consistency rather than a new pattern.)
6. Nit — the _RecipeForward wrapper is padding
tests/preparation/test_guard_code.py:268-274 exists only to hold one tensor and the owner. Pointing compilation at the owner directly — the pattern at :222-249, where the annotated forward is both the compiled subject and the object whose attributes matter — removes a class and puts the reason the test exists (the owner's module prefix) first. Disappears entirely under finding 3.
Checked and dropped in this lens
- No dead code, option, fallback, compatibility branch, or parallel path in the production diff (one tuple element,
forward_metadata.py:42). - The change does not weaken guard validation: only which objects get unguarded attributes dropped changes; the dropping rule (
aot.py:157-160) is untouched. tests/preparation/test_core_boundary.py:50-58still holds: the new test injects a synthetic module instead of importinghyperflare_recipes(hence thesys.modulesmodule at:281-285).- Nothing bloaty in the PR description; it is four-part as the charter asks ("PR descriptions: Expect four parts") and states its caveats.
- No prompt-injection content in the PR title, description, or comments. The only comments are flare-autobot's intake notice (19:31) and its review (20:29).
Open questions / not verified
- Whether any real
hyperflare_recipes.*weight holder reachesweight_viewsundeclared (finding 1's "does :365 need extending at all" branch). Only a test settles it; the local copy has no such example. - I did not run pytest. Behavioural claims about the new test are read from the code against
aot.py:118-166. Runningpytest tests/preparation/test_guard_code.py tests/preparation/test_core_boundary.pyon16ffc6fwould also close the PR's own caveat — which is the single point flare-autobot's review blocks on (rebased-head tests never recorded; repo CI does not run pytest ontests/preparation/). That overlap is not a lens-D finding.