Skip to content

fix(gateway): use platform-aware force-kill semantics for stale gateway PIDs#6811

Closed
Dusk1e wants to merge 1 commit into
NousResearch:mainfrom
Dusk1e:fix/windows-gateway-force-kill
Closed

fix(gateway): use platform-aware force-kill semantics for stale gateway PIDs#6811
Dusk1e wants to merge 1 commit into
NousResearch:mainfrom
Dusk1e:fix/windows-gateway-force-kill

Conversation

@Dusk1e

@Dusk1e Dusk1e commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

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.

@teknium1

Copy link
Copy Markdown
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!

@teknium1 teknium1 closed this Apr 10, 2026
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.

2 participants