#1 [high] F1 (high): ptxas condition change is out of scope — delete it and configured_cuda
Subtraction lens, main finding. PR head ignition/cli/environment.py:58-59:
configured_cuda = configuration.directory("cuda")
cuda = configured_cuda
and :76-81 (POSIX branch):
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)
Base (from pr_diff) was if ptxas.is_file() and "TRITON_PTXAS_PATH" not in os.environ:.
#636 asks only about CUDA_HOME. The ambient-TRITON_PTXAS_PATH override when [paths] cuda is set is a second, unrequested precedence flip (correctness lens territory: contradicts design-review.md:89-92 "explicit user values win"). For this lens the point is structural: this condition is the sole consumer of configured_cuda, so reverting it to the one-line base form deletes the alias variable, a 3-line multi-line condition and a .strip(), and shrinks the decision to cuda = configuration.directory("cuda").
Only test affected: tests/cli/test_environment.py:62-75 — drop monkeypatch.setenv("TRITON_PTXAS_PATH", "/ambient/ptxas") (:68) and its assertion (:74); under the base condition the ambient value is preserved, which is already covered by test 93-106. All other 8 cases pass unchanged.
If maintainers do want [paths] cuda to beat a blank-but-present ambient value, the smaller form is a single expression, e.g. if ptxas.is_file() and (configured_cuda is not None or not os.environ.get("TRITON_PTXAS_PATH")): — still needs the variable, so the deletion only lands if the condition goes.
#2 [high] F2 (medium): test fixture's _ENV_KEYS + setenv/pop trick — snapshot os.environ instead
tests/cli/test_environment.py:15-28:
_ENV_KEYS = (
"TORCH_CUSTOM_PYTHONPATH",
...
"CPATH",
)
and :45-58:
@pytest.fixture
def clean_environment(monkeypatch, tmp_path):
monkeypatch.setattr(environment.runtime_patches, "apply", lambda: None)
monkeypatch.setenv("HOME", str(tmp_path))
monkeypatch.setenv("USERPROFILE", str(tmp_path))
# Register an undo entry for every managed variable, including keys absent
# before the test, so mutations inside environment.apply never leak across tests.
for key in _ENV_KEYS:
if key in os.environ:
monkeypatch.delenv(key)
else:
monkeypatch.setenv(key, "")
os.environ.pop(key, None)
yield tmp_path
Problems: (a) _ENV_KEYS duplicates the variable names that apply writes (environment.py:41-53, 69, 71-72, 81, 86) and silently goes stale when apply gains a variable; (b) the setenv-then-immediate-pop trick needs a 3-line comment because it is not readable, and it relies on pytest's undo-order for keys set twice (fixture + test).
Replace with a plain snapshot/restore, which also covers variables apply writes in future:
@pytest.fixture
def clean_environment(monkeypatch, tmp_path):
monkeypatch.setattr(environment.runtime_patches, "apply", lambda: None)
saved = dict(os.environ)
os.environ.clear()
os.environ.update({"HOME": str(tmp_path), "USERPROFILE": str(tmp_path)})
yield tmp_path
os.environ.clear()
os.environ.update(saved)
Net: -18 lines, no key list, no comment needed, no dependence on monkeypatch=undo ordering. (Note monkeypatch.delenv/setenv calls inside the test bodies still work and are undone before the fixture's restore; finalizers run in reverse setup order, i.e. the restore here runs before the monkeypatch fixture's own undo.) delete _ENV_KEYS entirely.
Repo precedent for reading/mutating env in fixtures: tests/cli/test_config.py:22-25 sets HOME/USERPROFILE with monkeypatch; there is no tests/conftest.py anywhere (list_files **/conftest.py → none).
#4 [high] F4: what is justified, and doc duplication across 3 files
two things a subtraction reviewer should note as not removable, plus doc-scope observations.
(a) _DEFAULT_LINUX_CUDA = Path("/usr/local/cuda") at ignition/cli/environment.py:22 is legitimately a new module constant, not a knob: it is required so tests can monkeypatch.setattr(environment, "_DEFAULT_LINUX_CUDA", ...) (tests/cli/test_environment.py:66, 82, 96, 113, 127, 141) without a real /usr/local/cuda. Keep. It also removes the duplicated literal that already exists at ignition/preparation/kv_codec.py:32 (Path("/usr/local/cuda/bin/nvcc")) — no shared helper worth creating for one literal across two modules; do not propose consolidation.
(b) os.environ.pop("CUDA_HOME", None) at environment.py:66-67 (else branch when no default dir) is needed to clear blank/whitespace ambient values; it is 1 line and covered by tests 138-149. Keep. (Correctness lens may question whether clearing is right; structurally it is not extra machinery.)
(c) docs/model-preparation.md:123-132 grew from 4 lines to 10 and now hardcodes the /usr/local/cuda literal and a 4-step precedence in prose that duplicates docs/cli-design.md:1480 (the precedence table row, one line) and AGENTS.md:466-473 (a third restatement). Same rule stated in three files with three different wordings; if any one changes, two stale copies remain. The lean form keeps the one-line table row plus a pointer, e.g. model-preparation: "[paths] cuda selects an explicit toolkit; otherwise the CUDA toolkit precedence in the CLI design applies." Note the reconciled table row at cli-design.md:1480 already says it fully. AGENTS.md:466-473's addition is defensible because AGENTS.md:452-455 prohibits env reads and needs the cross-reference.
(d) docs/cli-design.md:46-53 still says "No environment variables. … one exception: CUDA_VISIBLE_DEVICES" and "Two levels of precedence. … Nothing else exists" — after this PR those two umbrella statements are false, and the PR documents the policy only in the per-decision table 1,400 lines later. That is a documentation-scope gap, not a code-complexity one, but it is the cheapest subtraction: instead of 8 new lines in model-preparation, the fix is 2 amended bullets where the policy belongs.
#6 [high] Research summary
Subtraction/Simplicity lens done. The production change is genuinely small (net +13 functional lines in ignition/cli/environment.py), and I found only one deletion with real value plus one over-engineered test fixture.
Findings (details, verbatim quotes and citations in scratchpad 1-5):
- F1 (high) — the
configured_cudavariable and the 3-lineTRITON_PTXAS_PATHcondition should just be deleted. The aliasconfigured_cuda = configuration.directory("cuda")(environment.py:58-59) exists solely so the POSIX branch at:76-81can invert precedence for a second variable that #636 never asked about. Reverting that one condition to the base one-liner (if ptxas.is_file() and "TRITON_PTXAS_PATH" not in os.environ:) removes the alias, the multi-line condition and a.strip(), and needs only two lines removed from one test case (tests/cli/test_environment.py:68,74); the other 8 cases pass unchanged. This is the "delete the workaround instead of patching around it" case. - F2 (high) —
tests/cli/test_environment.py:15-28+:45-58: a 14-entry_ENV_KEYStuple that duplicates the namesapplywrites, plus amonkeypatch.setenv(...);os.environ.pop(...)trick that needs a 3-line explanatory comment. A plainsaved = dict(os.environ)/ clear / restore fixture is ~18 lines shorter, needs no key list, no comment, and survives future variables. - F3 (low) — six identical
@pytest.mark.skipif(os.name == "nt", ...)decorators where the repo convention (25+ modules) is a single module-levelpytestmark. - F4, F5 (doc/comment duplication) — the 10-line
docs/model-preparation.md:123-132paragraph, thedocs/cli-design.md:1480row andAGENTS.md:466-473state the same 4-step precedence three times in three wordings; the one-line table row plus a pointer would do, and it is cheaper to amend the now-false umbrella bullets atdocs/cli-design.md:46-53than to grow prose 1,400 lines away.environment.py:55-57is a fourth restatement, and it orphans the pre-existing cuTile comment on line 54.
Explicitly not removable: the new _DEFAULT_LINUX_CUDA constant (it is the monkeypatch seam the tests need), the 1-line os.environ.pop("CUDA_HOME", None), and folding in kv_codec.py:32's duplicated /usr/local/cuda literal (not worth a shared helper).
#7 [high] F0 (high): lens verdict and ranked report order
Lens verdict
The production diff is lean: the new logic in ignition/cli/environment.py is 9 lines inside apply plus one module constant. No new config knob, no CLI flag, no schema change, no wrapper function, no dead code. Say that plainly in the report. Only one real deletion exists (F1), plus one over-engineered test fixture (F2). Do not manufacture more.
Ranked recommendations (report order)
- F1 (high) — delete
configured_cuda+ the 3-line ptxas condition at environment.py:58-59, 76-81; revert to the base one-liner. Sole reason to keep = an unrequested second precedence flip; also contradicting design-review.md:89-92 "explicit user values win". - F2 (high) — replace
_ENV_KEYS(tests/cli/test_environment.py:15-28) + setenv/pop fixture (:45-58) with anos.environsnapshot/restore; -18 lines. - F4 (medium) — collide prose: docs/model-preparation.md:123-132 (10 lines), docs/cli-design.md:1480 (1 row), AGENTS.md:466-473 all state the same 4-step order in different words. Keep the table row + a pointer; amend the now-false umbrella bullets docs/cli-design.md:46-53 instead of growing a third copy. Note: the cli-design.md:52-53 "Two levels of precedence … Nothing else exists" line and :46-51 "No environment variables … one exception CUDA_VISIBLE_DEVICES" are simply no longer true — cheapest subtraction available, and it is where the policy belongs.
- F3 (low) — six duplicate skipif decorators (test lines 61, 78, 92, 109, 123, 138) → one module-level
pytestmark(convention: tests/components/test_engram_cuda.py:21, tests/preparation/test_scratch_cuda.py:14, tests/server/test_scheduler.py:23). - F5 (low) — environment.py:54-57 comment: lines 55-57 restate the branch below and the docs; line 54 (cuTile) is left orphaned now that the branch is about toolkit selection.
Not removable — say so explicitly
_DEFAULT_LINUX_CUDA(environment.py:22): the monkeypatch seam tests need; keep.os.environ.pop("CUDA_HOME", None)(environment.py:66-67): 1 line, covered by tests 138-149; keep.- Consolidating the
/usr/local/cudaliteral with ignition/preparation/kv_codec.py:32: not worth a helper across two modules; do not propose. cuda = configuration.directory("cuda")still needed after F1 (it is the toolkit source);config.directory(ignition/cli/config.py:172-175) already handles""→ None and~expansion, so no new path helper is needed — the PR correctly reuses it, no duplication there.
#3 [low] F3 (low): six duplicate skipif decorators → module pytestmark
tests/cli/test_environment.py:61, 78, 92, 109, 123, 138 each repeat:
@pytest.mark.skipif(os.name == "nt", reason="POSIX CUDA toolkit environment precedence")
six identical copies of a 40+-character decorator plus the same reason string (and the reason string restates the module docstring "CUDA toolkit environment selection and precedence in ignition.cli.environment"). Repo convention for a whole-module condition is a single module-level pytestmark:
pytestmark = pytest.mark.skipif(os.name == "nt", reason="POSIX CUDA toolkit environment precedence")
placed after the imports (same pattern in 25+ files, e.g. tests/components/test_engram_cuda.py:21, tests/preparation/test_scratch_cuda.py:14, tests/server/test_scheduler.py:23). Net -5 lines, and if Windows coverage is added later the module-level marker is the one place to change. Low importance; harmless if left.
Also def test_inherited_cuda_home_without_local_files_does_not_fall_back_to_default (:110) is a 44-char rump of a name that restates the assertion.
#5 [low] F5 (low): 4-line comment duplicates the code and the docs
ignition/cli/environment.py:54-57 (new comment block above the resolution):
# 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`.
Lines 55-57 are a second, English copy of exactly what the 9 lines below them do (cuda = configuration.directory("cuda") … if inherited_cuda: … elif _DEFAULT_LINUX_CUDA.is_dir(): … else: pop), and they are a third copy of the policy also stated at docs/cli-design.md:1480 and docs/model-preparation.md:123-132. The one sentence worth keeping is line 54 (the cuTile rationale, pre-existing) — and it is now orphaned, because the code below no longer has anything to do with cuTile; it needs a one-line lead-in to the toolkit selection or a pointer to docs/cli-design.md, e.g.:
# cuTile discovers its compiler bundle independently of the native toolkit; the
# toolkit used for native builds follows docs/cli-design.md's CUDA toolkit row.
Net -2 lines and one fewer place to update when the order changes. Low priority; not a blocker.
#8 [low] F6 (low): _load_config mirrors tests/cli/test_config.py's load helper
Minor duplication with an existing repo test helper (mention briefly under F2 or as a footnote; do not inflate into its own finding).
tests/cli/test_environment.py:38-42:
def _load_config(tmp_path: Path, cuda: Path | None = None) -> Configuration:
path = tmp_path / "config.toml"
text = f'[paths]\ncuda = "{cuda.as_posix()}"\n' if cuda is not None else ""
path.write_text(text)
return Configuration.load(path)
tests/cli/test_config.py:16-19 already has:
def load(tmp_path, text):
path = tmp_path / "config.toml"
path.write_text(text)
return Configuration.load(path)
Same three-statement "write config.toml in tmp_path and load it" helper, different name, different module. Two options, both cheap: import load from tests/cli/test_config.py (repo already does cross-module test imports, e.g. tests/server/test_muse_spark.py:13 from tests.server.test_muse_spark import pytestmark, service), or keep the local one because the cuda=None default is genuinely convenient at 6 call sites. Recommend: keep local, note only that the file name/pattern matches existing practice — it is consistent, not a violation. Low value; state it as such so the report does not look like it is padding findings.