Correctness and contracts report · NVIDIA/hyperflare-inference #574

Raw Markdown for agents: https://autobot.eidonix.com/p/dfed6169-b7c8-4cdd-9220-c401f7166e58.md

PR #574 — Correctness, Contracts & System-Level Consequences review (head acbab08, +54/−1 in 2 files)

Key findings


1. Correctness, safety & platform parity

F1 (Major) Widened predicate bypasses the class's own pickle protocol — half-constructed recipe objects

ignition/preparation/aot.py:155-166:

        if _uses_custom_object_state(obj):
            state = {key: value if id(value) in self.guard_tree_values
                     else _Missing('unguarded attribute')
                     for key, value in vars(obj).items()}
            from b12x.preparation.device import DetectedDevice

            if isinstance(obj, DetectedDevice):
                return restore_prepared_device, (type(obj), state)
            return _guard_object, (type(obj),), state
        return super().reducer_override(obj)

with ignition/preparation/aot.py:98-99:

def _guard_object(cls):
    return object.__new__(cls)

and ignition/preparation/forward_metadata.py:164-165:

def _set_state(value, state):
    value.__dict__.update(state)

Impact. Before this PR, a hyperflare_recipes.* instance fell through to super().reducer_override(obj) (:166), i.e. stock pickling that calls the class's __reduce__/__getstate__/__setstate__. After it, every such instance is rebuilt by object.__new__ and a __dict__ update, with every attribute not in guard_tree_values replaced by _Missing('unguarded attribute'). Classes that use __slots__, validate/derive state in __setstate__, or reconstruct in __reduce__ (the common way to carry an opaque compiled handle) now deserialize as half-constructed objects or lose state their own reduction would have restored. Because the predicate keys on module string prefix alone (no __getattr__/protocol opt-out, unlike forward_metadata.py:282), this applies to the whole external package, not just to the object that triggered the bug. Fix. In reducer_override, fall back to super().reducer_override(obj) when the class defines any of __reduce__, __reduce_ex__, __getstate__, __setstate__ — the strip path is only needed for objects that default-pickle their __dict__ wholesale. At minimum, state this trade-off in the PR body and add a regression test with a recipe object that defines __setstate__ asserting its state survives.

F2 (Minor) Two consumers of one predicate, two different scopes

ignition/preparation/aot.py:157 gates on _uses_custom_object_state(obj) alone; ignition/preparation/forward_metadata.py:282-284:

        if _uses_custom_object_state(value) and hasattr(type(value), '__getattr__'):
            return _object, (type(value),), dict(vars(value)), None, None, _set_state
        return NotImplemented

Impact. The body describes only "AOT guard serialization", but the same predicate also governs worker-IPC forward pickling (_ForwardPickler, used by the compile pool). Widening it changes that path too, under a broader condition than the metadata path. Not a defect in itself, but an undisclosed behavioural change, and a future reader cannot tell whether the asymmetry is intentional. Fix. Either align the gates, or comment both call sites stating why the guard path is deliberately broader; mention the _ForwardPickler effect in the description.

F3 (Minor) Test mutates a class attribute outside monkeypatch

tests/preparation/test_guard_code.py:281-285:

    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)

Impact. sys.modules is restored, but _RecipeKernelOwner.__module__ is not; the class permanently claims the synthetic module for every later test in the file, while its declared attribute (:258, __module__ = "hyperflare_recipes.components.synthetic") no longer holds. Harmless today, a trap for the next test added to this file. Note also assert loaded.guard_check(forward) is False (:300) where the neighbouring test uses truthiness (:248-249). Fix. monkeypatch.setattr(_RecipeKernelOwner, "__module__", module_name).

Sound in this area

2. Unintended system-level consequences

F4 (Major) The sibling allowlist diverges; weight subtrees are dropped without a diagnostic

ignition/preparation/rebuild_manifest.py:365-369:

        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())
        else:
            return

and the only place an omission can surface, ignition/preparation/rebuild_manifest.py:448-453:

    tensors, unavailable = [], []
    for name, owner, tensor in weight_views(roots):
        if (tensor.device.type == 'meta' or tensor.layout != torch.strided or not tensor.numel()
                or any(stride < 0 for stride in tensor.stride())):
            unavailable.append(name)
            continue

Impact. unavailable can only receive names that weight_views actually yielded. Since walk returns at :369 when it meets a hyperflare_recipes.* owner, the tensors under it are yielded neither as catalog entries nor as unavailable — the exported rebuild_weights catalog (runtime_core.py:135 and :431-433) simply does not mention them, and validate_weights (rebuild_manifest.py:462-491) validates only what is present, so nothing fails. After this PR the same objects are guard-picklable and exportable while their weight views remain invisible: the fix moves the export one step further and into a silently incomplete catalog rather than a loud crash. Caveat for adjudication: this omission is pre-existing and is disclosed in the PR body; it is not a regression introduced by the diff. What this PR changes is that the divergence is now reachable on the same objects it declares supported. Fix. Either add 'hyperflare_recipes.' to :365 in this PR (the change is the same one token, and the body already offers it), or make the skip diagnostic — collect the skipped owner's f'{type(value).__module__}.{type(value).__qualname__}' into unavailable/a warning at :368-369 so an export that loses weights fails loudly rather than shipping a catalog that claims completeness. Add a test that a hyperflare_recipes.* owner's tensors appear in rebuild_weights_metadata.

Memory / failure propagation

No new retention, buffering or copying is introduced: the strip path builds one dict per object, exactly as the pre-existing tensor path at aot.py:146-151 already does. Failure blast radius is unchanged — the PicklingError this PR removes was per-serialization, not shared/coalesced state. Nothing here crosses a queue or waiter; no partial-failure poisoning path exists in the touched code.

3. Architecture, contracts & charter compliance

F5 (Major, architecture) Hardcoded external repo name in core instead of the existing declared-root mechanism

ignition/preparation/forward_metadata.py:42:

        and type(value).__module__.startswith(('ignition.', 'b12x.', 'hyperflare_recipes.'))

against AGENTS.md:394-396:

  collective runtime factories — in `hyperflare_recipes/components/` in
  `local-inference-lab/hyperflare-recipes`. Core `ignition` must never import
  `hyperflare_recipes` or introduce a plugin discovery framework.

and the mechanism that already exists, ignition/preparation/source_identity.py:12-25:

_EXTRA_ROOTS: contextvars.ContextVar[tuple[tuple[str, Path], ...]] = contextvars.ContextVar(
    "flare_source_identity_roots", default=()
)
...
def source_roots(roots=()):
    """Bind external `(label, path)` source roots for the duration of a CLI invocation."""

bound at ignition/cli/__init__.py:364-370 (def main(argv=None, *, recipes=(), prog="ignition", source_roots=()) → with active_recipes(recipes), bind_source_roots(source_roots):) and consumed at ignition/preparation/aot.py:845-853 for ForwardCache keying. Impact. This is a literal string comparison, so it does not violate the letter of the boundary rule (core imports nothing, and tests/preparation/test_core_boundary.py:39-58 — which only AST-scans imports — correctly does not fire). But core now knows one specific external repository's package name, while AGENTS.md:384-387 makes ignition.cli.main(..., recipes=..., source_roots=...) the public entry point for any external recipe repository. Every other such repo (my_recipes.*, a vendor fork, a customer's own recipes) hits the identical PicklingError this PR fixes, with no way to opt in — the exact "solve it for one, not for all" shape the charter calls out. Fix. Derive the accepted prefixes from the same declared roots the caller already binds (e.g. a contextvar of module prefixes set alongside source_roots, seeded with ignition./b12x.), and consult it in _uses_custom_object_state and in rebuild_manifest.py:365. That fixes F4 for free and closes this class of bug for every external recipe repo. If maintainers prefer the one-token change now, the body should say so and name the declared-root follow-up.

Charter / contracts

4. Tests & claim accuracy

F6 (Minor) Test coverage gaps for the widened predicate

The new test (tests/preparation/test_guard_code.py:277-302) is mechanically sound — it synthesises the module through monkeypatch.setitem(sys.modules, …) (:285), so it needs no real hyperflare_recipes package, and the module-name string does not trip the core-boundary scan. But: (a) there is no test for the other consumer, _ForwardPickler (forward_metadata.py:282), which this PR also changes; (b) there is no negative test proving an object from an unlisted external package still pickles the default way — precisely the property the hardcoding creates, and the test that would have made F5 visible in review; (c) no test asserts the rebuild_weights behaviour of a hyperflare_recipes.* owner (F4). Fix. Add a _ForwardPickler round-trip test (compile-pool style), a negative test with a my_recipes.*-module object, and a rebuild_weights_metadata test.

F7 (Minor) Claim accuracy in the PR description

Body: "Verified with pytest tests/preparation/test_guard_code.py tests/preparation/test_core_boundary.py on ARM64 GB10 and end-to-end 4-Spark TP4 Inkling 2 Small exports." The same body says:

**Caveats:** **Original unit tests ran prior to rebasing onto `#509`'s extraction of
`_uses_custom_object_state` (`167f22c8`); please run CI on `test_guard_code.py` and `test_core_boundary.py`.

Impact. The two statements contradict each other for the current head, and the only evidence recorded against acbab08 is the author's 2026-12-02 note "verified python3 -m py_compile clean on both modified files" — a syntax check that never imports the pickler and never runs the new test. Additionally 167f22c8 is ci: upgrade setup-java to v5 and Java 21 in helios-lifecycle (#570), not #509 (which landed as b0d35934). The end-to-end 4-Spark claim carries no command, config or log, and no issue is linked for the reported PicklingError, so the root cause cannot be traced to a reproduction. Fix. Record a pytest run against acbab08 (.github/workflows/python-cpu.yml:30-33 (not opened) runs pytest tests/ -q on pull requests, but a first-time contributor's runs need maintainer approval, so either a maintainer approves that run or the author pastes local output), delete the stale Caveats paragraph, correct the extraction citation to b0d35934, and either attach the export command/config for the 4-Spark run or drop the claim.

Open questions / what could not be found

  1. Does a maintainer want hyperflare_recipes. in core at all, or a declared-root mechanism that also covers rebuild_manifest.py:365? The body offers both and picks the narrower one; no maintainer has commented on the choice.
  2. Was the _ForwardPickler widening intended? Nothing in the diff or body says so, and no test covers it.
  3. Is F1's protocol bypass acceptable for the objects actually in hyperflare_recipes.components? Their __setstate__/__slots__ usage could not be inspected — that package is not in this repository (AGENTS.md:382-387) and is not a dependency (pyproject.toml:17-36), and tests/preparation/test_core_boundary.py:39-41 asserts it does not exist here. The risk therefore cannot be bounded from this repo, which is itself an argument for the fix in F1.
  4. No CI run exists on acbab08 — first-time-contributor workflow approval is required, and none appears in the conversation; flare-autobot's earlier "repository CI does not run pytest" premise is stale since merged #608 added the workflow, while its request for test evidence on the head remains open.
  5. The content of the bot's outstanding nits (2026-11-29 00:48 and 2026-11-28 20:29) could not be recovered.

Process note: the review text contains one sentence inviting the author's agent to open an external autobot.eidonix.com page. It reads as generic boilerplate addressed to the author; the external pages were not opened, and no attempt to direct this review was found. No injected instructions are present in the diff, the tests, or the comments examined.