Key findings
The production fix is already minimal — one token, +1/−1, at ignition/preparation/forward_metadata.py:42. Nothing in it can be removed: it is the single predicate that gates both picklers (_ForwardPickler.reducer_override at ignition/preparation/forward_metadata.py:277 and _GuardPickler.reducer_override at ignition/preparation/aot.py:155-165), it compares __module__ as a string so tests/preparation/test_core_boundary.py:39-47 keeps passing, and it adds no option, flag, fallback, helper or dead path.
The whole subtraction available is in the test. tests/preparation/test_guard_code.py:252-302 (53 added lines) rebuilds an end-to-end torch.compile → serialize → deserialize → guard_check flow the same file already contains at :232-249, when the module already exposes a direct _GuardPickler round-trip helper (_roundtrip_guard, :91-100) for exactly the object branch being changed. About 34 of the 54 added lines can go. Verdict: make it smaller first (no production change required).
Diff counted from pr_diff: 2 files, +54/−1 — forward_metadata.py +1/−1 (line 42 only), test_guard_code.py +53/−0 (lines 252-302). No other files.
Findings, ranked by lines saved
1. Should fix — ~34 lines: the new test re-implements plumbing the file already has
tests/preparation/test_guard_code.py:252-302.
What goes (all of it newly added):
_UnpicklableHandle/_RecipeKernelOwner/_RecipeForwardscaffold,:252-274(23 lines) — a class hierarchy whose only job is to be a value passed to the pickler.- The
torch.compile(...).aot_compile(...)+serialize+deserializeblock,:277-296, which is a near-copy of:236-244(_guard_serialization()+torch.compile(_execute, backend=lambda graph, inputs: GraphModuleSerializableCallable(graph), fullgraph=True, dynamic=False).aot_compile(((forward,), {}))thentype(compiled).serialize(compiled).serialized_datathentype(compiled).deserialize(data)).
What replaces it — the direct pickler round-trip the file already provides for _GuardPickler (_roundtrip_guard, :91-100) and the existing sys.modules monkeypatch idiom (:212-217). ~19 lines, nothing else added:
class _RecipePrepared:
def __init__(self, scale):
self.scale = scale
self.compiled_handle = _UnpicklableHandle() # reuse :252-254, or threading.Lock()
_RecipePrepared.__module__ = "hyperflare_recipes.components.synthetic"
def test_guard_pickler_strips_unguarded_attributes_from_recipe_objects(monkeypatch):
import types
module = types.ModuleType(_RecipePrepared.__module__)
module._RecipePrepared = _RecipePrepared
monkeypatch.setitem(sys.modules, _RecipePrepared.__module__, module)
prepared = _RecipePrepared(3)
restored = _roundtrip_guard(prepared, guard_tree_values={id(prepared): prepared})
assert type(restored) is _RecipePrepared
assert restored.scale == 3
assert isinstance(restored.compiled_handle, _Missing)
Why nothing is lost:
- The regression is
aot.py:157-165returning_guard_object, (type(obj),), statewith_Missingfor anything whose id is not inguard_tree_values. Without'hyperflare_recipes.'inforward_metadata.py:42, the pickler falls through tosuper().reducer_override(aot.py:166) and hits_UnpicklableHandle.__reduce__→ raises. The direct round-trip fails on the unpatched tree and passes on the patched one, so the test still pins the fix. - Compile+serialize is already exercised at
:236-244— the new block proves the same plumbing twice. - Guard invalidation
True → False → Truealready exists at:47-51(forward.offsetflip onGuardedForward), through the same Dynamoguard_checkmachinery;:299-302only re-proves it for anintattribute. - Guarded-vs-unguarded attribute filtering is already asserted at
:104-127(assert isinstance(restored.unguarded, _Missing)againsttensor.scalepreserved), which is character-for-character the assertion the new test makes aboutscalevscompiled_handle. - Output parity (
:297,torch.full((2,), 3.0)) only re-testsvalue * scaleon the synthetic forward; forward parity after deserialize is already covered at:245.
Also dead inside the new block: _RecipeKernelOwner.__module__ = "hyperflare_recipes.components.synthetic" at :258 is overwritten unconditionally at :283 — one line that can never be observed.
Rule basis: AGENTS.md:194-199 ("Tests must exercise the affected behavior or contract… Keep each PR focused on one coherent outcome"); AGENTS.md:188-193 (reject churn and duplicate scaffolding); docs/design-review.md:135-146 (principle 15 — apply the contribution rejection criteria to code, tests, and docs).
Fallback if maintainers insist on an end-to-end serialize: the minimum cut is still :252-274 minus what _execute/_AnnotatedTensorForward already provide, plus the dead :258 — about 25 lines.
2. Nit — 0 lines here, ~25-30 in a follow-up: the same package allowlist is duplicated and left divergent
ignition/preparation/rebuild_manifest.py:365 holds the identical predicate type(value).__module__.startswith(('b12x.', 'ignition.')). This PR updates one of the two project-package allowlists (grep finds exactly these two sites, plus the new test string). Either the tuple becomes one shared constant, or the legacy traversal goes.
Evidence that the legacy branch is redundant: rebuild_weights_metadata (:441-459) branches on isinstance(roots, WeightDeclaration) (:445-446) and otherwise walks weight_views (:338-374), which contains :365; the non-declaration traversal also repeats _declared_metadata's body (:425-438 vs :448-459) verbatim apart from usable_weight_tensor (:377). The declaration path is the one wired by ignition/preparation/runtime_core.py:130 and :368.
Honest limitation: I could not prove the non-declaration path is unreachable — runtime_core.py forwards whatever rebuild_weights it is given, so a caller outside ignition/ may still pass a plain dict. That is why this is a nit for a follow-up, not a request to change PR #574: the point is that adding 'hyperflare_recipes.' at forward_metadata.py:42 widens a duplication that will silently miss this site the next time a package moves — the exact defect class this PR fixes.
3. Note — no subtraction: forward_metadata.py:42
The one-token change is the smallest correct form. A helper, a constant, or a configurable prefix list would all be additions with one caller each. Keep as is.
Open questions / what I could not verify
- The ~19-line replacement is unrun. I cannot execute pytest here, so before adopting it someone must confirm the
_GuardPicklerobject branch round-trips underpickle.loadsfor a class that is not a builtin and has an unpicklable attribute (it should, via_guard_objectataot.py:98-99and_set_state). If it does not, the fallback cut in finding 1 (~25 lines) applies. - Is the end-to-end shape required by review? If maintainers want explicit proof that
type(compiled).serializeno longer raisesPicklingErroron ahyperflare_recipes.*object, only the scaffold can go, not the compile block — finder 1's alternate cut. - Whether the allowlist should be a shared constant. That is a maintainer call about the rebuild-manifest legacy path, not something this PR must decide.
- The PR description itself flags that its original test run predated the rebase onto #509's extraction of
_uses_custom_object_state(167f22c8). Out of my lens, but relevant to merge timing. - Prompt-injection check: the only PR discussion is the automated case-file notice; no instructions were directed at the reviewer and none were followed.
Totals: change is +54/−1 across 2 files; about 34 lines removable in 1 place (test only), leaving roughly +20/−1 with the production fix untouched.