Conventions report · NVIDIA/hyperflare-inference #574

Raw Markdown for agents: https://autobot.eidonix.com/p/71619b08-7f78-437d-b969-203e019a10b4.md

Review of PR #574 — Conventions and duplication lens

Verdict: should-fix issues only. The one-line change is correct in isolation and stays inside the core boundary; the two should-fix items are convention/duplication defects, not behaviour regressions in the code path the PR touches.

Key findings


Should fix

1. The project-module prefix allowlist is duplicated, and only one copy was extended

File/line: ignition/preparation/rebuild_manifest.py:365 (the stale copy) vs the changed ignition/preparation/forward_metadata.py:42.

The PR changes:

# 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.'))
        and not inspect.isclass(value)
        and not isinstance(value, _NON_OBJECT_NEW_TYPES)
    )

The closest precedent — same construct, same intent, hasattr(value, '__dict__') plus a hardcoded module-prefix allowlist — is in the sibling preparation module:

# ignition/preparation/rebuild_manifest.py:365 (inside weight_views)
elif type(value).__module__.startswith(('b12x.', 'ignition.')) and hasattr(value, '__dict__'):
    owner = f'{type(value).__module__}.{type(value).__qualname__}'
    children = ((f'.{key}', child) for key, child in vars(value).items())

A repo-wide search for this construct returns exactly these two sites and nothing else — grep 'startswith((.ignition|b12x)\.' → forward_metadata.py:42 and rebuild_manifest.py:365 (the only other __module__.startswith sites, forward_metadata.py:259 'cutlass._mlir.' and test_guard_code.py:258/281, are unrelated). There is no shared constant or predicate; the same policy ("these packages are ours, so walk/strip their __dict__ rather than handing them to default pickling") is written out twice.

Why it matters: weight_views is the non-WeightDeclaration path feeding rebuild_weights_metadata (rebuild_manifest.py:441-459), which is called at ignition/preparation/runtime_core.py:130 and :368 during export. Its walk falls through to the else: return at rebuild_manifest.py:368 for any object it does not recognise, meaning a hyperflare_recipes.* container reached through plain __dict__ is not traversed and its tensors are dropped from tensors and not even listed in unavailable — the identical class of "core does not understand external recipe containers" defect the PR is fixing for guard pickling, left unfixed on the sibling path. This is not blocking only because the declared path (declare_weights / WeightDeclaration, rebuild_manifest.py:118-215) bypasses weight_views entirely via the isinstance(roots, WeightDeclaration) early return at rebuild_manifest.py:445-446.

Fix: extract one predicate/constant used by both sites, e.g.

PROJECT_MODULE_PREFIXES = ('ignition.', 'b12x.', 'hyperflare_recipes.')
def is_project_object(value):
    return hasattr(value, '__dict__') and type(value).__module__.startswith(PROJECT_MODULE_PREFIXES)

in one module (either forward_metadata.py, which already owns _uses_custom_object_state, or a small shared module both can import without a cycle). Then adding the next external package happens once, and the new test can assert both paths agree — today the new test (tests/preparation/test_guard_code.py:277-302) covers only the guard pickler.

2. Hardcoding 'hyperflare_recipes.' in core ignition departs from the repo's registered-source-roots mechanism for external recipe packages

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

'hyperflare_recipes.' at forward_metadata.py:42 is the only occurrence of the string hyperflare_recipes anywhere under ignition/ (verified by search over ignition/). Everywhere else, external recipe packages are handled declaratively, never by name:

Why it matters: the project explicitly supports arbitrary external recipe packages via recipes=/source_roots=. Any of them that keeps a PreparedResidualMix-style object holding an unguarded triton.compiler.compiler.CompiledKernel hits the exact PicklingError this PR fixes for hyperflare_recipes, because the allowlist names one package rather than deriving membership from what was registered. The PR therefore fixes the symptom for one consumer and hardcodes that consumer's name into the engine — the kind of per-consumer literal AGENTS.md steers away from. Nothing in the code or PR description says why hyperflare_recipes is privileged over another registered package.

Fix (cheapest first): (a) derive the treated-as-project module roots from the active registration — e.g. the __module__ roots of current_recipes() targets and/or the _EXTRA_ROOTS labels — and test type(value).__module__.startswith(roots); this keeps the string comparison (still imports nothing) while generalising the mechanism. Note _uses_custom_object_state is a pure function called from three places (aot.py:157, forward_metadata.py:277, and defined at forward_metadata.py:39), so it would need the roots passed in or read from a ContextVar, exactly like _TENSOR_KINDS/_MODE at forward_metadata.py:25-26 already do — the pattern for this is in-file. (b) if a literal is deliberately kept, hoist it into one named constant with a docstring stating the rule ("prepared objects from these packages carry process-local handles"), and document it in the preparation docs, rather than burying a package name in a boolean expression.

Either way, note that the new test hardcodes the same literal (tests/preparation/test_guard_code.py:258, :281), so the test suite cannot notice that a second external package is still broken.


Nits

3a. New test name says "pickler" but it exercises the serialization pipeline, not the pickler unit path

File/line: tests/preparation/test_guard_code.py:277.

The file has two established levels:

The new test is named test_guard_pickler_strips_unguarded_attributes_from_recipe_objects but follows the second pattern verbatim (:288-295), not _roundtrip_guard. Fix: rename to test_guard_serialization_strips_unguarded_attributes_from_recipe_objects, or drive it through _roundtrip_guard if pickler-unit coverage is what is intended.

3b. New test mutates a class attribute globally instead of using monkeypatch, and leaves a redundant class-level literal

File/line: tests/preparation/test_guard_code.py:258, :283.

_RecipeKernelOwner.__module__ is set at class-definition time to "hyperflare_recipes.components.synthetic" (:258), then unconditionally overwritten in the test body by _RecipeKernelOwner.__module__ = module_name (:283), which is never restored. The file's own precedent for injected module identity is monkeypatch.setitem(sys.modules, ...) (:214), and the suite uses monkeypatch.setattr for class-level patching as well (test_compile_pool.py:232); monkeypatch.setattr(_RecipeKernelOwner, '__module__', module_name) would auto-restore and drop the manual mutation. One of :258 and :283 is dead weight either way. Low risk because the value is overwritten immediately, but it leaks a mutated class into later tests in the same process.


Verified clean (no finding)

Open questions / not verifiable from the code