Repository navigation
Scope desktop startup warmups to user sessions - #8159
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5169e7f57d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| .onReceive(NotificationCenter.default.publisher(for: NSApplication.willTerminateNotification)) { _ in | ||
| log("DesktopHomeView: app terminating — cancelling startup warmups") | ||
| resetSessionScopedStartupWarmups() |
There was a problem hiding this comment.
Don't clear Crisp state during normal termination
When a signed-in user quits, this new termination handler calls resetSessionScopedStartupWarmups(), which calls CrispManager.shared.stop(); that method removes the persisted crisp_lastSeenTimestamp/crisp_latestOperatorTimestamp, and the next start() initializes a zero last-seen value to “now”. Any operator messages sent while the app is closed are therefore treated as already seen on the next launch and won't produce the unread badge/notification, regressing the persisted unread behavior. Use a cancel-only path on termination, or only clear Crisp timestamps on sign-out.
Useful? React with 👍 / 👎.
| onCancel: { initialFileIndexingBackfill.releaseReservation() } | ||
| ) { | ||
| log("DesktopHomeView: Running delayed background file scan for existing user") | ||
| await FileIndexerService.shared.backgroundRescan() | ||
| guard !Task.isCancelled else { | ||
| initialFileIndexingBackfill.releaseReservation() | ||
| return | ||
| } | ||
| guard await AuthState.shared.isSignedIn else { | ||
| initialFileIndexingBackfill.releaseReservation() | ||
| return | ||
| } | ||
| initialFileIndexingBackfill.markScanCompleted() |
There was a problem hiding this comment.
Recheck the session after file indexing finishes
This refactor moves the initial file-indexing backfill into the session warmup wrapper, but that wrapper only validates the session before invoking the operation. The previous code rechecked cancellation/sign-in after backgroundRescan() before setting hasCompletedFileIndexing; now if the user signs out or switches accounts while a long rescan is in progress, the canceled task can still resume and mark the global completion flag for the new/current session. Please recheck the captured session or cancellation after the rescan before mutating UserDefaults.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
4 issues found across 6 files
Confidence score: 2/5
- In
desktop/macos/Desktop/Sources/MainWindow/DesktopHomeView.swift,scheduleSessionWarmupno longer re-checks cancellation/sign-in state afterbackgroundRescan()before writingUserDefaults, so a canceled or signed-out session can still persist warmup state and cause incorrect startup behavior for the next session — restore the post-rescanTask.isCancelledandAuthState.shared.isSignedInguards before merging. - In
desktop/macos/Desktop/Sources/StartupWarmupCoordinator.swift, unconditional cleanup ofsessionTasks[id]can let an older canceled task remove a newer replacement task, which can break cancellation/reset control for the active warmup and leave session state unmanaged — make task-map removal conditional on task identity/current ownership. - In
desktop/macos/Desktop/Sources/StartupWarmupCoordinator.swift, consuming warmup reservations even when session-scoped scheduling fails can permanently skip warmups for the current run, reducing startup readiness in a way that is hard to recover from — only consume reservations after successful scheduling (or re-credit on failure). - In
desktop/macos/Desktop/Sources/MainWindow/DesktopHomeView.swift, callingCrispManager.stop()during generic startup-warmup reset clears persisted Crisp read state on terminate/reset paths, so users can lose messages received while the app was closed — limitstop()to true sign-out/full reset paths or preserve read-state across startup resets.
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1b011c6a14
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| didScheduleAgentVMProvisioning = false | ||
| proactiveMonitoringStartGate.finishAttempt() | ||
| initialFileIndexingBackfill.releaseReservation() | ||
| CrispManager.shared.stop(preserveReadState: true) |
There was a problem hiding this comment.
Clear Crisp read state on sign-out
Because .userDidSignOut also calls resetSessionScopedStartupWarmups(), this always stops Crisp with preserveReadState: true during sign-out. The Crisp timestamps are app-global UserDefaults keys and the backend filters messages by the authenticated user's email, so if user A signs out and user B signs in, user B inherits user A's lastSeenTimestamp/latestOperatorTimestamp and can miss older unread operator messages. Preserve these values only for termination, and use the default clearing path for sign-out/account reset.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b916931a51
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| log( | ||
| "DesktopHomeView: resetOnboardingRequested — clearing live onboarding state for current app" | ||
| ) | ||
| resetSessionScopedStartupWarmups(preserveCrispReadState: false) |
There was a problem hiding this comment.
Preserve Crisp state when resetting onboarding
When a signed-in user uses Settings/Menu Bar > Reset Onboarding, this new reset path now calls resetSessionScopedStartupWarmups(preserveCrispReadState: false), which reaches CrispManager.stop and removes the persisted crisp_lastSeenTimestamp / crisp_latestOperatorTimestamp. The reset only restarts onboarding for the same account, so after the app restarts Crisp initializes an empty last-seen value to “now” and any unread operator replies from before or during the reset can be treated as already seen; keep clearing this state on sign-out, but preserve it for onboarding resets.
Useful? React with 👍 / 👎.
620aa1d
into
BasedHardware:codex/desktop-startup-warmup-performance
Summary
Testing
git diff --checksh scripts/pre-commitxcrun swiftc -parse Desktop/Sources/StartupWarmupPolicy.swift Desktop/Sources/StartupWarmupCoordinator.swift Desktop/Sources/ViewModelContainer.swift Desktop/Sources/MainWindow/DesktopHomeView.swift Desktop/Sources/MainWindow/CrispManager.swift Desktop/Tests/StartupWarmupPolicyTests.swiftxcrun swift package --package-path Desktop describexcrun swift test --package-path Desktop --filter StartupWarmupPolicyTests; blocked/killed during SwiftPM binary artifact downloads with duplicate GitHub keychain-entry warning, same local environment blocker seen on earlier Desktop runs.Stacked on #8013.
Fixes #8123