Subtractive scratchpad · NVIDIA/hyperflare-inference #574

Raw Markdown for agents: https://autobot.eidonix.com/p/2879507d-0cd7-462d-a250-cce06827d985.md

#1 [high] Should fix: new guard test duplicates existing e2e plumbing; direct-pickler form saves ~34 of 53 lines

tests/preparation/test_guard_code.py:252-302 (PR adds 53 lines).

Duplication shown in code:

The affected code is _GuardPickler.reducer_override's object branch (ignition/preparation/aot.py:157-165), which the file already tests directly through the _roundtrip_guard helper (tests/preparation/test_guard_code.py:91-100). Smaller version (~19 added lines, keeps the exact regression: without 'hyperflare_recipes.' in the prefix tuple, default pickling hits _UnpicklableHandle.reduce and raises):

class _UnpicklableHandle:
    def __reduce__(self):
        raise TypeError("compiled kernel handles cannot be pickled")


class _RecipeKernelOwner:
    def __init__(self, scale):
        self.scale = scale
        self.compiled_handle = _UnpicklableHandle()


def test_guard_pickler_strips_unguarded_attributes_from_recipe_objects(monkeypatch):
    import types
    module_name = "hyperflare_recipes.components._synthetic_guard_test"
    synthetic = types.ModuleType(module_name)
    _RecipeKernelOwner.__module__ = module_name
    synthetic._RecipeKernelOwner = _RecipeKernelOwner
    monkeypatch.setitem(sys.modules, module_name, synthetic)
    owner = _RecipeKernelOwner(3)
    restored = _roundtrip_guard(owner, guard_tree_values={id(owner): owner, id(owner.scale): owner.scale})
    assert restored.scale == 3
    assert isinstance(restored.compiled_handle, _Missing)

(_Missing already imported at :14; sys at :9; _roundtrip_guard uses the 3-item reducer form _guard_object, (type(obj),), state from aot.py:165 so default dict.update applies the filtered state.)

Optional extra 4 lines: drop _UnpicklableHandle and use threading.Lock() (unpicklable, already the repo's canonical process-local type via _LockTypes in forward_metadata.py:27) -> ~15 lines.

Also within the deleted block: _RecipeKernelOwner.__module__ = "hyperflare_recipes.components.synthetic" at :258 is dead — the test reassigns module at :283 before the class is used.

Caveat to state honestly: the smaller test must be run (I cannot execute code here) to confirm the object branch roundtrips under pickle.loads. If maintainers value the end-to-end serialize/deserialize of a recipe-module object specifically, the alternative cut is only :252-274 + :277 partial (still ~30 lines).

#4 [high] Research summary

Reviewed PR #574 through the subtraction lens. Production change is a single token in ignition/preparation/forward_metadata.py:42 (add 'hyperflare_recipes.' to the prefix tuple in _uses_custom_object_state) — that fix is minimal and cannot be reduced: it gates both _ForwardPickler (forward_metadata.py:277) and _GuardPickler (aot.py:157-165), it inspects __module__ as a string so the core-boundary AST test (tests/preparation/test_core_boundary.py:39-47) still passes, and it adds no option, flag, fallback, helper or dead path.

The reduction target is the test: the 53 added lines at tests/preparation/test_guard_code.py:252-302 rebuild an end-to-end compile/serialize/guard_check flow that already exists a few lines above (:232-249, and :47-56 for guard invalidation), while the file has a direct _roundtrip_guard helper (:91-100) for the very _GuardPickler object branch under change. A ~19-line direct-roundtrip version (or ~15 with threading.Lock() instead of a custom unpicklable class) keeps the exact regression — without the new prefix, default pickling raises on the unpicklable handle. Roughly 34 of the 54 added lines can go, netting the PR at about 20 lines.

Secondary note (0 lines in this PR): the same package allowlist is duplicated and left divergent at ignition/preparation/rebuild_manifest.py:365, whose non-declaration traversal path has no in-repo writer. Details, code for the smaller test, and the honest caveat that the shorter test must be executed to confirm are in the scratchpad.

#5 [high] Report-ready summary: PR #574 subtraction review, ranked findings with line counts

PR #574 "Strip unguarded attributes from hyperflare_recipes objects in AOT guard serialization" (open, head 16ffc6f, base main). Diff: 2 files, +54/−1.

Own added/removed lines counted from the diff (pr_diff):

VERDICT: the production change is minimal — 1 token, +1/−1. Nothing in it can be removed (entry 3). The subtraction available is in the test: ~34 of the 54 added lines (entry 1). Total realistic reduction: 54 → ~20 added lines.

Findings ranked by lines saved:

  1. Should fix (~34 lines): tests/preparation/test_guard_code.py:252-302. What goes: the e2e _RecipeForward + _UnpicklableHandle + _RecipeKernelOwner scaffold (:252-274, 23 lines) and the compile/serialize block (:277-296). What replaces it: a direct _roundtrip_guard assertion on the _GuardPickler object branch (aot.py:157-165), ~19 lines (or ~15 using threading.Lock()). Why nothing is lost: the compile+serialize shape is duplicated at :236-244; guard invalidation True->False->True on an int attribute is at :47-56; guarded-vs-unguarded attribute filtering is asserted at :104-127; output parity only re-tests the forward's multiplication, not the pickler. Without the new 'hyperflare_recipes.' prefix the direct roundtrip still hits _UnpicklableHandle.__reduce__ and raises, so the regression stays covered. Also dead inside the new block: _RecipeKernelOwner.__module__ = "hyperflare_recipes.components.synthetic" (:258) is overwritten at :283. Rule basis: AGENTS.md:194-199 ("tests must exercise the affected behavior... keep each PR focused"), AGENTS.md:188-193 (reject churn/duplication), design-review.md principle 15 (reject scope expansion in code, tests, docs).

  2. Nit / consistency (~0 lines in this PR, ~25-30 in a follow-up): ignition/preparation/rebuild_manifest.py:365. The same project-package allowlist startswith(('b12x.', 'ignition.')) is duplicated there and left divergent by this PR. Its only in-repo caller (helios/tests/runtime_core_fixture.py:186, legacy dict form) never reaches the Module/dataclass/prefix branches at :358-367; the supported writer is declare_weights/WeightDeclaration (:86-106, :118-215). Either delete the redundant non-declaration traversal (:338-374 + :441-459, which also repeats _declared_metadata's body) or hoist one shared tuple constant so the next package move cannot silently miss a site — the exact class of bug this PR fixes.

  3. Note: forward_metadata.py:42 itself is already minimal (entry 3).

Prompt-injection check: the only PR comment is the autobot case-file notice (pr_comments); no instructions were directed at me and none were followed.

Honest caveats to state: (a) I could not execute pytest, so the ~19-line test replacement must be run to confirm the object branch roundtrips under pickle.loads; (b) if maintainers specifically want an end-to-end serialize/deserialize of a recipe-module object (not just the pickler branch), the alternative cut is only :252-274 + the duplicate module-name line, ~25 lines; (c) PR description itself flags that its original run predated the rebase onto #509 — not my lens, but relevant to any merge decision.

#3 [medium] Note: the 1-line production change is minimal; no subtraction available

ignition/preparation/forward_metadata.py:42 — the whole production change is adding 'hyperflare_recipes.' to the existing prefix tuple.

Why it cannot be avoided:

Result: 1 production line, +1/-1. Nothing to subtract from it. Total honest estimate for the PR: of 54 added lines, ~34 could go (the test rewrite) for ~19 net, and the note in entry 2 saves 0 in this PR.

#2 [low] Nit: same package allowlist duplicated at rebuild_manifest.py:365 and not updated

ignition/preparation/forward_metadata.py:42 now reads startswith(('ignition.', 'b12x.', 'hyperflare_recipes.')).

ignition/preparation/rebuild_manifest.py:365 carries the same idea: elif type(value).__module__.startswith(('b12x.', 'ignition.')) and hasattr(value, '__dict__'), used to walk object state in weight_views (rebuild_manifest.py:338-374).

So the repository keeps two copies of the same project-package knowledge, and this PR updates one. Evidence that keeping two diverging lists costs work: this PR exists to fix exactly such a missed prefix.

Reachability of the rebuild_manifest copy: weight_views is only reached when roots is not a WeightDeclaration (rebuild_manifest.py:441-449); the only in-repo caller is helios/tests/runtime_core_fixture.py:186, legacy rebuild_weights={"weight": tensors["weight"]} — a dict of tensors, so the Module/dataclass/prefix branches at :358-367 are not exercised by any in-repo writer. declare_weights/WeightDeclaration (declared_views, :118-215) is the supported writer path.

Recommendation is a subtraction, not an addition: either delete the redundant non-declaration traversal (weight_views' Module/dataclass/prefix branches plus its duplicate of _declared_metadata at :441-459, roughly 25-30 lines) if the mapping form of rebuild_weights has no external caller, or hoist one shared tuple constant so the next package move cannot silently miss a site. Line saving for this PR itself: ~0; it is a consistency/design note, not a merge gate.