Skip to content

fix(pathfinder): remove dead/misleading error handling in platform loaders#2239

Open
aryanputta wants to merge 2 commits into
NVIDIA:mainfrom
aryanputta:fix/pathfinder-loader-diagnostics
Open

fix(pathfinder): remove dead/misleading error handling in platform loaders#2239
aryanputta wants to merge 2 commits into
NVIDIA:mainfrom
aryanputta:fix/pathfinder-loader-diagnostics

Conversation

@aryanputta

@aryanputta aryanputta commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Removes two dead error-handling paths in the dynamic-lib platform loaders. Both are unreachable / no-ops today; the Linux one additionally carries a factually wrong message that would mislead anyone debugging a load failure. This aligns with the cuda_pathfinder policy of not masking why discovery/loading failed.

Details

load_dl_linux.load_with_system_search guarded the resolved path with:

abs_path = abs_path_for_dynamic_library(desc.name, handle)
if abs_path is None:
    raise RuntimeError(f"No expected symbol for libname={desc.name!r}")

abs_path_for_dynamic_library never returns None - it returns a resolved path (os.path.join(l_origin, basename)) or raises OSError from dlinfo. So the branch is unreachable, and its message is wrong: it talks about a missing symbol when the only real failure mode is dlinfo path resolution. Dropped the dead branch so the descriptive OSError surfaces directly, and updated the docstring Raises: accordingly.

load_dl_windows.add_dll_directory had:

result = kernel32.AddDllDirectory(dirpath)
if not result:
    # Fallback: just update PATH if AddDllDirectory fails
    pass

The if not result: pass is a no-op - the PATH update below already runs unconditionally. Removed the dead branch and clarified why PATH is updated regardless.

Behavior

No behavior change: both removed branches were unreachable or no-ops.

Testing

ruff check and ruff format --check (v0.15.9, repo-pinned) pass on both changed files.

…aders

Two dead error-handling paths in the dynamic-lib platform loaders:

- load_dl_linux.load_with_system_search guarded abs_path with
  'if abs_path is None: raise RuntimeError("No expected symbol ...")'.
  abs_path_for_dynamic_library never returns None (it returns a resolved
  path or raises OSError), so the branch is unreachable and its message is
  factually wrong (it concerns dlinfo path resolution, not symbols). Drop
  the dead branch and let the descriptive OSError surface, matching the
  deterministic-loader policy of not masking discovery/load failures.

- load_dl_windows.add_dll_directory had 'if not result: pass', a no-op; the
  PATH update below already runs unconditionally. Remove the dead branch and
  clarify the comment on why PATH is updated regardless.

No behavior change: both removed branches were unreachable or no-ops.

Signed-off-by: Aryan <aryansputta@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Jun 21, 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.

@github-actions github-actions Bot added the cuda.pathfinder Everything related to the cuda.pathfinder module label Jun 21, 2026
@aryanputta

Copy link
Copy Markdown
Contributor Author

Note for triage: I can't set labels/milestones as an external contributor. Intended metadata for pr-metadata-check: label cuda.pathfinder, milestone cuda.pathfinder next. Happy to adjust if a different bucket fits better.

Comment on lines +177 to +179
# abs_path_for_dynamic_library never returns None: it returns a
# resolved path or raises OSError. Let that error surface rather
# than masking it, consistent with the deterministic-loader policy.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment explains behavior elsewhere. It could easily drift. Please remove.

# resolved path or raises OSError. Let that error surface rather
# than masking it, consistent with the deterministic-loader policy.
abs_path = abs_path_for_dynamic_library(desc.name, handle)
if abs_path is None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

            assert abs_path

will make the expectation explicit and obvious, without risking drift.

Comment on lines +168 to +169
RuntimeError: If the library is loaded but no expected symbol is found
OSError: If the library is loaded but its absolute path cannot be
resolved via dlinfo (surfaced from abs_path_for_dynamic_library).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather delete the entire Raises section: this is documenting behavior elsewhere / risks drift. It's not a public API. agents will figure this out anyway, and might even get distracted by this part of the docstring.

# Fallback: just update PATH if AddDllDirectory fails
pass
# Add the DLL directory to the native search path. AddDllDirectory only
# affects the LOAD_LIBRARY_SEARCH_USER_DIRS search; PATH is updated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a remark: I'm not sure if there is actually any situation where PATH is still searched on Windows. Modern Python versions disabled that AFAIK, but I don't know the exact version details. I.e. the change here looks good as-is for the purpose of this PR.

@aryanputta

Copy link
Copy Markdown
Contributor Author

@rwgk I pushed c1ce967698 with the loader review cleanup. Changes: removed the drift-prone Raises docstring section, removed the explanatory comment that duplicated behavior from abs_path_for_dynamic_library(), and added assert abs_path before returning LoadedDL. Local validation: ruff-check, ruff-format, py_compile, and git diff --check passed. GitHub pre-commit.ci is green; the remaining red check is the repo metadata gate for assignee/label/milestone, which I cannot set from the fork. Could you have another look when ready?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants