Architecture & scope review — PR #574 "Strip unguarded attributes from hyperflare_recipes objects in AOT guard serialization"
2 files, +54/−1 (head 16ffc6f). Reviewed against AGENTS.md, docs/design-review.md, docs/cli-design.md, docs/preparation-development.md, docs/runtime-core-design.md, reading both changed files in context and following the changed predicate to its two callers.
Key findings
- Blocking (evidence): the author states the unit-test run predates the rebase onto #509, and CI reports no checks on the head commit.
tests/preparation/test_guard_code.pyis a CPU-only test, sodocs/design-review.md:247-251makes disclosure an unacceptable substitute for running it. - Should fix (approach): the fix keys prepared-object detection on a third hardcoded Python package name inside core Ignition, while
AGENTS.md:381-384explicitly permits external recipe repositories under any name — those keep hitting the samePicklingError. The pickler already holds the correct, package-independent key (self.guard_tree_values). - Should fix (test quality): the new test duplicates the allowlist literal at class level (
test_guard_code.py:258vs:281) and mutates a module-level class attribute in place without restoring it. - Nits: a second, now-divergent package-prefix list survives at
ignition/preparation/rebuild_manifest.py:365; and the one-line widening quietly imposes a new__dict__-state contract on every external recipe class, documented nowhere.
Scope verdict: the change belongs in this repository and in this layer. Prepared-forward guard serialization is core Ignition's job (ignition/preparation/aot.py:102-166, ignition/preparation/forward_metadata.py:172-279), per AGENTS.md:408-428 ("Python prepares; Helios serves") and docs/preparation-development.md's rule that process-local kernel handles are bound at startup. No flag, enum, Protobuf field, or Helios code is added, and the core-format/ABI surface is untouched, so the PR's "No runtime, core-format, or Helios behavior changes" claim holds. The problem is not where the fix was made but what it keys on, plus the missing post-rebase run.
Blocking
B1. The rebased tip has never been run, and the PR asks the reviewer to run it
PR #574 description: "The original unit-test run predated rebasing onto #509's extraction of _uses_custom_object_state into ignition/preparation/forward_metadata.py (167f22c8); please run CI on tests/preparation/test_guard_code.py and tests/preparation/test_core_boundary.py to confirm on the rebased tip." The head commit (16ffc6f) reports no checks.
Why this matters here rather than being a formality: the rebase moved the predicate the test exercises (the diff now edits forward_metadata.py:42, not aot.py), so the pre-rebase green run exercised a different import path and a different call site. test_guard_code.py needs no GPU and no checkpoint — it is torch.compile(...).aot_compile(...) plus serialize/deserialize on CPU — and docs/design-review.md:180-186 names tests/preparation as a layer-1 required suite. docs/design-review.md:247-251: "Disclosure does not excuse skipping runnable CPU checks… Leaving an applicable … test unrun blocks commit and PR acceptance; noting it as a limitation does not make the omission acceptable."
Fix: run pytest tests/preparation/test_guard_code.py tests/preparation/test_core_boundary.py on 16ffc6f and paste the summary line into the description. Nothing else in this PR can be accepted before that.
Should fix
S1. The fix hardcodes one external package's name in core Ignition instead of generalizing the predicate
ignition/preparation/forward_metadata.py:39-45:
def _uses_custom_object_state(value):
return (
hasattr(value, '__dict__')
and type(value).__module__.startswith(('ignition.', 'b12x.', 'hyperflare_recipes.'))
...
)
The predicate decides which prepared non-nn.Module objects get attribute state (with _Missing for anything outside the guard tree) purely from the name of the Python package that defines the class. Adding a third literal fixes exactly one package name, not the class of failure the PR description itself names. AGENTS.md:379-384 says official recipes live in hyperflare_recipes/recipes/, and "external recipe repositories can pass their own Recipe tuples directly to ignition.cli.main(...)." Any such repository — a vendor repo, an internal fork, a second recipe package — keeps raising PicklingError: Can't pickle ... CompiledKernel for exactly the same reason, and the next fix will be a fourth literal. This is the special-case pattern AGENTS.md:188-193 rejects ("Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement") and the per-repository knowledge docs/cli-design.md:19-20 says belongs in external packages, "never in core ignition". The coupling is only a string, so tests/preparation/test_core_boundary.py:39-47 (which collects ast.Import/ImportFrom names only, at :28-36) still passes — the boundary test cannot see this kind of coupling.
There is a concrete, already-available alternative: _GuardPickler holds the ground truth in self.guard_tree_values and already uses it for tensors (aot.py:127) and for object attributes (aot.py:158-160). An object whose attributes are not in the guard tree is unguarded whichever package defined it, so membership (or "does this object appear anywhere in the guard tree") decides the question with no allowlist and no edits when the next recipe repository appears. If module scoping must be retained, derive the roots from the registered recipes/source roots rather than a literal.
Settling evidence: a second synthetic class with __module__ set to, say, some_external_recipes.components reproducing the same PicklingError on main and on this PR. That is a two-line variation of the test this PR already adds.
S2. The new test duplicates the allowlist literal and mutates a global class attribute without restoring it
tests/preparation/test_guard_code.py:252-302. _RecipeKernelOwner carries __module__ = "hyperflare_recipes.components.synthetic" at the class level (:258), then inside the test the same attribute is overwritten with "hyperflare_recipes.components._synthetic_guard_test" (:281-285) and a synthetic module is injected into sys.modules:
module_name = "hyperflare_recipes.components._synthetic_guard_test"
synthetic = types.ModuleType(module_name)
_RecipeKernelOwner.__module__ = module_name # :283, never restored
synthetic._RecipeKernelOwner = _RecipeKernelOwner
monkeypatch.setitem(sys.modules, module_name, synthetic)
Two problems. First, both names share the hyperflare_recipes. prefix that forward_metadata.py:42 matches, so the rewrite at :283 adds no discrimination about the package — the literal at :258 already decides the outcome, and the pair now encodes the allowlist prefix in two places. Second, :283 mutates a process-global class attribute directly instead of through monkeypatch.setattr, so it leaks into every later test in the session; the neighbouring test at :212-214 does the same trick correctly (monkeypatch.setitem(sys.modules, ...)). The sys.modules injection at :285 is genuinely needed for by-reference unpickling of the class, so keep it; the unrestored attribute is not.
Fix: set __module__ once, via monkeypatch.setattr(_RecipeKernelOwner, '__module__', module_name, raising=False), drop the duplicate literal at :258, and — so the test pins the behaviour this PR introduces rather than restating it — add the contrasting case from S1 (same class shape, __module__ outside the allowlist, unpicklable handle, asserting the failure). As written, the file is a mock harness that satisfies AGENTS.md:194-196's letter (it does drive real aot_compile and real serialize/deserialize) but not its spirit about a test that discriminates the behaviour under change.
Nits
N1. A second package-prefix allowlist for the same question was left diverging
ignition/preparation/rebuild_manifest.py:365-367:
elif type(value).__module__.startswith(('b12x.', 'ignition.')) and hasattr(value, '__dict__'):
This is the same "is this a prepared non-module object?" enumeration that the PR edits in forward_metadata.py:42, and it was not updated. weight_views feeds BundleIndex.rebuild_weights (rebuild_manifest.py:449 → runtime_core.py:130-131, 367-369), per docs/runtime-core-design.md:422-433; tensors held by a hyperflare_recipes.* container that is not an nn.Module (:358) or a dataclass (:362-364) are silently skipped, landing in neither tensors nor unavailable. AGENTS.md:497-503 requires inspecting equivalent paths across supported recipes when a deficiency appears in one. I cannot show this bites the Inkling 2 PreparedResidualMix case without the external repo, and it is out of scope for a guard-serialization PR, so this is a follow-up, not a defect introduced here: check whether any hyperflare_recipes.* non-module, non-dataclass type reachable from declare_weights(roots=...) holds weight tensors, and if so widen or generalize :365 with the same reasoning as S1.
N2. The one-line widening silently adds a contract on external recipe classes that is documented nowhere
The same predicate change reaches two different serialization contracts:
_GuardPickler(aot.py:155-165): for anyhyperflare_recipes.*instance, state is rebuilt with_guard_object(object.__new__,aot.py:98-99) plus_set_state, and every attribute not inguard_tree_valuesbecomes_Missing. Any__getstate__/__setstate__/__reduce__the recipe class defines is bypassed. That is the intent, but the policy now governs classes this repository does not own._ForwardPickler(forward_metadata.py:277-278): reached for values whose type has__getattr__; such ahyperflare_recipes.*object now takes theobject.__new__+_set_statepath across the compiler-worker IPC boundary instead of default pickling.
Recipe authors therefore must keep serializable state in __dict__. Suggest one sentence in docs/preparation-development.md (the section that already states what compiled artifacts and guards retain) or in the new test's docstring, so the contract is discoverable without reading the predicate.
Also worth one line in the description: the evidence bullet "Verified across 4-Spark TP4 compiled 48-layer Inkling 2 Small exports (154 multimodal graphs)" names no command, core, or revision; AGENTS.md:103-112 requires reproduction inputs and configuration directly or by precise reference.
Verified and deliberately not reported
- Core boundary is intact.
tests/preparation/test_core_boundary.py:28-36collects only import statements, so the string'hyperflare_recipes.'atforward_metadata.py:42is not a violation of:39-47; and the new test builds a synthetictypes.ModuleTyperather than importing the package, so:50-58stays satisfied. The PR's claim on this point holds. - Exactly two callers of
_uses_custom_object_state:aot.py:155-165andforward_metadata.py:277(the latter additionally gated onhasattr(type(value), '__getattr__')). No other dispatch changes hands. - No weakening of the #509 fixes.
_NON_OBJECT_NEW_TYPES(forward_metadata.py:33-36) and theinspect.isclassguard are untouched, soenum.Enumand builtin subclasses stay excluded; theDetectedDevicespecial case (aot.py:161-164) sits inside the widened branch but matchesb12x.preparation.device, so its behaviour is unchanged. - Guard strength preserved by construction: guarded values still pass through because membership in
self.guard_tree_values(aot.py:158-160) is unchanged; only the set of objects taking the attribute-state path grows.
Open questions / not verifiable in this repository
- Whether Inkling 2's
PreparedResidualMixreally reaches the widened branch (it must be a non-nn.Module,hyperflare_recipes.*, traced-through object) — the class lives inlocal-inference-lab/hyperflare-recipes; the synthetic_RecipeKernelOwnerstands in for it. The description's end-to-end claim cannot be checked or reproduced from the information given. - Whether the author is willing to generalize the predicate (S1) or intends the allowlist as a stopgap; if a stopgap, it should say so and reference the follow-up, per
AGENTS.md:188-193. - Whether
rebuild_manifest.py:365loses weight views for recipes outside the two old prefixes (N1) — needs the external recipe definitions to settle.