Skip to content

The agent that grows with you

docs(gateway): restate the Windows pid_exists rationale as measured; HX012 allow names the empty Context

Tekniumb63fbbac4d27
diff --git a/gateway/status.py b/gateway/status.py
index 078b146f67a..1fa16014e07 100644
--- a/gateway/status.py
+++ b/gateway/status.py
@@ -946,8 +946,8 @@ def _pid_exists(pid: int) -> bool:
dead: treating one as alive makes --replace wait forever under systemd Restart=always."""
pid = int(pid)
if os.name == "nt":
- # psutil's Windows liveness calls (EnumProcesses, NtQuerySystemInformation) hold the GIL, so a
- # slow one froze every thread for minutes (#142085); ctypes releases it. No zombies on Windows.
+ # ctypes keeps psutil off this hot path (no zombies here). Not a GIL fix: pid_exists measured ~4 us; the
+ # #142085 stall is Process.status() (process_identity). PID 0 is alive to psutil, dead here.
return pid_exists_stdlib(pid)
try:
import psutil # type: ignore
diff --git a/gateway/turn_executor.py b/gateway/turn_executor.py
index 822c5df3686..0de792df105 100644
--- a/gateway/turn_executor.py
+++ b/gateway/turn_executor.py
@@ -65,7 +65,7 @@ class _UnboundedThreadExecutor(concurrent.futures.Executor):
return fut
self._n += 1
worker = _Worker()
- # health: allow HX012 -- a worker serves many items; each runs in the context its caller captured (ctx.run)
+ # health: allow HX012 -- a worker serves many items; each runs in a fresh empty Context, as a new thread would
t = threading.Thread(target=self._work, args=(worker, item), name=f"{self._prefix}_{self._n}", daemon=True)
worker.thread = t
# Start BEFORE registering: at the OS thread limit start() raises, and an unstarted thread
diff --git a/tests/gateway/test_status.py b/tests/gateway/test_status.py
index 1fdf4892d4a..7dec8214c43 100644
--- a/tests/gateway/test_status.py
+++ b/tests/gateway/test_status.py
@@ -744,10 +744,9 @@ class TestPidExistsZombieProbe:
@pytest.mark.platforms("windows")
def test_windows_never_touches_psutil_at_all(self, monkeypatch):
- """#142085: psutil's Windows liveness path does not release the GIL, so one slow
- ``EnumProcesses``/``NtQuerySystemInformation`` call freezes every other Python thread in
- the process (Desktop backend and gateway stall for minutes under load). The Windows
- branch must go straight to the ctypes probe and never import psutil."""
+ """#142085: the Windows branch goes straight to the ctypes probe and never calls psutil, so
+ the liveness check carries no psutil dependency on this hot path. (The measured GIL stall is
+ ``Process.status()``, covered in test_process_identity; ``pid_exists`` itself is ~4 us.)"""
psutil = pytest.importorskip("psutil")
calls = []
real_pid_exists = psutil.pid_exists