Review: PR #690 — "Preserve inherited CUDA_HOME in ignition.cli.environment" (Correctness, Contracts & System-Level Consequences)
Head 682152b, base main, 5 files +183/−10. Fixes #636. Every finding below was verified by opening the file at PR head; line numbers are from the head tree.
Key findings
- No Blocker. The change is in the right layer and the ordering is correct.
- Major: the inherited
CUDA_HOMEis preserved without any validation (ignition/cli/environment.py:61-63), while the/usr/local/cudafallback one line later is gated onis_dir()(:64). A stale, relative or typo'd value is re-exported as the toolkit root for the whole process tree, and the compiler's libdevice identity is derived from that root (ignition/preparation/tuning.py:52-65). One test asserts this invalid behavior as correct. - Major:
TRITON_PTXAS_PATHprecedence silently reverses —[paths] cudanow beats an explicit ambient value, and blank ambient values are now filled (environment.py:78-81vs base"TRITON_PTXAS_PATH" not in os.environ). This sits against design-review principle 10 ("explicit user values win over defaults",docs/design-review.md:89-92) and is beyond #636's ask, which is aboutCUDA_HOMEonly. The new blank-value arm has no test. - Major: the design-doc contract is not reconciled. The PR documents the new rule in three places but leaves
docs/cli-design.md:46-51("No environment variables. Flare reads none, with one exception:CUDA_VISIBLE_DEVICES"),docs/cli-design.md:52-53("Nothing else exists") andAGENTS.md:461("CUDA_VISIBLE_DEVICESis the only variable Flare interprets") stating the opposite. The principle-10 exception the PR relies on points at exactly that documentation. This is the third revision of this 4-line decision in six weeks, and issue #636 carriestriage:design-reviewwith zero maintainer comments. - Major (contract/evidence): the resolved toolkit is never recorded in the plan or its printed report (
ignition/planning.py:383-420), contrary toAGENTS.md:456-460; two exports built with different ptxas/libdevice print identical plans. The #636 scenario (a host with/usr/local/cudaand a second toolkit) is never reproduced — all 10 tests monkeypatch_DEFAULT_LINUX_CUDA. - Minor: stale #71 cuTile comment directly above code implementing the opposite policy (
environment.py:54-57);docs/model-preparation.md:128-130says "when unset" where the code also overwrites blank values; whitespace normalization of a non-empty inheritedCUDA_HOMEuntested; Windows claimed unchanged and correct by inspection but every test skips onnt; latent non-idempotency (applyreads aCUDA_HOMEit wrote itself), unreachable today becauseapplyruns once per process. - Sound, stated plainly: correct layer and ordering, Windows branch untouched, no concurrency/lock/memory/hot-path/partial-failure surface, no metric/rate/admission sample changed (the metric-span check does not apply),
[paths] cudaresolution unchanged, and the description's arithmetic/claims otherwise check out.
1. Correctness, safety & platform parity
M1 — Major: inherited CUDA_HOME is accepted without validation and then exported process-wide
ignition/cli/environment.py:58-69:
configured_cuda = configuration.directory("cuda")
cuda = configured_cuda
if cuda is None and os.name != "nt":
inherited_cuda = os.environ.get("CUDA_HOME", "").strip()
if inherited_cuda:
cuda = Path(inherited_cuda)
elif _DEFAULT_LINUX_CUDA.is_dir():
cuda = _DEFAULT_LINUX_CUDA
else:
os.environ.pop("CUDA_HOME", None)
if cuda is not None:
os.environ["CUDA_HOME"] = str(cuda)
Path(inherited_cuda) gets no is_dir() test, no bin/nvcc or bin/ptxas test, no absolute-path test — yet :69 exports it as CUDA_HOME for the entire process tree (compile workers and subprocesses inherit the environment). The asymmetry with the adjacent line is the bug: /usr/local/cuda is only trusted when it exists (:64), the less trustworthy ambient value never is.
Concrete impact: CUDA_HOME=/opt/cuda-12.4 left over after an upgrade, a relative path, or CUDA_HOME=1 is preserved verbatim. It then reaches compiler-identity selection, ignition/preparation/tuning.py:52-65:
def _prepare_compiler_toolchain():
"""Resolve forward math libraries before native program identities are recorded."""
...
# Inductor selects the CUDA toolkit's libdevice for eager precision. Native
# discovery and later materialization must see that same library identity.
with config.patch(emulate_precision_casts=_OPTIONS["emulate_precision_casts"]):
_set_triton_libdevice_path()
That is, the bad root can select a different libdevice — a different compiler identity, recorded into native program identities — rather than failing early with a message naming CUDA_HOME. Scope note for fairness: ignition/preparation/kv_codec.py:21-38 (_find_nvcc) degrades gracefully (it falls back to shutil.which("nvcc") then /usr/local/cuda/bin/nvcc), so kv_codec is not part of the blast radius; libdevice/torch and TRITON_PTXAS_PATH are.
The suite locks the invalid behavior in: tests/cli/test_environment.py:110-120 sets CUDA_HOME to clean_environment / "custom-cuda" and never creates it, then asserts os.environ["CUDA_HOME"] == str(inherited) (:118). The test name — test_inherited_cuda_home_without_local_files_does_not_fall_back_to_default — makes "accept a non-toolkit" the specification.
Fix: validate the inherited path (cuda.is_dir(), and ideally (cuda / "bin/ptxas").is_file()); when it is not a toolkit, either fail with a clear message naming CUDA_HOME or fall through to the next documented source — but state which in the docs. Then split the current test into (a) an existing toolkit is preserved and (b) a non-directory CUDA_HOME is rejected or falls through.
m1 — Minor: latent non-idempotency
environment.py:61 reads CUDA_HOME and :69 writes it. Because apply runs exactly once per process on every path (serve.py export/_export_hosts/debug_serve/join, bench.py:205), a second call is unreachable today, so this is latent only: CUDA_HOME=" /opt/cuda " is normalized to /opt/cuda on pass one, which a future second call would read as a different-but-equal value. Worth one comment; not a defect.
m2 — Minor: platform parity is correct by inspection but completely untested
environment.py:70-75 (the os.name == "nt" branch) is untouched and the reversed configured_cuda is not None or … condition at :78-81 is inside the non-Windows branch, so [paths] cuda still wins on Windows exactly as before. But all 10 cases carry @pytest.mark.skipif(os.name == "nt", …) (tests/cli/test_environment.py:61, 78, 92, 109, 123, 138), so the PR's "Windows behavior unchanged" claim rests on inspection alone. Since the claim is cheap to keep true, at minimum a non-parametrized assertion of the Windows ordering (monkeypatching os.name) would protect it.
Sound areas (no issue)
- Ordering is correct and load-bearing.
environment.applyprecedes every torch import:ignition/cli/serve.py:291apply→ :292import flare_heliopause→ :305import torch(also :210→:219, :436→:444, :545;ignition/cli/bench.py:205→:206).runtime_patches.apply()is the first torch import insideapply(environment.py:87), so this is the only place the fix can take effect. - Windows path: genuinely unchanged (
environment.py:70-75). - No concurrency / lock / queue / memory-amplification / partial-failure surface.
applyis synchronous once-per-process startup environment setup; no threads, no I/O amplification, no buffering, no shared waiter. The "optimization slows the hot path" question does not arise. - Metric / rate / admission-pricing span check: does not apply — this PR changes no metric, rate, latency or admission sample, so there is no measured-span shrinkage to trace.
[paths] cudaresolution unchanged:Configuration.directory(ignition/cli/config.py:172-175) still returnsNonefor the built-in default""(config.py:51), so default-config runs simply fall through, as before.
2. Unintended system-level consequences
M2 — Major: TRITON_PTXAS_PATH precedence silently reverses, and blank values now get filled
ignition/cli/environment.py:76-81:
else:
ptxas = cuda / "bin/ptxas"
if ptxas.is_file() and (
configured_cuda is not None or not os.environ.get("TRITON_PTXAS_PATH", "").strip()
):
os.environ["TRITON_PTXAS_PATH"] = str(ptxas)
The base condition was if ptxas.is_file() and "TRITON_PTXAS_PATH" not in os.environ: — any ambient value, blank or not, won and was never overwritten. Two behavior changes beyond #636 (which asks only about CUDA_HOME):
- A caller's non-blank
TRITON_PTXAS_PATHnow loses to[paths] cuda, silently and with no message.docs/design-review.md:89-92is explicit: "Settings belong in recipe declarations, configuration files, or CLI flags; explicit user values win over defaults." A user who exports a specific ptxas for Triton to match a pinned compiler gets the configured toolkit's ptxas instead — changing generated code with no diagnostic and no cache-key change. - Blank/whitespace
TRITON_PTXAS_PATHis now overwritten rather than left alone. This is disclosed in the PR description ("orTRITON_PTXAS_PATHis unset/blank"), so it is not a claim-accuracy problem — but it is untested and understated in the docs (see m3).
System-level framing: the interaction of concern is not concurrency but cache/artifact identity. TRITON_CACHE_DIR and TORCHINDUCTOR_CACHE_DIR (environment.py:50-51) are stable per configuration, so a silently different ptxas produces different cubins under the same cache paths across sessions, and nothing visible records which ptxas produced a core.
Fix: restore "caller value wins" ("TRITON_PTXAS_PATH" not in os.environ), or, if the override is deliberate, state it in docs/model-preparation.md and print/log which ptxas won. Add the missing test: blank/whitespace TRITON_PTXAS_PATH + [paths] cuda configured. If the override is intended, it needs its own justification — #636's report is about CUDA_HOME, and the ambient-ptxas override is the one change in this PR that takes precedence away from an explicit user value.
3. Architecture, contracts & charter compliance
M3 — Major: the normative design doc still forbids what the code now does
docs/cli-design.md:46-53, unmodified by this PR:
- **No environment variables.** Flare reads none, with one exception:
`CUDA_VISIBLE_DEVICES` restricts which GPUs the caller exposed, which changes
the GPU each index names, so Flare inspects it to interpret `--gpus`.
Variables that underlying libraries read are set by Flare from its own
configuration, and b12x's from the recipe's declared settings, before those
libraries are imported.
- **Two levels of precedence.** Flags override the configuration file, which
overrides the recipe. Nothing else exists.
and AGENTS.md:461: "CUDA_VISIBLE_DEVICES is the only variable Flare interprets" — while the same section, edited by this PR at AGENTS.md:466-473, now says ignition.cli.environment "preserves a non-empty inherited CUDA_HOME before falling back to /usr/local/cuda".
environment.py:58-67 does read CUDA_HOME to choose behavior, so after this PR cli-design.md:46 ("with one exception") and :52-53 ("Nothing else exists") are false, and the doc contradicts its own decision table at docs/cli-design.md:1480, which the PR did update:
| CUDA toolkit | `[paths] cuda`; otherwise on non-Windows hosts inherited `CUDA_HOME`, then `/usr/local/cuda` when present; otherwise native build libraries discover the system toolkit |
Why this matters for merge: principle 10 exempts "the documented CUDA device selection and dependency setup policies" (docs/design-review.md:89-92). The exception is conditional on the policy being documented. Documenting it in the per-decision table row (:1480), docs/model-preparation.md:123-132 and AGENTS.md:468-471 while the two umbrella clauses say the opposite gives a reviewer solid grounds to say the exception is not met. Process context: issue #636 carries bug, enhancement, priority:P2, triage:design-review and zero comments — no maintainer has recorded the decision this PR implements; #690 itself has zero reviews and no CI checks on 682152b. This is the third revision of these four lines in six weeks (#71 eugr → c9935887 Luke Alonso → this PR), and each prior revision broke the other camp. Landing the third revision of a failed-twice decision without a recorded design decision, and with the governing doc still asserting the opposite, is the architectural risk here.
Fix: extend cli-design.md:46-51 to name CUDA_HOME (and TRITON_PTXAS_PATH/CPATH as library variables set from the selected toolkit) as part of the dependency-setup exception; amend :52-53 so the toolkit decision's third source is acknowledged; align AGENTS.md:461. That is three sentences and it converts this from "unilateral precedence change" to "documented policy".
M4 — Major: the selected toolkit is invisible in the plan report, and #636 is never reproduced
AGENTS.md:456-460:
- A setting has one of three homes: the recipe declaration, the configuration
file, or a command-line flag, as [the CLI design](docs/cli-design.md)
specifies. A setting that only experiments need is an advanced flag carried
through the plan into the recipe's `PreparationConfig`, so the plan, its
printed report, and its recorded measurements describe what was prepared.
After this PR the selected toolkit depends on the ambient environment, but ignition/planning.py:383-420 (Plan.to_dict()) emits alias/repository/revision/architecture/gpus/…/fill-tier/memory fields and no toolkit or cuda field — and that dict is what serve.py:213 and :440 print. Consequence: two ignition export runs of the same model that build native code with different ptxas/libdevice print byte-identical plans, so cores are not attributable to the toolkit that produced them — which is exactly the visibility that makes an environment-derived setting acceptable under principle 10, and exactly what is missing.
Fix (cheap, one startup-time line): add the resolved toolkit path and its source (paths.cuda / inherited CUDA_HOME / /usr/local/cuda) to the plan report. This also resolves the "is env-derived config OK here" question in the PR's favor by making it visible rather than silent.
Evidence gap that compounds it (author-disclosed, so this is a scope note not a deception finding): no end-to-end, GPU, or multi-toolkit run reproduces #636's actual scenario. Every one of the 10 tests monkeypatches _DEFAULT_LINUX_CUDA (tests/cli/test_environment.py:66, 82, 96, 113, 127, 141), so the real /usr/local/cuda branch and the real fallback ordering are never exercised. #231's review asks for precisely the downstream assertion this PR lacks: importing torch/Triton and asserting libdevice and ptxas really come from the preserved toolkit (the shape of tests/preparation/test_toolchain.py:31-36).
4. Tests & claim accuracy
m3 — Minor: docs understate the blank-value case
docs/model-preparation.md:128-130:
toolkit. On non-Windows hosts, Ignition also sets `TRITON_PTXAS_PATH`
(overriding the environment when `[paths] cuda` is configured, or populating it
when unset) and prepends the toolkit's `include` directory to `CPATH` from the
selected toolkit.
"populating it when unset" omits blank/whitespace, which environment.py:79 also overwrites. The PR description is accurate here; the doc is not. Also, the CPATH clause puts "from the selected toolkit" in an awkward place to the point of ambiguity. Fix: "populating it when unset, blank, or whitespace-only".
m4 — Minor: stale comment states the opposite policy from the code beneath it
ignition/cli/environment.py:54-57:
# cuTile discovers its compiler bundle independently of the native toolkit.
# Explicit `[paths] cuda` overrides the process environment; on non-Windows hosts
# without `[paths] cuda`, preserve a non-empty inherited `CUDA_HOME` before
# falling back to `/usr/local/cuda`.
The first line is #71's justification for not reading the environment; it now sits directly above code that reads it. Two opposite policies in one comment block, in the file #71 already had to correct once. Fix: keep the cuTile sentence as its own comment (still true, docs/model-preparation.md:134-137) or move it beside the [paths] cuda line.
m5 — Minor: untested arms
- Blank/whitespace
TRITON_PTXAS_PATHwith[paths] cudaconfigured — the newnot … .strip()arm (environment.py:79) has no test; every case either sets a non-blank value (tests/cli/test_environment.py:68, 98) or leaves it absent (fixture pops it, :52-57). - Whitespace-padded non-empty
CUDA_HOME(e.g." /opt/cuda") — normalization atenvironment.py:61/:69is untested; the parametrization only coversNone,""," "(:124, :139). - Windows ordering — see m2.
clean_environment(tests/cli/test_environment.py:45-58) is sound: registering an undo entry viasetenv-then-popfor originally-absent keys does restore absence, so the "post-session restoration verified" claim is credible.
Claims checked and found accurate (no issue)
- "Previously … leaving whitespace-only
CUDA_HOMEvalues inos.environwhen/usr/local/cudawas absent" — true; the baseif cuda is not Noneblock simply never ran. - "
[paths] cudaoverrides inheritedCUDA_HOME" — matchesenvironment.py:58-59, :68-69and tests :62-75. - "removing any blank/whitespace
CUDA_HOME" — matches:66-67and tests :138-149. - CPATH prepend/dedupe description — matches
:82-86. - Test count: 4 single + 3 + 3 parametrized = 10 cases, consistent with "146 passed" arithmetic. The run itself remains author-reported; head
682152bhas no CI checks, and the repo's CPU workflow has no CUDA toolkit, so CI would exercise these tests only through the monkeypatched_DEFAULT_LINUX_CUDA— i.e. the same blind spot as the local run. - Description follows the required four-part form and carries the Discord handle; the blank-value behavior is disclosed in the description (only the docs lag).
Open questions / what could not be found
- Does a maintainer endorse #636's premise that
CUDA_HOMEshould outrank/usr/local/cudaby default? #636 is labeledtriage:design-reviewwith zero comments; no decision is recorded anywhere. This is the single question that governs whether M3 is a doc nit or a blocker. - Is the
TRITON_PTXAS_PATHoverride intended as part of this fix, or incidental? It is not in #636's ask and it takes precedence from an explicit user value. - Can #71's
cannot find -lcudartfailure recur if a user'sCUDA_HOMEpoints at a pipcuda-tilebundle (which shipslib/libcudart.so.13while the linker wantslib64/)? Plausible, untested, undiscussed — and #690 never selects a pip bundle itself, so it would require the user to have exported that path. - What verifies downstream consumers actually follow the preserved value on a real multi-toolkit host (torch's frozen
CUDA_HOME, Triton libdevice, ptxas)? Nothing in this PR; #231's review asks for that test. - Windows path — claimed unchanged, correct by inspection, untested.
- Commit trailer compliance (
Design-Signed-Off-By: …; design-review=<sha256[:4]>per.githooks/commit-msg) could not be verified, and no CI check ran on head682152b.