fix(kanban): catch RuntimeError from expanduser() in workspace root resolver - #44005
Open
liuhao1024 wants to merge 1 commit into
Open
fix(kanban): catch RuntimeError from expanduser() in workspace root resolver#44005liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
…esolver Path.expanduser() raises RuntimeError (not OSError) when the path contains a ~user token for a non-existent user account (e.g. "~nonexistent_user/x"). The HERMES_KANBAN_WORKSPACES_ROOT env var resolver only caught OSError, allowing the RuntimeError to propagate and crash the kanban subsystem. Same bug pattern as NousResearch#43963 (_add_path_candidate in subdirectory_hints.py). Fix: broaden except to (OSError, RuntimeError) so invalid workspace-root overrides are silently skipped instead of crashing. Fixes NousResearch#43963 (same pattern, different call site)
tonydwb
approved these changes
Jun 11, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Looks Good
- hermes_cli/kanban_db.py:10 — Clean fix:
RuntimeErrorfromPath.expanduser()for non-existent~usertokens is now caught alongsideOSError, preventing crashes whenHERMES_KANBAN_WORKSPACES_ROOTpoints to a non-existent user's home. - tests/hermes_cli/test_kanban_db.py:22-31 — Dedicated test case covering the exact scenario. Clear docstring explaining the
RuntimeErrorbehavior. Assertion is minimal and correct.
Minor Suggestion
- The test's
monkeypatch.setenvapproach is correct, but note that since_is_managed_scratch_pathcallskb._is_managed_scratch_path(task_dir)with/tmp, it only validates that the path doesn't crash — not that non-existent user paths in the scratch root are actually skipped. This is fine for the scope of this fix; the assertion correctly reflects the intended behavior.
Reviewed by Hermes Agent
teknium1
reviewed
Jul 14, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for tracing the Path.expanduser() failure in the cleanup containment guard. The current-main premise is valid at hermes_cli/kanban_db.py:4405.
Problems
- The same
HERMES_KANBAN_WORKSPACES_ROOTvalue is expanded without aRuntimeErrorguard inworkspaces_root()athermes_cli/kanban_db.py:554. Standard scratch resolution calls it athermes_cli/kanban_db.py:5768, so an invalid~useroverride can still abort ordinary workspace creation. - The proposed test covers only
_is_managed_scratch_path; it does not cover that remaining normal workspace-resolution path.
Suggested changes
- Apply the same invalid-override fallback in
workspaces_root()and add a regression test throughworkspaces_root()orresolve_workspace().
Automated hermes-sweeper review.
| @@ -3779,7 +3779,7 @@ def _is_managed_scratch_path(p: Path) -> bool: | |||
| if override: | |||
Contributor
There was a problem hiding this comment.
This protects the cleanup containment resolver, but workspaces_root() still expands the same HERMES_KANBAN_WORKSPACES_ROOT value without handling RuntimeError (current main: hermes_cli/kanban_db.py:554). Normal scratch resolution calls it, so please cover that sibling path and add a regression test through workspace resolution.
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
RuntimeErrorcrash in_is_managed_scratch_path()when theHERMES_KANBAN_WORKSPACES_ROOTenvironment variable contains a~userpath whereuseris not a real account (e.g.~nonexistent_user/workspace).Path.expanduser()raisesRuntimeError("Could not determine home directory.")for the~userform with a non-existent user — this is distinct from$HOME-based~expansion and is not caught byexcept OSError. The workspace-root resolver now catchesRuntimeErroralongsideOSErrorso invalid overrides are silently skipped instead of crashing the kanban subsystem.This is the same bug pattern as #43963 (
_add_path_candidateinagent/subdirectory_hints.py), applied to a sibling call site that was not covered by PR #43970.Related Issue
Same pattern as #43963
Type of Change
Changes Made
hermes_cli/kanban_db.py: Broadenedexcept OSErrortoexcept (OSError, RuntimeError)on theexpanduser().resolve()call inside_is_managed_scratch_path()'sHERMES_KANBAN_WORKSPACES_ROOTresolver.tests/hermes_cli/test_kanban_db.py: Addedtest_is_managed_scratch_path_tilde_user_env_does_not_crash— sets the env var to~nonexistent_user/workspaceand asserts the function returnsFalseinstead of raising.How to Test
HERMES_KANBAN_WORKSPACES_ROOT=~nonexistent_user/workspacein your environment_is_managed_scratch_path()— it should not crashpytest tests/hermes_cli/test_kanban_db.py::test_is_managed_scratch_path_tilde_user_env_does_not_crash -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
_is_managed_scratch_pathinhermes_cli/kanban_db.py(callers:_cleanup_workspace, workspace management)expanduser()RuntimeError pattern as [Bug]: _add_path_candidate crashes the agent turn on ~user expanduser() RuntimeError (except misses RuntimeError) #43963 / PR Fix _add_path_candidate crash on ~user expanduser() RuntimeError #43970 (agent/subdirectory_hints.py)