Skip to content

fix: hermes update kills freshly-restarted gateway service (salvage #5409) - #5448

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-3c9f4a9e
Apr 6, 2026
Merged

fix: hermes update kills freshly-restarted gateway service (salvage #5409)#5448
teknium1 merged 2 commits into
mainfrom
hermes/hermes-3c9f4a9e

Conversation

@teknium1

@teknium1 teknium1 commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Salvage of #5409 by @kshitijk4poor onto current main.

After hermes update, the gateway service restarts via systemd/launchd, then find_gateway_pids() sweeps for stale manual processes — but returns ALL matching PIDs, including the one just spawned by the service manager. The sweep kills it immediately.

Fix

  • Add _get_service_pids() helper that queries systemd MainPID and launchd PID for active gateway services
  • Add exclude_pids parameter to find_gateway_pids() and kill_gateway_processes()
  • After restarting services in cmd_update(), call _get_service_pids() and pass the result to exclude them from the sweep

Tests

9 new tests (29 total in file, all passing):

  • TestGetServicePids: systemd MainPID, launchd PID, empty, zero-PID exclusion
  • TestFindGatewayPidsExclude: exclude_pids filtering
  • TestServicePidExclusion: integration tests proving service PID survives after restart, manual PIDs still killed

Cherry-picked with contributor authorship preserved. Merged cleanly with recent #5424 (subprocess timeouts).

After restarting a service-managed gateway (systemd/launchd), the
stale-process sweep calls find_gateway_pids() which returns ALL gateway
PIDs via ps aux — including the one just spawned by the service manager.
The sweep kills it, leaving the user with a stopped gateway and a
confusing 'Restart manually' message.

Fix: add _get_service_pids() to query systemd MainPID and launchd PID
for active gateway services, then exclude those PIDs from the sweep.
Also add exclude_pids parameter to find_gateway_pids() and
kill_gateway_processes() so callers can skip known service-managed PIDs.

Adds 9 targeted tests covering:
- _get_service_pids() for systemd, launchd, empty, and zero-PID cases
- find_gateway_pids() exclude_pids filtering
- cmd_update integration: service PID not killed after restart
- cmd_update integration: manual PID killed while service PID preserved
…f-import, harden launchd parsing

- Loop over user/system scope args instead of duplicating the systemd block
- Call get_launchd_label() directly instead of self-importing from hermes_cli.gateway
- Validate launchd output by checking parts[2] matches expected label (skip header)
- Add race-condition assumption docstring
@teknium1
teknium1 merged commit d3d5b89 into main Apr 6, 2026
5 of 6 checks passed
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