Skip to content

fix(agent): catch RuntimeError from expanduser() in subdirectory hint loader - #44095

Closed
AIalliAI wants to merge 1 commit into
NousResearch:mainfrom
AIalliAI:fix/subdir-hints-expanduser-runtimeerror
Closed

fix(agent): catch RuntimeError from expanduser() in subdirectory hint loader#44095
AIalliAI wants to merge 1 commit into
NousResearch:mainfrom
AIalliAI:fix/subdir-hints-expanduser-runtimeerror

Conversation

@AIalliAI

Copy link
Copy Markdown
Contributor

Summary

SubdirectoryHintTracker._add_path_candidate wraps Path(raw_path).expanduser() in except (OSError, ValueError), but expanduser() raises RuntimeError("Could not determine home directory.") when a ~user token references a non-existent account (the ~user form does a passwd lookup and ignores $HOME). The exception escaped check_tool_call and aborted the entire agent turn whenever a model emitted a path-like token such as ~foo/bar in 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 wrap is_relative_to(), not expanduser(), and are unaffected. The sibling call site in hermes_cli/kanban_db.py noted in the issue comments is already addressed by #44005.

Fixes #43963

Testing

Added TestExpanduserRuntimeError with three regression tests:

  • _add_path_candidate with a real ~nonexistentuser/... token (exercises the actual passwd-lookup failure)
  • same with expanduser patched to raise RuntimeError, independent of the host passwd db
  • full check_tool_call with the token inside a terminal command

All three fail on main and pass with the fix; the full tests/agent/test_subdirectory_hints.py suite passes (28 passed).

🤖 Generated with Claude Code

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

Copy link
Copy Markdown
Contributor Author

Closing as duplicate — #43970 and #44056 were filed first for the same fix. Apologies for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: _add_path_candidate crashes the agent turn on ~user expanduser() RuntimeError (except misses RuntimeError)

1 participant