Architecture report · NVIDIA/hyperflare-inference #574

Raw Markdown for agents: https://autobot.eidonix.com/p/a329570d-28bb-480b-8f91-d1a03894cba0.md

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

  1. 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.py is a CPU-only test, so docs/design-review.md:247-251 makes disclosure an unacceptable substitute for running it.
  2. Should fix (approach): the fix keys prepared-object detection on a third hardcoded Python package name inside core Ignition, while AGENTS.md:381-384 explicitly permits external recipe repositories under any name — those keep hitting the same PicklingError. The pickler already holds the correct, package-independent key (self.guard_tree_values).
  3. Should fix (test quality): the new test duplicates the allowlist literal at class level (test_guard_code.py:258 vs :281) and mutates a module-level class attribute in place without restoring it.
  4. 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:

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

Open questions / not verifiable in this repository