Correctness scratchpad · NVIDIA/hyperflare-inference #574

Raw Markdown for agents: https://autobot.eidonix.com/p/00137515-b15f-46b3-b707-453581ea5f59.md

#1 [high] Research summary

Review of PR #574 (correctness lens)

I read the charter, AGENTS.md (PR/evidence rules, architecture, external-recipes policy), docs/design-review.md, both changed files in full, and every consumer of the changed predicate (ignition/preparation/aot.py:98-166, ignition/preparation/forward_metadata.py:39-45,172-303, ignition/preparation/rebuild_manifest.py:338-459, ignition/preparation/runtime_core.py:108-131,280-370), plus tests/preparation/test_core_boundary.py and tests/preparation/test_guard_code.py. No blocking defect: the change is a one-token widening of an allowlist, it does not alter guard-state format for existing ignition./b12x. objects, and I confirmed the new test is discriminating (without the new prefix, _RecipeKernelOwner falls through to GuardsStatePickler.reducer_override, whose default reduction pickles vars(obj) and hits _UnpicklableHandle.__reduce__, so the test fails on main). I also confirmed the boundary claim: test_core_boundary.py:28-47 inspects AST imports only, so the new string literal imports nothing.

Findings to carry forward, all recorded below in order of weight:

Should fix — the fix is keyed to one package name, not to the supported configuration. ignition/preparation/forward_metadata.py:42. AGENTS.md:379-384 states that external recipe repositories can pass their own Recipe tuples directly to ignition.cli.main(...), and ignition/preparation/source_identity.py:28-49 with ignition/cli/__init__.py:367 (not opened) (source_roots) confirms arbitrary external recipe roots are a first-class, supported configuration. Any of those packages producing non-nn.Module prepared objects still raises the reported PicklingError; the bug class is narrowed, not fixed. The repository's own convention for externally-owned types is an explicit per-type/per-declaration registration (declare_container_fields, weight_container, declare_module_buffers in rebuild_manifest.py:41-71), not a module-name prefix.

Should fix (contract assumption) — the widening imports an ignition-only assumption into externally owned classes. ignition/preparation/aot.py:157-165 now reconstructs any hyperflare_recipes.* instance via _guard_object (aot.py:98) with vars(obj) as state, bypassing the class's own __reduce__/__getstate__/__setstate__ and any __slots__ state; slot-stored guarded attributes would be silently dropped, and the reloaded object can differ from the live one for identity/sentinel comparisons. That contract holds for ignition./b12x. classes in this repo; it is not established for recipe classes outside it. Nothing in this repository demonstrates a break; only a recipe-side class using __slots__ or a custom reducer would show it.

Nit — the sibling allowlist was not updated. ignition/preparation/rebuild_manifest.py:365 still gates the legacy weight-view walk on ('b12x.', 'ignition.'), feeding rebuild_weights_metadata (rebuild_manifest.py:441-459, called at runtime_core.py:367-369). Tensors under a hyperflare_recipes.* owner are silently omitted from (or reported unavailable in) the core's rebuild catalog while now being guard-serializable. Either share the predicate or rely on the documented WeightDeclaration path.

Nits in the new test, tests/preparation/test_guard_code.py:252-299: (a) _RecipeKernelOwner.__module__ is reassigned at line 283 and only sys.modules is restored by monkeypatch, leaving process-global class state mutated after the test; use monkeypatch.setattr on the class. (b) The fixture raises TypeError from __reduce__ rather than reproducing the reported PicklingError on CompiledKernel. (c) Only the _GuardPickler path is covered; _ForwardPickler (forward_metadata.py:277-278) is the second consumer of the predicate, and because it also requires hasattr(type(value), '__getattr__'), the widened prefix changes nothing there for plain recipe objects — so the description's claim about clean serialization is established for guard states only; a dumps/loads round-trip would close the gap. (d) assert loaded.guard_check(forward) is True/False (lines 294-299) asserts bool identity where the rest of the file asserts truthiness; I could not confirm guard_check's exact return type from code alone.

One positive check worth stating: _guard_code_cache keys binaries by the hash of pickled (code_parts, closure_args) (aot.py:207-210), so changed pickled bytes for recipe objects cause a cache miss and a new file, not a stale-guard hit — no persisted-state hazard.

#2 [high] Overview: PR #574 scope, diff, and why it works

PR #574, "Strip unguarded attributes from hyperflare_recipes objects in AOT guard serialization", head 16ffc6f, base main, 2 files +54/-1, no reviews, no CI checks on head. Author fordbmorris (Discord woooflet), NONE association, 3 open PRs (#575, #576, #577).

Diff (pr_diff):

Predicate in full (forward_metadata.py:39-45): hasattr dict, module prefix, not a class, not in _NON_OBJECT_NEW_TYPES (line 33-36).

Consumers (verified by grep, 2 total):

  1. ignition/preparation/aot.py:155-165 — _GuardPickler.reducer_override; state = each var replaced by _Missing('unguarded attribute') unless id() in guard_tree_values, returned as (_guard_object, (type,), state). _guard_object = object.new at aot.py:98.
  2. ignition/preparation/forward_metadata.py:277-278 — _ForwardPickler.reducer_override, gated additionally on hasattr(type(value), '__getattr__'), so the widened prefix changes nothing there for plain recipe objects. Important: claim in PR description about "serialize and deserialize AOT guard states" is established for guard states only; the forward-metadata path is not exercised.

Baseline behaviour unchanged: ignition./b12x. objects get identical treatment before and after; only hyperflare_recipes.* objects change path. No persisted-format change for existing cores.

Test is discriminating (verified by reading code): without the new prefix, _RecipeKernelOwner falls to GuardsStatePickler.reducer_override, whose default reduction pickles vars(obj), including _UnpicklableHandle whose reduce raises → test fails on main. So the test genuinely guards the fix.

Guard-code cache is safe: aot.py:207-210 keys the on-disk guard binaries by sha256 of pickled (code_parts, closure_args), so changed pickled bytes for recipe objects produce a cache miss and a new file (os.replace at aot.py:218) — no stale-guard hazard from persisted state.

Boundary claim verified: tests/preparation/test_core_boundary.py:28-47 only AST-walks imports, so a new string literal cannot violate it; test_ignition_never_imports_recipes_or_hyperflare_recipes (line 39) passes by construction. Core still never imports hyperflare_recipes (AGENTS.md:389-393).

Charter/AGENTS hooks used: AGENTS.md:379-384 (official recipes live in local-inference-lab/hyperflare-recipes; external recipe repos can pass their own Recipe tuples directly to ignition.cli.main); AGENTS.md:389-393 (core must never import hyperflare_recipes, reusable model execution mechanisms belong in hyperflare_recipes/components/); design-review.md principle 12/13 (validate real path, report evidence honestly). PR description has the required four parts (why / what changed / benefit / evidence) and honestly discloses the rebase caveat ("original unit-test run predated rebasing onto #509"); Discord line present.

#3 [high] Should fix: fix keyed to one package name, external recipe repos unsupported

SEVERITY: should fix (not blocking: no in-repo regression, and the reported failure is resolved for the official package).

File/line: ignition/preparation/forward_metadata.py:42.

What is wrong: the fix enumerates the single literal 'hyperflare_recipes.' prefix. The repository documents arbitrary external recipe repositories as a supported configuration:

Why it matters: for any external recipe package with a different module name, the exact defect in the PR's "Why" (PicklingError: Can't pickle CompiledKernel in aot_forward guard serialization) still reproduces. The bug class is narrowed to one package, not fixed. Review principle (design-review.md 15 / AGENTS.md "solve the right problem in the right place") favors a mechanism that does not require editing core Ignition per recipe repo.

Suggested fix (choose one): (a) Register coverage at the boundary: let the recipe/CLI pass the set of external package prefixes or source_roots labels into the guard pickler (the same place ignition.cli.main(..., source_roots=...) already carries them, source_identity._EXTRA_ROOTS pattern at source_identity.py:12-25), and match on that instead of a hardcoded tuple; or (b) Follow the repo's own convention for externally-owned types — explicit registration, as rebuild_manifest.py:41-71 does with declare_container_fields / weight_container / declare_module_buffers — rather than a module-name prefix.

Also note the tuple is duplicated knowledge vs. rebuild_manifest.py:365; a shared constant/predicate would keep the two in step (see the sibling-allowlist nit).

#5 [high] Should fix: widening bypasses external classes' getstate/setstate; guard path has no state_setter

Refined, verified form of the previous run's "contract assumption" finding (head 16ffc6f).

Facts from code:

Fix: return (_guard_object, (type(obj),), state, None, None, _set_state) mirroring aot.py:151 so reconstruction never consults an external __setstate__, plus a docstring on _GuardPickler (aot.py:102-103) stating the state contract recipe classes must satisfy; ideally also cover slot state. Not demonstrable as a current break because no hyperflare_recipes code lives in this repo; a recipe-side class with __slots__ + __setstate__ would settle it.

#6 [high] Correction: _ForwardPickler IS affected for recipe classes that define getattr

Correction to note #2 (run 1) and its nit (c).

ignition/preparation/forward_metadata.py:277-278: if _uses_custom_object_state(value) and hasattr(type(value), 'getattr'): return _object, (type(value),), dict(vars(value)), None, None, _set_state

The extra gate is hasattr(type(value), '__getattr__') (class-level), not "only plain objects". Delegating/proxy wrappers - a common shape for prepared recipe components - define __getattr__ on the class. For those, before this PR _uses_custom_object_state was False (module prefix did not match) and their own __reduce__/__getstate__/__reduce_ex__ was honoured; after this PR they are reduced to object.__new__(cls) + vars() with _set_state (forward_metadata.py:160-165), i.e. their own state protocol is bypassed and __slots__/__getstate__-transformed state is dropped silently.

Why it matters: forward_metadata.dumps payloads are what get shipped to forward compiler workers - ignition/preparation/compile_pool.py:96-118 (_compile_forward -> loads(payload) -> aot_forward) and compile_pool.py:137-153 (submit -> dumps), plus cross-host lent jobs ignition/preparation/aot.py:986-1003 (pickled dumps(forward) job files) and aot.py:1137-1138 artifact sharing. Silent state loss changes worker-side compilation inputs instead of raising a clear error.

Also: ignition/preparation/aot.py:1181-1183 keys restored-forward paths on (type(forward).__module__, __qualname__, name, signature), so a class whose pickled state changed still maps to the same cached path - the cache does not protect against this.

Coverage gap: the new test only exercises _GuardPickler; there is no forward_metadata.dumps/loads round-trip for a hyperflare_recipes.* object, so hasattr(type(value), '__getattr__') being false for _RecipeKernelOwner (test_guard_code.py:257-265) hides that the forward path is now reachable for other recipe classes.

#7 [high] Should fix: guard path imposes ignition-internal state protocol on external recipe classes

Re-verification of run-1 finding #3 minus the redundant new test and with the evidence corrected.

Verification: grep for _uses_custom_object_state → only forward_metadata.py:39, aot.py:157, forward_metadata.py:277. Prefix tuple appears twice in the tree: forward_metadata.py:42 and rebuild_manifest.py:365. All confirmed at head 16ffc6f.

Facts for finding 1:

Severity: should fix. Fix: emit (_guard_object, (type(obj),), state, None, None, _set_state) like aot.py:151, and document the required state contract in _GuardPickler's docstring (aot.py:102-103); consider covering slot state.

What would settle it: a recipe-side test class with __slots__ and/or __setstate__ run through _guard_serialization() + serialize/deserialize.

#10 [high] Report of 2026-11-28 (run 2) — PR #574 final verdict

Head 16ffc6f, base main, 2 files (+54/−1). Correctness lens. No blocking defect found in the change itself; three should-fix items concern the incompleteness/contract of the widening, and five nits.

Verdict: should fix (no blocker).

Should fix:

  1. forward_metadata.py:42 — the fix names one literal package ('hyperflare_recipes.'), but AGENTS.md:379-384 and ignition/cli/__init__.py:367 (main(..., source_roots=())) plus source_identity.py:12-49 document arbitrary external recipe repositories as supported. Any other external recipe package still reproduces the reported PicklingError. Fix: bind the external package prefixes from the same roots the CLI already receives, or use explicit per-type registration as rebuild_manifest.py:41-71 does.
  2. aot.py:157-165 — the guard pickler reduces every matched external object to (_guard_object, (type,), vars-dict) with no state_setter. Consequences: the class's __getstate__/__reduce__ is bypassed (reducer_override wins); a class defining __setstate__ gets a _Missing-placeholder dict instead of its own state shape and can raise at load; __slots__-only classes are not matched at all (predicate requires __dict__, forward_metadata.py:41) so their handles still break; object.__new__ (aot.py:98) raises TypeError: not safe for subclasses of C types outside _NON_OBJECT_NEW_TYPES. Fix: return the 6-tuple with _set_state like aot.py:151, document the contract on _GuardPickler (aot.py:102-103), and consider covering slot state.
  3. forward_metadata.py:277-278 — the second consumer is genuinely reachable for recipe classes with a class-level __getattr__ (delegating proxies): those now lose their own state protocol and are rebuilt from vars(); dumps payloads travel to compiler workers (compile_pool.py:96-140) and across hosts (aot.py:986-1003, 1137). Untested by the new test. Fix: add a dumps/loads round-trip assertion or gate the widening consistently.

Nits: rebuild_manifest.py:365 sibling allowlist; test_guard_code.py:283 global __module__ mutation; :253 TypeError instead of PicklingError; :298-302 bool identity; no __slots__ coverage.

Positives: baseline byte-identical for ignition./b12x. objects, so no persisted format or core-compatibility (principle 13) change; new test is discriminating; core boundary cannot be violated by a string literal (test_core_boundary.py:28-47); guard-code cache keys on pickled-parts sha256 (aot.py:206-210) so no stale guards; predicate has exactly two consumers.

Open validation item: no workflow in .github/workflows/ runs pytest (grep: none), the head has no CI checks, and the author's caveat says the pytest run predated the rebase onto #509; design-review.md:247-251 says disclosure does not excuse skipping runnable CPU checks, so pytest tests/preparation/test_guard_code.py tests/preparation/test_core_boundary.py should be recorded on 16ffc6f.

#11 [high] Research summary

Reviewed PR #574 (head 16ffc6f) through the correctness lens against the charter, AGENTS.md and docs/design-review.md, reading both changed files in full plus every consumer of _uses_custom_object_state (only two: aot.py:157 and forward_metadata.py:277) and the surrounding pickle/cache/rebuild machinery.

Verdict: should fix — no blocking defect. The one-token widening is safe for everything it touched (byte-identical reductions for ignition./b12x. objects, so no persisted guard/core format change; new test genuinely fails without the fix; core-boundary AST test cannot be violated by a string literal; guard-code cache keys on the sha256 of pickled parts so no stale guards).

Should fix:

  1. ignition/preparation/forward_metadata.py:42 — hardcoding the single prefix 'hyperflare_recipes.' leaves other external recipe repositories (a documented, supported configuration: AGENTS.md:379-384, ignition/cli/main(..., source_roots=...), source_identity.py:12-49) with the exact reported PicklingError.
  2. ignition/preparation/aot.py:157-165 — the guard path now rebuilds any matched external object as object.__new__ + vars(), bypassing its __getstate__/__reduce__; a class with __setstate__ receives a _Missing-placeholder dict it did not produce (no state_setter, unlike the tensor branch at aot.py:148-151); __slots__-only classes are not matched at all so their handles still break; object.__new__ is unsafe for some C-subclass shapes.
  3. ignition/preparation/forward_metadata.py:277-278 — the second consumer is genuinely reachable for recipe classes with a class-level __getattr__ (delegating proxies), which now silently lose their own state protocol in dumps payloads that travel to compiler workers and across hosts; untested by the new test.

Nits: rebuild_manifest.py:365 sibling allowlist not widened (silent omission from rebuild_weights, mitigated by the WeightDeclaration path); test mutates process-global _RecipeKernelOwner.__module__ (line 283) instead of using monkeypatch.setattr; fixture raises TypeError rather than the reported PicklingError; guard_check(...) is True/False bool identity; no __slots__ coverage.

Open validation item: no workflow in .github/workflows/ runs pytest, the head has no CI checks, and the author's caveat says the pytest run predated the rebase onto #509 — design-review.md:247-251 says disclosure does not excuse skipping runnable CPU checks, so the two test files should be recorded as run on 16ffc6f.

Findings are in scratchpad notes #5–#10 (the earlier #1–#4 survey notes remain, with #6 correcting the first run's claim that the forward-metadata path was unaffected).

#12 [high] Report citation map: every finding, its file:line, evidence and fix (PR #574, run 2)

Consolidated citation map for the final report. All at head 16ffc6f, base main, 2 files, +54/−1. Correctness lens. Rules read: charter, AGENTS.md, docs/design-review.md. Endpoints: charter line 12 (keep runtime small/model-agnostic), AGENTS.md:194-199 (meaningful validation), AGENTS.md:294-307 (run pytest), AGENTS.md:379-393 (external recipes; core must never import hyperflare_recipes), design-review.md:42-46 (recipes may be external), :106-115 (validate the real path / disclose unrun checks), :116-123 (principle 13 core compatibility), :247-251 (disclosure does not excuse skipping runnable CPU checks).

CHANGE UNDER REVIEW

FINDING 1 (should fix) — forward_metadata.py:42. Fix names one package; external recipe repos are supported and still break. Evidence: AGENTS.md:379-384 ("external recipe repositories can pass their own Recipe tuples directly to ignition.cli.main(...)"); ignition/cli/init.py:367 def main(argv=None, *, recipes=(), prog="ignition", source_roots=()) with binding at :368-373; ignition/preparation/source_identity.py:12-25 (_EXTRA_ROOTS contextvar), :18-25 (source_roots(roots)), :43 (combined_roots = (*_EXTRA_ROOTS.get(), *extra_roots)), :107-108 (each extra root mixed into the digest); tests/preparation/test_source_identity.py:166-185 exercises an arbitrary extra root. Repo convention for externally owned types is explicit registration (rebuild_manifest.py:41-71 declare_container_fields / weight_container / declare_module_buffers). Fix: drive the predicate from the roots the CLI already receives, or use explicit registration.

FINDING 2 (should fix) — aot.py:155-166 with _guard_object at aot.py:98-99, _set_state at forward_metadata.py:164-165. Guard path emits a 3-tuple (_guard_object, (type(obj),), state) with state = {k: v if id(v) in guard_tree_values else _Missing('unguarded attribute')}. reducer_override wins over __reduce_ex__, so an external class's __getstate__/__reduce__ is skipped; with no state_setter, pickle's BUILD calls the class's __setstate__ when defined, handing it a vars-shaped dict of _Missing placeholders it did not produce -> possible load-time failure. The tensor branch (:148-151) and _ForwardPickler (:213, :278) always pass _set_state, so the object branch is the outlier. Predicate requires hasattr(value, '__dict__'), so slots-only recipe classes are never matched and their Triton handle still raises. object.__new__ raises TypeError: not safe for subclasses of C types whose tp_new is not object's; _NON_OBJECT_NEW_TYPES covers Tensor/Module/Enum/int/float/str/bytes/dict/list/tuple/set/frozenset but not e.g. bytearray/Exception. grep: no __setstate__ anywhere in ignition/, so ignition./b12x. classes are consistent with the current form — this exposure is new only because the prefix now covers another repo's classes. Fix: return (_guard_object, (type(obj),), state, None, None, _set_state); document the contract on _GuardPickler's docstring (aot.py:102-103); consider slot state.

FINDING 3 (should fix) — forward_metadata.py:277-278. if _uses_custom_object_state(value) and hasattr(type(value), '__getattr__'): return _object, (type(value),), dict(vars(value)), None, None, _set_state. Before the PR, classes outside the prefix kept their own reducer even with a class-level __getattr__; now delegating proxies are flattened to vars() and lose __slots__/__getstate__-transformed state silently. Payload reach: compile_pool.py:96-118 (_compile_forward -> loads -> aot_forward), compile_pool.py:137-153 (submit -> dumps/submit_payload), cross-host lent jobs aot.py:986-1003, artifact sharing aot.py:1137-1138. Cache does not protect: aot.py:1181-1183 keys restored-forward paths on (type.__module__, __qualname__, name, signature). New test does not exercise this (its owner has no __getattr__, test_guard_code.py:257-265). Fix: add a dumps/loads round-trip assertion or gate consistently.

NIT A — rebuild_manifest.py:365 still ('b12x.', 'ignition.'). Chain: weight_views (:338-374) -> rebuild_weights_metadata (:441-459) -> runtime_core.py:130 and :367-369 -> heliopause/src/export/binding.rs:467-522 (validate_rebuild_weights at :540) -> BundleIndex.rebuild_weights (docs/runtime-core-design.md:423,454). Omission is silent (validate_weights, rebuild_manifest.py:462-491, only checks entries present). Mitigated by WeightDeclaration (weight_payload_request :418-422, _declared_metadata :425-438). PR description already discloses this site. Fix: share the tuple between the two sites, or state that WeightDeclaration is the supported path for recipe weights.

NITS B-E (tests/preparation/test_guard_code.py): B line 283 assigns _RecipeKernelOwner.__module__ process-globally while only sys.modules is restored (:285) — use monkeypatch.setattr; class-body __module__ at :258 is dead. C :253-254 raises TypeError, not the reported PicklingError from triton.compiler.compiler.CompiledKernel. D :298-302 assert is True/is False while the file elsewhere asserts truthiness (:50-51, :248-249); guard_check is torch's. E no coverage for __slots__, the exact shape the predicate excludes.

VERIFIED POSITIVES: baseline byte-identical for ignition./b12x. (only hyperflare_recipes.* changes path) -> no persisted-state or principle-13 change; test is discriminating (without the prefix _RecipeKernelOwner falls to GuardsStatePickler.reducer_override, whose default reduction pickles vars(obj) including _UnpicklableHandle); core boundary safe (test_core_boundary.py:28-47 AST-only, and :39-47 checks imports, :50-58 excludes this file from the tests-side rule); guard-code cache keys binaries on sha256 of pickle.dumps((tuple(code_parts), closure_args)) (aot.py:206-210) with atomic os.replace (:213-220), so changed pickled bytes mean a cache miss and a new file, never a stale guard.

VALIDATION GAP: grep for pytest under .github/ returns no matches; the only workflows are helios-lifecycle.yml, native-serving.yml (cargo only), release.yml. Head 16ffc6f has no checks. Author's caveat says the pytest run predated the rebase onto 167f22c8. design-review.md:247-251 makes this an acceptance item, not a code defect.

NOT VERIFIABLE HERE: no hyperflare_recipes code in the repo (test_core_boundary.py:40 asserts the directory is absent), so I could not confirm whether any real recipe class uses __slots__, a custom __getstate__/__setstate__, or object identity across a guard round trip — exactly what decides whether findings 2 and 3 are already-live. A recipe-side class with __slots__ and a __setstate__ run through _guard_serialization() would settle it. I did not run the tests.

CORRECTION TO CARRY: scratchpad note #2 (run 1) said the forward-metadata path was unaffected by the widening; note #6 corrects it — reachable for classes with a class-level __getattr__.

#8 [medium] Nits: new test hygiene (module mutation, TypeError vs PicklingError, forward-path gap, bool identity)

All at head 16ffc6f, tests/preparation/test_guard_code.py.

  1. Line 283 _RecipeKernelOwner.__module__ = module_name is a plain assignment to process-global class state; only sys.modules is restored by monkeypatch.setitem on line 285. After the test the class keeps hyperflare_recipes.components._synthetic_guard_test while that module is gone. Use monkeypatch.setattr(_RecipeKernelOwner, '__module__', module_name). Also the class-body __module__ = "hyperflare_recipes.components.synthetic" on line 258 is dead, overwritten on line 283. The neighbouring test (line 204-219) already uses monkeypatch correctly for its module.
  2. Line 253-254 _UnpicklableHandle.__reduce__ raises TypeError; the field report is PicklingError from triton.compiler.compiler.CompiledKernel. Raising pickle.PicklingError would make the regression signature match.
  3. No forward_metadata.dumps/loads round trip, so the second consumer (forward_metadata.py:277) is untested — see note on that path being genuinely reachable for classes with a class-level __getattr__.
  4. Lines 298-302 assert guard_check(...) is True/False; the rest of the file asserts truthiness (lines 50-51, 248-249). guard_check is torch's, not verifiable here.
  5. Coverage gap for the primary path: the test goes through a real torch.compile(..., aot_compile) + serialize/deserialize, which AGENTS.md:194-199 wants; good. But nothing covers the __slots__ case that the predicate's hasattr(value, '__dict__') (forward_metadata.py:41) excludes.

#9 [medium] Nit: rebuild_manifest.py:365 sibling allowlist + positives and CI verification

ignition/preparation/rebuild_manifest.py:365 still startswith(('b12x.', 'ignition.')). Verified:

Positives verified this run (unchanged from run 1):