Skip to content

fix(gateway): track + reap no-systemd gateway restart runtimes (WSL orphan) - #51678

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-ee064db6
Jun 24, 2026
Merged

teknium1 merged 2 commits into
mainfrom
hermes/hermes-ee064db6

Conversation

@teknium1

Copy link
Copy Markdown
Collaborator

Summary

On WSL/no-systemd hosts, a tracked gateway now survives gateway restart / /restart / dashboard / hermes update without leaving an orphaned, untracked listener on :8644 — status reports it accurately, stop can see it, and a follow-up restart reaps the prior instance instead of stacking duplicates.

Root cause (#51325): With no service supervisor, hermes gateway restart falls to run_gateway() in the same process (hermes_cli/gateway.py restart branch), so the live gateway's argv stays … gateway restart. The strict looks_like_gateway_command_line() matcher only accepts gateway run, so process scans and the runtime-record validator both reject the live gateway → status says "stopped", stop --all can't find it, restarts can't reap the prior orphan → duplicates pile up on the port.

Changes

  • gateway/status.py (@wgu9): add looks_like_gateway_runtime_command_line() accepting restart; use it for runtime-record validation; get_running_pid() falls back to a validated live gateway_state.json PID when no pidfile path is given. Strict matcher unchanged for everything else.
  • hermes_cli/gateway.py (@wgu9): _scan_gateway_pids(include_restart_managers=…); find_gateway_pids() enables it only when not supports_systemd_services(), so supervised hosts never false-match a transient gateway restart.
  • hermes_cli/gateway.py (follow-up): stop_profile_gateway() now falls back to _reap_unsupervised_gateway_orphans() when the pidfile/runtime record yields nothing — a profile-scoped, no-systemd-gated SIGTERM→SIGKILL of the orphan, closing the duplicate-accumulation path (suggested fix Architecture planning #3 in the issue). SIGKILL mirrors the field report where SIGTERM released the port but the process kept running.

Validation

Before After
status on no-systemd restart runtime "Stopped" (alive) accurate (running)
stop / scan sees orphan no yes (no-systemd only)
follow-up restart stacks duplicate on :8644 reaps prior orphan
systemd host behavior — unchanged (gated off)
  • Targeted suite: tests/hermes_cli/test_gateway.py tests/gateway/test_gateway_command_line_matcher.py tests/gateway/test_status.py tests/hermes_cli/test_gateway_proc_fallback.py → 159 passed.
  • E2E (real /proc entry + real process, temp HERMES_HOME): strict matcher rejects gateway restart, runtime matcher accepts; find_gateway_pids(all_profiles=True) finds the live orphan; reaper SIGTERM/SIGKILLs it; foreign---profile process is correctly excluded from the profile-scoped reap.

Salvage of #51468 by @wgu9 (cherry-picked, authorship preserved) + follow-up reap.

Fixes #51325. Closes #51468.

Infographic

gateway-orphan-reaper

@github-actions

github-actions Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

🔎 Lint report: hermes/hermes-ee064db6 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 11172 on HEAD, 11172 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5900 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

Builds on @wgu9's runtime-tracking fix: now that find_gateway_pids() can
see a no-supervisor `gateway restart` runtime, have stop_profile_gateway()
fall back to an orphan-aware, profile-scoped reap (SIGTERM then SIGKILL)
when the pidfile/runtime record is missing or stale. Closes the duplicate-
accumulation path in #51325 — a follow-up restart now kills the prior
orphan instead of stacking another listener on :8644. Gated on
not supports_systemd_services() so a transient `gateway restart` argv on
supervised hosts is never killed.

Also adds the AUTHOR_MAP entry for the salvaged contributor.
@teknium1
teknium1 force-pushed the hermes/hermes-ee064db6 branch from aeda22e to 47c3166 Compare June 24, 2026 05:00
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists labels Jun 24, 2026
@teknium1
teknium1 merged commit 3d56807 into main Jun 24, 2026
24 checks passed
@teknium1
teknium1 deleted the hermes/hermes-ee064db6 branch June 24, 2026 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

3 participants