fix: detect OpenClaw-managed launchd/systemd services in process respawn#27655
Merged
steipete merged 1 commit intoopenclaw:mainfrom Feb 26, 2026
Merged
Conversation
restartGatewayProcessWithFreshPid() checks SUPERVISOR_HINT_ENV_VARS to decide whether to let the supervisor handle the restart (mode=supervised) or to fork a detached child (mode=spawned). The existing list only had native launchd vars (LAUNCH_JOB_LABEL, LAUNCH_JOB_NAME) and systemd vars (INVOCATION_ID, SYSTEMD_EXEC_PID, JOURNAL_STREAM). macOS launchd does NOT automatically inject LAUNCH_JOB_LABEL into the child environment. OpenClaw's own plist generator (buildServiceEnvironment in service-env.ts) sets OPENCLAW_LAUNCHD_LABEL instead. So on stock macOS LaunchAgent installs, isLikelySupervisedProcess() returned false, causing the gateway to fork a detached child on SIGUSR1 restart. The original process then exits, launchd sees its child died, respawns a new instance which finds the orphan holding the port — infinite crash loop. Fix: add OPENCLAW_LAUNCHD_LABEL, OPENCLAW_SYSTEMD_UNIT, and OPENCLAW_SERVICE_MARKER to the supervisor hint list. These are set by OpenClaw's own service environment builders for both launchd and systemd and are the reliable supervised-mode signals. Fixes openclaw#27605
Contributor
Greptile SummaryFixes crash loop on macOS LaunchAgent installs by detecting OpenClaw-managed service environments.
Confidence Score: 5/5
Last reviewed commit: 38d0362 |
Contributor
3 tasks
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
restartGatewayProcessWithFreshPid()checksSUPERVISOR_HINT_ENV_VARSto decide whether to let the supervisor handle the restart (mode=supervised) or fork a detached child (mode=spawned). The existing list only included native launchd vars (LAUNCH_JOB_LABEL,LAUNCH_JOB_NAME) and systemd vars (INVOCATION_ID,SYSTEMD_EXEC_PID,JOURNAL_STREAM).macOS launchd does NOT automatically inject
LAUNCH_JOB_LABELinto the child environment. OpenClaw's own plist generator (buildServiceEnvironmentinservice-env.ts) setsOPENCLAW_LAUNCHD_LABELinstead.So on stock macOS LaunchAgent installs:
isLikelySupervisedProcess()returnsfalse(no native launchd env vars)Fix
Add
OPENCLAW_LAUNCHD_LABEL,OPENCLAW_SYSTEMD_UNIT, andOPENCLAW_SERVICE_MARKERtoSUPERVISOR_HINT_ENV_VARS. These are set by OpenClaw's own service environment builders for both launchd and systemd, making them the reliable supervised-mode signals.Tests
OPENCLAW_LAUNCHD_LABEL,OPENCLAW_SYSTEMD_UNIT, andOPENCLAW_SERVICE_MARKERFixes #27605