Skip to content

Fix _add_path_candidate crash on ~user expanduser() RuntimeError - #43970

Closed
gtyler wants to merge 1 commit into
NousResearch:mainfrom
gtyler:fix/add-path-candidate-expanduser-runtimeerror
Closed

Fix _add_path_candidate crash on ~user expanduser() RuntimeError#43970
gtyler wants to merge 1 commit into
NousResearch:mainfrom
gtyler:fix/add-path-candidate-expanduser-runtimeerror

Conversation

@gtyler

@gtyler gtyler commented Jun 11, 2026

Copy link
Copy Markdown

Problem

_add_path_candidate in agent/subdirectory_hints.py calls Path(raw_path).expanduser() inside try/except (OSError, ValueError). But Path.expanduser() raises RuntimeError("Could not determine home directory.") — not OSError/ValueError — for a ~user token whose user is not a real account (no /etc/passwd entry), even when $HOME is set (the ~user form does a passwd lookup, not a $HOME substitution).

Because RuntimeError isn't caught, it escapes _extract_paths_from_commandcheck_tool_callexecute_tool_calls_sequential_execute_tool_callsrun_conversation and aborts the whole agent turn. On a long-running gateway this fires whenever a model emits a path-like ~name/... token for a non-existent user (~3×/24h in our deployment; each one kills the turn, e.g. an aborted scheduled run).

Reproduce

from pathlib import Path
Path("~nonexistent_user/x").expanduser()   # RuntimeError: Could not determine home directory.

Fix

The directory-hint walk is best-effort, so broaden the except to include RuntimeError and skip the bad path instead of crashing. Only the _add_path_candidate block is changed — the two structurally-identical except (OSError, ValueError) blocks in _is_valid_subdir / _load_hints_for_directory operate on already-resolved Paths (no expanduser) and are left untouched.

Fixes #43963

Path.expanduser() raises RuntimeError("Could not determine home
directory.") for a "~user" token whose user is not a real account
(no passwd entry) — even when $HOME is set. That RuntimeError is not
in the surrounding except (OSError, ValueError) in _add_path_candidate,
so it escapes _extract_paths_from_command -> check_tool_call ->
execute_tool_calls_sequential and aborts the entire agent turn.

The directory-hint walk is best-effort, so broaden the except to
include RuntimeError and skip the bad path instead of crashing.

Fixes NousResearch#43963

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Tyler Koblasa <tyler@koblasa.com>
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists labels Jun 11, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #29433 — that open PR adds RuntimeError to the except clauses in agent/subdirectory_hints.py for the same Path.expanduser() crash on ~user/tilde tokens. Related: #41870 (shared safe_expanduser() sweep).

@gtyler

gtyler commented Jun 20, 2026

Copy link
Copy Markdown
Author

Closing as a duplicate of the earlier #29433, which makes the same RuntimeError fix to _add_path_candidate. Deferring to it — added a comment there noting the second call site (hermes_cli/kanban_db.py:_is_managed_scratch_path) and a regression-test suggestion. Repro/diagnosis tracked in #43963.

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 duplicate This issue or pull request already exists 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.

[Bug]: _add_path_candidate crashes the agent turn on ~user expanduser() RuntimeError (except misses RuntimeError)

2 participants