Skip to content

refactor(pathfinder): search steps return their misses - #3607

Open
rparolin wants to merge 5 commits into
pathfinder-readability/5-use-resolved-search-contextfrom
pathfinder-readability/6-search-steps-return-misses
Open

rparolin wants to merge 5 commits into
pathfinder-readability/5-use-resolved-search-contextfrom
pathfinder-readability/6-search-steps-return-misses

Conversation

@rparolin

@rparolin rparolin commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

— codex on behalf of Ralf —

Description

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

Until now a failed probe appended its error text to two lists on the search context, so every step mutated shared state as a side effect.

Now a step returns either a FindResult (hit) or a NotFound (miss) that carries its error text. run_find_steps combines the misses, and _load_lib_no_cache hands the combined result to raise_not_found. SearchContext loses both lists and is a plain immutable record. FindResult is frozen too.

A step that does not apply returns an empty NotFound(), not None.

Tests: result is None becomes not result.found, and result is not None becomes result.found, for step results only. Tests that read ctx.error_messages read result.error_messages. One new test covers how misses are combined.

No behavior change. Checked beyond the test suite: for every catalog entry on Linux, Windows x64 and Windows arm64, each step's hit (path and found_via) or miss (messages and listings) and the final error text are byte-identical to main, over two fake install trees (1800 step results), as is _load_lib_no_cache for all 50 libraries.

Also in this PR: ask a search result whether it found something.

Callers told a hit from a miss with isinstance(result, FindResult). Both result types now carry a found flag, so callers write if result.found: instead. Tests ask .found too. The flag is typed as a literal True on FindResult and False on NotFound, so a type checker still narrows the type inside the if.

To make that uniform, the two file probes in search_platform.py return a FindResult instead of a bare path, and FindResult moves there, next to NotFound. search_steps.py still exports it.

Also in this PR: pin the not-found error text and its order.

The search steps now return their misses, and the error text is put together in six places. Only run_find_steps was tested, so reversing or dropping any of the other five went unnoticed.

Three tests pin the exact text. The first pins the full DynamicLibNotFoundError for a library that misses in the early steps, the late steps and the canary root. It lives in #3606: it passes there on the old code and is untouched here, which shows the text did not change. Two new tests here pin the misses reported by the product-root and Program Files steps. Seven planted bugs that reverse or drop a part each fail a test.

Also renames ten tests whose names still said "returns none"; a miss is a NotFound now.

Testing

  • Full cuda_pathfinder test suite at this commit: 1650 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:34
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.

Next included review available in 26 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 12 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8f0be82 and 07afb1a.

Files selected for processing: 7

  • cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py
  • cuda_pathfinder/cuda/pathfinder/_dynamic_libs/search_platform.py
  • cuda_pathfinder/cuda/pathfinder/_dynamic_libs/search_steps.py
  • cuda_pathfinder/tests/test_ctk_root_discovery.py
  • cuda_pathfinder/tests/test_driver_lib_loading.py
  • cuda_pathfinder/tests/test_load_nvidia_dynamic_lib_using_mocker.py
  • cuda_pathfinder/tests/test_search_steps.py

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • When a required NVIDIA library cannot be found, the error now includes details from each searched location, including directory listings where available.
    • Search misses are reported in search order, making it easier to see which locations were checked and why they did not contain a compatible library.

Library search functions now return typed success or miss results. Miss diagnostics accumulate across searched locations and steps. The dynamic library loader uses these results to load a found library or raise an exception with the combined diagnostics.

Changes: Typed library search results

Layer / File(s) Summary
Search result types and directory diagnostics
cuda_pathfinder/cuda/pathfinder/_dynamic_libs/search_platform.py, cuda_pathfinder/tests/test_search_steps.py
FindResult carries the path and discovery source. NotFound carries error messages and attachments. Directory searches return these values, and SearchContext.raise_not_found formats a supplied NotFound.
Search-step results and miss aggregation
cuda_pathfinder/cuda/pathfinder/_dynamic_libs/search_steps.py, cuda_pathfinder/tests/test_ctk_root_discovery.py, cuda_pathfinder/tests/test_search_steps.py
Search steps return FindResult or NotFound. The step runner returns the first hit or combines misses in search order. Tests cover result types, individual search steps, and aggregation.
Loader result handling and error reporting
cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py, cuda_pathfinder/tests/test_ctk_root_discovery.py, cuda_pathfinder/tests/test_driver_lib_loading.py, cuda_pathfinder/tests/test_load_nvidia_dynamic_lib_using_mocker.py
The loader checks early, late, and canary search results. If they all miss, it passes the combined diagnostics to raise_not_found. Tests cover canary results and the reported error text.

Possibly related PRs

  • NVIDIA/cuda-python#3623: Both changes alter _load_lib_no_cache control flow, including search order and handling of search misses.

Suggested reviewers: dekhtiarjonathan, cpcloud

Change: Refactor

Merge Risk: Minimal · previous review 8f0be

This is a behavior-preserving refactor. Library search results become typed values, and the not-found error now includes diagnostics from every searched location. No concrete defect was found, so the change looks safe to merge. The author's tests did not run on native Windows.

Security architecture risk: Minimal · up to 8f0be

The search now returns explicit hits and misses, but the reviewed change preserves where it looks, which files it accepts, and how it reports a failed search. No new loading route or weakened check was found.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The affected execution scope remains the calling process. The search refactor adds no path source or caller at the native loading boundary; the same search locations and platform checks determine which candidate can reach it.

Trust Boundaries and Controls

  • observed — Filesystem probes still require a descriptor-named file. Windows also rejects suppressed DLL names and checks PE architecture where configured. The found flag distinguishes the returned outcomes; it does not replace these checks or give a miss access to native loading.
- [ ] 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 8f0be82.

Files selected for processing: 7

  • cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py
  • cuda_pathfinder/cuda/pathfinder/_dynamic_libs/search_platform.py
  • cuda_pathfinder/cuda/pathfinder/_dynamic_libs/search_steps.py
  • cuda_pathfinder/tests/test_ctk_root_discovery.py
  • cuda_pathfinder/tests/test_driver_lib_loading.py
  • cuda_pathfinder/tests/test_load_nvidia_dynamic_lib_using_mocker.py
  • cuda_pathfinder/tests/test_search_steps.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

rparolin and others added 5 commits November 26, 2026 11:17
Until now a failed probe appended its error text to two lists on the
search context, so every step mutated shared state as a side effect.

Now a step returns either a `FindResult` (hit) or a `NotFound` (miss)
that carries its error text. `run_find_steps` combines the misses, and
`_load_lib_no_cache` hands the combined result to `raise_not_found`.
`SearchContext` loses both lists and is a plain immutable record.
`FindResult` is frozen too.

A step that does not apply returns an empty `NotFound()`, not `None`.

Tests: `result is None` becomes `isinstance(result, NotFound)`, and
`result is not None` becomes `isinstance(result, FindResult)`, for step
results only. Tests that read `ctx.error_messages` read
`result.error_messages`. One new test covers how misses are combined.

No behavior change. Checked beyond the test suite: for every catalog
entry on Linux, Windows x64 and Windows arm64, each step's hit (path and
`found_via`) or miss (messages and listings) and the final error text
are byte-identical to `main`, over two fake install trees (1800 step
results), as is `_load_lib_no_cache` for all 50 libraries.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Rob Parolin <rparolin@nvidia.com>
Callers told a hit from a miss with `isinstance(result, FindResult)`.
Both result types now carry a `found` flag, so callers write
`if result.found:` instead. The flag is typed as a literal `True` on
`FindResult` and `False` on `NotFound`, so a type checker still narrows
the type inside the `if`.

To make that uniform, the two file probes in `search_platform.py`
return a `FindResult` instead of a bare path, and `FindResult` moves
there, next to `NotFound`. `search_steps.py` still exports it.

No behavior change. 1647 passed, 6 skipped, and every comparison
against `main` is still byte-identical, including simulated Windows.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Rob Parolin <rparolin@nvidia.com>
The search steps now return their misses, and the error text is put
together in six places. Only `run_find_steps` was tested, so reversing
or dropping any of the other five went unnoticed.

Three new tests pin the exact text: the full `DynamicLibNotFoundError`
for a library that misses in the early steps, the late steps and the
canary root, and the misses reported by the product-root and Program
Files steps. Each of the seven ways to reverse or drop a part now fails
a test.

Also renames eight tests whose names still said "returns none"; a miss
is a `NotFound` now.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Rob Parolin <rparolin@nvidia.com>
…ance

Package code asks a search result `result.found`. The tests still used
`isinstance(result, FindResult)` and `isinstance(result, NotFound)` in
41 places. They now ask `.found` too, so tests read like the code they
cover.

One assert became redundant and is removed: the line above it already
checks the same flag.

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/6-search-steps-return-misses branch from 8206eaf to 07afb1a 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.

1 similar comment
@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.

@rwgk
rwgk added this pull request to stack #3633 November 26, 2026 19:19

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