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
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~