fix(agent): guard subdirectory_hints against unset HOME RuntimeError - #45484
fix(agent): guard subdirectory_hints against unset HOME RuntimeError#45484Kewe63 wants to merge 1 commit into
Conversation
_pathlib.Path.expanduser() and Path.home() raise RuntimeError (not OSError/ValueError) on Python 3.11+ when $HOME is unset. This crashed the entire agent conversation loop. Fix: catch RuntimeError in all 5 affected except clauses in agent/subdirectory_hints.py. Fixes NousResearch#45401
Verification: clean defensive fixReviewed the diff — adding
The fallback behavior (keep absolute path, skip directory) is safe. No behavioral change for normal environments — |
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Overview
Adds RuntimeError to exception handling in SubdirectoryHintTracker to guard against Path.home() raising RuntimeError when $HOME is unset (a RuntimeError is raised when the HOME environment variable is not set, unlike OSError for other path errors).
Changes
- Catches
RuntimeErroralongsideOSErrorandValueErrorin_add_path_candidate,_is_valid_subdir, and_load_hints_for_directory - Minor cosmetic changes (tuple formatting, line wrapping)
Assessment
- Correctness:
Path.home()raisesRuntimeErrorwhen HOME is unset — this is a known edge case on systems where HOME is not defined. The fix is targeted and correct. - No security or performance concerns.
Reviewed by Hermes Agent
|
Thanks for pointing this out. Closing in favour of #29433 same fix, earlier PR. Happy to review or test if that helps move it forward. |
Summary
Path.expanduser()andPath.home()raiseRuntimeError(notOSError/ValueError) on Python 3.11+ when$HOMEis unset. This was not caught by the existing except clauses inagent/subdirectory_hints.py, crashing the entire agent conversation loop. This fix addsRuntimeErrorto all 5 affected except clauses.Changes
File:
agent/subdirectory_hints.pyRuntimeErrorto except clauses at lines 147, 191, 213, 244, 248.How to Test
pytest tests/agent/test_subdirectory_hints.py -xvs # ✅ 25/25 passedChecklist
Risk & Impact
Minimal. Five-character additive change per clause — no behavioral change in environments where
$HOMEis set. Prevents a full conversation loop crash in containerized or minimal environments where$HOMEmay be unset.Type: 🐛 Bug fix
Closes: #45401