Skip to content

refactor(pathfinder): search steps read the resolved search context - #3606

Open
rparolin wants to merge 3 commits into
pathfinder-readability/4-add-resolved-search-contextfrom
pathfinder-readability/5-use-resolved-search-context
Open

rparolin wants to merge 3 commits into
pathfinder-readability/4-add-resolved-search-contextfrom
pathfinder-readability/5-use-resolved-search-context

Conversation

@rparolin

@rparolin rparolin commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

— codex on behalf of Ralf —

Description

Part 6 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.

The search steps now read plain fields from the SearchContext record added in the previous change, instead of calling through a platform object. This removes the SearchPlatform protocol, both platform classes, the PLATFORM singleton, and the two copies of the site-packages finder (one per platform).

search_platform.py goes from 339 to 180 lines. The one remaining platform branch is in _find_lib_file, where the real difference lives: which file names to try, and the Windows DLL checks.

Tests: construction changes only. platform=WindowsSearchPlatform(target_arch="x64") becomes windows_arch="x64". Six assertions read the same value from the context instead of from the platform object; the expected values are unchanged. The comparison test from the previous change is removed with the classes it compared against.

Also in this PR: pin the not-found error text before the refactor.

test_not_found_error_lists_every_miss_in_search_order pins the full DynamicLibNotFoundError text for a library that misses everywhere. It passes on this code unchanged. #3607 rewrites how misses are reported and does not touch this test, so CI shows the text is the same before and after.

No behavior change. 1646 passed, 6 skipped.

Testing

  • Full cuda_pathfinder test suite at this commit: 1646 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.

@github-actions github-actions Bot added the cuda.pathfinder Everything related to the cuda.pathfinder module label Nov 25, 2026
@rparolin
rparolin added this pull request to stack #3612 November 25, 2026 21:14
@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:52
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes

    • Library search failures now distinguish between missing directories and directories without an architecture-compatible library.
    • Search diagnostics include directory contents when available and list failed search locations in order.
  • Refactor

    • Updated the library-search flow while preserving platform-specific lookup behavior.

Platform-specific library search settings and lookup functions now use SearchContext. Search steps, the library loader, and tests use context factories and properties.

Changes: Dynamic library search

Layer / File(s) Summary
Search context and lookup
cuda_pathfinder/cuda/pathfinder/_dynamic_libs/search_platform.py, cuda_pathfinder/tests/test_ctk_root_discovery.py
SearchContext now holds platform-specific search settings and diagnostic details. Shared functions select soname or DLL lookup, search configured directories, and record failure details. A test checks that not-found errors list misses in search order and include directory listings.
Search routing and context adoption
cuda_pathfinder/cuda/pathfinder/_dynamic_libs/search_steps.py, cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py, cuda_pathfinder/tests/*
Search steps now read search settings from the context and call shared lookup functions. The loader creates contexts with search_context. Tests use platform-specific context factories and retain search assertions. The former SearchPlatform implementations and the SearchContext definition in search_steps.py were removed.

Possibly related PRs

  • NVIDIA/cuda-python#3605: This PR uses the SearchContext record and factories added by #3605.
  • NVIDIA/cuda-python#3607: This PR changes search-step result handling and builds on the SearchContext and search-step code updated here.

Suggested reviewers: cpcloud

Change: Refactor

Merge Risk: Minimal · up to 3574f

This refactor moves dynamic library search settings into a context record without intended behavior change. No concrete defect was found, and the author reports tests passing, so the merge risk is minimal.

Security architecture risk: Minimal · up to 3574f

The refactor changes how library search rules are passed around, but the reviewed code preserves the search order and the checks that determine which files can be loaded. The review found no new or widened loading path. Native Windows behavior was not tested.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed policy applies within each Python process that uses the non-driver loader. A selected library still loads with that process's existing authority; the refactor adds no caller-controlled path parameter or separate privileged loading mechanism.

Trust Boundaries and Controls

  • observed — Process environment, installation directories, and native search policy can still influence candidate selection, as they did before this PR. The refactor preserves these inputs and their precedence; filename and PE compatibility checks are not file-authenticity checks.
- [ ] 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 4b27865 and 3574f0b.

Files selected for processing: 2

  • cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py
  • cuda_pathfinder/tests/test_ctk_root_discovery.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.

@github-actions

Copy link
Copy Markdown
Contributor

rparolin and others added 3 commits November 26, 2026 11:17
The search steps now read plain fields from the `SearchContext` record
added in the previous change, instead of calling through a platform
object. This removes the `SearchPlatform` protocol, both platform
classes, the `PLATFORM` singleton, and the two copies of the
site-packages finder (one per platform).

`search_platform.py` goes from 339 to 180 lines. The one remaining
platform branch is in `_find_lib_file`, where the real difference lives:
which file names to try, and the Windows DLL checks.

Tests: construction changes only. `platform=WindowsSearchPlatform(
target_arch="x64")` becomes `windows_arch="x64"`. Assertions are
unchanged. The comparison test from the previous change is removed
with the classes it compared against.

No behavior change. 1645 passed, 6 skipped.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Rob Parolin <rparolin@nvidia.com>
Add `test_not_found_error_lists_every_miss_in_search_order` here. It
was first added one change later, together with the refactor it guards.

The test passes on this code unchanged. The next change in the stack
rewrites how search steps report misses and no longer touches this
test, so CI shows the error text is the same before and after.

Test only. No package code changes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Rob Parolin <rparolin@nvidia.com>
Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
@rwgk
rwgk removed this pull request from stack #3616 November 26, 2026 19:19
@rwgk
rwgk force-pushed the pathfinder-readability/5-use-resolved-search-context branch from 0b7c8c3 to 3574f0b Compare November 26, 2026 19:19
@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.

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