Skip to content

The agent that grows with you

fix(gateway): restart watcher drops the cwd from sys.path itself instead of -P

Teknium000861be39aa
diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.py
index 9b238f17c83..b75e3d0f3a9 100644
--- a/hermes_cli/gateway.py
+++ b/hermes_cli/gateway.py
@@ -1086,13 +1086,13 @@ def _spawn_gateway_restart_watcher(old_pid: int, run_argv: list[str], *, host: b
# cwd/env overlay are embedded as JSON literals in the watcher source (no extra argv plumbing).
watcher = textwrap.dedent(
"""
+ import sys
+ if sys.path[:1] == [""]: del sys.path[0] # -c puts the cwd first: never import from it
import os
import subprocess
- import sys
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.
+ # Stdlib-only imports: after the package-manager handoff this is the bare store Python;
+ # 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,
@@ -1166,7 +1166,7 @@ def _spawn_gateway_restart_watcher(old_pid: int, run_argv: list[str], *, host: b
watcher_timeout_literal=json.dumps(GATEWAY_RESTART_WATCHER_TIMEOUT_S),
project_root_literal=json.dumps(str(PROJECT_ROOT)))
- watcher_argv = [sys.executable, "-P", "-c", watcher, str(old_pid), *run_argv]
+ watcher_argv = [sys.executable, "-c", watcher, str(old_pid), *run_argv]
devnull = {"stdout": subprocess.DEVNULL, "stderr": subprocess.DEVNULL}
# Host respawn must not inherit a named launcher's dotenv. The watcher copies os.environ
# into the gateway child, so the scrub has to be the watcher's own environ.