Skip to content

fix(subdirectory_hints): catch RuntimeError from Path.expanduser() - #56355

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-95befa65
Jul 1, 2026
Merged

fix(subdirectory_hints): catch RuntimeError from Path.expanduser()#56355
teknium1 merged 2 commits into
mainfrom
hermes/hermes-95befa65

Conversation

@teknium1

@teknium1 teknium1 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

A literal ~ in a tool-call argument no longer crashes the conversation loop.

pathlib.Path('~user').expanduser() raises RuntimeError: Could not determine home directory when the tilde-user can't be resolved — e.g. ~500-700 (an LLM writing "approximately 500-700"), ~45,000, or ~unknownuser. The hint walker's except (OSError, ValueError) clauses didn't catch it, so it escaped _add_path_candidate_extract_directoriescheck_tool_call and surfaced in the loop as a misleading "Could not determine home directory" API error.

Changes

  • agent/subdirectory_hints.py: add RuntimeError to three except clauses — the _add_path_candidate catch around Path().expanduser(), and the two _load_hints_for_directory catches around hint_path.relative_to(Path.home()).
  • tests/agent/test_subdirectory_hints_tilde.py: 3 regression tests (tilde-as-approximately, ~unknownuser, and a no-regression guard for legit ~/).
  • scripts/release.py: AUTHOR_MAP entry for @udatny.

Validation

Before After
~500-700 in a command arg RuntimeError crashes loop absorbed, no crash
~unknownuser/x RuntimeError crashes loop absorbed, no crash
legit ~/Documents works works (no regression)
tests 28 pass (3 new + 25 existing)

E2E-verified against a real SubdirectoryHintTracker on all three cases.

Salvages @udatny's #29433 (earliest of a 3-PR duplicate cluster; #49263 and #50926 fixed the same bug and will be closed with credit).

Infographic

infographic

Nous Research

ud and others added 2 commits July 1, 2026 04:36
`pathlib.Path('~user').expanduser()` raises RuntimeError when the
tilde-expansion can't resolve the user (e.g. `~500-700` where the LLM
meant "approximately 500-700" rather than a path). The hint walker's
existing `except (OSError, ValueError):` clauses do not catch
RuntimeError, so it escapes through the tool dispatcher and surfaces
in the conversation loop as a misleading

    Error during OpenAI-compatible API call #N:
    Could not determine home directory.

Reproduced across three unrelated models (openai/gpt-5-mini,
openai/gpt-5.1-codex, deepseek/deepseek-v4-flash) on terminal-tool
commands containing literal tildes in non-path contexts — common in
LLM output ("~500 agencies", "~45,000 CVEs", "~80/hr blended rate").

Reproduction (one-liner):
    >>> from pathlib import Path
    >>> Path("~500-700").expanduser()
    RuntimeError: Could not determine home directory.

Fix: extend the three `except` clauses in
agent/subdirectory_hints.py to also catch RuntimeError:

  line 138 (_add_path_candidate's outer catch around the Path().expanduser() call)
  lines 198+202 (_load_hints_for_directory's nested catches around hint_path.relative_to(Path.home()))

Tests: tests/agent/test_subdirectory_hints_tilde.py adds three cases
covering: tilde-as-approximately in heredoc commands, ~unknown_user paths,
and a regression guard that legitimate ~/path expansion still works.
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists labels Jul 1, 2026
@teknium1
teknium1 merged commit 55c8b2c into main Jul 1, 2026
31 checks passed
@teknium1
teknium1 deleted the hermes/hermes-95befa65 branch July 1, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants