Skip to content

refactor(pathfinder): static and bitcode finders share one search - #3608

Open
rparolin wants to merge 1 commit into
pathfinder-readability/6-search-steps-return-missesfrom
pathfinder-readability/7-share-static-bitcode-locate
Open

rparolin wants to merge 1 commit into
pathfinder-readability/6-search-steps-return-missesfrom
pathfinder-readability/7-share-static-bitcode-locate

Conversation

@rparolin

@rparolin rparolin commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

— 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.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
License N/A - no dependencies changed
Container N/A - no container changed

Checklist

  • I have read the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@rparolin
rparolin added this pull request to stack #3612 November 25, 2026 21:14
@github-actions github-actions Bot added the cuda.pathfinder Everything related to the cuda.pathfinder module label Nov 25, 2026
@rparolin rparolin added the enhancement Any code-related improvements label Nov 25, 2026
@rparolin rparolin added this to the cuda.pathfinder next milestone Nov 25, 2026
@rparolin
rparolin removed this pull request from stack #3612 November 25, 2026 22:28
@rparolin
rparolin added this pull request to stack #3616 November 25, 2026 22:29
@rparolin rparolin self-assigned this Nov 25, 2026
@rparolin
rparolin requested review from juenglin and rwgk November 25, 2026 23:06
@rparolin
rparolin marked this pull request as ready for review November 26, 2026 16:16
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

Reviews paused

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.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

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
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 358af9b and 35add32.

Files selected for processing: 4

  • cuda_pathfinder/cuda/pathfinder/_static_libs/find_bitcode_lib.py
  • cuda_pathfinder/cuda/pathfinder/_static_libs/find_static_lib.py
  • cuda_pathfinder/tests/test_find_bitcode_lib.py
  • cuda_pathfinder/tests/test_find_static_lib.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 0 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor comments: 1

cuda_pathfinder/cuda/pathfinder/_static_libs/find_bitcode_lib.py: 1

87-87: Minor · Functional Correctness · Low value

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.

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4bc2808 and ec43040.

Files selected for processing: 4

  • cuda_pathfinder/cuda/pathfinder/_static_libs/find_bitcode_lib.py
  • cuda_pathfinder/cuda/pathfinder/_static_libs/find_static_lib.py
  • cuda_pathfinder/tests/test_find_bitcode_lib.py
  • cuda_pathfinder/tests/test_find_static_lib.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 3 remain after this review.

@copy-pr-bot

copy-pr-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@juenglin juenglin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!

@rparolin

rparolin commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test 35add32

@rparolin
rparolin force-pushed the pathfinder-readability/7-share-static-bitcode-locate branch from 35add32 to bc024a5 Compare December 4, 2026 17:54
`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>
@rparolin
rparolin force-pushed the pathfinder-readability/7-share-static-bitcode-locate branch from bc024a5 to 6573aa1 Compare December 4, 2026 20:44

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.pathfinder Everything related to the cuda.pathfinder module enhancement Any code-related improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants