Skip to content

fix(tui_gateway): tolerate deleted cwd in slash worker and path completion - #40153

Open
Dusk1e wants to merge 1 commit into
NousResearch:mainfrom
Dusk1e:fix/tui-gateway-deleted-cwd
Open

fix(tui_gateway): tolerate deleted cwd in slash worker and path completion#40153
Dusk1e wants to merge 1 commit into
NousResearch:mainfrom
Dusk1e:fix/tui-gateway-deleted-cwd

Conversation

@Dusk1e

@Dusk1e Dusk1e commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

What & why

os.getcwd() raises FileNotFoundError when 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 final return

So a deleted launch directory crashed slash commands, path completion, and — because _completion_cwd() feeds the unguarded session.create handler — new-session creation.

Fix

Add a small _safe_getcwd() helper that mirrors the existing tools.terminal_tool._safe_getcwd (fall back to TERMINAL_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.py adds 3 focused tests covering the helper and both surfaces under a deleted CWD:

  • test_safe_getcwd_falls_back_when_cwd_deleted
  • test_completion_cwd_tolerates_deleted_cwd
  • test_slash_worker_tolerates_deleted_cwd

Test results

  • tests/test_tui_gateway_server.py + tests/tools/test_terminal_task_cwd.py218 passed
  • tests/tui_gateway/103 passed
  • ruff check → clean

…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
Dusk1e force-pushed the fix/tui-gateway-deleted-cwd branch from 9732be2 to 43361ef Compare June 5, 2026 22:26
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/tui Terminal UI (ui-tui/ + tui_gateway/) labels Jun 5, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 _SlashWorker subprocess setup at tui_gateway/server.py:295-324, including profile-home environment scoping and platform process flags.

Automated hermes-sweeper review.

Comment thread tui_gateway/server.py
text=True,
bufsize=1,
cwd=os.getcwd(),
cwd=_safe_getcwd(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants