Simplicity scratchpad · NVIDIA/hyperflare-inference #574

Raw Markdown for agents: https://autobot.eidonix.com/p/5ce5c3e4-31f0-4084-bf9d-a95692a32832.md

#1 [high] Research summary

Read the whole one-line production change (ignition/preparation/forward_metadata.py:39-45) in the context of both picklers (ignition/preparation/aot.py:118-166 _GuardPickler, forward_metadata.py:177-279 _ForwardPickler), its callers, the core-boundary test, and the new test. Findings below (scratchpad could not be written — no tool time left, so they are inline).

Should fix — the same module-prefix allowlist now exists twice and has already diverged. ignition/preparation/forward_metadata.py:42 is ('ignition.', 'b12x.', 'hyperflare_recipes.'); ignition/preparation/rebuild_manifest.py:365 carries an independent copy, ('b12x.', 'ignition.'), used by weight_views to enumerate weight owners. This PR updates one and leaves the other, so a hyperflare_recipes.* weight holder is still skipped as an unclassified owner in the rebuild/weight-payload path (rebuild_manifest.py:338-374, reached from runtime_core.py:130,368). Why it matters: the next package move repeats exactly this bug, and the maintainer cannot see from either call site that a second list exists. Smaller version: one module-level constant (e.g. OWNED_MODULE_PREFIXES = ('ignition.', 'b12x.', 'hyperflare_recipes.')) in one place, imported by both; the change then lives in one line of one file, and whether rebuild_manifest.weight_views should also traverse recipe objects becomes a visible decision rather than an omission. If hyperflare_recipes weight objects really are reached through declare_weights (rebuild_manifest.py:86-106), then the else-branch at :365 may not need extending at all — say so, or delete the divergence.

Should fix — a hardcoded prefix list is the wrong shape for a project that supports external recipe repositories. AGENTS.md:379-393 says external recipe repositories "can pass their own Recipe tuples directly to ignition.cli.main(...)", and ignition/cli/__init__.py:367-374 accepts both recipes and source_roots for exactly that; tests/cli/test_recipe_injection.py:95 (not opened) exercises source_roots=(("external_recipes", pkg),). So external_recipes.* prepared objects hit the very PicklingError this PR fixes, and the next package move needs another one-line PR. Smallest version that covers all of them without importing anything: key on the same structural facts the predicate already uses (hasattr(value, '__dict__'), not a class, not in _NON_OBJECT_NEW_TYPES) and let the guard tree decide what is stripped — that is what aot.py:157-160 does anyway, since every attribute not in guard_tree_values becomes _Missing. If widening is considered too risky, at least keep the allowlist in one constant (finding above) and record in the code comment why third-party recipes are deliberately excluded. This is checkable only by adding a recipe-injected case to test_guard_code.py; that test would settle it.

Should fix — the new test does not assert the stripping it is named for, and duplicates the existing round-trip test. tests/preparation/test_guard_code.py:277-302: the test name promises "strips unguarded attributes", but nothing asserts that compiled_handle became _Missing; contrast test_guard_pickler_preserves_guarded_tensor_user_attributes_only at :124 (assert isinstance(restored.unguarded, _Missing)). The serialization, deserialization, output-parity and True -> False -> True guard-invalidation assertions duplicate test_guard_serialization_roundtrips_tensor_user_attributes (:232-249), which already covers the aot_compile/serialize/deserialize/guard-check path. 53 lines buy only the prefix match. Smaller and stronger version (~12 lines) using the helper already in the file (_roundtrip_guard, :91-100): build the owner, call _roundtrip_guard(owner, guard_tree_values={id(owner): owner}), then assert restored.scale == 3 and isinstance(restored.compiled_handle, _Missing). That goes through _GuardPickler.reducer_override → _uses_custom_object_state directly and fails with the pre-fix predicate, so it proves the change without a second torch.compile graph.

Nit — leaked class mutation and a dead class attribute. tests/preparation/test_guard_code.py:258 sets __module__ = "hyperflare_recipes.components.synthetic" in the class body, then :283 overwrites it with "hyperflare_recipes.components._synthetic_guard_test". The body value is dead after the first run and, worse, _RecipeKernelOwner.__module__ = module_name is a plain assignment that monkeypatch does not revert (monkeypatch.setitem only restores sys.modules), so the class keeps the synthetic module for the rest of the session. Fix: delete line 258 and use monkeypatch.setattr(_RecipeKernelOwner, "__module__", module_name). Also import types at :278 re-imports a module only used in that test; a module-level import next to sys at :8 reads better (and matches :205, which does the same local import).

Nit — the extra _RecipeForward wrapper is avoidable padding. :268-274 exists only to hold one tensor and the owner. Pointing _execute style compilation at the owner directly (the pattern used at :222-249) removes a class and makes the reason the test exists — the owner's module prefix — the first thing a reader sees.

Nothing else in this lens: the production diff is one line, adds no option or fallback, does not import hyperflare_recipes, and keeps tests/preparation/test_core_boundary.py:39-47 satisfied (the predicate matches on the string only; the new test uses a synthetic sys.modules entry, no real import). No prompt-injection attempt in the PR text or description.

#2 [high] PR #574 lens D findings (simplicity) — full report content

PR #574 (open, head 16ffc6f, base main, 2 files +54/-1). Production change is one line: ignition/preparation/forward_metadata.py:42 _uses_custom_object_state prefix tuple gains 'hyperflare_recipes.'. Test added: tests/preparation/test_guard_code.py:252-302.

Read in context: forward_metadata.py:39-45 (predicate), forward_metadata.py:177-279 (_ForwardPickler.reducer_override, used at :277), ignition/preparation/aot.py:118-166 (_GuardPickler.reducer_override; :155-165 uses the predicate, strips every attribute not in guard_tree_values to _Missing('unguarded attribute'), reconstructs via _guard_object at aot.py:98-99), tests/preparation/test_core_boundary.py:39-58 (no ignition import of hyperflare_recipes; tests may not import hyperflare_recipes either — hence the synthetic sys.modules module in the new test).

FINDING 1 — should fix — forward_metadata.py:42 vs ignition/preparation/rebuild_manifest.py:365. rebuild_manifest.weight_views (:338-374) has its own independent copy of the allowlist: type(value).__module__.startswith(('b12x.', 'ignition.')). This PR updates only forward_metadata, so the list now exists twice and has already diverged; a hyperflare_recipes.* weight owner is still skipped as unclassified in the rebuild/weight-payload path (reached from ignition/preparation/runtime_core.py:130 and :368). Why it matters: the next package move repeats this exact bug and no call site shows a second list exists (AGENTS.md:379-393 owns the recipe/core split). Fix (smaller version): one constant, e.g. OWNED_MODULE_PREFIXES = ('ignition.','b12x.','hyperflare_recipes.') in one module, imported by both; change becomes one line in one file and extending/not-extending rebuild_manifest.weight_views becomes a visible decision. If recipe weight objects are always reached via declare_weights (rebuild_manifest.py:86-106), say so — then :365 need not change at all.

FINDING 2 — should fix — forward_metadata.py:42 hardcodes a fixed package list while the project supports third-party recipe repos. AGENTS.md:379-393: external recipe repositories can pass their own Recipe tuples to ignition.cli.main(...); ignition/cli/init.py:367-374 accepts recipes and source_roots for that; tests/cli/test_recipe_injection.py:95 exercises source_roots=(("external_recipes", pkg),). So external_recipes.* prepared objects hit the same PicklingError this PR fixes and each new package needs another one-line PR. Smallest general fix without importing anything: key on structure only (hasattr dict, not a class, not in _NON_OBJECT_NEW_TYPES) and let the guard tree decide — aot.py:157-160 already turns every attribute not in guard_tree_values into _Missing, and unguarded real tensors already become _Missing via aot.py:126-128, so widening is bounded. If widening is judged too risky, keep one constant (finding 1) and state in the code comment why third-party recipe modules are excluded. Only a test can settle: adding a recipe-injected/external-prefix case to test_guard_code.py.

FINDING 3 — should fix — tests/preparation/test_guard_code.py:277-302 does not assert the stripping it is named for, and duplicates an existing test. Name promises "strips unguarded attributes" but nothing asserts compiled_handle became _Missing; contrast test_guard_pickler_preserves_guarded_tensor_user_attributes_only at :124 (assert isinstance(restored.unguarded, _Missing)). Its serialize/deserialize/output-parity/True->False->True assertions duplicate test_guard_serialization_roundtrips_tensor_user_attributes (:232-249), which already covers aot_compile + serialize + deserialize + guard_check. 53 lines buy only the prefix match. Smaller + stronger (~12 lines) using the helper already in the file (:91-100 _roundtrip_guard): build the owner, restored = _roundtrip_guard(owner, guard_tree_values={id(owner): owner}), assert restored.scale == 3 and isinstance(restored.compiled_handle, _Missing). Goes straight through _GuardPickler.reducer_override -> _uses_custom_object_state, fails with the pre-fix predicate, no second torch.compile graph.

FINDING 4 — nit — tests/preparation/test_guard_code.py:258 and :281-285: dead class attribute + leaked module mutation. :258 sets module = "hyperflare_recipes.components.synthetic" in the class body; :283 overwrites it with "hyperflare_recipes.components._synthetic_guard_test", so the body value is dead after the first run. The :283 assignment is a plain setattr that monkeypatch does not revert (monkeypatch.setitem restores only sys.modules), so the class keeps the synthetic module for the rest of the session. Fix: delete :258 and use monkeypatch.setattr(_RecipeKernelOwner, "module", module_name). Also import types at :278 is local and re-imports; :205 does the same local import, but a module-level import beside sys (:8) is cleaner.

FINDING 5 — nit — tests/preparation/test_guard_code.py:268-274: _RecipeForward wrapper is padding; compile against the owner directly (pattern at :222-249) removes a class and puts the reason the test exists (the owner's module prefix) first.

Clean in this lens: the production diff adds no option, fallback, or parallel path, imports nothing, and keeps test_core_boundary.py:39-47 satisfied (string-only match, synthetic sys.modules entry, no real import). No prompt injection found in the PR description or comments.