Skip to content

fix(macos): first-run gateway startup survives state migrations - #121012

Merged
steipete merged 2 commits into
mainfrom
steipete/gateway-firstrun-tolerance
Aug 9, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/gateway-firstrun-tolerance

Conversation

@steipete

@steipete steipete commented Aug 9, 2026

Copy link
Copy Markdown
Contributor
Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.

What Problem This Solves

Fixes an issue where fresh macOS onboarding could report “The Gateway didn’t start” while healthy first-run state integrity checks and migrations were still running.

The reproduced sequence was:

01:29:47 [ai.openclaw:gateway.launchd] Gateway daemon command failed (timeout): [state/db] state database schema migration pending; verifying integrity first
01:30:01 [ai.openclaw:gateway.process] gateway readiness wait timed out; preserving existing failure
01:30:12 node-host worker stderr: [state-migrations] Auto-migrated legacy state: ... (migration finished fine 11s AFTER the app already gave up)

Why This Change Was Made

The Mac app owned shorter watchdogs than the CLI startup-migration lifecycle it launched: daemon mutations were killed after 15–20 seconds, fresh-install readiness stopped after 60 seconds, and onboarding’s follow-up health audit stopped after 12 seconds. One named 120-second first-run tolerance now governs daemon mutations, fresh-install readiness, and onboarding’s bounded follow-up audit.

The readiness waiter now continues with its own health re-check when the startup owner finishes with a prior failure, while preserving cancellation and generation guards. This avoids duplicating the CLI’s startup-migration lease policy or adding IPC. After the full budget expires, the existing visible error remains unchanged.

The CLI-page activation path was also checked against the attach-only marker and already honors ~/.openclaw/disable-launchagent; it does not bypass the marker.

User Impact

Fresh macOS setup now waits for legitimate first-run migration work and proceeds as soon as Gateway health becomes ready, instead of manufacturing a setup failure while migration is still making progress. Truly stalled starts remain bounded and keep the existing retryable error.

Evidence

  • cd apps/macos && swift build — passed (Build complete! (36.82s)).
  • swift test --filter GatewayProcessManagerTests — 41 tests passed, including owner failure followed by bounded readiness recovery.
  • swift test --filter GatewayLaunchAgentManagerTests — 9 tests passed.
  • swift test --filter CLIInstallerTests — 20 tests passed.
  • swiftformat --lint on all five touched Swift files — clean.
  • node scripts/check-changed.mjs -- <changed files> — passed on Blacksmith Testbox; 5 Vitest shards passed and the native-state schema guard remained at v6.
  • Autoreview — clean, no accepted/actionable findings.
  • Production Swift delta: +14/-10 (net +4); tests: +14/-7 (net +7); changelog: +1.

@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 9, 2026 08:57
@openclaw-barnacle openclaw-barnacle Bot added app: macos App: macos size: XS maintainer Maintainer-authored PR labels Aug 9, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 9, 2026
@clawsweeper

clawsweeper Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 9, 2026, 5:48 AM ET / 09:48 UTC.

ClawSweeper review

What this changes

The PR gives macOS Gateway launch commands, first-run readiness polling, and onboarding activation a 120-second migration allowance and retries readiness after a failed startup owner.

Merge readiness

⛔ Blocked by patch quality or review findings - 9 items remain

Keep this maintainer PR open: it addresses a real macOS first-run failure, but the proposed shared timeout both remains shorter than the core migration lease and unintentionally lengthens shutdown blocking.

Priority: P1
Reviewed head: f401b01fa229357d9f70211831d00b92999169e5

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch has useful validation context but two availability regressions must be repaired before it is quality-ready.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer-owned PR; its body supplies focused build and test evidence, while the remaining blockers are source-proven lifecycle defects rather than missing contributor proof.
Patch quality 🧂 unranked krab (1/6) 3 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-owned PR; its body supplies focused build and test evidence, while the remaining blockers are source-proven lifecycle defects rather than missing contributor proof.
Evidence reviewed 5 items Current main still needs the repair: Current macOS code retains the 12-second activation wait, 15-second daemon-command default, 20-second restart timeout, first-install six-second grace windows, and immediate false return from the startup owner.
Core migration contract exceeds the new fixed cap: Core restart health conditionally honors an active startup-migration lease for up to five minutes, and its regression test covers successful health after 140 seconds; a fixed 120-second macOS ceiling is therefore not equivalent to the owner policy.
Shared default reaches shutdown: The proposed default timeout is used by the disable path; GatewayProcessManager deliberately waits for that pending disable before allowing a later local start, so a stuck uninstall would block recovery for 120 seconds.
Findings 3 actionable findings [P1] Honor the active migration lease instead of a fixed 120-second cap
[P1] Keep the uninstall timeout separate from first-run startup
[P3] Remove the release-owned changelog entry
Security None None.

How this fits together

macOS onboarding starts the local Gateway through launchd and waits for its health endpoint. Core startup may perform state integrity work and migrations before that endpoint is ready, while the app must also preserve bounded stop-to-start lifecycle transitions.

flowchart LR
  A[macOS onboarding] --> B[Gateway launch command]
  B --> C[Core state migration lease]
  C --> D[Gateway health endpoint]
  D --> E[Mac readiness waiter]
  E --> F[Setup success or retryable failure]
Loading

Before merge

  • Honor the active migration lease instead of a fixed 120-second cap (P1) - The new fixed budget can still fail a healthy 121–300 second migration, while core restart health explicitly waits on the renewable startup-migration lease and tests a 140-second success. Make this waiter follow that owner policy or prove a safe equivalent bound.
  • Keep the uninstall timeout separate from first-run startup (P1) - Changing the shared daemon-command default also gives uninstall 120 seconds. A later local start deliberately awaits the pending disable task, so a stuck shutdown now blocks recovery far longer even though it cannot be waiting for startup migration work.
  • Remove the release-owned changelog entry (P3) - This normal fix PR adds a release changelog line, but repository policy reserves CHANGELOG.md for release generation; retain the release-note context in the PR body instead.
  • Resolve merge risk (P1) - A permanently unhealthy first run can consume the startup-owner wait and then a separate readiness recheck, so the stated 120-second tolerance is not yet demonstrated as an end-to-end failure bound.
  • Resolve merge risk (P1) - The current tests use synthetic sub-second budgets and do not cover an active migration beyond 120 seconds or update-triggered activation callers.
  • Complete next step (P2) - This protected maintainer PR has concrete repair blockers, but selecting the macOS-to-core lease integration belongs with the lifecycle owner.
  • Improve patch quality - Replace the fixed cap with the authoritative migration-lease policy and add a migration-over-120-seconds regression.
  • Improve patch quality - Keep uninstall on its short timeout and add a stop-to-start stalled-uninstall regression.
  • Improve patch quality - Remove the release-owned changelog change.

Findings

  • [P1] Honor the active migration lease instead of a fixed 120-second cap — apps/macos/Sources/OpenClaw/GatewayProcessManager.swift:702-708
  • [P1] Keep the uninstall timeout separate from first-run startup — apps/macos/Sources/OpenClaw/GatewayLaunchAgentManager.swift:237-240
  • [P3] Remove the release-owned changelog entry — CHANGELOG.md:68
Agent review details

Security

None.

PR surface

Docs +1, Other +11. Total +12 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 5 28 17 +11
Total 6 29 17 +12

Review metrics

Metric Value Why it matters
Production versus test delta production Swift +14/-10; tests +14/-7 The small production increase changes the lifecycle timeout contract and needs the named first-run ownership justification.
First-run timeout policy 3 waiting surfaces changed to 120 seconds Daemon commands, readiness polling, and onboarding activation must remain consistent with the core migration owner.

Merge-risk options

Maintainer options:

  1. Scope and align the migration allowance (recommended)
    Make macOS wait according to the active core migration lease, and pass the longer allowance only to install or restart operations while preserving the shutdown timeout.
  2. Accept a fixed macOS cap
    Retain the 120-second cap only with explicit maintainer acceptance that legitimate longer core migrations may still fail macOS onboarding.

Technical review

Best possible solution:

Use the core migration lease as the authoritative first-run policy, scope any longer timeout to startup operations only, and retain the short bounded timeout for uninstall and other shutdown work.

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

Yes: source establishes both a legitimate core migration lease beyond 120 seconds and a stop-to-start path that waits for a pending uninstall task; focused regression tests can inject those two conditions.

Is this the best way to solve the issue?

No: a fixed shared 120-second default is not the core lease-backed policy and also applies to shutdown; the longer allowance must be scoped to startup operations and aligned with the owner lease.

Full review comments:

  • [P1] Honor the active migration lease instead of a fixed 120-second cap — apps/macos/Sources/OpenClaw/GatewayProcessManager.swift:702-708
    The new fixed budget can still fail a healthy 121–300 second migration, while core restart health explicitly waits on the renewable startup-migration lease and tests a 140-second success. Make this waiter follow that owner policy or prove a safe equivalent bound.
    Confidence: 0.94
  • [P1] Keep the uninstall timeout separate from first-run startup — apps/macos/Sources/OpenClaw/GatewayLaunchAgentManager.swift:237-240
    Changing the shared daemon-command default also gives uninstall 120 seconds. A later local start deliberately awaits the pending disable task, so a stuck shutdown now blocks recovery far longer even though it cannot be waiting for startup migration work.
    Confidence: 0.95
  • [P3] Remove the release-owned changelog entry — CHANGELOG.md:68
    This normal fix PR adds a release changelog line, but repository policy reserves CHANGELOG.md for release generation; retain the release-note context in the PR body instead.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 135278c8968f.

Labels

Label changes:

  • add P1: The PR targets a false first-run Gateway failure, but its remaining cap can still block onboarding during a healthy migration and its shared default can delay Gateway recovery.
  • add merge-risk: 🚨 availability: Changing launchd command and Gateway readiness timeouts can delay or incorrectly fail local Gateway availability.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🌊 off-meta tidepool and patch quality is 🧂 unranked krab.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This is a maintainer-owned PR; its body supplies focused build and test evidence, while the remaining blockers are source-proven lifecycle defects rather than missing contributor proof.

Label justifications:

  • P1: The PR targets a false first-run Gateway failure, but its remaining cap can still block onboarding during a healthy migration and its shared default can delay Gateway recovery.
  • merge-risk: 🚨 availability: Changing launchd command and Gateway readiness timeouts can delay or incorrectly fail local Gateway availability.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🌊 off-meta tidepool and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This is a maintainer-owned PR; its body supplies focused build and test evidence, while the remaining blockers are source-proven lifecycle defects rather than missing contributor proof.

Evidence

What I checked:

  • Current main still needs the repair: Current macOS code retains the 12-second activation wait, 15-second daemon-command default, 20-second restart timeout, first-install six-second grace windows, and immediate false return from the startup owner. (apps/macos/Sources/OpenClaw/GatewayProcessManager.swift:698, 135278c8968f)
  • Core migration contract exceeds the new fixed cap: Core restart health conditionally honors an active startup-migration lease for up to five minutes, and its regression test covers successful health after 140 seconds; a fixed 120-second macOS ceiling is therefore not equivalent to the owner policy. (src/cli/daemon-cli/restart-health.ts:379, 7dc4dc83fe8b)
  • Shared default reaches shutdown: The proposed default timeout is used by the disable path; GatewayProcessManager deliberately waits for that pending disable before allowing a later local start, so a stuck uninstall would block recovery for 120 seconds. (apps/macos/Sources/OpenClaw/GatewayLaunchAgentManager.swift:240, 562129d5df37)
  • Current lifecycle ownership: The affected macOS Gateway/onboarding lifecycle was introduced and is currently attributed to the same recent macOS-area history; current main has not absorbed this PR head. (apps/macos/Sources/OpenClaw/CLIInstaller.swift:571, 562129d5df37)
  • Release status: The proposed head is unmerged and no release tag contains it; it is not a shipped fix. (f401b01fa229)

Likely related people:

  • steipete: Recent history and blame tie the launch-agent, readiness, and activation paths to this area’s current implementation. (role: current macOS Gateway and onboarding lifecycle author; confidence: high; commits: 562129d5df37, 167a8ef20a2a, b0a091644f; files: apps/macos/Sources/OpenClaw/GatewayProcessManager.swift, apps/macos/Sources/OpenClaw/GatewayLaunchAgentManager.swift, apps/macos/Sources/OpenClaw/CLIInstaller.swift)

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 self-assigned this Aug 9, 2026
@steipete
steipete merged commit ab5e10f into main Aug 9, 2026
56 checks passed
@steipete
steipete deleted the steipete/gateway-firstrun-tolerance branch August 9, 2026 10:11
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 10, 2026
…claw#121012)

* fix(macos): tolerate first-run state migrations during gateway start

* fix(macos): tolerate loaded-host version probes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: macos App: macos maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant