Skip to content

fix(desktop): watchdog shutdown must not hard-kill on Windows - #302

Merged
thcp merged 2 commits into
mainfrom
fix/watchdog-graceful-shutdown
Jul 17, 2026
Merged

fix(desktop): watchdog shutdown must not hard-kill on Windows#302
thcp merged 2 commits into
mainfrom
fix/watchdog-graceful-shutdown

Conversation

@thcp

@thcp thcp commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Closes #282. Phase 2 of #273 — plan: #273 (comment) (PR-2D).

What

_desktop_parent_watchdog stopped the backend with os.kill(os.getpid(), signal.SIGTERM), commented as "so uvicorn runs its shutdown sequence." That's only true on POSIX — on Windows, os.kill with SIGTERM is TerminateProcess, a hard kill that bypasses every cleanup path. Low impact today (the registry persists per-job), but any future shutdown hook would silently never run on Windows desktop.

One-line root-cause fix: signal.raise_signal(signal.SIGTERM) triggers the in-process Python-level handler uvicorn installed via signal.signal, with identical semantics on both platforms. Comment updated to say why.

Testing

New tests/test_watchdog.py: dead parent → exactly one in-process raise_signal(SIGTERM) and zero os.kill calls; alive parent → loops without signaling until the parent disappears.

Full suite: 182 passed; ruff clean.

🤖 Generated with Claude Code

Thales added 2 commits July 17, 2026 01:34
The desktop parent watchdog used os.kill(os.getpid(), SIGTERM) to stop
the backend, with a comment promising uvicorn's shutdown sequence would
run. On Windows that call is TerminateProcess -- a hard kill that
bypasses every cleanup path, so the promise only held on POSIX.

signal.raise_signal(SIGTERM) triggers the in-process Python-level
handler uvicorn installed, with identical semantics on both platforms.

Closes #282
@thcp
thcp merged commit 1050789 into main Jul 17, 2026
8 checks passed
@thcp
thcp deleted the fix/watchdog-graceful-shutdown branch July 17, 2026 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows watchdog does a hard kill, not graceful shutdown

1 participant