#1 [high] Should fix: new guard test duplicates existing e2e plumbing; direct-pickler form saves ~34 of 53 lines
tests/preparation/test_guard_code.py:252-302 (PR adds 53 lines).
Duplication shown in code:
- The compile+serialize block at :288-296 is byte-for-byte the same shape as :236-244 in test_guard_serialization_roundtrips_tensor_user_attributes (GraphModuleSerializableCallable backend, fullgraph=True, dynamic=False, aot_compile, serialize().serialized_data, deserialize).
- Guard invalidation on a plain object's int attribute (True -> False -> True) is already asserted at :47-56 on GuardedForward.value/.offset.
- Guard-tree-vs-unguarded attribute filtering is already asserted at :104-127 for tensors (restored.scale kept, restored.unguarded is _Missing).
- Output parity
torch.testing.assert_close(loaded(forward), torch.full((2,), 3.0))tests the forward's arithmetic (multiply by scale), not the pickler. - _RecipeForward (:268-274, 7 lines) and its
applyindirection exist only to serve the e2e compile.
The affected code is _GuardPickler.reducer_override's object branch (ignition/preparation/aot.py:157-165), which the file already tests directly through the _roundtrip_guard helper (tests/preparation/test_guard_code.py:91-100). Smaller version (~19 added lines, keeps the exact regression: without 'hyperflare_recipes.' in the prefix tuple, default pickling hits _UnpicklableHandle.reduce and raises):
class _UnpicklableHandle:
def __reduce__(self):
raise TypeError("compiled kernel handles cannot be pickled")
class _RecipeKernelOwner:
def __init__(self, scale):
self.scale = scale
self.compiled_handle = _UnpicklableHandle()
def test_guard_pickler_strips_unguarded_attributes_from_recipe_objects(monkeypatch):
import types
module_name = "hyperflare_recipes.components._synthetic_guard_test"
synthetic = types.ModuleType(module_name)
_RecipeKernelOwner.__module__ = module_name
synthetic._RecipeKernelOwner = _RecipeKernelOwner
monkeypatch.setitem(sys.modules, module_name, synthetic)
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)
(_Missing already imported at :14; sys at :9; _roundtrip_guard uses the 3-item reducer form _guard_object, (type(obj),), state from aot.py:165 so default dict.update applies the filtered state.)
Optional extra 4 lines: drop _UnpicklableHandle and use threading.Lock() (unpicklable, already the repo's canonical process-local type via _LockTypes in forward_metadata.py:27) -> ~15 lines.
Also within the deleted block: _RecipeKernelOwner.__module__ = "hyperflare_recipes.components.synthetic" at :258 is dead — the test reassigns module at :283 before the class is used.
Caveat to state honestly: the smaller test must be run (I cannot execute code here) to confirm the object branch roundtrips under pickle.loads. If maintainers value the end-to-end serialize/deserialize of a recipe-module object specifically, the alternative cut is only :252-274 + :277 partial (still ~30 lines).
#4 [high] Research summary
Reviewed PR #574 through the subtraction lens. Production change is a single token in ignition/preparation/forward_metadata.py:42 (add 'hyperflare_recipes.' to the prefix tuple in _uses_custom_object_state) — that fix is minimal and cannot be reduced: it gates both _ForwardPickler (forward_metadata.py:277) and _GuardPickler (aot.py:157-165), it inspects __module__ as a string so the core-boundary AST test (tests/preparation/test_core_boundary.py:39-47) still passes, and it adds no option, flag, fallback, helper or dead path.
The reduction target is the test: the 53 added lines at tests/preparation/test_guard_code.py:252-302 rebuild an end-to-end compile/serialize/guard_check flow that already exists a few lines above (:232-249, and :47-56 for guard invalidation), while the file has a direct _roundtrip_guard helper (:91-100) for the very _GuardPickler object branch under change. A ~19-line direct-roundtrip version (or ~15 with threading.Lock() instead of a custom unpicklable class) keeps the exact regression — without the new prefix, default pickling raises on the unpicklable handle. Roughly 34 of the 54 added lines can go, netting the PR at about 20 lines.
Secondary note (0 lines in this PR): the same package allowlist is duplicated and left divergent at ignition/preparation/rebuild_manifest.py:365, whose non-declaration traversal path has no in-repo writer. Details, code for the smaller test, and the honest caveat that the shorter test must be executed to confirm are in the scratchpad.
#5 [high] Report-ready summary: PR #574 subtraction review, ranked findings with line counts
PR #574 "Strip unguarded attributes from hyperflare_recipes objects in AOT guard serialization" (open, head 16ffc6f, base main). Diff: 2 files, +54/−1.
Own added/removed lines counted from the diff (pr_diff):
- ignition/preparation/forward_metadata.py: +1 / −1 (line 42 only).
- tests/preparation/test_guard_code.py: +53 / −0 (lines 252-302). No other files touched (pr_files / orientation packet agree).
VERDICT: the production change is minimal — 1 token, +1/−1. Nothing in it can be removed (entry 3). The subtraction available is in the test: ~34 of the 54 added lines (entry 1). Total realistic reduction: 54 → ~20 added lines.
Findings ranked by lines saved:
-
Should fix (~34 lines): tests/preparation/test_guard_code.py:252-302. What goes: the e2e
_RecipeForward+_UnpicklableHandle+_RecipeKernelOwnerscaffold (:252-274, 23 lines) and the compile/serialize block (:277-296). What replaces it: a direct_roundtrip_guardassertion on the_GuardPicklerobject branch (aot.py:157-165), ~19 lines (or ~15 using threading.Lock()). Why nothing is lost: the compile+serialize shape is duplicated at :236-244; guard invalidation True->False->True on an int attribute is at :47-56; guarded-vs-unguarded attribute filtering is asserted at :104-127; output parity only re-tests the forward's multiplication, not the pickler. Without the new 'hyperflare_recipes.' prefix the direct roundtrip still hits_UnpicklableHandle.__reduce__and raises, so the regression stays covered. Also dead inside the new block:_RecipeKernelOwner.__module__ = "hyperflare_recipes.components.synthetic"(:258) is overwritten at :283. Rule basis: AGENTS.md:194-199 ("tests must exercise the affected behavior... keep each PR focused"), AGENTS.md:188-193 (reject churn/duplication), design-review.md principle 15 (reject scope expansion in code, tests, docs). -
Nit / consistency (~0 lines in this PR, ~25-30 in a follow-up): ignition/preparation/rebuild_manifest.py:365. The same project-package allowlist
startswith(('b12x.', 'ignition.'))is duplicated there and left divergent by this PR. Its only in-repo caller (helios/tests/runtime_core_fixture.py:186, legacy dict form) never reaches the Module/dataclass/prefix branches at :358-367; the supported writer is declare_weights/WeightDeclaration (:86-106, :118-215). Either delete the redundant non-declaration traversal (:338-374 + :441-459, which also repeats _declared_metadata's body) or hoist one shared tuple constant so the next package move cannot silently miss a site — the exact class of bug this PR fixes. -
Note: forward_metadata.py:42 itself is already minimal (entry 3).
Prompt-injection check: the only PR comment is the autobot case-file notice (pr_comments); no instructions were directed at me and none were followed.
Honest caveats to state: (a) I could not execute pytest, so the ~19-line test replacement must be run to confirm the object branch roundtrips under pickle.loads; (b) if maintainers specifically want an end-to-end serialize/deserialize of a recipe-module object (not just the pickler branch), the alternative cut is only :252-274 + the duplicate module-name line, ~25 lines; (c) PR description itself flags that its original run predated the rebase onto #509 — not my lens, but relevant to any merge decision.
#3 [medium] Note: the 1-line production change is minimal; no subtraction available
ignition/preparation/forward_metadata.py:42 — the whole production change is adding 'hyperflare_recipes.' to the existing prefix tuple.
Why it cannot be avoided:
- _uses_custom_object_state (forward_metadata.py:39-45) gates two call sites: _ForwardPickler.reducer_override at :277-278 and _GuardPickler.reducer_override at aot.py:157-165. Both replace unguarded attributes with _Unavailable/_Missing only for matched types; without the extra prefix, the guard path falls through to
super().reducer_override(obj)(aot.py:166) and default pickling of a triton CompiledKernel raises PicklingError — the failure the PR describes. - It inspects the class's module string only, so core ignition still never imports hyperflare_recipes; tests/preparation/test_core_boundary.py:39-47 (AST scan of ignition/**/*.py imports) stays satisfied, and :50-58 (tests may not import hyperflare_recipes) is why the test synthesizes the module via monkeypatch.setitem(sys.modules, ...) instead of importing it.
- No option, flag, fallback or new helper is introduced; no dead path is left behind. Charter "smallest footprint in shared code" is respected.
Result: 1 production line, +1/-1. Nothing to subtract from it. Total honest estimate for the PR: of 54 added lines, ~34 could go (the test rewrite) for ~19 net, and the note in entry 2 saves 0 in this PR.
#2 [low] Nit: same package allowlist duplicated at rebuild_manifest.py:365 and not updated
ignition/preparation/forward_metadata.py:42 now reads startswith(('ignition.', 'b12x.', 'hyperflare_recipes.')).
ignition/preparation/rebuild_manifest.py:365 carries the same idea: elif type(value).__module__.startswith(('b12x.', 'ignition.')) and hasattr(value, '__dict__'), used to walk object state in weight_views (rebuild_manifest.py:338-374).
So the repository keeps two copies of the same project-package knowledge, and this PR updates one. Evidence that keeping two diverging lists costs work: this PR exists to fix exactly such a missed prefix.
Reachability of the rebuild_manifest copy: weight_views is only reached when roots is not a WeightDeclaration (rebuild_manifest.py:441-449); the only in-repo caller is helios/tests/runtime_core_fixture.py:186, legacy rebuild_weights={"weight": tensors["weight"]} — a dict of tensors, so the Module/dataclass/prefix branches at :358-367 are not exercised by any in-repo writer. declare_weights/WeightDeclaration (declared_views, :118-215) is the supported writer path.
Recommendation is a subtraction, not an addition: either delete the redundant non-declaration traversal (weight_views' Module/dataclass/prefix branches plus its duplicate of _declared_metadata at :441-459, roughly 25-30 lines) if the mapping form of rebuild_weights has no external caller, or hoist one shared tuple constant so the next package move cannot silently miss a site. Line saving for this PR itself: ~0; it is a consistency/design note, not a merge gate.