fix(gateway): wire launchd_restart to drain-aware SIGUSR1 path (#27745)#27781
Closed
briandevans wants to merge 1 commit into
Closed
fix(gateway): wire launchd_restart to drain-aware SIGUSR1 path (#27745)#27781briandevans wants to merge 1 commit into
briandevans wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates launchd_restart() to prefer a drain-aware SIGUSR1 restart path (with an immediate unforced launchctl kickstart) and adjusts tests to cover the new drain-first behavior and SIGTERM fallback.
Changes:
- Replace the launchd “self-restart request” path with
_graceful_restart_via_sigusr1(...)drain behavior. - On successful drain, run
launchctl kickstart(without-k) to avoid killing in-flight work. - Update/rename gateway service tests to validate the new drain/kickstart flow and fallback behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tests/hermes_cli/test_gateway_service.py | Updates tests to validate SIGUSR1 drain + unforced kickstart, and fallback-to-SIGTERM when drain fails. |
| hermes_cli/gateway.py | Changes launchd restart logic to use SIGUSR1 drain path and unforced kickstart to respawn immediately. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -3026,8 +3026,19 @@ def launchd_restart(): | |||
|
|
|||
| try: | |||
| pid = get_running_pid() | |||
| if pid is not None and _request_gateway_self_restart(pid): | |||
| print("✓ Service restart requested") | |||
| if pid is not None and _graceful_restart_via_sigusr1(pid, drain_timeout + 5): | |||
Comment on lines
+3036
to
3042
| subprocess.run( | ||
| ["launchctl", "kickstart", target], | ||
| check=False, | ||
| timeout=30, | ||
| ) | ||
| print("✓ Service restarted (drained)") | ||
| return |
Comment on lines
+3036
to
+3040
| subprocess.run( | ||
| ["launchctl", "kickstart", target], | ||
| check=False, | ||
| timeout=30, | ||
| ) |
| @@ -3026,8 +3026,19 @@ def launchd_restart(): | |||
|
|
|||
| try: | |||
| pid = get_running_pid() | |||
| if pid is not None and _request_gateway_self_restart(pid): | |||
| print("✓ Service restart requested") | |||
| if pid is not None and _graceful_restart_via_sigusr1(pid, drain_timeout + 5): | |||
fdc7649 to
7fd7be5
Compare
…esearch#27745) `hermes gateway restart` on macOS (launchd) called the ancestor-guarded `_request_gateway_self_restart`, which returns False when the calling shell isn't a descendant of the gateway. Operators running the command from a fresh terminal therefore fell straight through to SIGTERM, no SIGUSR1 was ever sent, and the gateway's drain handler never ran — in-flight agent runs were SIGKILL'd after the short terminate timeout. systemd_restart and the macOS `hermes update` flow already use the unconditional `_graceful_restart_via_sigusr1` helper. This change brings launchd_restart in line: send SIGUSR1, wait up to drain_timeout + 5 for the planned exit-75, then `launchctl kickstart` (without -k) to respawn immediately instead of waiting for KeepAlive's throttle. The SIGTERM + kickstart -k fallback is preserved for the case where the drain doesn't complete. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
7fd7be5 to
521a5a9
Compare
Contributor
Author
|
Closing to focus the queue on security/file-safety work where civilian merges are landing. Happy to reopen if maintainers want this picked up. |
This was referenced May 30, 2026
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 does this PR do?
hermes gateway restarton macOS (launchd) bypassed its own SIGUSR1 drain handler when invoked from a fresh shell — operator-requested restarts went straight to SIGTERM and killed in-flight agent runs.launchd_restart(hermes_cli/gateway.py:3021) gated its only SIGUSR1 call on_request_gateway_self_restart, which is itself guarded by_is_pid_ancestor_of_current_process. That ancestor guard is correct for the in-process self-restart case (gateway/run.pyhandlers asking their own gateway ancestor to restart) but returns False whenever the calling CLI process is a sibling under launchd — which is exactly the fresh-shell case. The fallback wasterminate_pid(pid, force=False)(SIGTERM, no drain wait). This PR switcheslaunchd_restartto the unconditional drain-aware helper_graceful_restart_via_sigusr1(...), matching whatsystemd_restart(line 2585) and the macOShermes updateflow already use. On successful drain, runslaunchctl kickstart(without-k) to bypass launchd's throttle while preserving the drained in-flight runs.Related Issue
Fixes #27745
Type of Change
Changes Made
hermes_cli/gateway.py—launchd_restartnow calls_graceful_restart_via_sigusr1(pid, drain_timeout + 5)unconditionally (same budget assystemd_restart). On success,launchctl kickstartwithout-kbypasses throttle but preserves drained runs. On failure, the original SIGTERM +kickstart -kfallback is kept intact.tests/hermes_cli/test_gateway_service.py— newtest_launchd_restart_drains_then_kickstarts_without_force(mocks a non-ancestor PID, verifies SIGUSR1 fires and unforcedlaunchctl kickstartfollows), and rewrotetest_launchd_restart_falls_back_to_sigterm_when_drain_failsto mock the drain failing and verify the SIGTERM +kickstart -kpath is preserved.How to Test
uv run --with pytest --with pytest-xdist --with pytest-asyncio python3 -m pytest tests/hermes_cli/test_gateway_service.py -v -k launchd— 13 passed._request_gateway_self_restartwas mocked to False in the drain test, proving the SIGTERM path. After the fix that mock is unreachable; the new test exercises the SIGUSR1 path explicitly and asserts no SIGTERM call.Checklist
Code
fix(scope):,feat(scope):, etc.)Documentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/ASibling Audit
Related