Repository navigation
Description
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
- Run the gateway under a system-domain LaunchDaemon at
/Library/LaunchDaemons/ai.openclaw.gateway.plist(KeepAlive=true), listening on port 18789. - From a user session, run
openclaw gateway install(oropenclaw gateway install --force). - Observe a second registration created at
~/Library/LaunchAgents/ai.openclaw.gateway.plist(gui-domain), same label and port, also KeepAlive=true. - 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 installis 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 runinstallto "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.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Jun 27, 2026
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:
canonicalCanonical: #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:
fixed_by_candidate: fix(daemon): refuse duplicate launchd gateway managers #97285 - It explicitly targets this issue and implements the cross-domain duplicate-manager guard.partial_overlap: gateway install/status hardcodes ~/Library/LaunchAgents — prevents boot-without-login on macOS #51860 - It also concerns system/user launchd detection but requests system installation and boot-without-login support beyond this bug.partial_overlap: [Feature]: Improve gateway stop/uninstall to handle system-level LaunchDaemons #14251 - It concerns stop and uninstall support for system daemons, which is a broader lifecycle problem.same_root_cause: fix: gateway avoids duplicate macOS launchd services #97296 - It proposed a similar guard but was closed unmerged, so it is not a safe canonical replacement.Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.
Maintainer decision needed
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:
Codex review notes: model internal, reasoning high; reviewed against 313daad5496a.
Label changes
Label changes:
P1: The reported deterministic duplicate supervisor state can make the gateway flap and disconnect active clients.clawsweeper:linked-pr-open: Current issue advisory state selects this label.clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.clawsweeper:needs-product-decision: Current issue advisory state selects this label.P2: Current review triage priority is P1, so this older priority label is no longer current.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:
src/daemon/launchd.ts,src/daemon/launchd.test.ts,src/cli/daemon-cli/launchd-recovery.test.ts)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.prasithg commentedon Jun 27, 2026
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, andgateway statusis blind to it — which is the precise trigger that leads an operator into adding a duplicategui-domainLaunchAgent.Environment
2026.6.10(CLI + gateway version-matched)/Library/LaunchDaemons/ai.openclaw.gateway.plist(root)Observed live — the gateway is up and launchd-supervised:
PPID 1= supervised by launchd (the system LaunchDaemon), port listening, healthy.The trigger —
gateway statusonly probesgui/$UID, so it declares the service uninstalled and tells you to install it:So an operator (or a repair/automation path) following the tool's own advice runs
openclaw gateway install/doctor --repair. Becauseinstalllikewise doesn't detect the system-domain daemon, it writes and bootstraps a second manager — agui-domainLaunchAgent— on top of the already-running systemLaunchDaemon.Result: two launchd managers both own and (with
KeepAlive) relaunch the gateway on the same port18789. 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):
LaunchDaemonin/Library/LaunchDaemons/(the workable model for a headless, SSH-administered box —gui/$UIDcan't be bootstrapped from SSH with no Aqua session).openclaw gateway status→ note it reportsLaunchAgent (not loaded)/Service not installed/Run: openclaw gateway install, despite the daemon running and the port listening (thegui: <uid>domain miss shown above).openclaw gateway install(ordoctor --repair) as the tool suggests → it adds agui-domainLaunchAgentalongside the system daemon.18789→ restart storm / crash-loop.What I did not do: I did not run
openclaw gateway installon this production host, because it would re-trigger the storm live and take the box down. The precondition (running system daemon +statusfalse-negative steering toinstall) is captured above; the duplicate-manager creation is whatinstall's bootstrap does by design when it can't see the system daemon.Suggested fix direction: before declaring "not installed" or writing a
guiLaunchAgent,status/install/doctorshould also probe the system domain (launchctl print system/ai.openclaw.gateway). If a systemLaunchDaemonalready manages the port,statusshould report it as loaded/running andinstallshould refuse or merge rather than add a secondgui-domain manager. A documented--systeminstall mode for headless hosts would also prevent operators from being routed into the duplicate-manager state.openclaw-barnacle commentedon Jul 12, 2026
This issue has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.
prasithg commentedon Jul 12, 2026
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
statusfalse-negative is unchanged on this headless macOS host (Apple Silicon, SSH-administered, no GUI login session). The gateway is up and supervised by a systemLaunchDaemon(/Library/LaunchDaemons/ai.openclaw.gateway.plist,PPID 1, listening on18789), yet:So
status/install/doctorstill only probegui/$UIDand never the system domain, which is exactly what steers an operator (or an automated repair path) into runningopenclaw gateway installand creating a duplicategui-domainLaunchAgenton top of the running system daemon → dueling supervisors on port18789→ restart storm.Fix direction from the earlier comment still stands: probe
launchctl print system/ai.openclaw.gatewaybefore declaring "not installed" / writing aguiLaunchAgent, and offer a documented--systeminstall mode for headless hosts. Happy to test a patch on this box.openclaw-barnacle commentedon Jul 27, 2026
This issue has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.
prasithg commentedon Jul 27, 2026
Still relevant — please keep open.
Confirmed on
2026.7.1-2. I can't re-run a freshgateway installrepro 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).