fix(gateway): use drain-aware SIGUSR1 in launchd_restart#35178
Open
liuhao1024 wants to merge 1 commit into
Open
fix(gateway): use drain-aware SIGUSR1 in launchd_restart#35178liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
launchd_restart() called _request_gateway_self_restart() which is guarded by _is_pid_ancestor_of_current_process(). When invoked from a fresh shell (not a gateway descendant), the ancestor check fails and the code falls through to SIGTERM — bypassing the drain-aware SIGUSR1 path that cleanly finishes in-flight agent runs. Use _graceful_restart_via_sigusr1() instead, matching the systemd path. SIGUSR1 triggers gateway/run.py's request_restart(via_service=True) which drains agent runs then exits with code 75. launchd's KeepAlive.SuccessfulExit=false relaunches the process automatically. Fixes NousResearch#27745
Collaborator
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?
Fixes
launchd_restart()to use the drain-aware_graceful_restart_via_sigusr1()helper instead of the ancestor-guarded_request_gateway_self_restart(). Previously, runninghermes gateway restartfrom a fresh shell always fell through to SIGTERM because the shell is not a descendant of the gateway process, bypassing the drain path that cleanly finishes in-flight agent runs.Related Issue
Fixes #27745
Type of Change
Changes Made
hermes_cli/gateway.py: Replace_request_gateway_self_restart(pid)with_graceful_restart_via_sigusr1(pid, drain_timeout)inlaunchd_restart(), and update the success message to reflect the drain-aware behavior.tests/hermes_cli/test_gateway_service.py: Update two launchd restart tests to mock_graceful_restart_via_sigusr1instead of_request_gateway_self_restart, adjust assertions for the new function signature and output message.How to Test
pytest tests/hermes_cli/test_gateway_service.py -k "launchd_restart" -v— all 3 launchd restart tests should pass.hermes gateway restartfrom a fresh terminal. The gateway should log a drain-aware restart (SIGUSR1) rather than an immediate SIGTERM.gateway.logfor drain completion messages).Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/hermes_cli/test_gateway_service.py -qand all launchd tests pass (systemd tests fail pre-existing on macOS)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/Ahasattr(signal, 'SIGUSR1'), returns False on WindowsCode Intelligence
launchd_restart()inhermes_cli/gateway.py(callers: 2 —gateway restartCLI andhermes updateflow)_graceful_restart_via_sigusr1()(callers: 2 —systemd_restartand nowlaunchd_restart)systemd_restartsystemd_restart()at line 2645 uses the same_graceful_restart_via_sigusr1(pid, drain_timeout + 5)pattern. The+5buffer is not needed for launchd becauselaunchctl kickstarthandles the relaunch after exit.