Skip to content

[Bug]: openclaw gateway install adds a duplicate gui-domain LaunchAgent over an existing system LaunchDaemon (restart storm) #97178

Closed

Description

@prasithg

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

On a host where the gateway is managed by a system-domain LaunchDaemon, openclaw gateway install registers a second, gui-domain LaunchAgent for the same label/port; the two KeepAlive managers then fight and restart-loop the gateway, dropping all connected clients.

Steps to reproduce

  1. Run the gateway under a system-domain LaunchDaemon at /Library/LaunchDaemons/ai.openclaw.gateway.plist (KeepAlive=true), listening on port 18789.
  2. From a user session, run openclaw gateway install (or openclaw gateway install --force).
  3. Observe a second registration created at ~/Library/LaunchAgents/ai.openclaw.gateway.plist (gui-domain), same label and port, also KeepAlive=true.
  4. Observe the gateway restart every few seconds and clients disconnect.

Expected behavior

openclaw gateway install detects an existing registration of the same label in any domain (both system/ and gui/<uid>, i.e. /Library/LaunchDaemons and ~/Library/LaunchAgents) and refuses, warns, or offers to replace it, rather than silently adding a conflicting duplicate.

Actual behavior

A second gui-domain LaunchAgent is created for the same label/port. The two KeepAlive managers fight: each freshly launched instance logs service-mode: cleared 1 stale gateway pid before bind on port 18789 and kills the other, and both keepalives respawn it. The gateway flaps every few seconds and webchat clients drop with code=1012 reason=service restart. launchctl print system/ai.openclaw.gateway shows runs= climbing.

OpenClaw version

2026.6.10 (aa69b12)

Operating system

macOS 26.5.1 (Darwin 25.5.0, arm64)

Install method

npm global (/opt/homebrew/lib/node_modules/openclaw); gateway supervised as a system-domain LaunchDaemon.

Model

Not applicable — this is a gateway process-management / install bug, independent of model. (Effective default on the affected host: amazon-bedrock/us.anthropic.claude-opus-4-8.)

Provider / routing chain

Not applicable — the defect is in launchd service registration during gateway install, not in any provider/model request path.

Additional provider/model setup details

NOT_ENOUGH_INFO

Logs, screenshots, and evidence

# Each restarting instance logs this before binding:
service-mode: cleared 1 stale gateway pid before bind on port 18789

# Connected webchat clients drop with:
client disconnect: code=1012 reason=service restart

# launchctl print system/ai.openclaw.gateway shows runs= climbing on each respawn.

# Two registrations exist for the same label/port after `gateway install`:
#   /Library/LaunchDaemons/ai.openclaw.gateway.plist   (system domain, KeepAlive=true)
#   ~/Library/LaunchAgents/ai.openclaw.gateway.plist   (gui domain,    KeepAlive=true)

Impact and severity

  • Affected: any host where the gateway runs as a system-domain LaunchDaemon (e.g. headless boxes with no GUI login session) and gateway install is later run.
  • Severity: High — the restart storm drops all connected clients while it persists.
  • Frequency: deterministic once the duplicate registration is created.
  • Consequence: gateway is unusable (flapping) until the duplicate is removed. It is easy to trigger because user-level launchctl list / launchctl print gui/<uid>/... do not show system-domain jobs, and a system daemon's process legitimately has ppid=1, so an operator can wrongly conclude the gateway is unmanaged/orphaned and run install to "fix" it — which creates the duplicate.

Additional information

Workaround / recovery: remove the duplicate and keep the system daemon — launchctl bootout gui/<uid>/ai.openclaw.gateway then rm ~/Library/LaunchAgents/ai.openclaw.gateway.plist; the single system-daemon-managed instance becomes stable immediately. Suggested guard, in addition to the install-time duplicate check: the "cleared stale pid before bind" path could detect a rapid bind/kill ping-pong and log a clear "duplicate manager detected" error.

Activity

  1. clawsweeper commented on Jun 27, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed July 27, 2026, 7:41 PM ET / 23:41 UTC.

    Summary
    Keep open. This is a concrete gateway availability bug, and the open candidate fix at #97285 explicitly targets it; the issue should remain open until that PR merges or a maintainer chooses a replacement direction.

    Likely related people: harjothkhara is the candidate-fix author (medium confidence); prasithg supplied the live headless-macOS reproduction (high confidence).

    Reproducibility: yes. at source/report level: the reporter gives a concrete headless-macOS system-daemon setup and the linked fix identifies the missing system-domain guard. This review could not execute the macOS launchd scenario locally.

    Root-cause cluster
    Relationship: canonical
    Canonical: #97178
    Summary: This issue is the canonical report for the same-label system-LaunchDaemon and user-LaunchAgent conflict. An open pull request is the candidate repair; related issues request broader lifecycle support.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Maintainer decision needed

    Question Recommendation
    Should OpenClaw land the narrow same-label system LaunchDaemon guard now, or first define full user/system launchd lifecycle support? Land the narrow guard: Prevent user LaunchAgent install, restart, and repair when a same-label system LaunchDaemon owns the gateway, while leaving full lifecycle support to the related issues.

    Why: The immediate duplicate-manager prevention is well scoped, but its fail-closed behavior changes the operator outcome for externally managed system daemons and requires an explicit compatibility decision.

    Next step
    An open pull request already claims this issue with a focused candidate repair; the next action is maintainer review of that implementation and its compatibility policy.

    Review details

    Best possible solution:

    Land a narrow cross-domain ownership guard for install, restart, and recovery, with clear remediation guidance; keep full system LaunchDaemon lifecycle management as separate product work.

    Do we have a high-confidence way to reproduce the issue?

    Yes, at source/report level: the reporter gives a concrete headless-macOS system-daemon setup and the linked fix identifies the missing system-domain guard. This review could not execute the macOS launchd scenario locally.

    Is this the best way to solve the issue?

    Yes for the immediate bug: checking cross-domain ownership before writing or activating a user LaunchAgent is narrower and safer than adding full system-daemon lifecycle support in the same repair.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The candidate fix changes existing externally managed same-label system LaunchDaemon setups from permissive user LaunchAgent activation to a fail-closed error, so maintainers should explicitly accept that compatibility policy before merge.

    Codex review notes: model internal, reasoning high; reviewed against 313daad5496a.

    Label changes

    Label changes:

    • add P1: The reported deterministic duplicate supervisor state can make the gateway flap and disconnect active clients.
    • add clawsweeper:linked-pr-open: Current issue advisory state selects this label.
    • add clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.
    • add clawsweeper:needs-product-decision: Current issue advisory state selects this label.
    • remove P2: Current review triage priority is P1, so this older priority label is no longer current.
    • remove maturity:stable: Current issue review selected no maturity labels.

    Label justifications:

    • P1: The reported deterministic duplicate supervisor state can make the gateway flap and disconnect active clients.
    • impact:crash-loop: Two KeepAlive launchd managers can repeatedly restart gateway processes on the same port.
    • impact:message-loss: Gateway restarts disconnect clients and interrupt message delivery while the conflict persists.
    Evidence reviewed

    What I checked:

    Likely related people:

    • harjothkhara: Authored the open pull request implementing the focused system-daemon conflict guard for this issue. (role: candidate-fix author; confidence: medium; commits: 7437f7faf8e8; files: src/daemon/launchd.ts, src/daemon/launchd.test.ts, src/cli/daemon-cli/launchd-recovery.test.ts)
    • prasithg: Provided detailed headless macOS behavior, including the system-domain status false-negative and resulting duplicate-manager risk. (role: live reproduction reporter; confidence: high)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. added
    P2Normal backlog priority with limited blast radius.
    impact:crash-loopCrash, hang, restart loop, or process-level availability failure.
    impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.
    maturity:stableBroken existing behavior primarily owned by an M4/M5 scorecard surface.
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    on Jun 27, 2026
  3. prasithg commented on Jun 27, 2026

    @prasithg
    Author

    Live repro on a headless macOS host (v2026.6.10)

    Confirming this on a real, always-on headless macOS host (Apple Silicon, administered over remote SSH with no Aqua/GUI login session). The gateway is correctly installed and supervised as a system LaunchDaemon, and gateway status is blind to it — which is the precise trigger that leads an operator into adding a duplicate gui-domain LaunchAgent.

    Environment

    • OpenClaw 2026.6.10 (CLI + gateway version-matched)
    • macOS, Apple Silicon, headless (no GUI login session; managed via SSH)
    • Gateway installed as a system daemon: /Library/LaunchDaemons/ai.openclaw.gateway.plist (root)

    Observed live — the gateway is up and launchd-supervised:

    $ lsof -ti TCP:18789 -sTCP:LISTEN
    94203
    $ ps -o pid,ppid,command -p 94203
      PID  PPID COMMAND
    94203     1 /opt/homebrew/opt/node/bin/node .../openclaw/dist/index.js gateway --port 18789
    

    PPID 1 = supervised by launchd (the system LaunchDaemon), port listening, healthy.

    The trigger — gateway status only probes gui/$UID, so it declares the service uninstalled and tells you to install it:

    $ openclaw gateway status
    Service: LaunchAgent (not loaded)
    ...
    Runtime: unknown (Bad request.
    Could not find service "ai.openclaw.gateway" in domain for user gui: 501)
    Connectivity probe: ok
    ...
    Service unit not found.
    Service not installed. Run: openclaw gateway install   <-- while the daemon is up & supervised
    Listening: 127.0.0.1:18789, [::1]:18789
    

    So an operator (or a repair/automation path) following the tool's own advice runs openclaw gateway install / doctor --repair. Because install likewise doesn't detect the system-domain daemon, it writes and bootstraps a second manager — a gui-domain LaunchAgent — on top of the already-running system LaunchDaemon.

    Result: two launchd managers both own and (with KeepAlive) relaunch the gateway on the same port 18789. They contend for the port and fight each other → restart storm / crash-loop. We hit exactly this dueling-supervisor port contention during a prior incident on this host before cutting fully over to a single system daemon.

    Reproduction steps (on a disposable headless macOS host):

    1. Install/run the gateway as a system LaunchDaemon in /Library/LaunchDaemons/ (the workable model for a headless, SSH-administered box — gui/$UID can't be bootstrapped from SSH with no Aqua session).
    2. openclaw gateway status → note it reports LaunchAgent (not loaded) / Service not installed / Run: openclaw gateway install, despite the daemon running and the port listening (the gui: <uid> domain miss shown above).
    3. Run openclaw gateway install (or doctor --repair) as the tool suggests → it adds a gui-domain LaunchAgent alongside the system daemon.
    4. Both managers now supervise port 18789 → restart storm / crash-loop.

    What I did not do: I did not run openclaw gateway install on this production host, because it would re-trigger the storm live and take the box down. The precondition (running system daemon + status false-negative steering to install) is captured above; the duplicate-manager creation is what install's bootstrap does by design when it can't see the system daemon.

    Suggested fix direction: before declaring "not installed" or writing a gui LaunchAgent, status / install / doctor should also probe the system domain (launchctl print system/ai.openclaw.gateway). If a system LaunchDaemon already manages the port, status should report it as loaded/running and install should refuse or merge rather than add a second gui-domain manager. A documented --system install mode for headless hosts would also prevent operators from being routed into the duplicate-manager state.

  4. openclaw-barnacle commented on Jul 12, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale due to inactivity.
    Please add updates or it will be closed.

  5. prasithg commented on Jul 12, 2026

    @prasithg
    Author

    Not stale — still reproduces on the current beta 2026.7.1-beta.2, and there's been no maintainer response to the live repro above yet.

    The core status false-negative is unchanged on this headless macOS host (Apple Silicon, SSH-administered, no GUI login session). The gateway is up and supervised by a system LaunchDaemon (/Library/LaunchDaemons/ai.openclaw.gateway.plist, PPID 1, listening on 18789), yet:

    $ openclaw gateway status
    Service: LaunchAgent (not loaded)
    Gateway version: 2026.7.1-beta.2
    Runtime: unknown (Bad request.
    Could not find service "ai.openclaw.gateway" in domain for user gui: 501)
    Connectivity probe: ok
    Service not installed. Run: openclaw gateway install   <-- while the daemon is up & supervised
    Listening: 127.0.0.1:18789, [::1]:18789
    

    So status/install/doctor still only probe gui/$UID and never the system domain, which is exactly what steers an operator (or an automated repair path) into running openclaw gateway install and creating a duplicate gui-domain LaunchAgent on top of the running system daemon → dueling supervisors on port 18789 → restart storm.

    Fix direction from the earlier comment still stands: probe launchctl print system/ai.openclaw.gateway before declaring "not installed" / writing a gui LaunchAgent, and offer a documented --system install mode for headless hosts. Happy to test a patch on this box.

  6. openclaw-barnacle commented on Jul 27, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale due to inactivity.
    Please add updates or it will be closed.

  7. prasithg commented on Jul 27, 2026

    @prasithg
    Author

    Still relevant — please keep open.

    Confirmed on 2026.7.1-2. I can't re-run a fresh gateway install repro on the affected box (this host runs a system LaunchDaemon in production, and the install path re-triggers the exact restart storm described here), but the underlying install codepath that adds the gui-domain LaunchAgent alongside an existing system LaunchDaemon is unchanged, and no fix has landed upstream.

    The prior live repro is still the reference: #issuecomment-4818404382.

    Net: the duplicate-manager conflict is not yet resolved, so this shouldn't be auto-closed on staleness. Happy to gather more targeted diagnostics if a maintainer can point at the install-path guard they'd want tested (e.g. detecting a pre-existing system-domain daemon before writing a gui-domain agent).

  8. added
    P1High-priority user-facing bug, regression, or broken workflow.
    clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.
    and removed
    P2Normal backlog priority with limited blast radius.
    maturity:stableBroken existing behavior primarily owned by an M4/M5 scorecard surface.
    on Jul 27, 2026
  9. locked as resolved and limited conversation to collaborators on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper-recovery-stuckclawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-product-decisionClawSweeper 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.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions