Skip to content

fix(cargo-oxide): doctor probes two toolkit tools on PATH only - #1181

Merged
nihalpasham merged 1 commit into
NVIDIA:mainfrom
vyncint:fix/doctor-toolkit-aware-tool-probes
Aug 28, 2026
Merged

nihalpasham merged 1 commit into
NVIDIA:mainfrom
vyncint:fix/doctor-toolkit-aware-tool-probes

Conversation

@vyncint

@vyncint vyncint commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Closes #1180.

cargo oxide doctor reports the CUDA toolkit missing, and exits non-zero, on an install where the toolkit is not on PATH — immediately after reporting four components of that same toolkit as found.

Before → after

Same machine, same environment, CUDA_HOME set, toolkit not on PATH:

before                                          after
────────────────────────────────────────────    ────────────────────────────────────
CUDA headers (cuda.h)... ✓ .../include/cuda.h   unchanged
CUDA toolkit (nvcc)... ✗ nvcc not found         ✓ Cuda compilation tools, release
                                                  13.3, V13.3.33 (.../bin/nvcc)
libNVVM (libnvvm.so)... ✓ libNVVM 2.0           unchanged
nvJitLink... ✓ nvJitLink 13.3                   unchanged
libdevice... ✓ .../libdevice.10.bc              unchanged

nvcc was present at $CUDA_HOME/bin/nvcc the whole time — in the very toolkit those four ✓ lines resolved.

Root cause, across all three tools

doctor probes three CUDA toolkit executables by two different mechanisms:

tool how doctor finds it how the command that uses it finds it
compute-sanitizer find_cuda_toolkit_executable sanitize — same helper
nvcc Command::new("nvcc"), PATH only nothing else invokes it
cuda-gdb Command::new("cuda-gdb"), PATH only debug — via the helper
find_cuda_toolkit_executable:   PATH → CUDA_TOOLKIT_PATH/CUDA_HOME/cuda-oxide.toml → standard roots
Command::new(name):             PATH

Two consequences:

  • nvcc sits in the required tier, so a working environment sets ok = false and doctor exits 1.
  • cuda-gdb contradicts cargo oxide debug, which resolves it through the helper. Doctor calls absent a tool that the command it exists to predict would find.

The toolkit-root contract is doctor's own stated model — its cuda.h failure prints "Set CUDA_TOOLKIT_PATH or CUDA_HOME to a CUDA Toolkit install root". And COMPUTE_SANITIZER_FALLBACK_PATHS states the rule the other two break, in its own doc comment: "Shared by sanitize … and doctor so both use the same discovery order by construction." That helper arrived with the compute-sanitizer probe in #537; the older two probes were never moved onto it.

Exactly three toolkit executables are referenced anywhere in cargo-oxide, so this is the whole affected path rather than the one symptom I noticed first.

The change

All three probes go through DOCTOR_TOOLKIT_TOOLS, one table pairing each tool with its fallbacks, resolved by doctor_toolkit_tool. The cuda-gdb list becomes CUDA_GDB_FALLBACK_PATHS, shared by doctor and codegen_debug, so the two answer identically by construction rather than by coincidence — codegen_debug's inline copy is gone.

Deliberately out of scope: the required/optional tiers. Whether nvcc should be required at all is a policy question, and mixing it in would make a discovery fix harder to judge. Say the word if you want it demoted and I will do that separately. ptxas is not probed by doctor at all — also a separate coverage question.

Tests

kind what it pins
regression every tool in the table resolves under a configured toolkit root with nothing on PATH — the broken case
unaffected control the configured root is still preferred over the standard install roots, so discovery order is unchanged; only which function doctor calls changed
negative absent from PATH, the configured root and the fallbacks is still None; the fix invents no path
source invariant no CUDA toolkit executable may be probed with a bare Command::new, read out of the source rather than from the table, so a tool left out of the table is still caught
single list doctor and debug reference one cuda-gdb fallback list; a second inline copy fails

PATH precedence is asserted end to end against the real binary rather than by mutating the process PATH — that is unsafe in edition 2024 and racy across test threads, and I would rather not add a flaky test to prove a property the CLI can demonstrate directly.

Each was confirmed to bite by reverting the thing it guards:

  • the whole nvcc probe restored to its original form compiles, fails no_toolkit_executable_is_probed_by_bare_path, and the CLI returns to ✗ nvcc not found;
  • re-adding an inline cuda-gdb list fails the single-list test;
  • adding a bare ptxas probe fails the source invariant;
  • a stub nvcc placed earlier on PATH still resolves from PATH, checked against the real binary.

Verification

183 tests pass, fmt clean, clippy --all-targets -- -D warnings clean, RUSTDOCFLAGS="-D warnings" cargo doc clean, all guard scripts pass. Rebased onto b22efa99.

Doctor's exit status on my machine is still 1, for a genuinely absent clang — the fix does not paper over a real failure.

One file. No open PR touches crates/cargo-oxide/src/commands.rs; re-checked immediately before opening.

@nihalpasham

nihalpasham commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator

Fix verified, closes #1180:

  • those were the last two bare toolkit probes in cargo-oxide (audited every Command::new)
  • one table + the shared discovery helper is the right mechanism, and the cuda-gdb fallback list is now a single constant

The test-hermeticity blocker from the earlier version of this comment is resolved by your force-push: the real-name test is gone, the fabricated-name replacements match the sibling idiom, and the table coverage moved to source-based tests. Confirmed on a toolkit-on-PATH machine:

old head:  every_doctor_toolkit_tool_resolves_under_the_configured_root
           FAILED (which nvcc -> /usr/local/cuda/bin/nvcc wins the probe)
new head:  cargo test -p cargo-oxide  185 passed, 0 failed
           fmt + clippy -D warnings   clean

One behavior change to note: a found nvcc whose --version fails now prints ✓ <path> instead of failing doctor. That matches the compute-sanitizer arm, so we're keeping it. Labels added, CI approved on the new head. Mergeable as-is after CI.

@nihalpasham nihalpasham added bug Something isn't working cargo-oxide The `cargo oxide` subcommand and build automation build-related Build scripts, toolchain discovery, or compilation setup labels Aug 28, 2026
@vyncint
vyncint force-pushed the fix/doctor-toolkit-aware-tool-probes branch from df32985 to 37386c8 Compare August 28, 2026 12:43
`cargo oxide doctor` reports the CUDA toolkit missing, and exits non-zero, on
an install where the toolkit is not on `PATH` -- immediately after reporting
four components of that same toolkit as found.

## Before -> after

Same machine, same environment, `CUDA_HOME=$HOME/cuda-13.3`, toolkit not on
`PATH`:

    before                                        after
    CUDA headers (cuda.h)... ✓ .../include/cuda.h  (unchanged)
    CUDA toolkit (nvcc)... ✗ nvcc not found        ✓ Cuda compilation tools,
                                                     release 13.3, V13.3.33
                                                     (.../cuda-13.3/bin/nvcc)
    libNVVM (libnvvm.so)... ✓ libNVVM 2.0          (unchanged)
    nvJitLink... ✓ nvJitLink 13.3                  (unchanged)
    libdevice... ✓ .../libdevice.10.bc             (unchanged)

`nvcc` was present at `$CUDA_HOME/bin/nvcc` throughout, in the toolkit those
four lines resolved.

## Root cause, across all three tools

`doctor` probes three CUDA toolkit executables by two different mechanisms:

| tool | doctor | the command that uses it |
|---|---|---|
| `compute-sanitizer` | `find_cuda_toolkit_executable` | `sanitize`, same helper |
| `nvcc` | `Command::new("nvcc")`, PATH only | nothing else invokes it |
| `cuda-gdb` | `Command::new("cuda-gdb")`, PATH only | `debug`, via the helper |

`find_cuda_toolkit_executable` tries PATH, then the root from
`CUDA_TOOLKIT_PATH` / `CUDA_HOME` / `cuda-oxide.toml`, then the standard install
roots. The two bare probes see only PATH. So:

* `nvcc` is in the required tier, so a working environment sets `ok = false`
  and `doctor` exits 1;
* `cuda-gdb` contradicts `cargo oxide debug`, which resolves it through the
  helper -- doctor calls absent a tool the command it is predicting would find.

The toolkit-root contract is doctor's own stated model; its `cuda.h` failure
prints "Set CUDA_TOOLKIT_PATH or CUDA_HOME to a CUDA Toolkit install root".
`COMPUTE_SANITIZER_FALLBACK_PATHS` states the rule the other two break, in its
own doc comment: "Shared by `sanitize` ... and `doctor` so both use the same
discovery order by construction." That helper arrived with the
compute-sanitizer probe in NVIDIA#537 and the older probes were never moved onto it.

Exactly three toolkit executables are referenced anywhere in `cargo-oxide`, so
this is the whole affected path, not the one symptom I noticed first.

## The change

All three probes now go through `DOCTOR_TOOLKIT_TOOLS`, one table pairing each
tool with its fallbacks, resolved by `doctor_toolkit_tool`. The `cuda-gdb`
fallback list becomes `CUDA_GDB_FALLBACK_PATHS`, shared by `doctor` and
`codegen_debug`, so the two answer identically by construction rather than by
coincidence -- `codegen_debug`'s inline copy is gone.

The required/optional tiers are deliberately untouched. Whether `nvcc` should be
required at all is a policy question; this is a discovery bug, and mixing the two
would make the change harder to judge.

## Behaviour change, deliberate

A discovered `nvcc` whose `--version` fails now reports `✓ <path>` instead of
failing doctor. Previously a broken `nvcc` on PATH fell to the catch-all arm and
printed `✗ nvcc not found`, which was also wrong -- it was found. The new arm
mirrors the `compute-sanitizer` probe, which has always reported the path when
the version banner cannot be read. Recording it because it is a real change in
verdict for one input, not only a discovery fix.

## Tests

* **Table pairing** -- every entry pairs a tool with its own fallback list.
  Pure, so it covers all three tools on every host; pairing `nvcc` with
  `CUDA_GDB_FALLBACK_PATHS` is a one-token slip no filesystem test could see.
* **Lookup** -- each tool gets its own list and an unknown name gets none
  rather than another tool's.
* **Call sites** -- every `doctor_toolkit_tool` call names a tool the table
  knows, since an unknown name silently loses its standard install roots.
* **Source invariant** -- no CUDA toolkit executable may be probed with a bare
  `Command::new`. Read out of the source rather than from the table, so a tool
  left out of the table is still caught.
* **Single list** -- `doctor` and `debug` reference one `cuda-gdb` fallback
  list; a second inline copy fails.

Every test here is hermetic: pure or source-based, no filesystem and no
environment. That is deliberate. `find_cuda_toolkit_executable` probes PATH
first through `which`, and that probe has no injection point, so a test using
real tool names asserts a temp root while resolving whatever the host has
installed. An earlier version of this commit did exactly that and passed only
because this machine has no `nvcc` on PATH -- the very configuration the fix is
about. Toolkit-root resolution itself stays covered by the existing
`sanitizer_tool_lookup_uses_project_cuda_toolkit_root`, which fabricates a name
for the same reason.

Each test confirmed to bite by breaking what it guards: mispairing the table,
probing a tool absent from it, making the lookup return one list for every
tool, and re-adding an inline `cuda-gdb` list each fail their own test.
Reverting a probe to `Command::new` does not compile; restored to its original
form so it does, it fails the source invariant and the CLI returns to
`✗ nvcc not found`.

Suite runs clean in all three host shapes: toolkit on PATH, toolkit on PATH
with `CUDA_HOME` elsewhere, and no toolkit on PATH at all.

Verified: 185 tests pass, fmt clean, `clippy --all-targets -- -D warnings`
clean, `RUSTDOCFLAGS="-D warnings" cargo doc` clean, and all guard scripts pass.
Manual `doctor` runs agree in both configurations -- toolkit on PATH and not --
resolving the same `nvcc`. Exit status on this machine is still 1, for a
genuinely absent `clang`: the fix does not paper over a real failure.

Closes NVIDIA#1180.

Signed-off-by: Vyncint Ng <[email protected]>
@vyncint
vyncint force-pushed the fix/doctor-toolkit-aware-tool-probes branch from 37386c8 to faacc26 Compare August 28, 2026 12:45
@vyncint

vyncint commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Both points addressed; force-pushed, rebased onto 60cee76d.

The blocker — you are right, and I reproduced it

Putting a real-named nvcc on PATH and rerunning the old test:

assertion `left == right` failed: nvcc did not resolve under the configured toolkit root
  left: Some("/tmp/pathnvcc/nvcc")
 right: Some("/tmp/cargo_oxide_doctor_tool_.../bin/nvcc")

Worth stating plainly: that test passed here only because this machine has no nvcc on PATH — the very configuration the fix is about. The bug and my bad test shared a root cause in my environment, and I copied the sibling test's structure while changing the one thing that made it hermetic.

Rather than fabricate a name for the same filesystem test — which would then be a near-duplicate of sanitizer_tool_lookup_uses_project_cuda_toolkit_root — I split the lookup out and made the whole set hermetic:

test kind
each_toolkit_tool_is_paired_with_its_own_fallback_paths pure — catches pairing nvcc with CUDA_GDB_FALLBACK_PATHS
the_fallback_lookup_returns_each_tools_own_list pure — each tool gets its own list, unknown gets none
every_doctor_toolkit_tool_call_names_a_tool_in_the_table source — an unknown name silently loses its install roots
no_toolkit_executable_is_probed_by_bare_path source — unchanged
doctor_and_debug_share_one_cuda_gdb_fallback_list source — unchanged

No filesystem, no environment, so no host shape can move them. Toolkit-root resolution itself stays covered by the existing sibling test.

Suite is clean in all three shapes — toolkit on PATH, toolkit on PATH with CUDA_HOME pointing elsewhere, and no toolkit on PATH: 185 passed each time.

Each still bites, confirmed by breaking what it guards: mispairing the table, probing a tool absent from it, making the lookup return one list for every tool, and re-adding an inline cuda-gdb list each fail their own test. Reverting a probe to Command::new no longer compiles; restored to its original form so it does, it fails the source invariant and the CLI returns to ✗ nvcc not found.

The behaviour change — now on the record

Recorded in the commit message under its own heading. One correction to the framing: it is slightly broader than a discovered nvcc. Before, a broken nvcc on PATH also fell to the catch-all and printed ✗ nvcc not found — wrong, since it was found. After, both cases report ✓ <path>, matching the compute-sanitizer arm. Demonstrated with a stub that exits 3:

CUDA toolkit (nvcc)... ✓ /tmp/brokencuda/bin/nvcc

Manual doctor runs, both configurations

toolkit NOT on PATH, CUDA_HOME set:
  CUDA toolkit (nvcc)... ✓ Cuda compilation tools, release 13.3, V13.3.33 (.../cuda-13.3/bin/nvcc)

toolkit ON PATH:
  CUDA toolkit (nvcc)... ✓ Cuda compilation tools, release 13.3, V13.3.33 (.../cuda-13.3/bin/nvcc)

Same resolution either way. Exit status here is still 1, for a genuinely absent clang — the fix does not paper over a real failure.

fmt, clippy --all-targets -- -D warnings, RUSTDOCFLAGS="-D warnings" cargo doc and every guard script pass. Thanks for catching this one before it landed.

@nihalpasham nihalpasham left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hermetic-test rework verified on a toolkit-on-PATH machine; CI green. Merging.

@nihalpasham
nihalpasham merged commit 516f84c into NVIDIA:main Aug 28, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working build-related Build scripts, toolchain discovery, or compilation setup cargo-oxide The `cargo oxide` subcommand and build automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cargo oxide doctor reports the CUDA toolkit missing when it is not on PATH, right after finding four of its components

2 participants