Skip to content

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

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

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

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. If a directory cannot be listed, the error reports that failure.
    • Search misses are reported in search order, making it easier to see which locations were checked and why they did not contain the library. Search continues to later locations after a miss and uses the first successful result.

important: 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#3606: This PR changes the search context and miss-reporting behavior introduced by #3606.
  • NVIDIA/cuda-python#3623: Both PRs change _load_lib_no_cache; #3623 changes search ordering, while this PR aggregates diagnostics from search misses.

Suggested reviewers: cpcloud, dekhtiarjonathan

Change: Refactor

Merge Risk: Minimal · up to 8fd5a

This refactor changes how library search results and miss diagnostics are passed internally. It is intended to keep behavior unchanged, and the tests cover the changed paths. No merge-blocking risk is evident from the supplied evidence.

Security architecture risk: Low · up to 8fd5a

cuda.pathfinder keeps the same public loading API and library search order. One availability regression remains: when the Windows cuDNN fallback encounters many nonmatching installations, it repeatedly copies diagnostics that the caller never receives if a later installation succeeds.

Retained concerns

  • Trivial · reliability · inferred: Keep miss aggregation linear in the diagnostics collected. The refactor replaces list extension with repeated copying of accumulated tuples. The Windows x64 cuDNN Program Files fallback can visit a variable number of versioned roots, so many misses can delay a successful load from a later root even though no diagnostics are returned. A local accumulator frozen once at the result boundary would preserve immutable results and diagnostic order without repeatedly copying prior misses.

View findings in the submitted review

Security review details

Security Blast Radius

  • inferred — The demonstrated availability effect is on the Python process performing the load, when configured search locations contain many misses. The comparison does not establish a new external entrypoint, privilege change, or broader exposure.

Trust Boundaries and Controls

  • observed — Discovery remains separate from loading. Windows file discovery still rejects suppressed DLLs and applies PE architecture matching where configured. The canary still obtains a loader-selected path in a subprocess, derives a toolkit root, and only then searches that root for the requested library. A typed hit carries the selected path; it does not grant new loading authority or imply file authenticity.

Data and control flow

  • observed — The loader still rechecks for an already-loaded handle after early discovery and gives that handle precedence over the discovered path. It then tries an early hit, native system search, late discovery, and the descriptor-enabled canary fallback in that order.

Resilience and Maintainability Implications

  • observed — When discovery exhausts the cascade normally, the final error receives early, late, and canary diagnostics in order. A nonapplicable probe contributes an empty miss. This does not make the diagnostic result a recovery record: a native-load or canary subprocess exception can still terminate the attempt instead of producing the combined error.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@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
…nto pathfinder-readability/6-search-steps-return-misses

# Conflicts:
#	cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py
#	cuda_pathfinder/cuda/pathfinder/_dynamic_libs/search_platform.py
#	cuda_pathfinder/tests/test_load_nvidia_dynamic_lib_using_mocker.py

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

Actionable comments

Trivial 1
  1. Keep miss aggregation linear in the diagnostics collected. The refactor replaces list extension with repeated copying of accumulated tuples. The Windows x64 cuDNN Program Files fallback can visit a variable number of versioned roots, so many misses can delay a successful load from a later root even though no diagnostics are returned. A local accumulator frozen once at the result boundary would preserve immutable results and diagnostic order without repeatedly copying prior misses.
Review info

Run configuration

Commits

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

Files selected for processing: 5

  • cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py
  • cuda_pathfinder/cuda/pathfinder/_dynamic_libs/search_platform.py
  • cuda_pathfinder/tests/test_ctk_root_discovery.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; 0 remain after this review.

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.

3 participants