fix: /restart uses via_service=True on launchd (macOS)#33393
Conversation
macOS launchd does not set INVOCATION_ID, so /restart was falling through to the detached restart path (exit code 0) instead of the service-aware restart path (exit code 75). Use XPC_SERVICE_NAME as the launchd indicator — it is set by launchd for all managed jobs and survives across process lifetimes.
|
Confirming this fix from production use, not just a manual test. We've been running the exact same two-line change (
One adjacent gap worth a separate fix (not this PR): |
|
Follow-up to my earlier confirmation: the handler this patches has since moved to |
Problem
On macOS, Hermes Gateway runs under launchd. When a user sends
/restart, the gateway checks forINVOCATION_ID(systemd) or container files to decide whether to use service-aware restart (exit code 75) vs detached restart (exit code 0).launchd does not set
INVOCATION_IDand macOS is not a container, so/restartfell through to the detached path —SystemExit(0)— which launchd does not restart from.Fix
Detect launchd via
XPC_SERVICE_NAME, which launchd injects into all managed jobs. When present, usevia_service=Trueso the gateway exits with code 75 and launchd'sKeepAlive → SuccessfulExit: falsepolicy restarts it immediately.Verification
Manual test confirmed:
/restartnow triggers launchd auto-restart on macOS.