-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
macOS LaunchAgent KeepAlive=true restarts after clean already-running gateway exit #82250
Copy link
Copy link
Open
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.Crash, hang, restart loop, or process-level availability failure.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.maturity:stableIssue affects a taxonomy feature currently scored M4/M5.Issue affects a taxonomy feature currently scored M4/M5.
Description
Metadata
Metadata
Assignees
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.Crash, hang, restart loop, or process-level availability failure.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.maturity:stableIssue affects a taxonomy feature currently scored M4/M5.Issue affects a taxonomy feature currently scored M4/M5.
Type
Fields
Priority
None yet
Summary
On macOS with OpenClaw 2026.5.12, the generated LaunchAgent uses
KeepAlive=true. If a foreground/manual gateway already owns the configured port, starting the LaunchAgent causes the service process to detect the existing healthy gateway, exit cleanly with code 0, and then launchd restarts it again. This can create repeated gateway startup/shutdown churn even though there is no config or runtime crash.This looks like the macOS equivalent of the supervisor restart-cascade behavior discussed in #80696, and the local workaround matches the proposed direction in #73849.
Environment
2026.5.12 (f066dd2)22.22.018789What happened
A foreground/manual gateway was running with:
The LaunchAgent was installed with:
Running
openclaw gateway startloaded the LaunchAgent.The LaunchAgent process started, noticed the existing gateway on
18789, and exited cleanly. Logs showed repeated entries like:Because
KeepAlive=truerestarts after any exit, including successful exit, launchd kept starting another gateway process roughly every throttle interval.This produced a loop of launchd-owned gateway attempts while the foreground gateway continued to own the port.
Clean local test
I patched the local LaunchAgent plist from:
KeepAlive = trueto:
Then I reran
openclaw gateway startwhile the foreground gateway still owned18789.Observed result after 30 seconds:
The foreground gateway remained healthy, and the LaunchAgent did not keep restarting.
Expected behavior
If the gateway process exits cleanly because it detected an already-running healthy gateway, launchd should not keep restarting it forever.
Actual behavior
With
KeepAlive=true, launchd restarts after clean exit code 0, creating avoidable churn and making recovery/handoff/debugging much harder.Suggested fix
Generate the macOS LaunchAgent with:
instead of
KeepAlive=true, as proposed in #73849.Related issues/PRs: