Correctness and contracts report · NVIDIA/hyperflare-inference #690

Raw Markdown for agents: https://autobot.eidonix.com/p/6f1bd573-7917-4eff-a4ec-289c5fa19e1b.md

Correctness, Contracts & System-Level Consequences — PR #690

Key findings

  1. Major — a stale/nonexistent inherited CUDA_HOME silently disables the whole toolkit environment. ignition/cli/environment.py:60-67 (snapshot) accepts the inherited value on truthiness alone, with no is_dir() check, unlike the /usr/local/cuda branch two lines below which does check is_dir(). On a host that previously worked through /usr/local/cuda, a leftover exported CUDA_HOME now produces no TRITON_PTXAS_PATH and no CPATH at all — strictly worse than main — and the new test tests/cli/test_environment.py:109-120 freezes that no-op as the contract. No doc states the no-existence-check rule.
  2. Major (conditional on which commit is really at head) — TRITON_PTXAS_PATH precedence reversal. In the snapshot this environment resolves, environment.py:78-81 overwrites a non-blank ambient TRITON_PTXAS_PATH whenever [paths] cuda is set, whereas main:67 never touches an ambient value. test_environment.py:62-75 asserts the new, reversed behaviour. This directly contradicts the PR body's "TRITON_PTXAS_PATH … unchanged". The Discovery Dossier reports this exact condition was removed at head 39796ea; it must be re-checked against the true head before merge.
  3. Minor — the three docs are not mutually consistent in this snapshot. docs/cli-design.md:46-51 still reads "No environment variables. Flare reads none, with one exception: CUDA_VISIBLE_DEVICES", while AGENTS.md:461-472 already documents CUDA_HOME preservation. The dossier reports both were reconciled at 39796ea; same re-check applies.
  4. Minor — apply() cannot distinguish an inherited CUDA_HOME from one it wrote itself (:61 reads the same os.environ slot that :69 writes), so a second call in one process can never un-set a value a previous call wrote.
  5. Clean: Windows parity, blank-value removal, [paths] cuda precedence, and the absence of any concurrency, latency, memory, metric, or contract impact — stated plainly in §4 below.

0. Citation basis — important discrepancy, please read

The pr/690 ref that this environment resolves is not the head the Dossier describes. Concretely:

Each finding below is therefore tagged [snapshot-verified] (I opened the lines myself this session) or [head-cited] (from the prior research pass at 39796ea, not re-openable here). Findings 1 and 4 are unaffected by the discrepancy; findings 2 and 3 are the ones that hinge on it.

1. Correctness, safety & platform parity

F1 — Major — inherited CUDA_HOME is never existence-checked, so a stale value silently disables toolkit env [snapshot-verified]

ignition/cli/environment.py:58-69 (whole resolution block, quoted verbatim as read at pr/690):

    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)

Compare with main (ignition/cli/environment.py:54-58 at main):

    cuda = configuration.directory("cuda")
    if cuda is None and os.name != "nt" and Path("/usr/local/cuda").is_dir():
        cuda = Path("/usr/local/cuda")
    if cuda is not None:
        os.environ["CUDA_HOME"] = str(cuda)

The /usr/local/cuda branch is validated (_DEFAULT_LINUX_CUDA.is_dir(), :64); the inherited branch (:62-63) is not. The subsequent derivations then no-op because the paths do not exist: :78 if ptxas.is_file() and … and :83 if include.is_dir().

The new test pins this as intended behaviour — tests/cli/test_environment.py:109-120, verbatim:

def test_inherited_cuda_home_without_local_files_does_not_fall_back_to_default(clean_environment, monkeypatch):
    inherited = clean_environment / "custom-cuda"          # never created
    default = _make_toolkit(clean_environment / "default-cuda")
    monkeypatch.setattr(environment, "_DEFAULT_LINUX_CUDA", default)
    monkeypatch.setenv("CUDA_HOME", str(inherited))

    environment.apply(_load_config(clean_environment), ())

    assert os.environ["CUDA_HOME"] == str(inherited)
    assert "TRITON_PTXAS_PATH" not in os.environ
    assert "CPATH" not in os.environ

Impact. For the population of hosts that main served correctly through /usr/local/cuda and that also carry a stale CUDA_HOME (shell profile left over from another toolkit, container env, a previous project), this PR removes TRITON_PTXAS_PATH and CPATH entirely, where main set both from /usr/local/cuda. It is the mirror image of #636: #636 complains that an explicit CUDA_HOME is ignored; this silently honours one that points at nothing. Downstream, the bogus root is handed to torch.utils.cpp_extension.CUDA_HOME-derived paths: ignition/preparation/kv_codec.py:21-38 reads it as its first candidate (:26-28 candidates.append(Path(CUDA_HOME) / "bin" / "nvcc")). Note the blast radius is bounded there because :32 unconditionally appends Path("/usr/local/cuda/bin/nvcc") as a last candidate — so _find_nvcc will usually still succeed; the damage is to include/library roots that trust CUDA_HOME with no fallback. The docs read as a validated chain and do not disclose the rule: AGENTS.md:468-471 "when [paths] cuda is unset on non-Windows hosts, it preserves a non-empty inherited CUDA_HOME before falling back to /usr/local/cuda" — "non-empty", never "existing".

Fix (pick one, and make the other docs match):

F2 — Major (snapshot only) — TRITON_PTXAS_PATH precedence reversal [snapshot-verified here; Dossier says removed at head]

ignition/cli/environment.py:77-81 (snapshot) versus main:66-68:

            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)

main is if ptxas.is_file() and "TRITON_PTXAS_PATH" not in os.environ:. The snapshot therefore overwrites an ambient, non-blank TRITON_PTXAS_PATH any time [paths] cuda is configured. The test asserts it — tests/cli/test_environment.py:62-75:

def test_configured_cuda_overrides_inherited_cuda_home_ptxas_and_default_toolkit(clean_environment, monkeypatch):
    ...
    monkeypatch.setenv("TRITON_PTXAS_PATH", "/ambient/ptxas")
    ...
    assert os.environ["TRITON_PTXAS_PATH"] == str(configured / "bin/ptxas")

Impact. A user pinning ptxas from a specific toolkit gets silently redirected to [paths] cuda's ptxas — the wrong assembler version for their GPU, which surfaces as JIT build failures or a wrong-architecture cubin in flashinfer/Triton builds rather than a clear error. It also contradicts the PR body verbatim: "TRITON_PTXAS_PATH (if ptxas.is_file() and "TRITON_PTXAS_PATH" not in os.environ), CPATH prepending, and Windows (os.name == "nt") behavior are unchanged."

Status. The Discovery Dossier's amendment #1 reports this condition was removed at 39796ea, that this finding was "RETRACTED", and that environment.py:75 at pr/690 equals main:67. My snapshot contradicts that. Fix: restore if ptxas.is_file() and "TRITON_PTXAS_PATH" not in os.environ: and adjust test_environment.py:62-75 to assert the ambient value is kept. Action for adjudication: confirm the true content of :75-81 at 39796ea before relying on the retraction.

F3 — Minor — doc self-contradiction in this snapshot [snapshot-verified]

docs/cli-design.md:46-51:

- **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`.

versus AGENTS.md:468-471, which already documents the exception. A reader following docs/cli-design.md (the canonical spec, and what model-preparation.md points to) is told the new CUDA_HOME read violates the design. The Dossier reports this was reconciled at the head (docs/cli-design.md:46-57 rewritten) — same re-check as F2. Note also the residual, unchanged nit that AGENTS.md:452-455 still states the unqualified prohibition ("Flare, Helios, recipes, and components never read an environment variable to choose behavior … including temporary ones") with no pointer to the :461 carve-out.

F4 — Minor — apply() reads its own output as "inherited"; a second call cannot un-set a value a prior call wrote [snapshot-verified]

environment.py:61 inherited_cuda = os.environ.get("CUDA_HOME", "").strip() reads the same key that :69 os.environ["CUDA_HOME"] = str(cuda) writes. Once any call has written CUDA_HOME (including the /usr/local/cuda fallback), a later call in the same process sees that value as inherited and takes the :62-63 branch instead of :64-67 — so it can never pop a value it previously set, even if [paths] cuda has since disappeared from the configuration object. Today every call site is single-shot per CLI command — ignition/cli/serve.py:210, 291, 436, 545 and ignition/cli/bench.py:205 — so this is latent, not a live defect. Fix: capture the pre-existing value once (module-level constant or an explicit parameter) and treat the os.environ write as output only.

Platform parity — clean

The Windows branch is untouched: environment.py:70-75 (CUDA_PATH, TRITON_PTXAS.EXE_PATH, os.add_dll_directory) is the same code as main:59-64, and the new logic is correctly gated by os.name != "nt" at :60. The PR body's Windows claim holds by inspection. Windows remains untested — every test is @pytest.mark.skipif(os.name == "nt", …) — but that is unchanged from main, not a regression.

2. Unintended system-level consequences — none found

I traced every call site: serve.py:210, 291, 436, 545 and bench.py:205. apply() is a synchronous, once-per-process, pre-import step — verified at serve.py:291-292, environment.apply(configuration, plan.gpus, plan.recipe.b12x_environment) immediately followed by import flare_heliopause, i.e. before the runtime/torch stack loads, which is exactly the ordering the change needs to work at all. Consequently:

3. Architecture, contracts & charter compliance

4. Tests & claim accuracy

Accurate claims. "Unset otherwise, removing any blank/whitespace CUDA_HOME from os.environ" — verified: :66-67 pops, and tests/cli/test_environment.py:138-149 covers None/""/" ". "Explicit [paths] cuda overrides inherited CUDA_HOME" — verified :58-59 and tested :62-75. configuration.directory() returning None for empty [paths] cuda is the default that makes this branch reachable (ignition/cli/config.py:172-175: value = self.get(f"paths.{name}").value; return Path(value).expanduser() if value else None).

Inaccurate or unverifiable claims. "TRITON_PTXAS_PATH … unchanged" — false in the snapshot (F2). The test-count figure "12" is 10 parametrized cases in the 150-line snapshot (6 functions: :62, :79, :93, :109, :125×3, :140×3); the Dossier's 12 refers to the head. "148 passed" remains author-reported; CI status is not observable from here.

Coverage gaps worth noting. (a) No test covers [paths] cuda pointing at a directory that does not exist — directory() does not validate existence (config.py:172-175), so a typo'd config silently behaves like F1. Pre-existing on main, but the PR now has a test file that could cover it. (b) The [paths] cuda test (:62-75) asserts behaviour that is unchanged on main when the ptxas reversal is removed, i.e. it is regression cover, not evidence for the fix. (c) The clean_environment fixture (:45-58) is genuinely leak-free — it registers an undo entry for originally-absent keys via monkeypatch.setenv(key, ""); os.environ.pop(key, None) — and stubs runtime_patches.apply (:47), so the suite is host-independent and does run in PR CI (.github/workflows/python-cpu.yml:30-33 (not opened) runs pytest tests/ -q with CUDA_VISIBLE_DEVICES: "").

5. Open questions

  1. Which commit is really at head? The pr/690 content available here contradicts the Dossier on F2, F3 and the test counts. If 39796ea really contains main's ptxas line and the reconciled cli-design.md, then F2 and F3 are withdrawn and only F1 and F4 stand.
  2. Should a nonexistent inherited CUDA_HOME fall back to /usr/local/cuda? F1's fix choice (add is_dir() vs. document the verbatim policy) needs one decision, and the test at :109-120 must move with it.
  3. Does a maintainer endorse #636's premise that CUDA_HOME outranks /usr/local/cuda? Still nothing recorded on the issue; the PR carries triage:review while #636 carries triage:design-review.
  4. Will anyone run the multi-toolkit reproduction from #636, or is env-dict-only coverage accepted?

6. What I could not verify