fix(agent): catch RuntimeError from Path.expanduser/home when $HOME is unset - #45430
Closed
liuhao1024 wants to merge 1 commit into
Closed
fix(agent): catch RuntimeError from Path.expanduser/home when $HOME is unset#45430liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
…s unset Python 3.11+ raises RuntimeError (not OSError/ValueError) from Path.expanduser() and Path.home() when the $HOME environment variable is not set. The except clauses in SubdirectoryHintTracker only caught (OSError, ValueError), so the RuntimeError propagated up and crashed the agent conversation loop. Add RuntimeError to all four except clauses: - _add_path_candidate: expanduser() call (line 147) - _is_valid_subdir: is_relative_to() call (line 191) - _load_hints_for_directory: is_relative_to() call (line 213) - relative-path fallback: Path.home() call (line 248) Fixes NousResearch#45401
Collaborator
tonydwb
approved these changes
Jun 13, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Adds RuntimeError to the exception handlers in _add_path_candidate, _is_valid_subdir, and _load_hints_for_directory throughout subdirectory_hints.py. Python 3.11+ raises RuntimeError from Path.expanduser() and Path.home() when $HOME is unset.
- Clean regression fix with dedicated test fixture covering all three error paths
- Test file is well-documented with issue reference (#45401)
- No security concerns
- No debug artifacts
Reviewed by Hermes Agent
Contributor
Author
3 tasks
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.
What does this PR do?
Catches
RuntimeErrorfromPath.expanduser()andPath.home()inSubdirectoryHintTrackerwhen the$HOMEenvironment variable is unset, preventing the agent conversation loop from crashing.Related Issue
Fixes #45401
Type of Change
Changes Made
agent/subdirectory_hints.py: AddedRuntimeErrorto 4exceptclauses that previously only caught(OSError, ValueError). On Python 3.11+,Path.expanduser()andPath.home()raiseRuntimeErrorwhen$HOMEis unset — this was unhandled and crashed the agent.tests/agent/test_subdirectory_hints_runtime_error.py: 4 tests covering each RuntimeError site —_add_path_candidate,_is_valid_subdir,_load_hints_for_directory(is_relative_to), and thePath.home()relative-path fallback.How to Test
python -m pytest tests/agent/test_subdirectory_hints_runtime_error.py -v— all 4 tests should passunset HOME && hermes chat— should no longer crash withRuntimeError: Could not determine home directory$HOMEset, hint tracking works as beforeChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/ACode Intelligence
agent/subdirectory_hints.py(callers: 2 inagent/tool_executor.py, 1 inagent/agent_init.py)