fix(gateway): use platform-aware force-kill semantics for stale gateway PIDs#6811
Closed
Dusk1e wants to merge 1 commit into
Closed
fix(gateway): use platform-aware force-kill semantics for stale gateway PIDs#6811Dusk1e wants to merge 1 commit into
Dusk1e wants to merge 1 commit into
Conversation
Contributor
|
Merged via PR #7123. Your commit was cherry-picked onto current main with your authorship preserved. Good centralization of the PID termination logic — thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
This patch fixes gateway shutdown and replacement flows to use platform-appropriate force-kill behavior.
Previously, gateway lifecycle code assumed POSIX semantics:
gateway run --replace escalated from SIGTERM to SIGKILL
CLI-side gateway stop/restart helpers also used SIGKILL on force paths
That works on Unix, but not on Windows. On Windows, these paths could fail to fully terminate stale gateway processes, leaving restart/replace flows unreliable.
This change introduces a shared helper in gateway/status.py:
POSIX:
graceful stop -> SIGTERM
force stop -> SIGKILL
Windows:
graceful stop -> existing os.kill(..., SIGTERM) behavior
force stop -> taskkill /PID /T /F
The helper is now used by:
gateway.run.start_gateway(..., replace=True)
hermes_cli.gateway.kill_gateway_processes(force=True)
hermes_cli.gateway._wait_for_gateway_exit()
Why this is necessary
The gateway PID replacement path is a critical operational flow:
hermes gateway restart
hermes gateway run --replace
stale PID cleanup during service management
Before this patch, those flows relied on Unix-only force-kill assumptions. On Windows, that could leave the old gateway process alive, causing:
failed or flaky restarts
duplicate-instance guard conflicts
stale PID/lock cleanup issues
This patch keeps Unix behavior unchanged and makes Windows force shutdown actually work.
Files changed
gateway/status.py
gateway/run.py
hermes_cli/gateway.py
tests/gateway/test_status.py
tests/gateway/test_runner_startup_failures.py
tests/hermes_cli/test_gateway.py
How to test
Unit tests:
tests/gateway/test_status.py
tests/gateway/test_runner_startup_failures.py
tests/hermes_cli/test_gateway.py
Manual verification on Windows:
Start a gateway instance so a live PID exists.
Trigger hermes gateway restart or hermes gateway run --replace.
Confirm the stale process is terminated and the new instance starts cleanly.
Confirm force-kill paths use taskkill semantics rather than Unix-only SIGKILL assumptions.
Backward compatibility / risk
Low risk.
Unix and macOS behavior are preserved.
Windows behavior is improved in force-stop paths only.
The change is intentionally small and localized to gateway lifecycle code.