Windows: _process_alive() reports dead services as running, and crashes on unknown PIDs
Summary
services._process_alive() uses the POSIX idiom os.kill(pid, 0), which does not carry to Windows — os.kill there is implemented over OpenProcess rather than signals. Measured on Windows 11 / CPython 3.13, it fails in two different ways:
| PID state | os.kill(pid, 0) |
_process_alive() returns |
|---|---|---|
| never existed | raises OSError(WinError 87) |
propagates — crashes the caller |
| recently exited | returns cleanly | True ← reports a dead service as running |
0 / negative |
returns cleanly | True |
The middle row is the one that matters. A Windows process handle stays openable while any handle to it remains, so os.kill(pid, 0) on a just-exited PID does not raise. cce services status therefore reports a crashed service as healthy — silently, with no error to notice.
The first row is the visible symptom and is what fails in CI.
Reproduction
import os, subprocess, sys
import context_engine.services as S
d = subprocess.Popen([sys.executable, "-c", "pass"]); d.wait()
print(S._process_alive(d.pid)) # True <- WRONG, it has exited
print(S._process_alive(999999)) # OSError: [WinError 87] The parameter is incorrect
print(S._process_alive(0)) # True <- WRONG
Current CI state
Two tests fail on main on Windows for this reason:
tests/test_services.py::test_process_alive_dead_pid—OSError: [WinError 87]atservices.py:60tests/test_cli_smoke.py::test_services—AssertionError: assert 1 == 0
.github/workflows/ci.yml runs the Windows job with || true, so these are currently swallowed rather than surfaced. Worth noting the mask is hiding a real defect, not just runner flakiness.
Note also that the existing test_process_alive_dead_pid uses PID 2**22 — beyond the max PID on Linux/macOS — so it exercises the "never existed" path but cannot reach the exited-process path where the silent wrong answer lives.
Suggested fix
psutil>=5.9 is already a core dependency and already imported by config.py, and it gets this right on every platform:
if pid <= 0:
return False
try:
return psutil.Process(pid).status() != psutil.STATUS_ZOMBIE
except psutil.NoSuchProcess:
return False
except psutil.AccessDenied:
return True # exists, owned by another user
Excluding zombies is deliberate — on POSIX a reaped-but-not-collected child still "exists" while not running, which is the same class of wrong answer.
PR follows, with regression tests covering the exited-child case (the one the current suite cannot reach), a known-running positive control, and non-positive PIDs.
Hello Raj,
Hope you don't mind me fixing the issues. Claude actually found the problem so I can't take credit for that. I have used CCE so much I thought I owed you guys the fix. Some really great work you have done here, makes running agentic tasks so much cheaper.
Regards, Richard
On Wed, 29 Jul 2026 at 20:43, Raj @.***> wrote:
Closed #149 https://github.com/elara-labs/code-context-engine/issues/149 as completed via #150 https://github.com/elara-labs/code-context-engine/pull/150.
— Reply to this email directly, view it on GitHub https://github.com/elara-labs/code-context-engine/issues/149?email_source=notifications&email_token=BQWEAFGDKJBCJMCKQILJB4D5HJHXNA5CNFSNUABQM5UWIORPF5TWS5BNNB2WEL2JONZXKZKFOZSW45CON52GSZTJMNQXI2LPNYXTEOBWHAZTAMJYHA3TRJTSMVQXG33OUZQXK5DIN5ZKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#event-28683018878, or unsubscribe https://github.com/notifications/unsubscribe-auth/BQWEAFHL5DDVT2TVZHPPTJ35HJHXNAVCNFSNUABGKJSXA33TNF2G64TZHMYTEMRSGQ2DIMRTGA5US43TOVSTWNJQGAZTMNZUHA2TFILWAI . Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS https://github.com/notifications/mobile/ios/BQWEAFGXO7NFB7QXD4KSGF35HJHXNA5CNFSNUABQM5UWIORPF5TWS5BNNB2WEL2JONZXKZKFOZSW45CON52GSZTJMNQXI2LPNYXTEOBWHAZTAMJYHA3TRJTSMVQXG33OUZQXK5DIN5ZKKZLWMVXHJKTGN5XXIZLSL5UW64Y and Android https://github.com/notifications/mobile/android/BQWEAFDDXXIYCUH5PUZFF2D5HJHXNA5CNFSNUABQM5UWIORPF5TWS5BNNB2WEL2JONZXKZKFOZSW45CON52GSZTJMNQXI2LPNYXTEOBWHAZTAMJYHA3TRJTSMVQXG33OUZQXK5DIN5ZKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI. Download it today! You are receiving this because you authored the thread.Message ID: @.*** com>
Thanks Richard! The contributions are genuinely appreciated, both the mcp pin (#148) and the Windows process check fix (#150) were solid, well-documented PRs. The silent wrong answer on exited PIDs was a particularly good catch.
Feel free to keep filing issues or sending fixes anytime. And glad CCE is saving you tokens on agentic tasks, that's exactly what it's built for.