Correctness scratchpad · NVIDIA/hyperflare-inference #581

Raw Markdown for agents: https://autobot.eidonix.com/p/cb6cbef4-6d71-4367-826b-89fce91ae645.md

#1 [high] Should fix: prior-flag rejection happens after graph mutation (partial mutation on error path)

File: ignition/preparation/runtime_core.py:208-243 (new code at 224-229 validate request, 237 instantiate_graph, 238-242 read+validate prior flags).

Issue: the requested-flag check (lines 224-229) runs before any mutation, but the executable-derived check runs after graph.retain_object((pools, tuple(owners)), synchronize_before_release=True) (236) and instantiate_graph(graph) (237). On prior_flags & ~PERMITTED (240-241) the function raises leaving the graph instantiated and holding newly retained pool/owner references, with no _flare_instantiation_flags set. Caller ignition/preparation/capture.py:193 (record_export_graph inside capture_forwards' try/except) just propagates, so the partially-mutated graph is abandoned mid-capture.

Why it matters: docs/design-review.md testing-hierarchy clause 1 requires Python suites to "validate rejection without partial mutation"; principle 6 ("Make storage and lifetimes explicit") and docs/preparation-development.md:140-150 (executables/pool owners retained until a confirmed native drain) make a half-retained, half-flagged graph a lifetime hazard. The PR description claims "rejecting unsupported bits on either source before mutating graph state", which is not true for the executable-derived source (voipmonitor's review finding 3 flagged the same description inaccuracy).

Verified by code reading; the new test at tests/preparation/test_capture_graph_metadata.py:244-249 only asserts the ValueError, not the post-failure state (contrast the bad case at 251-255 which does assert bad.instantiations == 0 and not bad._retained.objects).

Fix options: (a) check the reason before instantiating is impossible for bit 1 (set by instantiation), so on rejection undo — but torch has no cheap undo other than graph.reset(); (b) accept the mutation but document it and assert the resulting state in the test; (c) drop the executable-derived hard rejection and instead mask/report it. At minimum correct the PR description.

Note the executable-derived flags route is precisely where PyTorch may add bits over time (e.g. CUDA's DEVICE_LAUNCH=2 / UPLOAD=4 / STRICT_PRIORITY=0x10 exist in CUgraphInstantiate_flags), so this path is reachable in principle on other drivers/torch versions — exactly the "existing cores still load / supported targets" dimension of docs/design-review.md principle 13.

#2 [high] Findings verified OK: flag values, Rust-side contract, helios instantiation path

#3 [high] Should fix: new _flare_instantiation_flags state has no invalidation path (stale flags after reset / re-capture)

File: ignition/preparation/runtime_core.py:238-242 (sets graph._flare_instantiation_flags) and 282-287 (_graphs prefers the attribute over the live executable).

Two related issues, both about this new Python-side state living outside CUDA's own lifecycle:

  1. instantiation_flags=None keeps "executable-derived flags", but the implementation merely skips setting the attribute; it never clears an existing one. If a graph has been through record_export_graph once and the code path later re-records it with instantiation_flags=None, the stale _flare_instantiation_flags survives and _graphs() keeps emitting instantiate_flags (template-only export, no executable) instead of falling back to the live executable. The author's test at tests/preparation/test_capture_graph_metadata.py:236-242 exercises only a fresh graph, so the clearing branch is untested.

  2. Nothing clears _flare_instantiation_flags when the executable dies. Every other piece of export-time graph state is invalidated on the same event: _RecordedGraphMetadata.release (runtime_core.py:153-158) zeroes self.executable from the destroy callback, and RecordedExportGraph.reset (185-189) drops recorded/pools/owners. A torch.cuda.CUDAGraph may be reset() and re-captured; after that, _graphs() still prefers the stale attribute over the new executable, so the core records a flag word computed from an executable that no longer exists — precisely the executable/flags mismatch that capture_rank validates for the non-flag shape (heliopause/src/export/capture.rs:2820-2824 cannot detect this because the mismatch has been erased).

Severity: should fix (latent; the only current caller, capture.py:171-193, allocates a fresh graph per capture, so it is not reachable from capture_forwards today). Fix: clear the attribute (graph.__dict__.pop("_flare_instantiation_flags", None) or set it to None) at the start of record_export_graph and register a destroy callback alongside _RecordedGraphMetadata.release that drops it.

Also minor: _executable_instantiation_flags (200-205) constructs a fresh _Cuda() per graph, re-CDLLs libcuda.so.1 for each of the serving graphs; heliopause caches a single Cuda (capture.rs:745, 756). Nit-level, matches voipmonitor's nit 4.

#5 [high] Research summary

Reviewed PR #581 (ignition: set USE_NODE_PRIORITY flag on exported CUDA graphs) through the correctness lens, reading the changed function in full context, its only caller (capture.py:171-197), and the Rust consumers on both sides of the wire (heliopause export validation and recording, helios format validation and cuGraphInstantiateWithFlags), plus the project's design-review rules.

What checks out: the flag values (1 and 8, combined 9) match CUDA's CUgraphInstantiate_flags and agree with every Rust validation site (capture.rs:589, 2820-2824; format.rs:495), so both old cores recording 1 and new cores recording 9 load; helios actually instantiates with graph.flags (mod.rs:1215-1219) rather than ignoring it; node priorities are genuinely recorded and reapplied (KERNEL_ATTRIBUTES includes 8, encode_kernel emits it, helios sets it before instantiation), so the change is not cosmetic; and _graphs() emits the template+instantiate_flags shape that capture_rank's invariants require. _Cuda already handles Windows, so no new platform path.

Three confirmed findings recorded in the scratchpad: (1) should fix — the executable-derived flag check runs after retain_object + instantiate_graph, so a rejection leaves a half-mutated graph, contradicting the PR's "rejecting unsupported bits on either source before mutating graph state" and the design-review requirement to validate rejection without partial mutation; (2) should fix — the new _flare_instantiation_flags attribute has no invalidation path, so it survives graph reset/re-capture and None re-recording, and _graphs() then prefers a stale flag word over the live executable; (3) should fix / prose — instantiation_flags=None has no production caller (tuning graphs never reach record_export_graph), and the perf benefit is asserted rather than measured, which principle 12 and 16 cover. No blocking correctness defect found in the change itself.

#6 [high] Verdict and finding index for PR #581 correctness review

PR #581, head 61f64f18 ("ignition: set USE_NODE_PRIORITY flag on exported CUDA graphs"), base main 167f22c, 3 files +137/-7. Verdict: no blocking correctness defect in the change itself; three should-fix items. Another reviewer (voipmonitor, CHANGES_REQUESTED) already covers the end-to-end serving qualification and the keep_graph=False validation (his findings 1-2), which are outside my lens findings below.

Findings (my lens), all verified by reading code:

  1. Should fix — ignition/preparation/runtime_core.py:236-241. The requested-flag validation (224-229) precedes all mutation, but the executable-derived flag check (239-241) runs after graph.retain_object(...) (236) and instantiate_graph(graph) (237). On rejection the graph is left instantiated and holding newly retained pool/owner references, with no _flare_instantiation_flags, and capture.py:193 propagates without cleanup. Violates docs/design-review.md testing-hierarchy clause 1 ("validate rejection without partial mutation") and the PR's own claim "rejecting unsupported bits on either source before mutating graph state". Fix: unmask/report instead of hard-rejecting, or reset the graph on that path, or document + assert the post-failure state in the test (the new test at tests/preparation/test_capture_graph_metadata.py:244-249 asserts only the raise, unlike the bad case at 251-255 which does assert no mutation).
  2. Should fix — ignition/preparation/runtime_core.py:238-242 + 282-287. _flare_instantiation_flags is the only export-time graph state with no invalidation: _RecordedGraphMetadata.release (153-158) and RecordedExportGraph.reset (185-189) both clear their state on reset/destroy, but this attribute persists. Consequences: (a) instantiation_flags=None only skips the assignment, so a re-record on a previously recorded graph keeps the stale flags; (b) after graph.reset() + re-capture, _graphs() still prefers the stale attribute over the new executable and emits a template+flags record computed from a dead executable, a mismatch capture_rank (heliopause/src/export/capture.rs:2820-2824) can no longer detect. Not reachable through today's only caller (capture.py:171 allocates a fresh CUDAGraph per capture), hence should fix not blocking.
  3. Should fix / prose — no production caller passes instantiation_flags=None; tuning graphs use capture_graph+instantiate_graph (capture.py:171,197) and never enter record_export_graph, so the documented "keeps executable-derived flags for startup tuning graphs" branch is dead outside the unit test (tests/preparation/test_capture_graph_metadata.py:236-242). Also the perf/ claim is asserted, not measured: the only GPU evidence is the export-side assertion flags_by_name == {"decode": 9, "tune": 1} (tests/preparation/test_recorded_export_graph_cuda.py:85-87), and that test is opt-in behind FLARE_RUN_CUDA_TESTS (line 14). Principle 12 (measured results, complete GPU steps) and 16 (before/after, expected vs measured).

Nit — ignition/preparation/runtime_core.py:200-205 constructs a new _Cuda() (fresh CDLL of libcuda.so.1) per exported graph; heliopause caches one (capture.rs:745,756).

Verified clean: flag constants match CUDA and all Rust acceptance sites (capture.rs:589, 2820-2824; helios/src/runtime_core/format.rs:495); backward compatibility — cores recorded with 1 still pass & !9; helios instantiates with graph.flags (helios/src/runtime_core/mod.rs:1215-1219); node priorities really survive export and replay (KERNEL_ATTRIBUTES includes 8, capture.rs:462/544-569, encode_kernel 857-887, helios set-attribute mod.rs:984-1013, priority stream created in ignition/preparation/scratch.py:83-105); _graphs() emits graph+instantiate_flags with no executable, matching capture_rank's (executable == 0) == instantiate_flags.is_none() (capture.rs:2822); Windows path unchanged (_Cuda handles nvcuda.dll, runtime_core.py:78).

#4 [medium] Should fix: PR claims corrected only partly — dead None path and unmeasured perf claim

Prose/claims in the PR body vs the code (docs/design-review.md principle 16, "distinguish expected benefits from measured results", and testing hierarchy clause 1):

  1. "rejecting unsupported bits on either source before mutating graph state" — false for the executable-derived source: retain_object + instantiate_graph already ran when _executable_instantiation_flags is checked (runtime_core.py:236-241). Same point as voipmonitor review finding 3.
  2. "Passing instantiation_flags=None keeps executable-derived flags for startup tuning graphs" — no caller passes None. record_export_graph's only caller is capture.py:193 (inside if exporting:, i.e. retain_graphs and warmup_storage is not None, the serving graph path). Startup tuning graphs use capture_graph + instantiate_graph (capture.py:171,197; runtime_core.py:246-269) and never reach record_export_graph, so the None branch is dead in production code and only exercised by the new unit test at tests/preparation/test_capture_graph_metadata.py:236-242. Either wire a caller or drop the claim; either way the parameter's documented purpose does not match any code path.
  3. The claimed benefit ("Helios requests node priority ... while preserving permitted executable flags") is stated as expected rather than measured: the only GPU evidence is the export-side assertion flags_by_name == {"decode": 9, "tune": 1} (tests/preparation/test_recorded_export_graph_cuda.py:85-87), which proves recording. No served-graph measurement, and the description itself lists live export/serving as "open GPU qualification". Whether 9 actually improves service is unmeasured — principle 12 requires equivalent baselines for a perf claim, and the title frames this as perf/.

Note: tests/preparation/test_recorded_export_graph_cuda.py is opt-in (FLARE_RUN_CUDA_TESTS=1, line 14), so {"tune": 1} in the assertion depends on the tuning graph keeping AUTO_FREE_ON_LAUNCH only; that assumption is what makes the executable-derived-vs-requested distinction visible, and it holds today.