Skip to content

[Bug]: LaunchAgent KeepAlive: true causes restart loop when App and launchd both manage gateway lifecycle #20257

@Seraphim0916

Description

@Seraphim0916

Summary

When both LaunchAgent (KeepAlive: true) and the App's GatewayLaunchAgentManager manage the gateway lifecycle, they conflict — causing a restart loop, duplicate processes, and 100% CPU.

Steps to reproduce

  1. Install OpenClaw and start the App (macOS, Apple Silicon)
    1. App runs GatewayLaunchAgentManager → installs LaunchAgent with KeepAlive: true → kickstart gateway
    1. Close and reopen the App
    1. App runs ensure gateway → kickstart again, even though LaunchAgent already has gateway running
    1. Observe: two openclaw-gateway processes running simultaneously, CPU at 100%
      Additionally, App sends SIGUSR1 to gateway every 8-11 minutes with no config change (see [Bug]: OpenClaw.app (desktop) triggers periodic SIGUSR1 gateway restarts #10600), which combined with KeepAlive: true causes continuous restart loop.

Expected behavior

App opens → detects if gateway is running → if already running via LaunchAgent, does NOT kickstart again. Only one gateway process runs at a time. LaunchAgent KeepAlive should use SuccessfulExit: true so intentional stops are respected.

Actual behavior

Two openclaw-gateway processes run simultaneously, consuming ~100% CPU. Gateway repeatedly restarts (PID changes every few seconds). App UI shows gateway going up/down continuously. CPU only returns to normal after closing the App.

Log signature:

[gateway] signal SIGUSR1 received
[gateway] received SIGUSR1; restarting
[ws] unauthorized role: node (repeated every second)

Root cause: KeepAlive: true in LaunchAgent causes launchd to restart gateway whenever App's kickstart stops it. Combined with App's periodic SIGUSR1 signals (#10600), creates a continuous restart loop.

Suggested fix:

  1. Change plist KeepAlive from true to { SuccessfulExit: true } — only restart on crash, not on intentional stop
    1. Add ThrottleInterval: 5 to prevent exponential backoff on crash loops (Gateway crashes with EPIPE on LaunchAgent restart, causes exponential throttle #4632)
    1. App's GatewayLaunchAgentManager should check if gateway is already running before kickstart
      Reference: colima/issues/1490 (same KeepAlive conflict pattern)

OpenClaw version

v0.9.14 (gateway)

Operating system

macOS 15 (Sequoia), Apple Silicon (M4 Max)

Install method

npm global

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

Related issues: #10600 (App sends periodic SIGUSR1), #4632 (EPIPE crash + exponential backoff, ThrottleInterval suggestion)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions