You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(pathfinder): search steps return their misses - #3607
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
Reviewing files that changed from the base of the PR and between 18f3027 and 31f63a1.
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
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 · previous review 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.
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
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments
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.
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 0 remain after this review.
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
— 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 aNotFound(miss) that carries its error text.run_find_stepscombines the misses, and_load_lib_no_cachehands the combined result toraise_not_found.SearchContextloses both lists and is a plain immutable record.FindResultis frozen too.A step that does not apply returns an empty
NotFound(), notNone.Tests:
result is Nonebecomesnot result.found, andresult is not Nonebecomesresult.found, for step results only. Tests that readctx.error_messagesreadresult.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 tomain, over two fake install trees (1800 step results), as is_load_lib_no_cachefor 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 afoundflag, so callers writeif result.found:instead. Tests ask.foundtoo. The flag is typed as a literalTrueonFindResultandFalseonNotFound, so a type checker still narrows the type inside theif.To make that uniform, the two file probes in
search_platform.pyreturn aFindResultinstead of a bare path, andFindResultmoves there, next toNotFound.search_steps.pystill 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_stepswas tested, so reversing or dropping any of the other five went unnoticed.Three tests pin the exact text. The first pins the full
DynamicLibNotFoundErrorfor 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
NotFoundnow.Testing
cuda_pathfindertest suite at this commit: 1650 passed, 6 skipped (Linux, Python 3.14).mypy-pathfinder.PLC Local Security Evidence (Advisory)
Local advisory checks only, run over the whole stack. Not release-gate results.
subprocess.runcall in the canary probe inload_nvidia_dynamic_lib.pyChecklist
🤖 Generated with Claude Code