fix(gateway): use no-kill _pid_exists probe in lifecycle ledger

scripts/check-windows-footguns.py (blocking CI lint) rightly flagged the
os.kill(pid, 0) liveness probe: on Windows sig=0 collides with
CTRL_C_EVENT and GenerateConsoleCtrlEvent hard-kills the target's whole
console group (bpo-14484) — a forensics module must never be able to
kill the process it's checking on. Route through gateway.status._pid_exists,
the repo's canonical psutil-backed no-kill probe.
This commit is contained in:
Shannon Sands 2026-07-27 13:52:11 +10:00 committed by Teknium
parent 9c76c133b7
commit 6459b8df76

View file

@ -156,8 +156,14 @@ def _pid_alive_with_start_time(pid: Any, start_time: Any) -> bool:
if pid_int <= 0:
return False
try:
os.kill(pid_int, 0)
except (ProcessLookupError, PermissionError, OSError):
# NOT os.kill(pid, 0): on Windows that sends CTRL_C_EVENT to the
# target's console group (bpo-14484). _pid_exists is the repo's
# canonical no-kill cross-platform probe (psutil-backed).
from gateway.status import _pid_exists
if not _pid_exists(pid_int):
return False
except Exception:
return False
if start_time is None:
return True # alive; can't disambiguate PID reuse — err on "alive"