Correctness review — PR #581 ignition: set USE_NODE_PRIORITY flag on exported CUDA graphs
Head 61f64f18, base main 167f22c88076c1da801fe0ceca35f846d7295b24, 3 files, +137/−7.
Verdict: no blocking correctness defect in the change itself; three should-fix items plus one nit.
Key findings
- Should fix — validation order leaves a half-mutated graph. The executable-derived flag check runs after
retain_object()andinstantiate_graph()(ignition/preparation/runtime_core.py:236-241), so a rejection leaves the graph instantiated and holding newly retained pool/owner references. This contradicts the PR's own claim that unsupported bits are rejected "on either source before mutating graph state", anddocs/design-review.md:188("validate rejection without partial mutation"). - Should fix —
_flare_instantiation_flagshas no invalidation path. It is the only export-time graph state not cleared onreset()/destroy (compare_RecordedGraphMetadata.release,runtime_core.py:153-158, andRecordedExportGraph.reset,:185-189), and_graphs()prefers it over the live executable (:282-287). A re-record withinstantiation_flags=None, or areset()+ re-capture, keeps emitting a stale flag word. Not reachable through today's only caller, hence should-fix not blocking. - Should fix (prose/coverage) — the
instantiation_flags=Nonebranch has no production caller, and the perf benefit is asserted rather than measured (docs/design-review.md:154-155). - Clean where it matters for compatibility: flag values match CUDA, all Rust acceptance sites accept
9and still accept1, helios instantiates withgraph.flags, and node priorities genuinely survive export and replay.
Findings
1. Should fix — executable-derived flag rejection happens after graph mutation
ignition/preparation/runtime_core.py:224-229 (requested-flag check), :236 (retain_object), :237 (instantiate_graph), :238-242 (read + validate prior flags).
The requested-flag validation runs before any mutation, but the executable-derived check runs only after graph.retain_object((pools, tuple(owners)), synchronize_before_release=True) and instantiate_graph(graph). On a prior_flags & ~PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS hit at :240-241 the function raises with:
- the template already instantiated,
- the new pool/owner references already retained,
- and no
_flare_instantiation_flagsset — so the graph is in neither the old export shape nor the new one.
The only caller, ignition/preparation/capture.py:193, calls record_export_graph inside capture_forwards's try/except Exception as error: error.add_note(...); raise (:198-200), i.e. it propagates and abandons the partially-mutated graph mid-capture.
Why it matters:
docs/design-review.md:188requires tests to "validate rejection without partial mutation".docs/design-review.mdprinciple 6 (explicit storage and lifetimes) anddocs/preparation-development.md:140-150make a half-retained, half-flagged executable a lifetime hazard: the executable natively retains pools/owners while the metadata that would describe them is absent.- The PR description's claim "rejecting unsupported bits on either source before mutating graph state" is false for the executable-derived source. (This is the same inaccuracy voipmonitor's review finding 3 raised; their findings 1–2 cover end-to-end serving qualification and
keep_graph=False, which are outside my lens.) - The path is reachable in principle on other targets:
CUgraphInstantiate_flagsdefinesDEVICE_LAUNCH(2),UPLOAD(4),STRICT_PRIORITY(0x10) and others; a newer driver/torch combination that sets bit 2 on instantiation would now hard-fail export where the pre-PR code succeeded — a compatibility regression against the "existing cores still load / supported targets" dimension ofdocs/design-review.mdprinciple 13 and charter line 42.
Test coverage: the new case at tests/preparation/test_capture_graph_metadata.py (the unsupported_exec graph with exec_flags=2) asserts only that ValueError is raised. Contrast the bad case in the same test, which does assert post-failure state: assert bad.instantiations == 0 and not bad._retained.objects. So the new test actively documents the asymmetry rather than catching it.
Fix: either mask/report unpermitted executable bits instead of hard-rejecting, or define the post-failure state (e.g. graph.reset() on that path) and assert it in the test as the bad case does. At minimum correct the description.
2. Should fix — new _flare_instantiation_flags state is never invalidated
Set at ignition/preparation/runtime_core.py:238-242; consumed at :282-287.
Two related defects about state living outside CUDA's lifecycle:
(a) instantiation_flags=None skips rather than clears. record_export_graph defaults instantiation_flags to CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY (:213) and only assigns the attribute when the argument is not None (:238). If a graph that already carries _flare_instantiation_flags is recorded again with None, the stale attribute survives and _graphs() keeps emitting the template+instantiate_flags shape (no executable) instead of falling back to the live executable at :288-292. The new test asserts not hasattr(plain, "_flare_instantiation_flags") only for a fresh graph, so the clearing behaviour is untested — and absent.
(b) Nothing clears the attribute when the executable dies. Every other piece of export-time graph state is invalidated on that event: _RecordedGraphMetadata.release (:153-158) zeroes self.executable from the destroy callback registered in record() (:166), and RecordedExportGraph.reset (:185-189) drops recorded/pools/owners. torch.cuda.CUDAGraph supports reset() and re-capture (the CUDA test at tests/preparation/test_recorded_export_graph_cuda.py calls graph.reset() twice in a row). After such a reset, _graphs() still prefers the stale attribute (:282-283) over the new executable and publishes a flag word computed from an executable that no longer exists.
Crucially, the receiving side cannot detect this: heliopause capture_rank enforces (g.executable == 0) == g.instantiate_flags.is_none() (heliopause/src/export/capture.rs:2820-2824), and the flag shape satisfies that invariant by construction — the executable/flags mismatch has been erased from the wire, so the guard that protects the non-flag shape cannot fire here.
Severity is should-fix, not blocking, only because the sole caller allocates a fresh torch.cuda.CUDAGraph(keep_graph=True) per capture (capture.py:171), so the stale path is not reachable from capture_forwards today.
Fix: clear the attribute at the start of record_export_graph (graph.__dict__.pop("_flare_instantiation_flags", None)) and register a destroy callback alongside the one in _RecordedGraphMetadata.record that drops it. Note the deferred/reset graphs of issues #395 and #266 are exactly the nearby patterns where a graph outlives its executable.
3. Should fix (prose / coverage) — the documented None path is dead, and the perf claim is unmeasured
- Dead
Nonepath.record_export_graph's only caller iscapture.py:193, guarded byexporting = retain_graphs and warmup_storage is not None(capture.py:170), i.e. the serving-graph path only. Startup tuning graphs go throughcapture_graph+instantiate_graph(capture.py:171, 197;runtime_core.py:246-269) and never enterrecord_export_graph. So the description's "Passinginstantiation_flags=Nonekeeps executable-derived flags for startup tuning graphs" describes a branch with no production caller; it is exercised only by the unit test. Either wire a caller or drop the claim — as written, the parameter's documented purpose does not match any code path. - Unmeasured benefit.
docs/design-review.md:154-155requires an "explicit before/after explanation and distinguish expected benefits from measured results". The only GPU evidence in the PR is an export-side assertion,flags_by_name == {"decode": 9, "tune": 1}(tests/preparation/test_recorded_export_graph_cuda.py:85-87), which proves recording, not effect. The description itself lists "live CUDA export, nondefault kernel-priority instantiation across target drivers, and signed-coreflare runreplay" as open. Nothing measures whether instantiation with node priority changes service behaviour. - Supporting caveat for that GPU test: it is opt-in behind
FLARE_RUN_CUDA_TESTS=1(tests/preparation/test_recorded_export_graph_cuda.py:14), and{"tune": 1}depends on the tuning graph carrying onlyAUTO_FREE_ON_LAUNCH. That assumption holds today and is what makes the executable-derived-vs-requested distinction observable.
4. Nit — a fresh _Cuda per exported graph
ignition/preparation/runtime_core.py:200-205: _executable_instantiation_flags constructs a new _Cuda() per graph, re-CDLL-ing libcuda.so.1 for each serving graph, while heliopause caches one instance (heliopause/src/export/capture.rs:745, 756). Matches voipmonitor's nit 4.
Verified clean (checked, no defect)
- Flag values
AUTO_FREE_ON_LAUNCH = 1,USE_NODE_PRIORITY = 8, combined1 | 8 = 9(runtime_core.py:192-197) match CUDA'sCUgraphInstantiate_flagsand agree withhelios/src/runtime_core/format.rs:495as the PR claims. - Wire compatibility on both sides.
heliopause/src/export/capture.rs:589and:2820-2824both acceptflags & !9 == 0;format.rs:495likewise. Cores recorded before this PR with1still pass everywhere, and_graphs()'s own mask (runtime_core.py:284) matches. So existing exported cores keep loading. - Helios actually uses the flags:
helios/src/runtime_core/mod.rs:1215-1219callscuGraphInstantiateWithFlags(&mut executable, handle, graph.flags)— recording9changes instantiation, not just metadata, consistent withdocs/runtime-core-design.md:620-623. - Node priorities genuinely survive export and replay, so the change is not cosmetic:
KERNEL_ATTRIBUTESincludes id 8 (capture.rs:462, 544-569),encode_kernelemits every non-13 attribute including it (capture.rs:857-887), helios applies them viacuGraphKernelNodeSetAttributebefore instantiation (mod.rs:984-1013), and the priority-bearing stream is created inignition/preparation/scratch.py:83-105. - Export shape invariants hold.
_graphs()emits{name, graph(template), instantiate_flags}with no executable under the new path, satisfyingcapture_rank's(g.executable == 0) == g.instantiate_flags.is_none()(capture.rs:2822:0vsSome→false == false); heliopausegraph_metadatathen prefersgraph.instantiate_flagsover reading the live executable (capture.rs:788-794). - No new platform path.
_Cuda(runtime_core.py:76-91) already handles Windows vianvcuda.dll, socuGraphExecGetFlagsthrough ctypes works on the documented Windows target. - Unsupported-bit input handling at the API boundary (
instantiation_flagstype/negativity/mask,:224-229) is correct and ordered before mutation.
Open questions / what only a test or GPU run can settle
- Does any supported driver/torch combination set an instantiation bit outside
1 | 8(e.g.DEVICE_LAUNCH=2) on a captured exec? If so, finding 1 is a live export regression on that target, not merely an error-path hygiene issue. Settling it needs a CUDA run across the target matrix that printscuGraphExecGetFlagsfor both the decode/serving graph and the tuning graph. - Do the stale-flag scenarios in finding 2 occur in practice? They need either a
record_export_graph(..., instantiation_flags=None)call site (none exists today) or a graph that isreset()/re-captured after export (not done incapture_forwards, but permitted by theCUDAGraphAPI). A unit test that records, resets, re-captures and re-exports would settle it. - Whether instantiation with
USE_NODE_PRIORITYchanges served behaviour on non-default kernel priorities remains unmeasured in this revision, as the description acknowledges.
Rules cited
docs/design-review.md:188(testing hierarchy: "validate rejection without partial mutation").docs/design-review.md:154-155(principle 12/16: equivalent baselines, explicit before/after, expected vs measured results).docs/preparation-development.md:140-150(executables and pool owners retained until a confirmed native drain) — lifetime basis for finding 1.- Charter line 42 (supported matrix & compatibility, existing cores still load) and line 44 (GPU kernel code: report concrete defects only).