fix(tui_gateway): tolerate deleted cwd in slash worker and path completion - #40153
Open
Dusk1e wants to merge 1 commit into
Open
fix(tui_gateway): tolerate deleted cwd in slash worker and path completion#40153Dusk1e wants to merge 1 commit into
Dusk1e wants to merge 1 commit into
Conversation
…etion os.getcwd() raises FileNotFoundError on POSIX when the process's working directory is deleted out from under it. The TUI gateway called it unguarded in three spots — the _SlashWorker subprocess cwd and both _completion_cwd fallbacks — so a deleted launch dir crashed slash commands, path completion, and (via _completion_cwd) session.create. Add a _safe_getcwd() helper mirroring tools.terminal_tool._safe_getcwd (fall back to TERMINAL_CWD, then home) and route the three callsites through it. Behavior is unchanged when the CWD exists. Tests: tests/test_tui_gateway_server.py adds coverage for the helper, path completion, and the slash worker under a deleted CWD.
Dusk1e
force-pushed
the
fix/tui-gateway-deleted-cwd
branch
from
June 5, 2026 22:26
9732be2 to
43361ef
Compare
teknium1
reviewed
Jul 14, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for identifying a real deleted-CWD failure path. Current main still passes cwd=os.getcwd() when spawning _SlashWorker (tui_gateway/server.py:321) and retains both unguarded _completion_cwd() fallbacks (tui_gateway/server.py:1520, tui_gateway/server.py:1528). The proposed helper matches the established terminal behavior in tools/terminal_tool.py:1196-1207.
Problems
- Current main also has a later-added unguarded fallback in
_default_session_cwd()(tui_gateway/server.py:1116). A deleted launch CWD can still fail that default/resume route after this PR's three substitutions.
Suggested changes
- During salvage, apply the safe resolver to
_default_session_cwd()and add coverage for that path alongside the slash-worker and completion cases. - Preserve the current
_SlashWorkersubprocess setup attui_gateway/server.py:295-324, including profile-home environment scoping and platform process flags.
Automated hermes-sweeper review.
| text=True, | ||
| bufsize=1, | ||
| cwd=os.getcwd(), | ||
| cwd=_safe_getcwd(), |
Contributor
There was a problem hiding this comment.
When salvaging this helper onto current main, also route the later-added _default_session_cwd() fallback through it (tui_gateway/server.py:1116). Otherwise a deleted launch CWD still fails the default/resume session path.
12 tasks
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 & why
os.getcwd()raisesFileNotFoundErrorwhen the process's working directory is deleted out from under it (e.g. a scratch workspace cleaned up mid-session). The TUI gateway called it unguarded in three spots:_SlashWorker.__init__→subprocess.Popen(cwd=os.getcwd())_completion_cwd()→ the raw-chain fallback and the finalreturnSo a deleted launch directory crashed slash commands, path completion, and — because
_completion_cwd()feeds the unguardedsession.createhandler — new-session creation.Fix
Add a small
_safe_getcwd()helper that mirrors the existingtools.terminal_tool._safe_getcwd(fall back toTERMINAL_CWD, then the home directory) and route the three callsites through it. Behavior is unchanged when the CWD exists; only the error path changes.How to test
tests/test_tui_gateway_server.pyadds 3 focused tests covering the helper and both surfaces under a deleted CWD:test_safe_getcwd_falls_back_when_cwd_deletedtest_completion_cwd_tolerates_deleted_cwdtest_slash_worker_tolerates_deleted_cwdTest results
tests/test_tui_gateway_server.py+tests/tools/test_terminal_task_cwd.py→ 218 passedtests/tui_gateway/→ 103 passedruff check→ clean