fix(agent): catch RuntimeError from expanduser() in subdirectory hint loader - #44095
Closed
AIalliAI wants to merge 1 commit into
Closed
fix(agent): catch RuntimeError from expanduser() in subdirectory hint loader#44095AIalliAI wants to merge 1 commit into
AIalliAI wants to merge 1 commit into
Conversation
Path.expanduser() raises RuntimeError (not OSError/ValueError) when a ~user token references a non-existent account. _add_path_candidate only caught (OSError, ValueError), so a single path-like token such as ~foo/bar in a tool-call argument escaped the hint loader and aborted the whole agent turn. The directory-hint walk is best-effort, so the bad candidate is now skipped instead. Fixes NousResearch#43963 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
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.
Summary
SubdirectoryHintTracker._add_path_candidatewrapsPath(raw_path).expanduser()inexcept (OSError, ValueError), butexpanduser()raisesRuntimeError("Could not determine home directory.")when a~usertoken references a non-existent account (the~userform does a passwd lookup and ignores$HOME). The exception escapedcheck_tool_calland aborted the entire agent turn whenever a model emitted a path-like token such as~foo/barin a tool-call argument — per the issue report, ~3×/24h on a long-running gateway.The hint walk is purely advisory/best-effort, so the bad candidate is now skipped: the except tuple gains
RuntimeError, with a comment explaining why.The two other
except (OSError, ValueError)sites in this module wrapis_relative_to(), notexpanduser(), and are unaffected. The sibling call site inhermes_cli/kanban_db.pynoted in the issue comments is already addressed by #44005.Fixes #43963
Testing
Added
TestExpanduserRuntimeErrorwith three regression tests:_add_path_candidatewith a real~nonexistentuser/...token (exercises the actual passwd-lookup failure)expanduserpatched to raiseRuntimeError, independent of the host passwd dbcheck_tool_callwith the token inside aterminalcommandAll three fail on
mainand pass with the fix; the fulltests/agent/test_subdirectory_hints.pysuite passes (28 passed).🤖 Generated with Claude Code