fix: guard os.getcwd() against deleted CWD (FileNotFoundError) - #4982
Open
lbruceolson wants to merge 1 commit into
Open
fix: guard os.getcwd() against deleted CWD (FileNotFoundError)#4982lbruceolson wants to merge 1 commit into
lbruceolson wants to merge 1 commit into
Conversation
Terminals like Warp aggressively track the CWD in each pane. If a directory is deleted or renamed while a pane is sitting in it, the shell's CWD pointer becomes stale. Python's os.getcwd() then raises FileNotFoundError on the next launch, crashing hermes before it can even show the banner. Add a _safe_getcwd() helper that catches FileNotFoundError and falls back to the user's home directory. Replace all six bare os.getcwd() call sites in cli.py with _safe_getcwd(): - load_cli_config() – initial CWD resolution - HermesCLI.show_banner() – banner display - HermesCLI (checkpoint cmd) – checkpoint command handler - HermesCLI._show_config() – /config display - HermesCLI.run() (refresh) – tools-refresh path - preprocess_context_references() call – context file expansion
3 tasks
1 task
3 tasks
Collaborator
|
Likely duplicate of #10233 — same os.getcwd() FileNotFoundError guard in CLI startup. |
1 similar comment
Collaborator
|
Likely duplicate of #10233 — same os.getcwd() FileNotFoundError guard in CLI startup. |
This was referenced May 27, 2026
teknium1
reviewed
Jul 12, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for identifying a real deleted-CWD failure mode. The startup defect still exists on current main, but this patch needs current-tree salvage and broader launch-surface coverage.
Problems
cli.py:602still callsos.getcwd()unconditionally for the local backend inload_cli_config(), before the classic CLI can render its banner.- The PR only changes
cli.py; the TUI launcher independently callsos.getcwd()athermes_cli/main.py:2037. - Current
cli.py:2855also usesos.getenv("TERMINAL_CWD", os.getcwd()); the default expression is evaluated eagerly, so a deleted CWD still raises even whenTERMINAL_CWDis set. - The diff adds no regression test. Existing deleted-CWD tests cover only
tools/terminal_tool.py(tests/tools/test_terminal_task_cwd.py:226-247).
Suggested changes
- Port the guard to the current
load_cli_config()branch atcli.py:593-605and add a test that makescli.os.getcwd()raise while invoking the real loader. - Cover the TUI launch path at
hermes_cli/main.py:2037and the remaining current CLI callers.
Automated hermes-sweeper review.
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
Contributor
There was a problem hiding this comment.
Please extend this recovery to the TUI launcher as well: current hermes_cli/main.py:2037 independently calls os.getcwd() while setting HERMES_CWD, and this cli.py-only patch cannot protect that startup path.
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?
Python's
os.getcwd()raisesFileNotFoundErrorwhen the shell's current working directory no longer exists on disk. This happens when a terminal (e.g. Warp) is open in a directory that gets deleted or renamed while the pane is still sitting in it. The result is hermes crashing before it can even display the banner.This PR adds a
_safe_getcwd()helper that wrapsos.getcwd()in atry/except FileNotFoundErrorand falls back to the user's home directory (~). All six bareos.getcwd()call sites incli.pyare replaced with_safe_getcwd():load_cli_config()— initial CWD resolutionHermesCLI.show_banner()— banner displayHermesCLIcheckpoint command handlerHermesCLI._show_config()—/configdisplayHermesCLI.run()tools-refresh pathpreprocess_context_references()call — context file expansionRelated Issue
No existing issue. Discovered during normal use with the Warp terminal on Linux.
Type of Change
Reproducer
/tmp/test-dir)rm -rf /tmp/test-dirhermesfrom the original paneFileNotFoundError: [Errno 2] No such file or directory~