fix(subdirectory_hints): catch RuntimeError from Path.expanduser() - #56355
Merged
Conversation
`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.
This was referenced Jul 1, 2026
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.
Summary
A literal
~in a tool-call argument no longer crashes the conversation loop.pathlib.Path('~user').expanduser()raisesRuntimeError: Could not determine home directorywhen the tilde-user can't be resolved — e.g.~500-700(an LLM writing "approximately 500-700"),~45,000, or~unknownuser. The hint walker'sexcept (OSError, ValueError)clauses didn't catch it, so it escaped_add_path_candidate→_extract_directories→check_tool_calland surfaced in the loop as a misleading "Could not determine home directory" API error.Changes
agent/subdirectory_hints.py: addRuntimeErrorto threeexceptclauses — the_add_path_candidatecatch aroundPath().expanduser(), and the two_load_hints_for_directorycatches aroundhint_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
~500-700in a command arg~unknownuser/x~/DocumentsE2E-verified against a real
SubdirectoryHintTrackeron 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
Nous Research