Conventions scratchpad · NVIDIA/hyperflare-inference #574

Raw Markdown for agents: https://autobot.eidonix.com/p/cffbba65-b81e-4a64-9a50-e51706c06752.md

#1 [high] Should fix: project-package prefix allowlist duplicated in forward_metadata and rebuild_manifest, and only one copy extended

PR #574 changes _uses_custom_object_state (ignition/preparation/forward_metadata.py:39-45) from type(value).__module__.startswith(('ignition.', 'b12x.')) to ... ('ignition.', 'b12x.', 'hyperflare_recipes.').

Closest precedent / duplicate: ignition/preparation/rebuild_manifest.py:365 in weight_views: elif type(value).__module__.startswith(('b12x.', 'ignition.')) and hasattr(value, '__dict__'): — same construct (hasattr dict + module-prefix allowlist) encoding the same "our packages" policy, and it was NOT updated. There is no shared helper or constant: grep for the prefixes returns exactly these two sites (startswith(('ignition. / "'b12x.")).

Why it matters: weight_views feeds rebuild_weights_metadata (rebuild_manifest.py:441-459) for the legacy (non-WeightDeclaration) roots path used by runtime_core.py:130 and :368. A hyperflare_recipes.* container holding tensors reached through plain __dict__ is still not traversed there, so its tensors are silently reported in unavailable — the same class of "core doesn't know external recipe objects" defect the PR fixes for guard pickling, left unfixed on the sibling path. (The declared declare_weights/WeightDeclaration path at rebuild_manifest.py:118-215 is unaffected, which is why it isn't blocking.)

Fix: one module-level constant/predicate, e.g. PROJECT_MODULE_PREFIXES = ('ignition.', 'b12x.', 'hyperflare_recipes.') plus def is_project_object(value), in one place (forward_metadata or a small shared module), consumed by both sites. Then a new external package prefix is added once, and a test can assert both paths agree (the new test only covers the guard pickler).

#2 [high] Should fix: hardcoded recipe-package name departs from the repo's registered-source-roots mechanism for external recipe packages

Established pattern for external recipe packages in core ignition is declarative registration, not a name allowlist:

PR #574 instead hardcodes the literal string 'hyperflare_recipes.' in core ignition (forward_metadata.py:42). Consequence: any other external recipe package — which the project explicitly supports via recipes=/source_roots= — hits the identical PicklingError: Can't pickle ... CompiledKernel that this PR fixes for hyperflare_recipes. The fix generalizes one package, not the mechanism, and there is no documented reason hyperflare_recipes is privileged over another registered package.

Fix options, cheapest first: (a) derive the treated-as-project module roots from the active recipes (e.g. the __module__ roots of current_recipes() / registered source_roots) instead of a literal, keeping the string check so core still imports nothing; (b) if a literal is kept, put it in one named constant with a docstring stating the rule and update docs/preparation-development.md. Either way, note that the new test hardcodes the same literal (tests/preparation/test_guard_code.py:281), so the test cannot notice a second external package.

#3 [medium] Nit: new test name and monkeypatch style diverge from the sibling test's precedent

Nit-level convention notes for PR #574, verified in code (the previous attempt to save this was rejected because only finish was then available):

  1. Nit — new test name diverges from its closest precedent. tests/preparation/test_guard_code.py:232 has test_guard_serialization_roundtrips_tensor_user_attributes, which uses _guard_serialization() + torch.compile(...).aot_compile + serialize/deserialize. The new test (test_guard_code.py:277) is named test_guard_pickler_strips_unguarded_attributes_from_recipe_objects but exercises exactly the same serialization pipeline, not the direct _GuardPickler unit path used by _roundtrip_guard (test_guard_code.py:91-100, used by the test_guard_pickler_* tests at 104/146/178/204). Fix: rename to test_guard_serialization_strips_unguarded_attributes_from_recipe_objects, or drive it through _roundtrip_guard if the pickler unit level is what is meant.

  2. Nit — the new test mutates a class attribute globally rather than through monkeypatch. test_guard_code.py:283 does _RecipeKernelOwner.__module__ = module_name and never restores it; the file's other tests use monkeypatch.setitem(sys.modules, ...) (line 214) and monkeypatch.setattr elsewhere in the suite (test_compile_pool.py:232), and monkeypatch.setattr(_RecipeKernelOwner, '__module__', module_name) would auto-restore. Also note the class already carries a stale class-level default __module__ = "hyperflare_recipes.components.synthetic" (line 258) that is immediately overwritten by the test, so one of the two is redundant.

  3. Verified clean (no finding) in this lens:

    • No new duplication of existing helpers: the PR adds no helper; it reuses _GuardPickler (aot.py:102-166) and _uses_custom_object_state (forward_metadata.py:39), whose _Missing stripping at aot.py:157-165 is unchanged.
    • No import of hyperflare_recipes is introduced, so tests/preparation/test_core_boundary.py:39-58 stays satisfied; only a string comparison changes (forward_metadata.py:42). Consistent with AGENTS.md:392-393 ("Core ignition must never import hyperflare_recipes").
    • PR description follows AGENTS.md:72-153's four-part scheme and carries the required Discord: woooflet line (AGENTS.md:142-153).

Scratchpad entries: 1 (Should fix: prefix allowlist duplicated in forward_metadata.py:42 vs rebuild_manifest.py:365), 2 (Should fix: hardcoded hyperflare_recipes. literal vs the repo's registered recipes=/source_roots= mechanism), 3 (this nit note).