Skip to content

fix(desktop): screen capture starts seconds after launch instead of 30-60s (launch-anchored warmup) - #9021

Merged
Git-on-my-level merged 1 commit into
BasedHardware:mainfrom
eulicesl:fix/desktop-capture-startup-delay
Jul 4, 2026
Merged

Git-on-my-level merged 1 commit into
BasedHardware:mainfrom
eulicesl:fix/desktop-capture-startup-delay

Conversation

@eulicesl

@eulicesl eulicesl commented Jul 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Problem: since [codex] Improve desktop startup warmup performance #8013, the home-screen "Capture" pill stays paused for 30–60+ seconds after every launch before screen capture starts. StartupWarmupPolicy.proactiveAssistantsStartDelay (30s) is applied as a fixed delay from whatever event triggers scheduling, not from launch — so a launch with cached keys waits 30s, a launch whose API keys load late waits key-load + 30s (~40–60s), and re-activating the app (reason: "app active", e.g. right after granting Screen Recording) waits a fresh 30s even minutes after launch. For a product whose core feature is capturing your screen, the first half-minute of every session is silently lost.
  • What changed: the warmup delay is now a launch-anchored budget — remainingProactiveAssistantsStartDelay(elapsedSinceLaunch:) returns max(0, delay − elapsed), so the delay is paid once per session, not once per trigger — and the budget is reduced from 30s to 6s. A Scheduling screen analysis start in Xs (reason) log line makes the effective delay observable.
  • What did NOT change (scope boundary): the staged-warmup ordering from [codex] Improve desktop startup warmup performance #8013 is preserved — capture still starts strictly after initialSettingsSyncDelay (5s) so a remote screenAnalysisEnabled=false lands before monitoring starts, and still after deferredWarmupDelay (2s). Both existing ordering tests pass unchanged. No other warmup delays are touched.

Linked Issue / Bounty

Root Cause (bug fixes only)

  • Root cause: [codex] Improve desktop startup warmup performance #8013 introduced proactiveAssistantsStartDelay = 30.0 and scheduleProactiveMonitoringStart() passes it verbatim to scheduleSessionWarmup on every trigger (launch, key load, app active). The delay's purpose is to keep capture out of the busy launch window, but measuring it from the trigger instead of from launch makes late triggers re-pay the full 30s.
  • Why it wasn't caught before: [codex] Improve desktop startup warmup performance #8013 was validated with policy unit tests and build checks ("without changing product behavior"); the pill-stays-paused effect only shows up when running the app and watching the first minute. Verified on production v0.12.0 (which contains both [codex] Improve desktop startup warmup performance #8013 and the later paywall launch fix): capture consistently starts ~30s after window appear.

How It Works

StartupWarmupPolicy.remainingProactiveAssistantsStartDelay(elapsedSinceLaunch:) computes the remaining launch-anchored budget (clamping negative elapsed to the full delay). DesktopHomeView captures a proactiveMonitoringWarmupAnchor = Date() when the view is created (≈ launch) and passes the computed remainder to scheduleSessionWarmup. Behavior by scenario:

Scenario Before After
Launch, keys cached 30s 6s
Launch, keys load at +9s ~39s 9s (budget already elapsed → starts at key load)
Slow key fetch (e.g. +30s) ~60s at key load
App re-activation (e.g. after permission grant) +30s immediate

Change Type

  • Bug fix

Scope

  • Desktop app (Swift/macOS)

Security Impact

  • New permissions or capabilities introduced? No
  • Auth or token handling changed? No
  • Data access scope changed (screen data, OCR, user data)? No — capture still requires the same permission and enabled setting; it just starts sooner
  • New or changed network calls? No
  • Plugin or tool execution surface changed? No

Testing

  • Built locally — xcrun swift build -c debug --package-path Desktop, clean (macOS 26.5.1, arm64)
  • Manual verification: launch/key-load/app-active timing on a named bundle (see Human Verification)
  • Existing tests pass — StartupWarmupPolicyTests (including the two ordering invariants that pin capture after settings sync and deferred warmup)
  • New tests added — 4 cases covering the anchored-budget helper: full delay at elapsed 0, countdown mid-window, zero after the window, negative-elapsed clamp

Human Verification

Verified on a dedicated named bundle (com.omi.omi-verify-capture) built from this branch, signed in, macOS 26.5.1:

  • Verified scenarios:
    1. Launch with permission granted: capture running 5.5s after the main window appeared (Scheduling screen analysis start in 5.2s (launch) → Screen analysis started (launch, delayed)), versus +30.4s measured on production v0.12.0.
    2. Launch-anchoring: the scheduled delay is the launch budget minus elapsed time (logged 5.2s/5.4s across launches depending on view-appear latency), and the start attempt consistently fired at launch+6s.
    3. Permission still gates correctly: with Screen Recording not yet granted, the launch+6s attempt entered the existing dialog-free retry loop and left the setting enabled; after granting in System Settings, the next launch started capture at +5.5s and macOS registered active capture usage for the bundle (ScreenCaptureApprovals.plist LastUsed).
  • Edge cases checked: trigger arriving after the window has fully elapsed (app-active → 0.0s delay); re-launch repeats the 6s budget per session.
  • What was not verified: Intel macs; the key load trigger with a genuinely slow network fetch (exercised the code path via the anchored computation instead).

Evidence

  • Log output (before/after)

Production v0.12.0 (before — fixed 30s from window appear):

[13:33:09.220] DesktopHomeView: Showing mainContent (signed in and onboarded)
[13:33:18.221] DesktopHomeView: API keys loaded — retrying deferred services
[13:33:39.612] DesktopHomeView: Screen analysis started (launch, delayed)   ← +30.4s

This branch (after):

[19:06:38.366] DesktopHomeView: Showing mainContent (signed in and onboarded)
[19:06:38.410] DesktopHomeView: Scheduling screen analysis start in 5.2s (launch)
[19:06:43.830] DesktopHomeView: Screen analysis started (launch, delayed)      ← +5.5s

Permission-missing launch on the same build (retry loop intact, timing unchanged):

[18:56:41.588] DesktopHomeView: Scheduling screen analysis start in 5.4s (launch)
[18:56:47.320] Screen recording permission not yet granted, retrying in 2.0s (attempt 1/3)

Docs

  • N/A — no docs impact (changelog fragment added)

Performance, Privacy, and Reliability

Launch performance: capture-start work now runs at +6s instead of +30s. This sits after the first-window render and the 5s settings sync; the heavier startup warmups (crispInitialPoll 15s, agentVMProvisioning 20s, initialFileIndexing 45s) remain untouched, so launch responsiveness — the goal of #8013 — is preserved. If capture start measurably contends at +6s, the constant is a single knob to tune; the launch-anchoring fix stands on its own regardless of the chosen value.

Migration / Backward Compatibility

  • Backward compatible? Yes
  • Migration needed? No

Risks and Mitigations

  • Risk: starting capture at +6s could contend with remaining launch work on slow machines.
    • Mitigation: still strictly after settings sync (5s) and deferred warmup (2s); ordering tests enforce this. The 30s value predates any measured contention data for capture specifically.
  • Risk: remote screenAnalysisEnabled=false arriving after capture starts (settings sync slower than 6s on a slow network) would leave monitoring running this session.
    • Mitigation: pre-existing behavior — nothing stops a running monitor on remote-sync disable today, at 30s or 6s; the 5s-before-6s ordering keeps the common case correct. A remote-sync stop hook would be a separable follow-up.

AI Disclosure

  • Tools used: Claude Code
  • AI-assisted portions: diagnosis (production log timeline analysis), fix implementation, tests, and this PR body
  • How you verified correctness: measured the regression on production v0.12.0 logs; built and ran a named bundle from this branch and measured launch→capture-start and app-active→start timings from app logs; ran the warmup-policy test suite.

Review in cubic

…t to 6s

Since BasedHardware#8013, proactiveAssistantsStartDelay (30s) was applied as a fixed
delay from whatever event triggered scheduling (launch, key load, app
active), so late triggers re-paid the full 30s and the Capture pill sat
'paused' for 30-60+ seconds after every launch. Measure the delay as a
launch-anchored budget instead (max(0, delay - elapsedSinceLaunch)) and
reduce it to 6s, keeping capture start strictly after the 5s settings
sync and 2s deferred warmup that BasedHardware#8013's ordering tests pin.
@eulicesl
eulicesl requested a review from Copilot July 4, 2026 23:28
@eulicesl
eulicesl marked this pull request as ready for review July 4, 2026 23:28
@eulicesl eulicesl self-assigned this Jul 4, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adjusts the macOS desktop startup warmup policy so screen capture (“proactive assistants” monitoring) starts promptly after launch by anchoring the warmup delay to a launch-time budget rather than re-applying a full delay on every trigger (launch / key-load / app-active).

Changes:

  • Reduce StartupWarmupPolicy.proactiveAssistantsStartDelay from 30s to 6s and add remainingProactiveAssistantsStartDelay(elapsedSinceLaunch:) to compute a launch-anchored remaining delay budget.
  • Use the remaining-delay helper in DesktopHomeView.scheduleProactiveMonitoringStart(...) and log the effective scheduled delay for observability.
  • Add focused unit tests for the remaining-delay helper and add a desktop changelog fragment.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
desktop/macos/Desktop/Tests/StartupWarmupPolicyTests.swift Adds unit tests covering the new launch-anchored remaining-delay helper.
desktop/macos/Desktop/Sources/StartupWarmupPolicy.swift Reduces proactive-assistants startup delay and introduces remaining-delay computation anchored to launch elapsed time.
desktop/macos/Desktop/Sources/MainWindow/DesktopHomeView.swift Computes/uses remaining delay when scheduling screen analysis start and logs the effective delay.
desktop/macos/changelog/unreleased/20260704-capture-startup-delay.json Documents the user-visible improvement in capture startup timing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 4 files

Confidence score: 5/5

  • In desktop/macos/Desktop/Tests/StartupWarmupPolicyTests.swift, the new test names reference ProactiveMonitoring while they actually validate StartupWarmupPolicy.remainingProactiveAssistantsStartDelay, which risks future confusion or misinterpretation of test intent rather than product behavior; this looks safe to merge, but renaming the four methods to match ProactiveAssistants would de-risk maintenance.

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@Git-on-my-level
Git-on-my-level merged commit 5e6d1d1 into BasedHardware:main Jul 4, 2026
2 checks passed
eulicesl added a commit to eulicesl/omi-fork that referenced this pull request Jul 5, 2026
…nology

Post-merge review feedback on BasedHardware#9021: the four anchored-delay tests used
'ProactiveMonitoring' while the API and the rest of the suite say
'ProactiveAssistants' (StartupWarmupPolicy.remainingProactiveAssistantsStartDelay).
Rename-only; no behavior change.
eulicesl added a commit that referenced this pull request Jul 5, 2026
…nology (#9077)

## Summary

Addresses the post-merge Copilot/cubic review feedback on #9021: the
four anchored-delay tests were named
`testProactiveMonitoringRemainingDelay…` while the API they exercise is
`StartupWarmupPolicy.remainingProactiveAssistantsStartDelay` and the
rest of the suite uses the ProactiveAssistants terminology. Rename-only
— no behavior change.

## Testing

`xcrun swift test --package-path Desktop --filter StartupWarmupPolicy` →
40 tests, 0 failures (all four renamed tests pass).

## AI Disclosure

Authored and verified with Claude Code; ran the filtered suite locally
after the rename.

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/9077?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
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.

3 participants