Skip to content

fix(desktop): stop capture recovery from restarting the app during onboarding - #11891

Merged
kodjima33 merged 2 commits into
mainfrom
kodjima33/no-auto-restart-during-onboarding
Aug 20, 2026
Merged

kodjima33 merged 2 commits into
mainfrom
kodjima33/no-auto-restart-during-onboarding

Conversation

@kodjima33

@kodjima33 kodjima33 commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

What happened

David's first run on a new Mac (0.12.187 stable, macOS 15.1, Mac16,6): Omi quit by itself several times during onboarding — including on permission pages that have nothing to do with screen recording — and did not come back on its own.

His PostHog session shows it plainly:

21:11:43  App Launched          <- first run
21:12:28  Onboarding How Did You Hear
21:12:49  App Launched          <- quit + relaunch #1
21:13:13  App Launched          <- #2
21:13:34  App Launched          <- #3
21:14:35  Onboarding Completed

Cause

A new Mac has not granted screen recording yet, so every capture attempt fails. ProactiveAssistantsPlugin's failure tracker reads that as a broken install and calls attemptAutoReset(), whose final step is ScreenCaptureService.softRecoveryAndRestart() — it terminates and relaunches the process. The user sees the app vanish mid-permission-page with no explanation.

It repeats because the "already tried recovery this session" flag (hasSoftRecoveryThisSession) is static state in the process that just got killed, so the fresh process is free to do it again.

Fix

ScreenRecordingPermissionPolicy.mayRestartToRecoverCapture(grantedAtLaunch:onboardingComplete:) — the process-killing step now requires both:

  • the grant is live in this process — ScreenCaptureKit binds to the window-server connection opened at launch, so if the grant was not there at launch, no number of restarts can repair it; and
  • onboarding is finished — during onboarding, relaunch belongs to the "Reopen Omi" prompt, which is scoped to screen recording and advances the persisted step first.

Soft recovery still runs; only the restart is withheld, with the reason logged.

Failure-Class: none

Verification

  • Built as omi-onbfix with no screen-recording grant and hasCompletedOnboarding=false — David's exact state. The app held a single pid across the observation window, with no Restart scheduled in its log.
  • swift test --filter ScreenRecordingPermissionPolicyTests — 22 passed, including testCaptureRecoveryNeverRestartsDuringOnboardingOrBeforeTheGrantIsLive and a loop test that models the per-process flag resetting on each relaunch (the reason it happened three times rather than once).

Line-Count-Exception: desktop/macos/Desktop/Sources/ProactiveAssistants/ProactiveAssistantsPlugin.swift | 1786 -> 1798 | the recovery-restart guard plus the log line naming why a restart was withheld; the decision itself lives in ScreenRecordingPermissionPolicy

Review in cubic

…boarding

A new Mac has not granted screen recording yet, so every capture attempt
fails. The failure tracker reads that as a broken install and calls
attemptAutoReset, whose last step terminates and relaunches the process.
Nothing about that is visible to the user: the app simply quits, on
whatever permission page they happen to be on, including permissions that
have nothing to do with screen recording. The 'already recovered once'
flag lives in the process that just died, so the fresh process is free to
do it again — a first-run session on 0.12.187 / macOS 15.1 took three of
these in 45 seconds.

Gate the restart on ScreenRecordingPermissionPolicy.mayRestartToRecoverCapture:
it requires the grant to be live in this process (a restart cannot fix a
grant ScreenCaptureKit never saw) and onboarding to be finished (the
'Reopen Omi' prompt owns relaunch there). Recovery still runs; only the
process-killing last step is withheld, and the reason is logged.

Verification: PostHog session for the affected first run shows App Launched
at 21:11:43, then again at 21:12:49, 21:13:13 and 21:13:34 — three
relaunches between the onboarding steps. Built the fix as omi-onbfix with
no screen-recording grant and onboarding incomplete (that exact state):
the app held one pid across the observation window with no 'Restart
scheduled' in its log. swift test --filter ScreenRecordingPermissionPolicyTests
— 22 passed, including a loop test that models the per-process flag
resetting on every relaunch.

Failure-Class: none
@kodjima33
kodjima33 force-pushed the kodjima33/no-auto-restart-during-onboarding branch from abf68b6 to 32a81b3 Compare August 19, 2026 23:32

@undivisible undivisible left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes

The onboarding guard is focused, but this diff adds and rewrites multiple comments despite the repository rule to preserve existing comments verbatim and add no new comments.

Please

  1. Remove the new explanatory comments from the production policy/plugin and the two new test comments.
  2. Restore any edited existing comments verbatim; leave the policy, tests, and changelog behavior unchanged.

@kodjima33
kodjima33 merged commit 0b61d39 into main Aug 20, 2026
27 of 31 checks passed
@kodjima33
kodjima33 deleted the kodjima33/no-auto-restart-during-onboarding branch August 20, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants