Skip to content

fix(macos): remote-mode profile reports a Gateway uninstall failure when it has no local service - #164069

Merged
steipete merged 1 commit into
mainfrom
fix/macos-remote-profile-stop-teardown
Oct 3, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/macos-remote-profile-stop-teardown

Conversation

@steipete

@steipete steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: launching the macOS app in remote connection mode under a named profile runs openclaw gateway uninstall for a local service that profile never installed, and reports a Gateway failure when that no-op uninstall is refused.

User Impact

User impact: a remote-mode (or unconfigured) profile with no local Gateway LaunchAgent no longer spawns service teardown on launch or shows a spurious "Gateway daemon command failed" status. Profiles that do own an installed LaunchAgent still have it paused/removed exactly as before. No config, migration, or user action.

Why This Change Was Made

Root cause

ConnectionModeCoordinator.apply calls GatewayProcessManager.stop() on every remote/unconfigured launch. With service hosting, stop() captures this profile's service authority; when ~/Library/LaunchAgents/ai.openclaw.<profile>.plist does not exist, retainManagedServiceForResume returns it unchanged, and GatewayLaunchAgentManager.set(enabled: false) still dispatched openclaw --profile <name> gateway uninstall --json. The CLI target itself was correctly profile-scoped (the app strips OPENCLAW_LAUNCHD_LABEL and pins OPENCLAW_PROFILE), but with nothing to boot out it still took the service-operation lock and read the shared, install-scoped managed-update-handoffs.sqlite guard. A row there that this build cannot decode made the uninstall fail, and stop() then marked the remote profile's Gateway as failed.

Audit of what each launch path touches under a named profile (2026-10-02 field logs):

Log Resource Scope Verdict
[gateway.process] gateway stop requested → [gateway.launchd] launchd disable requested via CLI ai.openclaw.<profile> LaunchAgent, its service-lifecycle lock profile correctly scoped, but ran with nothing installed → fixed
Gateway uninstall failed: existing managed handoff lease is incompatible managed-update-handoffs.sqlite (read-only guard, keyed by install root) per install, shared by profiles refusal held; no longer reached from a profile with no service
[PeekabooBridge] Failed to start PeekabooBridge host: ... already owned by another host ~/Library/Application Support/OpenClaw/bridge.sock per user by design (Peekaboo clients discover it at a fixed path) Peekaboo's flock'd lease refuses a live owner without touching it → log clarified
[portguard] PortGuardian persistence unavailable; orphan reap skipped ~/Library/Application Support/OpenClaw/state/openclaw.sqlite tunnel ledger host-global by design; reaps only tunnels whose parent is pid 1 or this app refusal is the legacy-app guard → log names the ledger and blocking app

The global node service (ai.openclaw.node) is already skipped under named profiles.

Fix

  • GatewayLaunchAgentManager.set(enabled: false) returns without dispatching when the captured custody has no plist for this profile (after the existing currency, custody, and disable-marker checks). stop() is its only caller. The only state no longer booted out by stop is a loaded job whose plist was deleted out of band; the CLI's own install/uninstall never leaves that state.
  • Logs now say what they target: stop names profile and hosting, enable/disable name the LaunchAgent label, the Peekaboo shared-socket refusal is an info-level "served by another host; shared by all OpenClaw profiles", and PortGuardian names the shared ledger path and the legacy app's pid/bundle id.

Evidence

  • New named-profile regression AppStateIsolationTests/named remote profile stop leaves other profiles' Gateway services alone (runs in CI's named partition): remote config, a default-profile LaunchAgent present, every CLI command failing with the field error. Asserts no service command, status .stopped, no failure reason, default plist bytes unchanged.
  • pause preserves unretainable services and distinguishes absence now asserts no uninstall for the absent case. Lifecycle tests that relied on uninstall-without-plist now write a managed LaunchAgent for the current profile, keeping their original assertions.
  • Focused native runs on the macOS host inside a sandbox derived from scripts/macos-health-render.sb (no network, no reads of the real home, no writes outside a throwaway root and the per-user Darwin temp dir, cfprefsd/securityd denied):
    • with the guard removed: named regression fails all three behavior assertions (uninstall dispatched, .failed, lease error as failure reason); absent case fails; the 9 re-fixtured lifecycle tests pass.
    • with the fix: named regression passes; 10/10 focused GatewayProcessManagerTests pass.
  • swift build --package-path apps/macos --build-system native --build-tests and --product OpenClaw: pass.
  • Changed-file swiftlint --strict --config config/swiftlint.yml (sources): clean. Changed-file swiftformat --lint --config config/swiftformat: 0/6. git diff --check: clean.
  • Codex autoreview (local mode, direct route): scoped-clean, zero findings at any priority ("patch is correct", 0.98).
  • Full native suite: this PR's macos-swift CI job (default + named partitions).

Remote and unconfigured connection modes call GatewayProcessManager.stop()
on every launch. With service hosting and no LaunchAgent plist for the
current profile, stop() still dispatched `openclaw gateway uninstall`. The
CLI target was profile-scoped, but the no-op uninstall still took the
service-operation lock and read the shared install-scoped handoff lease
store; a row it could not decode made the uninstall fail and marked the
remote profile's Gateway as failed.

GatewayLaunchAgentManager.set(enabled: false) now returns without
dispatching when the captured custody has no plist for this profile.
Stop/enable/disable logs name the profile and LaunchAgent label, the
PeekabooBridge shared per-user socket refusal logs at info level, and
PortGuardian names its host-global ledger and the blocking legacy app.
@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 3, 2026 06:03
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 3, 2026
@clawsweeper

clawsweeper Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 2:08 AM ET / 06:08 UTC.

ClawSweeper review

What this changes

The macOS app skips Gateway uninstall when the current profile has no LaunchAgent plist, clarifies shared-resource diagnostics, and updates lifecycle regression tests.

Merge readiness

✅ Ready for maintainer review

Keep open: current main still has the reported failure path, and this focused repair has no actionable correctness finding. The author’s verified repository-admin role also excludes automatic cleanup.

Priority: P2
Reviewed head: e448c6c3154be25d32df8e83260470203d504625

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and no identified blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: Verified repository-admin authorship exempts the ordinary contributor proof gate. The reported sandboxed native tests exercise GatewayProcessManager.stop with intercepted CLI responses, providing supplemental regression evidence; no real launchd run was independently executed. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Verified repository-admin authorship exempts the ordinary contributor proof gate. The reported sandboxed native tests exercise GatewayProcessManager.stop with intercepted CLI responses, providing supplemental regression evidence; no real launchd run was independently executed. No stored-data contract changes.
Evidence reviewed 11 items Introduced change and merge ownership: The pinned merge-base-to-head diff introduces the absent-plist guard and diagnostic/test changes. The verified test merge contains the same six-file change against its main parent; base-branch drift is not attributed to this PR.
Existing safeguards remain intact: The new return follows the currency callback, current service-definition check, and disable-marker check. Installed services still use runDaemonCommand, which revalidates custody before process spawn. The patch does not introduce transferable authority or broaden which profiles can perform teardown.
Current-main necessity: At fetched main, the disable branch still dispatches uninstall after its existing checks without testing whether the captured plist is absent. ConnectionModeCoordinator reaches stop for remote profiles without local hosting, and stop publishes CLI errors as failed status.
Findings None None.
Security None None.

How this fits together

The macOS app translates connection and hosting choices into local Gateway lifecycle operations. Its LaunchAgent manager dispatches profile-scoped CLI commands and reports their results back to the app.

flowchart TD
  A[Connection mode] --> B[Gateway lifecycle manager]
  B --> C[Capture profile service files]
  C --> D{LaunchAgent plist present?}
  D -->|No| E[Remain stopped without uninstall]
  D -->|Yes| F[Validate custody and dispatch uninstall]
  F --> G[Publish stopped or failure status]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Other +118. Total +118 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 6 153 35 +118
Total 6 153 35 +118

Review metrics

None.

Technical review

Best possible solution:

Keep service teardown conditional on current profile service custody while preserving installed-service pause/resume and shared-resource ownership checks.

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

Yes, source establishes that stopping a service-hosted profile without a plist still dispatches uninstall and publishes any CLI refusal as failure. No runtime reproduction was executed during this read-only review.

Is this the best way to solve the issue?

Yes, the guard belongs in the existing LaunchAgent owner and preserves validation and installed-service teardown without adding another lifecycle path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0c96fd043ab3.

Labels

Label changes:

  • add P2: This repairs a bounded macOS profile lifecycle error that produces spurious Gateway failure status.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Verified repository-admin authorship exempts the ordinary contributor proof gate. The reported sandboxed native tests exercise GatewayProcessManager.stop with intercepted CLI responses, providing supplemental regression evidence; no real launchd run was independently executed. No stored-data contract changes.

Label justifications:

  • P2: This repairs a bounded macOS profile lifecycle error that produces spurious Gateway failure status.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Verified repository-admin authorship exempts the ordinary contributor proof gate. The reported sandboxed native tests exercise GatewayProcessManager.stop with intercepted CLI responses, providing supplemental regression evidence; no real launchd run was independently executed. No stored-data contract changes.

Evidence

What I checked:

  • Introduced change and merge ownership: The pinned merge-base-to-head diff introduces the absent-plist guard and diagnostic/test changes. The verified test merge contains the same six-file change against its main parent; base-branch drift is not attributed to this PR. (apps/macos/Sources/OpenClaw/GatewayLaunchAgentManager.swift:281, e448c6c3154b)
  • Existing safeguards remain intact: The new return follows the currency callback, current service-definition check, and disable-marker check. Installed services still use runDaemonCommand, which revalidates custody before process spawn. The patch does not introduce transferable authority or broaden which profiles can perform teardown. (apps/macos/Sources/OpenClaw/GatewayLaunchAgentManager.swift:274, e448c6c3154b)
  • Current-main necessity: At fetched main, the disable branch still dispatches uninstall after its existing checks without testing whether the captured plist is absent. ConnectionModeCoordinator reaches stop for remote profiles without local hosting, and stop publishes CLI errors as failed status. (apps/macos/Sources/OpenClaw/GatewayLaunchAgentManager.swift:276, 0c96fd043ab3)
  • Latest-release check: Pinned source from the supplied latest release also dispatches uninstall unconditionally in the disable branch. This repair is not already present in that release. (apps/macos/Sources/OpenClaw/GatewayLaunchAgentManager.swift:210, fc23bc864e45)
  • Regression coverage: The named-profile regression checks no daemon dispatch, stopped status, no failure reason, and unchanged default-profile plist bytes. Existing tests now supply installed-service fixtures where teardown is required, retaining custody, restart ordering, and remote-mode removal assertions. The body reports baseline failures and after-fix passes; these intercepted-CLI runs are supplemental tests, not real launchd execution. (apps/macos/Tests/OpenClawIPCTests/AppStateIsolationTests.swift:12, e448c6c3154b)
  • Recorded scope tradeoff: The PR body explicitly acknowledges that stop no longer boots out a loaded job whose plist was deleted out of band. The change preserves installed-service teardown, existing preferences, resume records, and update guards; it introduces no persisted-format change. (apps/macos/Sources/OpenClaw/GatewayLaunchAgentManager.swift:281, e448c6c3154b)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • 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.

@steipete
steipete merged commit 95529b5 into main Oct 3, 2026
129 of 130 checks passed
@steipete
steipete deleted the fix/macos-remote-profile-stop-teardown branch October 3, 2026 06:24
@steipete

steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
…penclaw#164069)

Remote and unconfigured connection modes call GatewayProcessManager.stop()
on every launch. With service hosting and no LaunchAgent plist for the
current profile, stop() still dispatched `openclaw gateway uninstall`. The
CLI target was profile-scoped, but the no-op uninstall still took the
service-operation lock and read the shared install-scoped handoff lease
store; a row it could not decode made the uninstall fail and marked the
remote profile's Gateway as failed.

GatewayLaunchAgentManager.set(enabled: false) now returns without
dispatching when the captured custody has no plist for this profile.
Stop/enable/disable logs name the profile and LaunchAgent label, the
PeekabooBridge shared per-user socket refusal logs at info level, and
PortGuardian names its host-global ledger and the blocking legacy app.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: macos App: macos P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant