← Back to PRs

#19573: fix(infra): detect OpenClaw service env vars in supervisor hint check

by heyhudson open 2026-02-17 23:55 View on GitHub →
size: XS trusted-contributor
## Summary `restartGatewayProcessWithFreshPid()` should avoid spawning a child when the gateway is already managed by a supervisor (launchd/systemd), and instead exit so the supervisor restarts it. Today, supervised detection in `src/infra/process-respawn.ts` can miss OpenClaw-managed services because it only checked native supervisor env hints (`LAUNCH_JOB_LABEL`, `INVOCATION_ID`, etc.). On macOS in particular, launchd does not reliably provide `LAUNCH_JOB_LABEL` to child environments. OpenClaw already injects its own service markers (`OPENCLAW_LAUNCHD_LABEL`, `OPENCLAW_SYSTEMD_UNIT`) in service env setup (`src/daemon/service-env.ts`), but those were not considered during respawn detection. That mismatch can cause a false "not supervised" result, leading to detached self-spawn while the supervisor also restarts, which creates duplicate gateway processes and port contention. ## What Changed ### Supervised restart detection for OpenClaw-managed services - `src/infra/process-respawn.ts`: Added `OPENCLAW_LAUNCHD_LABEL` and `OPENCLAW_SYSTEMD_UNIT` to `SUPERVISOR_HINT_ENV_VARS`. - `src/infra/process-respawn.test.ts`: Updated `clearSupervisorHints()` to clear both new env vars. - Added explicit tests that each env var triggers `mode: "supervised"` and avoids spawning. ## Design Notes This keeps the current lightweight heuristic approach (env-based hints) instead of adding platform-specific process inspection. The tradeoff is that detection still depends on env correctness, but now it aligns with the env contract OpenClaw itself establishes during service installation, which is the most reliable signal for managed deployments. ## Testing - `pnpm vitest run src/infra/process-respawn.test.ts` (Result: `1` file passed, `6` tests passed) ## AI Disclosure - [x] AI-assisted - [x] Fully tested ## Related Issues - #21685 - #14161 - #14315 - #21995 - #19521 --- Closes #21073 Closes #22257

Most Similar PRs