You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(pathfinder): static and bitcode finders share one search - #3608
find_static_lib.py was written as a copy of find_bitcode_lib.py (#1690). Each had its own finder class, its own copy of the three search steps, and its own error formatter, and later changes had to be made twice (#2493, #2708, #3418).
Both now call locate_file() in the new _static_libs/locate_file.py: site-packages, then $CONDA_PREFIX, then $CUDA_PATH. It returns the hit. On a miss it raises the caller's own documented error: each public function passes its error class. The two finder classes and their scratch lists are gone (379 -> 275 lines in _static_libs/).
An unreachable fallback message ("No search paths available") is dropped: the last search step always reported a reason.
Tests: the 15 monkeypatch.setattr(..., "find_sub_dirs_all_sitepackages") calls now patch locate_file, where that lookup lives. Nothing else changes.
No behavior change. Checked beyond the test suite: 831 scenarios (every supported name; Linux, Windows x64, Windows arm64; file in each search location or nowhere; CONDA_PREFIX set, unset, empty; CUDA_PATH, CUDA_HOME, unset, missing directory, relative path) give the same result, error type and error text as main, byte for byte.
Also in this PR: describe the shared static/bitcode search accurately.
The not-found message describes the first CUDA_PATH directory tried, not the last place searched; its docstring now says so. AGENTS.md names _static_libs/locate_file.py as the search both finders share.
Also in this PR: build the not-found error from the root that was searched.
A first version read get_cuda_path_or_home() twice: once to search and once to write the error. The original finders read it once. If two threads looked up at the same time on a cold cache while CUDA_HOME changed, the error could name a directory that was never searched. CodeRabbit found this.
locate_file now raises the finder's error itself, from the root it read. The message text is unchanged. A new test fails on the two-read version and passes now, and the 831 scenarios are still byte-identical to main.
Testing
Full cuda_pathfinder test suite at this commit: 1651 passed, 6 skipped (Linux, Python 3.14).
pre-commit clean, including mypy-pathfinder.
Not run on Windows. Windows rules are exercised by tests that simulate Windows on Linux.
PLC Local Security Evidence (Advisory)
Local advisory checks only, run over the whole stack. Not release-gate results.
Check
Status
Tool
Details
Secrets
SKIP
Pulse Secret Scanner
scanner image not available locally (registry login); the repo trufflehog pre-commit hook passed
SAST
WARN
Semgrep
1 finding, not from this stack: the existing subprocess.run call in the canary probe in load_nvidia_dynamic_lib.py
Dependencies
WARN
pip-audit / osv-scanner
no manifest or lockfile in scope, so the local scan could not run; this stack changes no dependencies
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
No actionable comments were generated in the recent review.
Summary
Summary by CodeRabbit
Bug Fixes
Static and bitcode library discovery now checks package directories first, followed by Conda environments and CUDA Toolkit paths. Windows Conda installations are searched in the appropriate library directory.
When a library cannot be found, the error identifies the first CUDA directory searched or indicates that CUDA_HOME/CUDA_PATH is unset.
Static and bitcode library lookup now uses a shared helper to search site-packages, Conda, and CUDA Toolkit locations. The helper returns the resolved path and source label, or raises the caller’s configured error with a not-found diagnostic.
Changes: CUDA library lookup
Layer / File(s)
Summary
Shared search and diagnostics cuda_pathfinder/cuda/pathfinder/_static_libs/locate_file.py, cuda_pathfinder/AGENTS.md
Adds ordered file lookup and shared not-found diagnostics. The architecture documentation identifies the helper and its callers.
Static and bitcode lookup integration cuda_pathfinder/cuda/pathfinder/_static_libs/find_static_lib.py, cuda_pathfinder/cuda/pathfinder/_static_libs/find_bitcode_lib.py, cuda_pathfinder/tests/test_find_static_lib.py, cuda_pathfinder/tests/test_find_bitcode_lib.py
Both lookup functions delegate searches to the shared helper. Tests patch site-packages discovery through the helper module. A bitcode test checks that the error reports the CUDA root used for the search.
Suggested reviewers:abhilash1910, cpcloud
Change: Refactor
Merge Risk: Minimal · previous review 35add
Static and bitcode library lookup now share one search with the same order of site-packages, Conda, then CUDA path. Not-found errors report the CUDA root that was actually searched, which resolves the earlier concern. No actionable merge-blocking risk remains.
Security architecture risk: Minimal · up to 35add
CUDA Pathfinder now uses one search implementation for static and bitcode libraries. The refactor preserves the search order, the public results and exceptions, and the diagnostic for the toolkit root that was searched. No caller or operator action is needed.
Security review details
Security Blast Radius
observed — Search-policy changes in locate_file now affect both finder families. Each still supplies its own candidate locations and filenames; the helper probes the filesystem and returns a path without loading or executing the file.
Trust Boundaries and Controls
observed — A caller-supplied name selects an entry in a supported-name table; it is not used as a filesystem path. The process environment and installed package directories still influence lookup as before. File existence and path resolution do not authenticate the selected artifact.
Resilience and Maintainability Implications
observed — On a miss, the shared helper uses the toolkit root value from that lookup rather than reading it again, preserving the merge-base behavior. The diagnostic describes only the first toolkit directory tried, or says no toolkit root was set. Its directory listing is read during error formatting, so it is not a snapshot of the earlier file check.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 0 remain after this review.
suggestion: Report the CUDA Toolkit root that locate_file searched.
When two lookups overlap on a cold get_cuda_path_or_home() cache, a CUDA_HOME change between their reads can replace the cached root. locate_file probes the root it read. not_found_message then reads the cache again. On a miss, the error can name a directory the lookup never searched, and it can list a file that exists there. The exception type stays the same. The base revision formatted the error from the root it searched.
The trigger is narrow. It needs overlapping cold-cache lookups and an environment change during them. A single-threaded change does not trigger it, because locate_file fills the cache before not_found_message runs.
Have locate_file return the searched root or the formatted diagnostic in its miss result. Use that value in each finder that raises a not-found error. Keep the early return on a hit. This also removes the second get_cuda_path_or_home() read on the miss path.
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 3 remain after this review.
`find_static_lib.py` was written as a copy of `find_bitcode_lib.py`
(#1690). Each had its own finder class, its own copy of the three
search steps, and its own error formatter, and later changes had to be
made twice (#2493, #2708, #3418).
Both now call `locate_file()` in the new `_static_libs/locate_file.py`:
site-packages, then `$CONDA_PREFIX`, then `$CUDA_PATH`. It returns the
hit or `None`, and each public function raises its own documented
error. The two finder classes and their scratch lists are gone
(379 -> 275 lines in `_static_libs/`).
An unreachable fallback message ("No search paths available") is
dropped: the last search step always reported a reason.
Tests: the 15 `monkeypatch.setattr(..., "find_sub_dirs_all_sitepackages")`
calls now patch `locate_file`, where that lookup lives. Nothing else
changes.
No behavior change. Checked beyond the test suite: 831 scenarios (every
supported name; Linux, Windows x64, Windows arm64; file in each search
location or nowhere; `CONDA_PREFIX` set, unset, empty; `CUDA_PATH`,
`CUDA_HOME`, unset, missing directory, relative path) give the same
result, error type and error text as `main`, byte for byte.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Rob Parolin <rparolin@nvidia.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
— codex on behalf of Ralf —
Description
Part 8 of 23 of a readability stack for
cuda.pathfinder(stack: #3623 → #3602 → #3603 → #3604 → #3605 → #3606 → #3607 → #3608 → #3609 → #3610 → #3611 → #3613 → #3618 → #3619 → #3620 → #3621 → #3622 → #3627 → #3628 → #3629 → #3630 → #3631 → #3632). No behavior change.find_static_lib.pywas written as a copy offind_bitcode_lib.py(#1690). Each had its own finder class, its own copy of the three search steps, and its own error formatter, and later changes had to be made twice (#2493, #2708, #3418).Both now call
locate_file()in the new_static_libs/locate_file.py: site-packages, then$CONDA_PREFIX, then$CUDA_PATH. It returns the hit. On a miss it raises the caller's own documented error: each public function passes its error class. The two finder classes and their scratch lists are gone (379 -> 275 lines in_static_libs/).An unreachable fallback message ("No search paths available") is dropped: the last search step always reported a reason.
Tests: the 15
monkeypatch.setattr(..., "find_sub_dirs_all_sitepackages")calls now patchlocate_file, where that lookup lives. Nothing else changes.No behavior change. Checked beyond the test suite: 831 scenarios (every supported name; Linux, Windows x64, Windows arm64; file in each search location or nowhere;
CONDA_PREFIXset, unset, empty;CUDA_PATH,CUDA_HOME, unset, missing directory, relative path) give the same result, error type and error text asmain, byte for byte.Also in this PR: describe the shared static/bitcode search accurately.
The not-found message describes the first
CUDA_PATHdirectory tried, not the last place searched; its docstring now says so.AGENTS.mdnames_static_libs/locate_file.pyas the search both finders share.Also in this PR: build the not-found error from the root that was searched.
A first version read
get_cuda_path_or_home()twice: once to search and once to write the error. The original finders read it once. If two threads looked up at the same time on a cold cache whileCUDA_HOMEchanged, the error could name a directory that was never searched. CodeRabbit found this.locate_filenow raises the finder's error itself, from the root it read. The message text is unchanged. A new test fails on the two-read version and passes now, and the 831 scenarios are still byte-identical tomain.Testing
cuda_pathfindertest suite at this commit: 1651 passed, 6 skipped (Linux, Python 3.14).mypy-pathfinder.PLC Local Security Evidence (Advisory)
Local advisory checks only, run over the whole stack. Not release-gate results.
subprocess.runcall in the canary probe inload_nvidia_dynamic_lib.pyChecklist
🤖 Generated with Claude Code