Skip to content

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

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

rparolin wants to merge 1 commit 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 →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 72adfbe and 67d9896.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

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 list failed locations in search order and include directory contents when available, making it easier to understand where a library search failed.
  • Refactor

    • Updated the library-search flow while preserving platform-specific lookup behavior and the information provided when a library cannot be found.

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.

Suggested reviewers: cpcloud

Change: Refactor

Merge Risk: Minimal · previous review 40874

This refactor keeps the dynamic library search behavior unchanged and moves platform rules into one context-based design. No merge-blocking issue was found, and Linux tests pass. Windows paths are checked only by simulation on Linux.

Security architecture risk: Minimal · up to 40874

CUDA Pathfinder now resolves platform search settings once per library search and passes them to the search steps. The reviewed change preserves search precedence, Windows DLL checks, and the public loading API. No expanded loading authority or new operator action was identified.

Security review details

Security Blast Radius

  • inferred — The changed lookup helpers affect native-library selection within the calling Python process. The inspected change does not add a caller-supplied search root to the public API or introduce a service or privilege boundary.

Trust Boundaries and Controls

  • observed — Candidate paths still come from the installed package layout, existing process environment settings, and native loader search. In the Windows filesystem search, the shared helper still requires an existing descriptor-named file, rejects suppressed DLLs, and checks PE architecture where the descriptor requires it. These are candidate-selection checks, not authenticity checks.

Data and control flow

  • observed — Driver libraries still bypass the toolkit search. For other libraries, the loader retains the already-loaded checks, wheel and Conda search, native system search, late filesystem search, and descriptor-configured canary fallback. A discovered path still goes to the existing platform loader.

Resilience and Maintainability Implications

  • observed — The shared helpers retain per-search diagnostics. An OSError while listing a directory for miss diagnostics is recorded rather than aborting discovery. That continuation guarantee applies to the diagnostic listing; it does not mean that a later native-load failure is treated as another miss.
- [ ] 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 3574f0b and 4087430.

Files selected for processing: 2

  • cuda_pathfinder/cuda/pathfinder/_dynamic_libs/search_platform.py
  • cuda_pathfinder/tests/test_load_nvidia_dynamic_lib_using_mocker.py

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

@github-actions

Copy link
Copy Markdown
Contributor

@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.

@rparolin

rparolin commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test 4087430

@rparolin
rparolin force-pushed the pathfinder-readability/5-use-resolved-search-context branch from 4087430 to 72adfbe Compare December 4, 2026 17:54
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>
@rparolin
rparolin force-pushed the pathfinder-readability/5-use-resolved-search-context branch from 72adfbe to 67d9896 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