Skip to content

The agent that grows with you

fix(gateway): restart watcher names its checkout instead of inheriting the cwd

teknium15a0225dfff8c
diff --git a/gateway/status.py b/gateway/status.py
index 4b30bf8d031..af85ad0548b 100644
--- a/gateway/status.py
+++ b/gateway/status.py
@@ -23,8 +23,6 @@ from typing import Any, Callable, NamedTuple, Optional
from hermes_constants import _get_platform_default_hermes_home, get_hermes_home, get_process_hermes_home
from hermes_cli._subprocess_compat import pid_exists_stdlib
-from hermes_cli._subprocess_compat import posix_is_zombie as _posix_is_zombie # noqa: F401 - historical name
-from hermes_cli._subprocess_compat import win32_pid_exists as _pid_exists_win32_ctypes # noqa: F401 - historical name
from utils import atomic_json_write
if sys.platform == "win32":
diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.py
index a86b6ff50ea..8ac557a7974 100644
--- a/hermes_cli/gateway.py
+++ b/hermes_cli/gateway.py
@@ -1075,6 +1075,8 @@ def _spawn_gateway_restart_watcher(old_pid: int, run_argv: list[str], *, host: b
import time
# Stdlib-only imports: the watcher runs on the updater's interpreter, which after the
# package-manager handoff is the bare store Python without the dependency environment.
+ # ``-c`` only puts the cwd on sys.path, so name the checkout explicitly.
+ sys.path.insert(0, {project_root_literal})
from hermes_cli._subprocess_compat import (
_WINDOWS_GATEWAY_BREAKAWAY_ENV, pid_exists_stdlib, windows_detach_flags,
windows_detach_flags_without_breakaway,
@@ -1144,7 +1146,8 @@ def _spawn_gateway_restart_watcher(old_pid: int, run_argv: list[str], *, host: b
pass
"""
).strip().format(respawn_cwd_literal=json.dumps(respawn_cwd), respawn_env_literal=json.dumps(respawn_env_overlay),
- watcher_timeout_literal=json.dumps(GATEWAY_RESTART_WATCHER_TIMEOUT_S))
+ watcher_timeout_literal=json.dumps(GATEWAY_RESTART_WATCHER_TIMEOUT_S),
+ project_root_literal=json.dumps(str(PROJECT_ROOT)))
watcher_argv = [sys.executable, "-c", watcher, str(old_pid), *run_argv]
devnull = {"stdout": subprocess.DEVNULL, "stderr": subprocess.DEVNULL}
diff --git a/tests/hermes_cli/test_gateway_restart_watcher_bare_python.py b/tests/hermes_cli/test_gateway_restart_watcher_bare_python.py
index 4b0e838a754..dde7a12f476 100644
--- a/tests/hermes_cli/test_gateway_restart_watcher_bare_python.py
+++ b/tests/hermes_cli/test_gateway_restart_watcher_bare_python.py
@@ -41,7 +41,8 @@ def test_restart_watcher_relaunches_from_an_interpreter_without_site_packages(tm
home = tmp_path / "home"
home.mkdir()
monkeypatch.setenv("HERMES_HOME", str(home))
- monkeypatch.chdir(REPO)
+ # The watcher must find the checkout on its own, not through an inherited cwd.
+ monkeypatch.chdir(tmp_path)
monkeypatch.setattr(sys, "executable", str(bare))
relaunch = [str(bare), "-c", f"open({str(marker)!r}, 'w').write('ok')"]