Skip to content

Comments

fix(macos): prevent gateway launchd race condition on startup#387

Closed
gupsammy wants to merge 1 commit intoopenclaw:mainfrom
gupsammy:fix/macos-gateway-launchd-race-306
Closed

fix(macos): prevent gateway launchd race condition on startup#387
gupsammy wants to merge 1 commit intoopenclaw:mainfrom
gupsammy:fix/macos-gateway-launchd-race-306

Conversation

@gupsammy
Copy link
Contributor

@gupsammy gupsammy commented Jan 7, 2026

Summary

Fixes #306 - macOS app menubar icon disappears + gateway launchd start timeout.

Root cause: Race condition during startup where:

  1. launchd starts the gateway service on login (via KeepAlive)
  2. Mac app starts shortly after
  3. Mac app's GatewayLaunchAgentManager.set(enabled: true, ...) unconditionally calls launchctl bootout → kills the just-started gateway
  4. Then calls launchctl bootstrap to start it again
  5. If the gateway wasn't fully ready, the Mac app can't attach and retries, causing a loop

Changes:

  • GatewayLaunchAgentManager.swift: Skip bootout if service is already running; add launchctl enable calls to ensure auto-start on login

Test plan

  • Verified gateway auto-starts on login via launchd
  • Mac app detects running gateway and logs "launchd service already running, skipping bootout"
  • Gateway survives Mac app startup and health checks pass
  • Tested across multiple restarts

AI-assisted

🤖 This PR was developed with Claude Code assistance. The fix was iteratively debugged and tested on a real macOS system.

🤖 Generated with Claude Code

@gupsammy gupsammy force-pushed the fix/macos-gateway-launchd-race-306 branch from 6a3c809 to 677c5c2 Compare January 7, 2026 12:41
@steipete
Copy link
Contributor

steipete commented Jan 7, 2026

Thanks Samarth! That's some great digging here. Welcome to the Clawtributors! Say hi on Discord!

@steipete steipete added the bug Something isn't working label Jan 7, 2026
@steipete steipete self-assigned this Jan 7, 2026
@steipete
Copy link
Contributor

steipete commented Jan 7, 2026

Landed on main via integration branch (rebased on 0e98371).

Included commits:

Local gate:

  • pnpm lint && pnpm build && pnpm test
  • (macOS) swift test --disable-xctest

@steipete steipete closed this Jan 7, 2026
@gupsammy gupsammy deleted the fix/macos-gateway-launchd-race-306 branch January 8, 2026 10:00
dgarson added a commit to dgarson/clawdbot that referenced this pull request Feb 9, 2026
…law#387)

- Add preserveRunningForJobIds option to recomputeNextRuns() to prevent
  stuck-run cleanup from clearing running markers on jobs that are still
  claimed and waiting to execute in the same batch
- Fix heartbeat status check: 'error' → 'failed' to match actual API
- Add comprehensive regression test suite (10 tests) covering:
  - Schedule change recalculation
  - Force mode execution
  - Isolated job wake time scheduling
  - allowUnsafeExternalContent persistence on payload patches
  - Far-future schedule timer delay capping
  - Hot-loop prevention while run in progress
  - Manual run skip while timer-triggered run active
  - wakeMode now → queued heartbeat degradation when busy
  - Per-job start time and duration for batched jobs
  - Claimed running markers not cleared mid-batch after long jobs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS app menubar icon disappears + gateway launchd start timeout

2 participants