fix(gateway): kickstart launchd after SIGUSR1 self-restart on macOS#24993
Closed
konsisumer wants to merge 1 commit into
Closed
fix(gateway): kickstart launchd after SIGUSR1 self-restart on macOS#24993konsisumer wants to merge 1 commit into
konsisumer wants to merge 1 commit into
Conversation
When `hermes update` runs inside the gateway process tree (e.g. invoked by the agent via its terminal tool), `launchd_restart()` was taking the SIGUSR1 path and returning immediately. The gateway then drained and exited with code 75, but launchd was observed to leave the domain in "on-demand-only mode" and never issue WILL_SPAWN, leaving the service permanently dead until manual `hermes gateway start`. Both branches now converge on `_wait_for_gateway_exit` + `launchctl kickstart -k`, mirroring the systemd restart path. The `launchctl` client talks to launchd over XPC, so the kickstart still works even after the gateway (our ancestor) exits and we are reparented. Fixes NousResearch#11932
Collaborator
Contributor
Author
|
Thanks for the context, @alt-glitch. I've reviewed each cross-reference:
|
19 tasks
This was referenced May 18, 2026
Contributor
Author
|
Closing — this PR removes the immediate-return-after-SIGUSR1 in |
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.
Fix the macOS
launchd_restart()path that left the gateway permanently dead whenhermes updateran inside the gateway process tree.What changed and why
hermes_cli/gateway.py—launchd_restart()no longer returns immediately after sending SIGUSR1. Both the SIGUSR1 path (when the gateway is an ancestor of the current process) and the SIGTERM path (when it is not) now fall through to_wait_for_gateway_exitand thenlaunchctl kickstart -k. This mirrors the systemd restart path and matches what the issue author proposed.hermes updatevia its terminal tool, the gateway was an ancestor of the update process, so_request_gateway_self_restartsucceeded and the function returned. The gateway drained and exited with code 75, but macOS launchd was observed to leave the domain in "on-demand-only mode" with no follow-upWILL_SPAWN, so the service stayed dead until manualhermes gateway start. Issuinglaunchctl kickstart -kunconditionally — which talks to launchd over XPC and works even after our ancestor process exits — restores the relaunch.tests/hermes_cli/test_gateway_service.py— the existingtest_launchd_restart_self_requests_graceful_restart_without_kickstarttest was asserting precisely the buggy behavior (thatlaunchctl should not run). It is replaced withtest_launchd_restart_self_request_waits_then_kickstarts, which asserts the corrected sequence: SIGUSR1 request →_wait_for_gateway_exitwith the drain timeout →launchctl kickstart -k <target>. The complementarytest_launchd_restart_drains_running_gateway_before_kickstart(Path B, gateway not an ancestor) is unchanged and still passes.How to test
pytest tests/hermes_cli/test_gateway_service.py -k launchd_restart -q— all 3launchd_restartcases pass.pytest tests/hermes_cli/test_gateway_service.py tests/hermes_cli/test_update_gateway_restart.py -q— 158 tests pass. 3 pre-existing systemd test failures on this Darwin host (UserSystemdUnavailableError: User D-Bus session is not available) are unrelated to this change and also fail onmain.hermes updatevia the terminal tool. Before the fix, the gateway would exit with code 75 and not come back. After the fix,launchctl kickstart -kruns after the drain and the new gateway process is spawned within seconds.What platforms tested on
systemd_restart) are untouched and were not exercised.Fixes #11932