Fix _add_path_candidate crash on ~user expanduser() RuntimeError - #43970
Closed
gtyler wants to merge 1 commit into
Closed
Fix _add_path_candidate crash on ~user expanduser() RuntimeError#43970gtyler wants to merge 1 commit into
gtyler wants to merge 1 commit into
Conversation
Path.expanduser() raises RuntimeError("Could not determine home
directory.") for a "~user" token whose user is not a real account
(no passwd entry) — even when $HOME is set. That RuntimeError is not
in the surrounding except (OSError, ValueError) in _add_path_candidate,
so it escapes _extract_paths_from_command -> check_tool_call ->
execute_tool_calls_sequential and aborts the entire agent turn.
The directory-hint walk is best-effort, so broaden the except to
include RuntimeError and skip the bad path instead of crashing.
Fixes NousResearch#43963
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Tyler Koblasa <tyler@koblasa.com>
Collaborator
13 tasks
2 tasks
13 tasks
Author
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
_add_path_candidateinagent/subdirectory_hints.pycallsPath(raw_path).expanduser()insidetry/except (OSError, ValueError). ButPath.expanduser()raisesRuntimeError("Could not determine home directory.")— notOSError/ValueError— for a~usertoken whoseuseris not a real account (no/etc/passwdentry), even when$HOMEis set (the~userform does a passwd lookup, not a$HOMEsubstitution).Because
RuntimeErrorisn't caught, it escapes_extract_paths_from_command→check_tool_call→execute_tool_calls_sequential→_execute_tool_calls→run_conversationand aborts the whole agent turn. On a long-running gateway this fires whenever a model emits a path-like~name/...token for a non-existent user (~3×/24h in our deployment; each one kills the turn, e.g. an aborted scheduled run).Reproduce
Fix
The directory-hint walk is best-effort, so broaden the except to include
RuntimeErrorand skip the bad path instead of crashing. Only the_add_path_candidateblock is changed — the two structurally-identicalexcept (OSError, ValueError)blocks in_is_valid_subdir/_load_hints_for_directoryoperate on already-resolved Paths (noexpanduser) and are left untouched.Fixes #43963