Skip to content

fix(macos): app quits with "Client credentials unavailable" after an in-place update while the previous Gateway service is running - #187000

Merged
RomneyDa merged 4 commits into
openclaw:mainfrom
anmol0b:fix/macos-stale-gateway-credential-startup
Oct 31, 2026
Merged

RomneyDa merged 4 commits into
openclaw:mainfrom
anmol0b:fix/macos-stale-gateway-credential-startup

Conversation

@anmol0b

@anmol0b anmol0b commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Related: #156712

What Problem This Solves

Fixes: the macOS app quits at launch with "Another OpenClaw process is using your data" / "Client credentials unavailable. Run openclaw doctor --fix before reopening the app." when it is updated in place (reproduced from the latest stable, 2026.10.8, and from 2026.10.7) while the previous build's app-managed Gateway LaunchAgent service is still running.

User Impact

User impact: after an in-place update, the app now starts normally. The Gateway service moves to the new build's runtime, client credentials are migrated, and existing config and cron jobs are kept. Users no longer have to run openclaw doctor --fix by hand. Normal launches, where the installed service already matches this build, are unchanged.

Operators who chose their Gateway version keep it: with update.channel = extended-stable or a channel install policy (stable, beta, dev), startup does not replace the service. This is the same gate setup and post-update repair already use. In that case startup behaves as it does today: the credential step can still fail while the old Gateway runs, and replacing the operator-pinned Gateway without consent would be worse. This is an accepted edge case.

Why This Change Was Made

At launch, the app prepares client credentials before anything that replaces the service (ConnectionModeCoordinator.apply, PostUpdateController). Stable builds up to and including 2026.10.8 have no client/credentials.sqlite, so preparation is required. doctor --client-credentials deliberately does not control services: it calls beginDoctorMaintenance({ root: null }), so the stop branch gated on params.root never runs. Its state acquire then runs into the old Gateway's state-ownership lease and throws GatewayStateOwnerContentionError. The app then terminates, so the post-update replacement never runs.

The CLI's own refusals force the order:

  • While the old Gateway runs, both the credential migration and gateway install refuse.
  • After a stop, gateway install still refuses until credentials are migrated ("Client credentials require backed-up migration custody").

At startup the app now detects an app-managed service pinned to a different build's runtime, provided CLIInstallPrompter.managedRepairGatesOpen allows a managed repair. It then:

  1. stops that service with this build's CLI;
  2. prepares credentials;
  3. installs the service on this build's runtime.

Stop, restore and install all carry the service custody captured at detection (expectedServiceAuthority) and recheck serviceUpdateAuthorityError before dispatch. So a service the operator reassigns while this build seeds its runtime or migrates credentials is refused instead of stopped or overwritten.

If credential preparation fails, the app restarts the previous service and the error surfaces as before. If the install fails, the failure is logged and startup continues, because credentials are valid and PostUpdateController still owns the retry. The CLI is unchanged.

Stopping only, without the install, was tried and rejected. Credentials migrated, but the app then kept retrying "gateway ensuring launchd" through the stale stable CLI, and the Gateway stayed down.

Evidence

Reproduction from the latest stable (isolated profile p178719; never the live ai.openclaw.gateway or ~/.openclaw).

  • Start: the official notarized OpenClaw-2026.10.8-arm64.dmg (sha256 7974be75…a3e899), with its app-managed service seeded with a custom timezone and a cron job.
  • Replace the .app bundle in place with the candidate build and launch it, with no manual steps.
  • Both candidates are ad-hoc packaged from this branch merged with current main (2026.10.8). The control build has the four changed files reverted.

Before the fix (main, 2026.10.8), red:

## before (stable 2026.10.8)
service bun: ~/.openclaw-p178719/runtime/2026.10.8-release-5413218d77df-2026-10-27T20-43-42.000Z/bin/bun
client credentials db: absent
timezone: Asia/Kolkata
proof cron: 1
stable Gateway still listening: pid 47099

## after replacing the bundle in place (180s)
service bun: ~/.openclaw-p178719/runtime/2026.10.8-release-5413218d77df-2026-10-27T20-43-42.000Z/bin/bun
listener pid: 47099
runtime dir: 2026.10.8-release-5413218d77df-2026-10-27T20-43-42.000Z current
client credentials db: absent
app log (credentials):
  credentials: Credential startup failed: Could not prepare local client credentials. [openclaw] The CLI command failed.
  [openclaw] Another OpenClaw process is using your data. Wait for it to finish before trying again.
  credentials: Client credentials unavailable. Run openclaw doctor --fix before reopening the app.

After the fix, green (first run at 396f68c; rerun at 3f4cc92 with detection-time custody, same result: service moved in 20 s, credentials present, timezone and cron kept, control channel connected):

## before (stable 2026.10.8)
service bun: ~/.openclaw-p178719/runtime/2026.10.8-release-5413218d77df-2026-10-27T20-43-42.000Z/bin/bun
client credentials db: absent
timezone: Asia/Kolkata
proof cron: 1
stable Gateway still listening: pid 19672

## after replacing the bundle in place (21s)
service bun: ~/.openclaw-p178719/runtime/2026.10.8-396f68ca0a72-2026-10-28T21-27-38.000Z/bin/bun
listener pid: 20188
app running: 19977
client credentials db: present
timezone: Asia/Kolkata
proof cron: 1
app log (credentials, control channel):
  credentials: Replacing the previous build's Gateway service before credential preparation
  control: control channel state -> degraded: Cannot reach gateway at localhost:29871 (old service stopped, new one starting)
  control: control channel state -> connected
  control: control channel recovery finished
  control: control channel state -> connected

Service reassigned after detection, through real process dispatch. These runs use the same isolated seeded upgrade from stable 2026.10.8, with an app packaged from clean 3f4cc925 (build 2026.10.8-3f4cc9259730-…, release configuration, no DEBUG interception). Partway through startup, an "operator" rewrites ~/Library/LaunchAgents/ai.openclaw.p178719.plist: same label, plus an EnvironmentVariables.OPENCLAW_PROOF_OPERATOR key. The rewrite is triggered by real effects, not sleeps.

Before stop. The trigger is the new build's runtime seed directory appearing, which happens after detection read the service. The operator also reloads the service:

## before (stable 2026.10.8, app quit, service running)
listener pid: 58900
plist sha: 3f9a0009d361d32c
client credentials db: absent
## in-place update
new build began seeding its runtime at +10s
reassigned at +10s: plist sha a15c66fc996d5df8
operator service loaded: listener pid 59937, launchd env marker 1
## app outcome (+20s)
plist sha: a15c66fc996d5df8 (operator wrote a15c66fc996d5df8)
service bun: ~/.openclaw-p178719/runtime/2026.10.8-release-5413218d77df-2026-10-27T20-43-42.000Z/bin/bun
launchd env marker: 1
listener pid: 59937
client credentials db: absent
  credentials: Replacing the previous build's Gateway service before credential preparation
  credentials: Credential startup failed: The Gateway service changed before dispatch; retry.
  credentials: Client credentials unavailable. Run openclaw doctor --fix before reopening the app.

The operator's service is not stopped: the same pid is still listening and the plist is unchanged. Startup then ends in the existing credential-recovery surface. This is the accepted edge case: an operator who reassigns the service during startup gets "retry", and their service is left alone.

After credential preparation, before install. The trigger is the old Gateway's listener going away after the app's stop:

## in-place update
old Gateway stopped by the app at +25s
reassigned at +25s: plist sha a15c66fc996d5df8
## app outcome (+33s)
plist sha: a15c66fc996d5df8 (operator wrote a15c66fc996d5df8)
service bun: ~/.openclaw-p178719/runtime/2026.10.8-release-5413218d77df-2026-10-27T20-43-42.000Z/bin/bun
client credentials db: present
  credentials: Replacing the previous build's Gateway service before credential preparation
  credentials: Stale Gateway service replacement failed: The Gateway service changed before dispatch; retry.

Credentials are migrated, the install is refused, and the operator's plist bytes are kept. The service is not moved to the new runtime.

The same flow starting from stable 2026.10.7 was also red on main (443530a) and green with the first commit, twice: the service moved to the new runtime in 20 s, and the timezone and cron job survived.

Tests: swift test --filter "stale service replacement keeps|StaleGatewayServiceReplacementTests|ClientCredentialStartupTests|UpdateOrchestrationTests" passes (35 tests, at 3f4cc92). The new tests pin:

  • a service reassigned after detection being refused before dispatch (The Gateway service changed before dispatch; retry., no daemon command recorded), while an unchanged service gets exactly stop --force. This test fails without the captured authority: the reassigned service receives the stop;
  • the order stop → credentials → install;
  • a credential failure leading to restore instead of install;
  • a refused stop skipping credential preparation;
  • detection admitting the default and exact policies, and rejecting extended-stable, beta and stable.

Not covered:

  • The restore path (credential preparation failing after the stop) is unit-tested only. One packaged attempt reloaded the operator's service right after the stop so that preparation would contend. The reload did not come up before the migration took the state, so that run repeated the before-install refusal instead: plist kept, credentials present.
  • After the install refusal, the app's existing ensuring launchd retries (a later owner) ran through the installed stable CLI and failed. They did not rewrite the operator's plist.
  • Remote mode with a local companion Gateway is excluded by the .local gate and was not exercised.
  • The policy rejection was unit-tested through detection, not run end to end.
  • Local packaging needed a temporary, uncommitted change that skips Finder .DS_Store files in src/infra/package-dist-inventory.ts. A stray dist/.DS_Store otherwise breaks the inventory/tarball check. This touches build tooling only, not the app code under test.

An in-place app update leaves the previous build's app-managed Gateway service running. Its state lease makes this build's client credential migration fail, so the app quit before post-update replacement ran. Startup now stops the stale service, prepares credentials, then installs the service on this build's runtime.
@clawsweeper

clawsweeper Bot commented Oct 28, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: macos App: macos size: S labels Oct 28, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 28, 2026
@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The macOS app replaces an eligible previous-build Gateway service before preparing client credentials during startup.

Example: Replace OpenClaw 2026.10.8 in place while its app-managed Gateway service is running.

  • Before: Credential preparation encounters the running Gateway’s state lease, and the app quits with “Client credentials unavailable.”
  • After: The app stops the eligible service, prepares credentials, installs its bundled runtime, and reconnects while preserving Asia/Kolkata and the existing cron job.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, focused repair with packaged upgrade and production authority-boundary evidence, preserved operator policy, and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Packaged Mac app traces cover an isolated upgrade from stable 2026.10.8, credential creation, runtime replacement, retained timezone and cron data, and control-channel reconnection, with a reported rerun at the reviewed head. Clean release-build traces at that head demonstrate reassignment invalidating custody before stop and before install, resolving the previous DEBUG-only evidence gap. Restore-on-preparation-failure remains unit-tested; its unchanged shared final-dispatch custody checks are covered by the production rejection scenarios.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: After an in-place update with the previous app-managed Gateway still running, the Mac app exits before it can complete automatic credential migration.
Reason: Automatic startup recovery restores the documented upgrade behavior while retaining existing ownership and update-policy boundaries.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

Keep this PR: it fixes a current macOS upgrade failure, addresses the earlier policy and custody findings, and now supplies production-path reassignment evidence; no actionable introduced defect remains.

Priority: P0
Reviewed head: 3f4cc9259730651a38f64fd7800c526ec2b409f4

Before merge

None.

Findings

None.

Agent review details

How this fits together

Native app startup calls the bundled CLI’s credential migration owner before admitting credential consumers; the new orchestration uses existing Gateway service owners to release state custody and publish the replacement runtime.

flowchart TD
 A[Mac app startup] --> B[Inspect service and update policy]
 B --> C[Stop eligible previous service]
 C --> D[Prepare client credentials]
 D --> E[Install bundled Gateway runtime]
 D --> F[Restore previous service on failure]
 E --> G[Continue startup and health recovery]
Loading

Technical review

Best possible solution:

Land the focused startup ordering repair using the existing migration, service-custody, update-policy, and post-update recovery owners.

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

Current-main startup ordering and Doctor’s root-gated service handling support the reported contention path, corroborated by the author’s packaged stable-upgrade control; no target code was executed during this review.

Is this the best way to solve the issue?

The smallest complete repair must release the eligible old service before credential migration and install the matching runtime afterward; this implementation reuses the existing owners without adding configuration or changing operator-selected update policy.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Native credential startup and bundled Gateway documentation keeps the original intent (5f40d22: Automatically prepare credentials through the matching bundled runtime before native admission, preserving existing identities and keeping service management outside the migration owner.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +116, Tests +84, Docs +3. Total +203 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 2 119 3 +116
Tests 2 84 0 +84
Docs 1 4 1 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 207 4 +203

Labels

Label changes:

No label changes.

Label justifications:

  • P0: An ordinary in-place Mac app update can prevent launch and require terminal-based credential recovery, blocking a community user without an in-product way forward.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-28T20:12:00.012Z sha 965fb58 :: needs real behavior proof before merge. :: [P1] Honor the existing update policy before replacing the service
  • reviewed 2026-10-28T22:10:40.416Z sha 396f68c :: needs changes before merge. :: [P1] Retain the detected service's authority through replacement
  • reviewed 2026-10-29T06:44:55.738Z sha 3f4cc92 :: needs real behavior proof before merge. :: none

Reviewed October 29, 2026, 4:12 AM ET / 08:12 UTC (Revision 4).

…ice replacement

Startup replacement now uses the managed repair gate shared with setup and post-update repair, so extended-stable and channel install policies keep their Gateway.
@anmol0b

anmol0b commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 28, 2026
…cement

Stop, restore and install now carry the service authority captured at detection and recheck the managed update authority before dispatch, so a service the operator reassigns while this build seeds or migrates is refused instead of stopped.
@anmol0b

anmol0b commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Oct 29, 2026
@clawsweeper clawsweeper Bot removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 29, 2026
@anmol0b

anmol0b commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 29, 2026
@roboclaw-bot roboclaw-bot added the clawtributors PR from a clawtributor label Oct 29, 2026
@RomneyDa
RomneyDa merged commit 96ceb48 into openclaw:main Oct 31, 2026
118 of 121 checks passed
@anmol0b
anmol0b deleted the fix/macos-stale-gateway-credential-startup branch October 31, 2026 09:24
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 1, 2026
…in-place update while the previous Gateway service is running (openclaw#187000)

* fix(macos): replace stale Gateway service before credential startup

An in-place app update leaves the previous build's app-managed Gateway service running. Its state lease makes this build's client credential migration fail, so the app quit before post-update replacement ran. Startup now stops the stale service, prepares credentials, then installs the service on this build's runtime.

* fix(macos): keep operator-selected Gateway versions during stale service replacement

Startup replacement now uses the managed repair gate shared with setup and post-update repair, so extended-stable and channel install policies keep their Gateway.

* fix(macos): keep detected Gateway service custody through stale replacement

Stop, restore and install now carry the service authority captured at detection and recheck the managed update authority before dispatch, so a service the operator reassigns while this build seeds or migrates is refused instead of stopped.
tideclaw-bot added a commit that referenced this pull request Nov 5, 2026
Carry the reviewed Peekaboo snapshot ownership, stale-service startup,
remote dashboard base-path, requester reconnect, timeout outcome, typed
authentication, and predecessor-stop attribution fixes. Keep Android Talk
and the stable-Bun service cutover separate until main-first disposition.

Adapted source provenance:
- #172116: 7861f59
- #187000: 96ceb48
- #185141: 292d171
- #180200: e937051
- #180247: 054516f
- #128175: e83fcca
- #187104: f8d52ec

Reviewed patch: 745077ecb0347992e605b58a42d2f82becb46c350b0c7d7de449f90d055110ff
All 69 postimages verified; 67 reuse the reviewed corrected full candidate.
Existing focused evidence retained; full release qualification remains pending.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: macos App: macos clawtributors PR from a clawtributor docs Improvements or additions to documentation P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

3 participants