fix(agent): catch RuntimeError from Path.expanduser/home when $HOME is unset - #45468
Closed
liuhao1024 wants to merge 1 commit into
Closed
fix(agent): catch RuntimeError from Path.expanduser/home when $HOME is unset#45468liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
…s unset Python 3.11+ raises RuntimeError (not OSError or ValueError) from Path.expanduser() and Path.home() when the $HOME environment variable is not set. The existing except clauses in subdirectory_hints.py only caught (OSError, ValueError), allowing the RuntimeError to propagate and crash the agent conversation loop. Added RuntimeError to both except clauses: - _add_path_candidate() line 147: expanduser() call - _load_hints_for_file() line 248: Path.home() fallback for relative display Fixes NousResearch#45401
tonydwb
approved these changes
Jun 13, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Fix: catch RuntimeError raised by Path.expanduser() or Path.home() when the $HOME environment variable is unset (common in certain container/entrypoint environments). Wraps the expansion in a try/except and falls back gracefully.
Looks Good
- Minimal, focused 3-line addition to one function
- Proper exception handling with a meaningful fallback
- No test changes (edge-case fix in a runtime detection path)
- No security concerns
Collaborator
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?
Fixes a crash in
subdirectory_hints.pywhen the$HOMEenvironment variable is unset. On Python 3.11+,Path.expanduser()andPath.home()raiseRuntimeError(notOSErrororValueError) when$HOMEis unset, but the existingexceptclauses only caught the latter two — allowing theRuntimeErrorto propagate and crash the agent conversation loop.Related Issue
Fixes #45401
Type of Change
Changes Made
agent/subdirectory_hints.py: AddedRuntimeErrorto bothexceptclauses that handlePath.expanduser()(line 147) andPath.home()(line 248) callstests/agent/test_subdirectory_hints.py: Added 2 regression tests verifying graceful handling whenexpanduser()andPath.home()raiseRuntimeErrorHow to Test
pytest tests/agent/test_subdirectory_hints.py -v— all 27 tests should pass$HOMEset:env -u HOME python -c "from agent.subdirectory_hints import SubdirectoryHintTracker; t = SubdirectoryHintTracker(working_dir='.'); print('OK')"— should not crashpytest tests/agent/test_subdirectory_hints.py::TestSubdirectoryHintTracker -vChecklist
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—_add_path_candidate(),_load_hints_for_file()Path.expanduser()/Path.home()RuntimeError on Python 3.11+ when$HOMEis unset (common in containers/CI)