fix(gateway): relaunch macOS launchd gateway after /restart - #37094
Closed
JiraiyaETH wants to merge 1 commit into
Closed
fix(gateway): relaunch macOS launchd gateway after /restart#37094JiraiyaETH wants to merge 1 commit into
JiraiyaETH wants to merge 1 commit into
Conversation
On macOS, `/restart` selected its restart strategy from `INVOCATION_ID`
(systemd) and `/.dockerenv` (container) only. launchd sets neither, so a
launchd-managed gateway fell through to the detached self-restart path:
the process exits 0, and the generated plist's `KeepAlive{SuccessfulExit:
false}` treats a clean exit as success and never relaunches it. The
detached helper also does not reliably survive under launchd, so
`/restart` could silently leave the gateway down until manual recovery.
Detect launchd via `XPC_SERVICE_NAME` (the launchd analog of
`INVOCATION_ID`; it is "0" for shell-launched processes) and route those
restarts through the existing service path, which already exits 75 on
darwin so `KeepAlive` relaunches it. An intentional `gateway stop` (clean
exit 0) still stays down, and bare-process restarts still use the
detached path. No plist change is required.
Adds unit coverage: launchd -> via_service=True; bare process -> detached.
Refs NousResearch#29180, NousResearch#9659, NousResearch#35043
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
4 tasks
Contributor
|
Thanks for the precise macOS launchd investigation. This is an automated hermes-sweeper review; the requested behavior is already on current
The original implementation was 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.
Problem
On macOS, sending
/restartto a launchd-managed gateway can leave it dead until manual recovery._handle_restart_commandselects its restart strategy fromINVOCATION_ID(systemd) and/.dockerenv(container) only:launchd sets neither variable, so a LaunchAgent-managed gateway takes the
elsebranch: it spawns a detached helper and exits 0. The generated plist usesKeepAlive{SuccessfulExit: false}, which treats a clean exit as success and does not relaunch — and the detached helper does not reliably survive under launchd. Net:/restartsilently kills the gateway.This is the macOS manifestation behind #29180, #9659, and #35043.
Fix
Detect launchd via
XPC_SERVICE_NAME— the launchd analog of systemd'sINVOCATION_ID(set to the job label for managed jobs,"0"for shell-launched processes) — and route those restarts through the existingvia_service=Truepath, which already exits75on darwin soKeepAliverelaunches:No plist change required — the macOS exit-75 path already exists; this just lets launchd-managed gateways reach it.
Preserved behavior
gateway stop(clean exit 0) still stays down.XPC_SERVICE_NAME) still use the detached path.Testing
Adds two cases to
tests/e2e/test_platform_commands.py:request_restart(detached=False, via_service=True)XPC_SERVICE_NAME="0") →request_restart(detached=True, via_service=False)Refs #29180, #9659, #35043