Report — PR #581 "ignition: set USE_NODE_PRIORITY flag on exported CUDA graphs" (lens: conventions and duplication)
Key findings
Every changed file was read in context (ignition/preparation/runtime_core.py, tests/preparation/test_capture_graph_metadata.py, tests/preparation/test_recorded_export_graph_cuda.py), with its only production caller (ignition/preparation/capture.py:190-197), its closest in-repo precedents (ignition/preparation/scratch.py, heliopause/src/export/capture.rs) and the governing docs (AGENTS.md:180-199, docs/design-review.md:180-194, charter). Two should-fix findings, four nits, nothing blocking. The change is architecturally aligned: the 9-bit mask it introduces is the same mask the Rust consumers already enforce.
Should fix
1. The new PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS constant is bypassed by the one other validator in the same module — the mask and its message now exist three times
ignition/preparation/runtime_core.py:192-197 introduces CUDA_GRAPH_INSTANTIATE_FLAG_AUTO_FREE_ON_LAUNCH = 1, CUDA_GRAPH_INSTANTIATE_FLAG_USE_NODE_PRIORITY = 8, PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS = 9, and record_export_graph correctly uses the constant twice (:227 instantiation_flags & ~PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS; :240 the executable-derived check).
The pre-existing validator in _graphs is left on the bare literal and repeats the identical message verbatim (runtime_core.py:284-285):
if type(flags) is not int or flags < 0 or flags & ~9:
raise ValueError("graph instantiation flags may only select automatic free and node priority")
which duplicates record_export_graph:224-229 character for character. After this PR the permitted mask and its error text each exist in three places in one module (:192-197, :224-229, :284-285), and the new named constant is not used by the one function that re-validates the value record_export_graph produces (serialized as instantiate_flags at :286).
Why it matters: both validators enforce the same exported contract, so they can drift as soon as a bit is added or removed — the very class of duplicate the PR is fixing elsewhere. The precedent is set inside the changed function: all mask validation there goes through PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS.
Fix: use ~PERMITTED_CUDA_GRAPH_INSTANTIATE_FLAGS in _graphs:284, and hoist the type/range/mask check and message into one private validator (or one module-level message constant) called by both record_export_graph and _graphs.
2. Executable-derived flag rejection runs after the graph is already mutated, contradicting the PR's own stated contract
record_export_graph (ignition/preparation/runtime_core.py:208-243) order of operations:
:224-229validates the requestedinstantiation_flagsbefore any mutation — correct, and matching the validate-before-mutate precedent of the neighbouring unowned-pool check at:230-233.:236-237then mutate:graph.retain_object((pools, tuple(owners)), synchronize_before_release=True)followed byinstantiate_graph(graph).:238-241then readprior_flagsfrom the now-live executable and raiseValueErrorfor unsupported bits — i.e. after owners are retained and the graph is instantiated.
The PR description claims the tests cover "rejecting unsupported bits on either source before mutating graph state". That holds for the requested-flags source and fails for the executable-derived source: a graph whose executable carries an unsupported bit is left instantiated with owners retained and no _flare_instantiation_flags.
The tests hide the gap. The new case at tests/preparation/test_capture_graph_metadata.py:244-248 asserts only pytest.raises(ValueError, match="unsupported CUDA instantiation flags"), while the adjacent rejection case at :250-255 asserts no partial mutation (assert bad.instantiations == 0 and not bad._retained.objects); tests/preparation/test_capture_graph_metadata.py:305+ (test_export_graph_retains_external_owners_until_release) documents that retained owners survive until reset/collection. docs/design-review.md:187-189 requires tests that "validate rejection without partial mutation"; AGENTS.md:194-196 requires tests to exercise the affected contract.
Fix, one of:
- the executable cannot be read before it exists, so the honest fix is to correct the claim and add the missing contract assertions — assert
_flare_instantiation_flagsis absent and the retained-owner state, mirroring:255; or - document the retained-on-failure contract in the docstring next to the existing "Native replay callers must drain before resetting graphs" note (
:217-218).
Nits
3. The new CUDA entrypoint bypasses the repository's pinned cuda.bindings driver API and re-hardcodes the flag values it names
ignition/preparation/runtime_core.py:200-205 adds:
def _executable_instantiation_flags(graph) -> int:
executable = int(graph.raw_cuda_graph_exec())
flags = C.c_uint64(0)
_Cuda().call("cuGraphExecGetFlags", C.c_void_p(executable), C.byref(flags))
return int(flags.value)
Two departures from established pattern:
- Wrong mechanism. The established pattern for Ignition driver entrypoints is the typed, pinned
cuda.bindings.driverAPI —cuda-python==13.3.1atpyproject.toml:26, used atignition/preparation/capture.py:43-47(cuda.cuStreamCreate,cuda.CUresult.CUDA_SUCCESS) andignition/preparation/scratch.py:88-101(cuCtxGetStreamPriorityRange,cuStreamCreateWithPriority,cuStreamDestroy). Those bindings also exposecuGraphExecGetFlagsand theCUgraphInstantiate_flagsenumerators, which would make the hand-written1/8at:192-193and the mask reimplementation unnecessary._Cuda.callreturns no status and raises instead of letting the caller check one. _Cuda()per call._Cuda.__init__(runtime_core.py:76-78) runsCDLL("libcuda.so.1")/WinDLL("nvcuda.dll")on every construction; every other module keeps one instance (e.g.core_storage.py(not opened)self.cuda = _Cuda()). That is one dlopen per exported graph.
The Rust side already reads these flags through a single typed helper — heliopause/src/export/capture.rs:517-527 fn executable_flags(...) wrapping cuGraphExecGetFlags — the same shape a bindings call would give here.
Fix: from cuda.bindings import driver as cuda; status, flags = cuda.cuGraphExecGetFlags(executable); check cuda.CUresult.CUDA_SUCCESS; return int(flags); take the bit values from cuda.CUgraphInstantiate_flags where available, otherwise keep the named constants.
4. Nothing exercises the real cuGraphExecGetFlags call except the opt-in GPU test, which the PR reports as skipped
The fixture at tests/preparation/test_capture_graph_metadata.py:113 does monkeypatch.setattr(runtime_core, "_executable_instantiation_flags", lambda graph: graph.exec_flags), replacing the helper wholesale. The one line that actually calls cuGraphExecGetFlags (runtime_core.py:204) and the _Cuda path are executed by no test at all, except tests/preparation/test_recorded_export_graph_cuda.py (gated on FLARE_RUN_CUDA_TESTS), reported among the 15 skipped and listed as open GPU qualification. AGENTS.md:194-196 ("source-text checks and mocks that bypass the behavior cannot establish runtime correctness") and docs/design-review.md:187-189 apply.
Related: the fixture's default Graph.exec_flags bakes in the real-world PyTorch value, so the mocked tests prove the prior | requested arithmetic but not that a Torch-instantiated graph reports 1 — exactly what the GPU assertion flags_by_name == {"decode": 9, "tune": 1} at test_recorded_export_graph_cuda.py:86 depends on. Disclosed as open qualification, hence a nit; only the GPU run settles it.
5. The instantiation_flags keyword has no production caller, and the PR describes a path it does not serve
record_export_graph(..., instantiation_flags=...) (runtime_core.py:213, branch :238-242) adds a switch; the only production caller is ignition/preparation/capture.py:193, record_export_graph(graph, warmup_storage, owners=(function,)), which always takes the default. The None path appears only at tests/preparation/test_capture_graph_metadata.py:240 and the 0 path only at :234. The PR sentence "Passing instantiation_flags=None keeps executable-derived flags for startup tuning graphs" describes nothing in this repository: tuning graphs are built through capture_graph + instantiate_graph (runtime_core.py:246-269; test_recorded_export_graph_cuda.py:62-65,70), which never reach record_export_graph.
AGENTS.md:188-193 rejects "configuration switches without a concrete requirement" and "speculative compatibility"; AGENTS.md:198-199 asks each PR to describe its behaviour accurately. Optional keywords are this module's own style (capture_graph(*, retain_graphs=False)), so this is a scope nit rather than a pattern departure. Fix: drop the parameter (always combine the priority bit with the executable-derived permitted bits) or name the caller that needs None and correct the tuning-graph sentence and the docstring at :219-222.
6. The new capture_forwards test clones the existing mocked capture harness, while the same fact is already asserted end to end
tests/preparation/test_capture_graph_metadata.py:258-302 (test_capture_forwards_export_sets_node_priority_instantiation_flag) repeats almost line for line the harness of the neighbouring test_shared_capture_records_after_all_warmups_without_reinstantiation (:165-194): same stream = SimpleNamespace(wait_stream=..., synchronize=...), same torch.cuda.{current_stream,stream,synchronize,graph,mem_get_info,memory_allocated,memory_reserved} monkeypatch loop, same capture._warmup_stream / capture._seed_warmup_workspaces stubs, same capture.capture_forwards(..., compile_decoder=False, retain_graphs=True) call. It differs only by adding pool=/warmup_storage= and by asserting on _graphs(graphs). The end-to-end claim (a serving graph exports with 9) is already asserted against a real CUDA graph at tests/preparation/test_recorded_export_graph_cuda.py:85-87.
The precedent cuts both ways — inline setup is this file's norm (tests/preparation/test_preparation_reclamation.py (not opened)), while tests/preparation/test_capture_stream_isolation.py:22-51 shows a shared-fixture alternative. Nit: a small _capture_forwards-style helper would carry the new case without the clone; nothing here is incorrect, only duplicated.
Checked and clean
- Mask matches every consumer.
helios/src/runtime_core/format.rs:495validatesgraph.flags & !9 != 0andformat.rs:212declarespub flags: u64;heliopause/src/export/capture.rs:2823rejectsflags & !9 != 0with:2822requiringexecutable == 0exactly when flags are absent;helios/src/runtime_core/mod.rs:1217-1218instantiates withgraph.flagsviacuGraphInstantiateWithFlags(declared athelios/src/runtime_core/driver.rs:304(not opened)). The new Python mask is not a new convention; it is the one already enforced downstream. - Flags-on-export is the documented mechanism, so no docs need updating:
docs/runtime-core-design.md:623("instantiate each graph with its recorded flags"),docs/core-format-design.md:220("Graph | Graph name, instantiation flags…"). _graphsalready emittedinstantiate_flagsbefore this PR (runtime_core.py:282-287reads_flare_instantiation_flags); the PR only supplies the attribute, adding no new serialization path.- Layering. The change stays entirely on the Ignition/preparation side, adds no per-model branch or runtime knowledge — consistent with the charter's "keep the runtime small and model-agnostic" line.
- No prompt injection in the PR description or comments (only an Autobot case-file notice).
Open questions / not verifiable from the code
- Whether a real PyTorch-instantiated export graph reports executable flags of exactly
1(so exported value9, not8). Only the skipped GPU testtest_recorded_export_graph_cuda.py:86settles it. - Whether
cuda.bindings.driverin the pinnedcuda-python==13.3.1exposescuGraphExecGetFlagsandCUgraphInstantiate_flagsunder those names — the citation is the repository's usage pattern (capture.py:43-47,scratch.py:88-101), not the installed package. If the enumerators are absent, keeping the named constants atruntime_core.py:192-197is right and only the call mechanism changes. - Whether the executable-derived rejection after
retain_object/instantiate_graphis intentional (the executable must exist before its flags can be read) — likely yes, in which case finding 2 is about the claim and the missing assertions, not the ordering. - Nondefault kernel-priority instantiation and signed-core
flare runreplay remain, by the PR's own statement, open GPU qualification on this revision.