hermes - ✅(Solved) Fix [Bug]: persistent_shell carries cwd into deleted directory; subsequent Popen calls fail with ENOENT until gateway restart [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#17558Fetched 2026-04-30 06:46:47
View on GitHub
Comments
0
Participants
1
Timeline
7
Reactions
0
Author
Participants
Timeline (top)
labeled ×5cross-referenced ×2

Error Message

ERROR tools.terminal_tool: Execution failed after 3 retries - Command: pwd - Error: FileNotFoundError: [Errno 2] No such file or directory: '/tmp/wedge-repro' - Task: default, Backend: local

Root Cause

In tools/environments/local.py:

  • Line 356–367: _run_bash passes cwd=self.cwd to subprocess.Popen.

  • Line 392–400: _update_cwd assigns self.cwd = cwd_path from a post-command marker file with no existence check:

    def _update_cwd(self, result: dict):
        try:
            with open(self._cwd_file) as f:
                cwd_path = f.read().strip()
            if cwd_path:
                self.cwd = cwd_path     # no Path(cwd_path).is_dir() guard
        except (OSError, FileNotFoundError):
            pass

When bash deletes its own cwd, it stays alive with an unlinked directory. The marker writes back the now-deleted path, self.cwd is updated to it, and every subsequent Popen fails with ENOENT before exec.

Fix Action

Workaround

Avoid cd <dir> followed by rm -rf <dir> in the same persistent_shell session. Use absolute paths for delete, or cd .. first. Or set terminal.persistent_shell: false.

PR fix notes

PR #17569: fix(local): recover when persistent_shell cwd is deleted (#17558)

Description (problem / solution / changelog)

Summary

  • Recover gracefully in LocalEnvironment._run_bash when self.cwd no longer exists on disk, so a single rm -rf on the cwd can no longer wedge every subsequent tool call until the gateway restarts.
  • Reject stale paths in LocalEnvironment._update_cwd so the marker-file write from a pwd -P against a deleted cwd doesn't get propagated back into self.cwd.

Fixes #17558.

The bug

With terminal.persistent_shell: true (the default), a single agent command can permanently break the LocalEnvironment for the rest of the gateway's lifetime:

mkdir -p /tmp/wedge-repro
cd /tmp/wedge-repro
rm -rf /tmp/wedge-repro
pwd

After rm -rf, self.cwd still holds /tmp/wedge-repro from the prior _update_cwd. The next call hits subprocess.Popen(args, ..., cwd=self.cwd), which raises FileNotFoundError: [Errno 2] No such file or directory: '/tmp/wedge-repro' before bash even starts. There is no path forward — every subsequent terminal/file-tool call fails the same way until the gateway is restarted.

The fix

  1. _run_bash — recover before Popen. A new _resolve_safe_cwd(cwd) helper returns cwd when it exists, otherwise the nearest existing ancestor (with tempfile.gettempdir() as a final guard). When the resolved path differs from self.cwd, log a WARNING ("LocalEnvironment cwd %r is missing on disk; falling back to %r ...") and update self.cwd so the next call doesn't re-warn. The wedge becomes a recoverable, observable event instead of a silent gateway-wide break.
  2. _update_cwd — refuse to store missing paths. pwd -P against a deleted cwd can leave stale text in the marker file. Adding os.path.isdir(cwd_path) to the existing truthy guard means we only adopt a new cwd that actually exists. The _run_bash recovery still handles paths that disappear between calls; this guard prevents propagating known-bad values during the same call.

The maintainer-flagged anti-pattern of "silently fall back to $HOME so commands run in the wrong project dir" (closed PR #13165) is avoided two ways: the warning makes the fallback visible, and the ancestor walk lands the recovery near the original cwd (e.g. /tmp when /tmp/wedge-repro was deleted) rather than $HOME.

Test plan

  • Focused regression: tests/tools/test_local_env_cwd_recovery.py (8 cases)
    • _resolve_safe_cwd unit tests: returns existing cwd, walks up to ancestor, handles empty path, falls back to tempdir when nothing exists.
    • _run_bash E2E: wedge scenario recovers (Popen receives existing dir, self.cwd updated, warning logged); no spurious warning when cwd still exists.
    • _update_cwd defense in depth: refuses missing path in marker file; still accepts valid replacement.
  • Adjacent suite: 68 passes across tests/tools/test_local_env_blocklist.py, test_local_tempdir.py, test_local_shell_init.py, test_local_background_child_hang.py, test_base_environment.py (one local-env-specific failure in test_local_interrupt_cleanup.py::test_wait_for_process_kills_subprocess_on_keyboardinterrupt reproduces on clean origin/main — baseline, unrelated).
  • Regression guard: with the recovery block in _run_bash neutralized AND the _update_cwd guard reverted, test_recovers_when_cwd_deleted_after_init and test_skips_assignment_when_marker_path_missing both fail; restoring both fixes flips them to passing.

Related

  • Fixes #17558.
  • Issue references #6607 (same root-cause class in checkpoint_manager._run_git) and #4982 (same class in cli.py via os.getcwd()); this PR is intentionally scoped to the tools/environments/local.py execution path. The other call sites can be addressed in follow-ups now that the helper exists.
  • #17342 (hypen-o, open) targets _update_cwd for a different scenario (Windows POSIX-path overwrite). Orthogonal — different surface, no overlap.
  • Closed PR #13165 (tangyuanjc, 2026-04-29) tried to silently fall back to $HOME at config-resolution time; the maintainer rejected it because it masked bad project config. This PR's fallback is at runtime (after the cwd was valid), is logged at WARNING, and lands in the closest existing ancestor rather than $HOME — so it surfaces the wedge instead of hiding it.

Changed files

  • tests/tools/test_local_env_cwd_recovery.py (added, +187/-0)
  • tools/environments/local.py (modified, +53/-2)

Code Example

mkdir -p /tmp/wedge-repro
cd /tmp/wedge-repro
rm -rf /tmp/wedge-repro
pwd

---

ERROR tools.terminal_tool: Execution failed after 3 retries -
  Command: pwd - Error: FileNotFoundError: [Errno 2] No such file or directory:
  '/tmp/wedge-repro' - Task: default, Backend: local

---

File ".../tools/file_operations.py", line 383, in _exec
    result = self.env.execute(command, cwd=effective_cwd, **kwargs)
File ".../tools/environments/base.py", line 758, in execute
    proc = self._run_bash(...)
File ".../tools/environments/local.py", line 356, in _run_bash
    proc = subprocess.Popen(args, ..., cwd=self.cwd)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/wedge-repro'

---

2026-04-29 10:41:42,822 ERROR [20260429_104125_34b2b8] tools.terminal_tool: Execution failed after 3 retries - Command: mkdir -p /data/projects/test-project - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local
2026-04-29 10:41:43,833 ERROR [20260429_104125_34b2b8] tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
Traceback (most recent call last):
  File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool
    result = file_ops.write_file(path, content)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file
    mkdir_result = self._exec(mkdir_cmd)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec
    result = self.env.execute(command, cwd=effective_cwd, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute
    proc = self._run_bash(
           ^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash
    proc = subprocess.Popen(
           ^^^^^^^^^^^^^^^^^
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
2026-04-29 10:41:44,847 ERROR [20260429_104125_34b2b8] tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
Traceback (most recent call last):
  File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool
    result = file_ops.write_file(path, content)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file
    mkdir_result = self._exec(mkdir_cmd)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec
    result = self.env.execute(command, cwd=effective_cwd, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute
    proc = self._run_bash(
           ^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash
    proc = subprocess.Popen(
           ^^^^^^^^^^^^^^^^^
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
2026-04-29 10:41:45,859 ERROR [20260429_104125_34b2b8] tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
Traceback (most recent call last):
  File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool
    result = file_ops.write_file(path, content)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file
    mkdir_result = self._exec(mkdir_cmd)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec
    result = self.env.execute(command, cwd=effective_cwd, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute
    proc = self._run_bash(
           ^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash
    proc = subprocess.Popen(
           ^^^^^^^^^^^^^^^^^
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
2026-04-29 10:41:46,869 ERROR [20260429_104125_34b2b8] tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
Traceback (most recent call last):
  File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool
    result = file_ops.write_file(path, content)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file
    mkdir_result = self._exec(mkdir_cmd)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec
    result = self.env.execute(command, cwd=effective_cwd, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute
    proc = self._run_bash(
           ^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash
    proc = subprocess.Popen(
           ^^^^^^^^^^^^^^^^^
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
2026-04-29 10:42:02,288 ERROR [20260429_104125_34b2b8] tools.terminal_tool: Execution failed after 3 retries - Command: mkdir -p /data/projects/test-project 2>&1 || echo "mkdir failed"; ls -la /data/projects/ 2>&1 || echo "data dir not found" - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local
2026-04-29 10:42:17,467 ERROR [20260429_104125_34b2b8] tools.terminal_tool: Execution failed after 3 retries - Command: ls -la /data 2>&1 || echo "No /data directory" - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local
2026-04-29 10:42:32,880 ERROR [20260429_104125_34b2b8] tools.terminal_tool: Execution failed after 3 retries - Command: pwd && ls / - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local
2026-04-29 10:42:35,759 ERROR tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
Traceback (most recent call last):
  File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool
    result = file_ops.write_file(path, content)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file
    mkdir_result = self._exec(mkdir_cmd)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec
    result = self.env.execute(command, cwd=effective_cwd, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute
    proc = self._run_bash(
           ^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash
    proc = subprocess.Popen(
           ^^^^^^^^^^^^^^^^^
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
2026-04-29 10:42:35,766 ERROR tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
Traceback (most recent call last):
  File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool
    result = file_ops.write_file(path, content)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file
    mkdir_result = self._exec(mkdir_cmd)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec
    result = self.env.execute(command, cwd=effective_cwd, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute
    proc = self._run_bash(
           ^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash
    proc = subprocess.Popen(
           ^^^^^^^^^^^^^^^^^
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
2026-04-29 10:42:35,766 ERROR tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
Traceback (most recent call last):
  File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool
    result = file_ops.write_file(path, content)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file
    mkdir_result = self._exec(mkdir_cmd)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec
    result = self.env.execute(command, cwd=effective_cwd, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute
    proc = self._run_bash(
           ^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash
    proc = subprocess.Popen(
           ^^^^^^^^^^^^^^^^^
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
2026-04-29 10:42:35,769 ERROR tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
Traceback (most recent call last):
  File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool
    result = file_ops.write_file(path, content)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file
    mkdir_result = self._exec(mkdir_cmd)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec
    result = self.env.execute(command, cwd=effective_cwd, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute
    proc = self._run_bash(
           ^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash
    proc = subprocess.Popen(
           ^^^^^^^^^^^^^^^^^
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
2026-04-29 10:42:50,895 ERROR [20260429_104125_34b2b8] tools.terminal_tool: Execution failed after 3 retries - Command: echo "attempting basic command" - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local
2026-04-29 10:42:52,776 ERROR [20260429_104125_34b2b8] tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
Traceback (most recent call last):
  File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool
    result = file_ops.write_file(path, content)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file
    mkdir_result = self._exec(mkdir_cmd)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec
    result = self.env.execute(command, cwd=effective_cwd, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute
    proc = self._run_bash(
           ^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash
    proc = subprocess.Popen(
           ^^^^^^^^^^^^^^^^^
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
2026-04-29 10:42:56,267 ERROR [20260429_104125_34b2b8] tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
Traceback (most recent call last):
  File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool
    result = file_ops.write_file(path, content)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file
    mkdir_result = self._exec(mkdir_cmd)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec
    result = self.env.execute(command, cwd=effective_cwd, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute
    proc = self._run_bash(
           ^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash
    proc = subprocess.Popen(
           ^^^^^^^^^^^^^^^^^
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
2026-04-29 10:42:58,068 ERROR [20260429_104125_34b2b8] tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
Traceback (most recent call last):
  File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool
    result = file_ops.write_file(path, content)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file
    mkdir_result = self._exec(mkdir_cmd)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec
    result = self.env.execute(command, cwd=effective_cwd, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute
    proc = self._run_bash(
           ^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash
    proc = subprocess.Popen(
           ^^^^^^^^^^^^^^^^^
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
2026-04-29 10:44:22,413 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: mkdir -p /data - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local
2026-04-29 10:44:37,950 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: df -h && ls -la / - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local
2026-04-29 10:44:53,991 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: pwd - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local
2026-04-29 10:45:10,255 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: mkdir -p /tmp/test-project - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local
2026-04-29 10:45:12,973 ERROR [20260429_102851_220f45] tools.checkpoint_manager: Git command skipped: git init (working directory not found: /tmp/test-project)
2026-04-29 10:45:12,984 ERROR [20260429_102851_220f45] tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
Traceback (most recent call last):
  File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool
    result = file_ops.write_file(path, content)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file
    mkdir_result = self._exec(mkdir_cmd)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec
    result = self.env.execute(command, cwd=effective_cwd, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute
    proc = self._run_bash(
           ^^^^^^^^^^^^^^^
  File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash
    proc = subprocess.Popen(
           ^^^^^^^^^^^^^^^^^
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project'
2026-04-29 10:45:29,233 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: cd / && pwd - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local
2026-04-29 10:45:45,089 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: ls -la / | grep data - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local
2026-04-29 10:46:34,413 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: pwd - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local
2026-04-29 10:46:50,956 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: ./test-project - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local
2026-04-29 10:47:15,015 INFO agent.auxiliary_client: Auxiliary auto-detect: using main provider lmstudio (hermes-4.3-36b)
2026-04-29 10:49:06,425 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: echo "test" > /tmp/test.txt - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local
2026-04-29 10:49:23,406 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: mkdir -p /data - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local
2026-04-29 10:56:42,964 INFO agent.auxiliary_client: Auxiliary auto-detect: using main provider lmstudio (hermes-4.3-36b)

---



---

def _update_cwd(self, result: dict):
      try:
          with open(self._cwd_file) as f:
              cwd_path = f.read().strip()
          if cwd_path:
              self.cwd = cwd_path     # no Path(cwd_path).is_dir() guard
      except (OSError, FileNotFoundError):
          pass
RAW_BUFFERClick to expand / collapse

Bug Description

With terminal.persistent_shell: true (the default), a single tool call that deletes the shell's current working directory wedges the terminal environment for the rest of the gateway's lifetime. Every subsequent subprocess.Popen raises FileNotFoundError: [Errno 2] on the cwd kwarg before the requested command runs.

Same root-cause class as #6607 and #4982, but in tools/environments/local.py — the executor for every shell command run by the agent.

Environment

  • Hermes Agent: v0.11.0 (2026.4.23), commit ff687c01 (v2026.4.23-948-gff687c01)
  • OS: Linux (Ubuntu 24.04, kernel 6.17)
  • Python: 3.12.13
  • Terminal backend: local, persistent_shell: true, lifetime_seconds: 300

Related

  • #6607 — same root-cause class in checkpoint_manager._run_git
  • #4982 — same root-cause class in cli.py via os.getcwd()
  • #4669 — workdir validation for the docker terminal backend
  • #6051 — downstream skill-curator damage when this wedge is misdiagnosed as an environmental restriction

Steps to Reproduce

In a single agent session with the local terminal backend:

mkdir -p /tmp/wedge-repro
cd /tmp/wedge-repro
rm -rf /tmp/wedge-repro
pwd

The final pwd fails with FileNotFoundError: [Errno 2] No such file or directory: '/tmp/wedge-repro'. Every terminal/file-tool call after this point fails the same way until the gateway is restarted.

Expected Behavior

A command leaving self.cwd at a non-existent path should not block all subsequent commands.

Actual Behavior

Observed Behavior

~/.hermes/logs/errors.log:

ERROR tools.terminal_tool: Execution failed after 3 retries -
  Command: pwd - Error: FileNotFoundError: [Errno 2] No such file or directory:
  '/tmp/wedge-repro' - Task: default, Backend: local

The path in the error is the cwd kwarg passed to Popen, not the command target. Stack trace:

File ".../tools/file_operations.py", line 383, in _exec
    result = self.env.execute(command, cwd=effective_cwd, **kwargs)
File ".../tools/environments/base.py", line 758, in execute
    proc = self._run_bash(...)
File ".../tools/environments/local.py", line 356, in _run_bash
    proc = subprocess.Popen(args, ..., cwd=self.cwd)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/wedge-repro'

terminal_tool retries 3× with ~5s timeout each, so each failure takes ~14–15s of wall clock.

Recovery requires restarting the gateway. There is no in-process recovery: cd / and similar fail with the same error because they too are Popen calls with the dead cwd.

Affected Component

Tools (terminal, file ops, web, code execution, etc.)

Messaging Platform (if gateway-related)

N/A (CLI only)

Debug Report

<details> <summary>Click to expand stack trace</summary> ```shell 2026-04-29 10:41:42,822 ERROR [20260429_104125_34b2b8] tools.terminal_tool: Execution failed after 3 retries - Command: mkdir -p /data/projects/test-project - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local 2026-04-29 10:41:43,833 ERROR [20260429_104125_34b2b8] tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' Traceback (most recent call last): File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool result = file_ops.write_file(path, content) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file mkdir_result = self._exec(mkdir_cmd) ^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec result = self.env.execute(command, cwd=effective_cwd, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute proc = self._run_bash( ^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash proc = subprocess.Popen( ^^^^^^^^^^^^^^^^^ File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' 2026-04-29 10:41:44,847 ERROR [20260429_104125_34b2b8] tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' Traceback (most recent call last): File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool result = file_ops.write_file(path, content) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file mkdir_result = self._exec(mkdir_cmd) ^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec result = self.env.execute(command, cwd=effective_cwd, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute proc = self._run_bash( ^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash proc = subprocess.Popen( ^^^^^^^^^^^^^^^^^ File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' 2026-04-29 10:41:45,859 ERROR [20260429_104125_34b2b8] tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' Traceback (most recent call last): File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool result = file_ops.write_file(path, content) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file mkdir_result = self._exec(mkdir_cmd) ^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec result = self.env.execute(command, cwd=effective_cwd, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute proc = self._run_bash( ^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash proc = subprocess.Popen( ^^^^^^^^^^^^^^^^^ File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' 2026-04-29 10:41:46,869 ERROR [20260429_104125_34b2b8] tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' Traceback (most recent call last): File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool result = file_ops.write_file(path, content) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file mkdir_result = self._exec(mkdir_cmd) ^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec result = self.env.execute(command, cwd=effective_cwd, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute proc = self._run_bash( ^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash proc = subprocess.Popen( ^^^^^^^^^^^^^^^^^ File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' 2026-04-29 10:42:02,288 ERROR [20260429_104125_34b2b8] tools.terminal_tool: Execution failed after 3 retries - Command: mkdir -p /data/projects/test-project 2>&1 || echo "mkdir failed"; ls -la /data/projects/ 2>&1 || echo "data dir not found" - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local 2026-04-29 10:42:17,467 ERROR [20260429_104125_34b2b8] tools.terminal_tool: Execution failed after 3 retries - Command: ls -la /data 2>&1 || echo "No /data directory" - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local 2026-04-29 10:42:32,880 ERROR [20260429_104125_34b2b8] tools.terminal_tool: Execution failed after 3 retries - Command: pwd && ls / - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local 2026-04-29 10:42:35,759 ERROR tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' Traceback (most recent call last): File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool result = file_ops.write_file(path, content) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file mkdir_result = self._exec(mkdir_cmd) ^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec result = self.env.execute(command, cwd=effective_cwd, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute proc = self._run_bash( ^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash proc = subprocess.Popen( ^^^^^^^^^^^^^^^^^ File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' 2026-04-29 10:42:35,766 ERROR tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' Traceback (most recent call last): File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool result = file_ops.write_file(path, content) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file mkdir_result = self._exec(mkdir_cmd) ^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec result = self.env.execute(command, cwd=effective_cwd, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute proc = self._run_bash( ^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash proc = subprocess.Popen( ^^^^^^^^^^^^^^^^^ File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' 2026-04-29 10:42:35,766 ERROR tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' Traceback (most recent call last): File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool result = file_ops.write_file(path, content) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file mkdir_result = self._exec(mkdir_cmd) ^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec result = self.env.execute(command, cwd=effective_cwd, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute proc = self._run_bash( ^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash proc = subprocess.Popen( ^^^^^^^^^^^^^^^^^ File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' 2026-04-29 10:42:35,769 ERROR tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' Traceback (most recent call last): File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool result = file_ops.write_file(path, content) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file mkdir_result = self._exec(mkdir_cmd) ^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec result = self.env.execute(command, cwd=effective_cwd, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute proc = self._run_bash( ^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash proc = subprocess.Popen( ^^^^^^^^^^^^^^^^^ File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' 2026-04-29 10:42:50,895 ERROR [20260429_104125_34b2b8] tools.terminal_tool: Execution failed after 3 retries - Command: echo "attempting basic command" - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local 2026-04-29 10:42:52,776 ERROR [20260429_104125_34b2b8] tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' Traceback (most recent call last): File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool result = file_ops.write_file(path, content) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file mkdir_result = self._exec(mkdir_cmd) ^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec result = self.env.execute(command, cwd=effective_cwd, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute proc = self._run_bash( ^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash proc = subprocess.Popen( ^^^^^^^^^^^^^^^^^ File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' 2026-04-29 10:42:56,267 ERROR [20260429_104125_34b2b8] tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' Traceback (most recent call last): File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool result = file_ops.write_file(path, content) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file mkdir_result = self._exec(mkdir_cmd) ^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec result = self.env.execute(command, cwd=effective_cwd, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute proc = self._run_bash( ^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash proc = subprocess.Popen( ^^^^^^^^^^^^^^^^^ File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' 2026-04-29 10:42:58,068 ERROR [20260429_104125_34b2b8] tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' Traceback (most recent call last): File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool result = file_ops.write_file(path, content) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file mkdir_result = self._exec(mkdir_cmd) ^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec result = self.env.execute(command, cwd=effective_cwd, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute proc = self._run_bash( ^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash proc = subprocess.Popen( ^^^^^^^^^^^^^^^^^ File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' 2026-04-29 10:44:22,413 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: mkdir -p /data - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local 2026-04-29 10:44:37,950 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: df -h && ls -la / - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local 2026-04-29 10:44:53,991 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: pwd - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local 2026-04-29 10:45:10,255 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: mkdir -p /tmp/test-project - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local 2026-04-29 10:45:12,973 ERROR [20260429_102851_220f45] tools.checkpoint_manager: Git command skipped: git init (working directory not found: /tmp/test-project) 2026-04-29 10:45:12,984 ERROR [20260429_102851_220f45] tools.file_tools: write_file error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' Traceback (most recent call last): File "/data/projects/hermes-agent/tools/file_tools.py", line 827, in write_file_tool result = file_ops.write_file(path, content) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 713, in write_file mkdir_result = self._exec(mkdir_cmd) ^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/file_operations.py", line 383, in _exec result = self.env.execute(command, cwd=effective_cwd, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/base.py", line 758, in execute proc = self._run_bash( ^^^^^^^^^^^^^^^ File "/data/projects/hermes-agent/tools/environments/local.py", line 356, in _run_bash proc = subprocess.Popen( ^^^^^^^^^^^^^^^^^ File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1026, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/home/nemy/.local/share/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/subprocess.py", line 1955, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' 2026-04-29 10:45:29,233 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: cd / && pwd - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local 2026-04-29 10:45:45,089 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: ls -la / | grep data - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local 2026-04-29 10:46:34,413 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: pwd - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local 2026-04-29 10:46:50,956 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: ./test-project - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local 2026-04-29 10:47:15,015 INFO agent.auxiliary_client: Auxiliary auto-detect: using main provider lmstudio (hermes-4.3-36b) 2026-04-29 10:49:06,425 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: echo "test" > /tmp/test.txt - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local 2026-04-29 10:49:23,406 ERROR [20260429_102851_220f45] tools.terminal_tool: Execution failed after 3 retries - Command: mkdir -p /data - Error: FileNotFoundError: [Errno 2] No such file or directory: '/data/projects/test-project' - Task: default, Backend: local 2026-04-29 10:56:42,964 INFO agent.auxiliary_client: Auxiliary auto-detect: using main provider lmstudio (hermes-4.3-36b) ``` </details> ### Operating System

Ubuntu 24.04

Python Version

3.12.13

Hermes Version

0.11.0

Additional Logs / Traceback (optional)

Root Cause Analysis (optional)

Root Cause

In tools/environments/local.py:

  • Line 356–367: _run_bash passes cwd=self.cwd to subprocess.Popen.

  • Line 392–400: _update_cwd assigns self.cwd = cwd_path from a post-command marker file with no existence check:

    def _update_cwd(self, result: dict):
        try:
            with open(self._cwd_file) as f:
                cwd_path = f.read().strip()
            if cwd_path:
                self.cwd = cwd_path     # no Path(cwd_path).is_dir() guard
        except (OSError, FileNotFoundError):
            pass

When bash deletes its own cwd, it stays alive with an unlinked directory. The marker writes back the now-deleted path, self.cwd is updated to it, and every subsequent Popen fails with ENOENT before exec.

Proposed Fix (optional)

Workaround

Avoid cd <dir> followed by rm -rf <dir> in the same persistent_shell session. Use absolute paths for delete, or cd .. first. Or set terminal.persistent_shell: false.

Possible Fixes

Two possible fixes:

  1. Validate before Popen in _run_bash: if Path(self.cwd).is_dir() is false, fall back to a known-good cwd (~, or terminal.cwd from config) and log a warning. Mirrors _safe_getcwd() in #4982.

  2. Validate at update time in _update_cwd: only assign self.cwd = cwd_path if Path(cwd_path).is_dir(). Keep the previous cwd otherwise.

(1) also handles the case where the cwd is deleted out-of-band by another process.

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

extent analysis

TL;DR

Set terminal.persistent_shell: false to avoid the issue or apply one of the proposed fixes to validate the working directory before executing commands.

Guidance

  • Validate the working directory before executing commands using Path(self.cwd).is_dir() to prevent FileNotFoundError.
  • Consider setting terminal.persistent_shell: false as a temporary workaround to avoid the issue.
  • Apply one of the proposed fixes:
    1. Validate before Popen in _run_bash: fall back to a known-good cwd if Path(self.cwd).is_dir() is false.
    2. Validate at update time in _update_cwd: only assign self.cwd = cwd_path if Path(cwd_path).is_dir().

Example

import pathlib

def _run_bash(self, ...):
    if not pathlib.Path(self.cwd).is_dir():
        # fall back to a known-good cwd
        self.cwd = '/'
    proc = subprocess.Popen(..., cwd=self.cwd, ...)

def _update_cwd(self, result: dict):
    try:
        with open(self._cwd_file) as f:
            cwd_path = f.read().strip()
        if cwd_path and pathlib.Path(cwd_path).is_dir():
            self.cwd = cwd_path
    except (OSError, FileNotFoundError):
        pass

Notes

The proposed fixes assume that the issue is caused by the working directory being deleted while the persistent shell is still active. If the issue is caused by another factor, additional debugging may be necessary.

Recommendation

Apply one of the proposed fixes to validate the working directory before executing commands. If a quick fix is needed, set terminal.persistent_shell: false as a temporary workaround.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix [Bug]: persistent_shell carries cwd into deleted directory; subsequent Popen calls fail with ENOENT until gateway restart [1 pull requests, 1 participants]