Skip to content

Cherry-pick 792ce7b: fix: detect managed launchd/systemd services in process respawn#1162

Merged
alexey-pelykh merged 1 commit intomainfrom
cherry-pick/792ce7b-detect-service-respawn
Mar 13, 2026
Merged

Cherry-pick 792ce7b: fix: detect managed launchd/systemd services in process respawn#1162
alexey-pelykh merged 1 commit intomainfrom
cherry-pick/792ce7b-detect-service-respawn

Conversation

@alexey-pelykh
Copy link
Copy Markdown

Cherry-pick from upstream

Upstream commit: 792ce7b
Author: taw0002
Tier: PICK (needs rebrand)

fix: detect OpenClaw-managed launchd/systemd services in process respawn

Rebranded OPENCLAW_LAUNCHD_LABEL, OPENCLAW_SYSTEMD_UNIT, OPENCLAW_SERVICE_MARKER env vars to REMOTECLAW_* prefix. Updated test values accordingly.

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

(cherry picked from commit 792ce7b)
@alexey-pelykh alexey-pelykh merged commit 5c94215 into main Mar 13, 2026
7 checks passed
@alexey-pelykh alexey-pelykh deleted the cherry-pick/792ce7b-detect-service-respawn branch March 13, 2026 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants