Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

fix(wrap): don't crash cleanup on Windows when os.kill liveness check raises SystemError (#1315)

quentinmaisonneuve3714a8c6ac18
diff --git a/headroom/cli/wrap.py b/headroom/cli/wrap.py
index be6feeee8..3dba737f1 100644
--- a/headroom/cli/wrap.py
+++ b/headroom/cli/wrap.py
@@ -2836,13 +2836,24 @@ def _unregister_proxy_client(port: int) -> None:
def _pid_alive(pid: int) -> bool:
"""Return True if ``pid`` names a live process."""
+ if pid <= 0:
+ return False # non-positive PIDs are never valid client markers
+ try:
+ import psutil # type: ignore[import-untyped] # optional dep, already used elsewhere
+
+ return bool(psutil.pid_exists(pid))
+ except Exception:
+ pass
try:
os.kill(pid, 0)
- except ProcessLookupError:
- return False
except PermissionError:
return True # exists but owned by another user
- except OSError:
+ except (ProcessLookupError, OSError, SystemError):
+ # On Windows, os.kill against a stale/invalid PID can fail with WinError
+ # 87 ("The parameter is incorrect"); CPython sometimes surfaces this as a
+ # SystemError rather than an OSError. SystemError is not an OSError
+ # subclass, so a bare `except OSError` lets it escape and crash cleanup(),
+ # leaving the shared proxy running.
return False
return True