Skip to content

Scope desktop startup warmups to user sessions - #8159

Merged
Git-on-my-level merged 3 commits into
BasedHardware:codex/desktop-startup-warmup-performancefrom
Git-on-my-level:fix/desktop-cancellable-startup-warmups
Jun 24, 2026
Merged

Git-on-my-level merged 3 commits into
BasedHardware:codex/desktop-startup-warmup-performancefrom
Git-on-my-level:fix/desktop-cancellable-startup-warmups

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jun 23, 2026 •

Copy link
Copy Markdown
Member

Summary

  • centralize delayed startup warmups behind a session-scoped coordinator task registry
  • cancel/reset startup warmups on sign-out, onboarding reset, and app termination
  • move DesktopHomeView delayed warmups through the coordinator and scope Crisp initial polling to the signed-in user
  • add focused lifecycle/source-invariant tests for session scoping and cancellation hooks

Testing

  • git diff --check
  • sh scripts/pre-commit
  • xcrun 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.swift
  • xcrun swift package --package-path Desktop describe
  • Attempted xcrun 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

Review in cubic

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment on lines +711 to 715
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()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@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.

4 issues found across 6 files

Confidence score: 2/5

  • In desktop/macos/Desktop/Sources/MainWindow/DesktopHomeView.swift, scheduleSessionWarmup no longer re-checks cancellation/sign-in state after backgroundRescan() before writing UserDefaults, so a canceled or signed-out session can still persist warmup state and cause incorrect startup behavior for the next session — restore the post-rescan Task.isCancelled and AuthState.shared.isSignedIn guards before merging.
  • In desktop/macos/Desktop/Sources/StartupWarmupCoordinator.swift, unconditional cleanup of sessionTasks[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, calling CrispManager.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 — limit stop() 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

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit 620aa1d into BasedHardware:codex/desktop-startup-warmup-performance Jun 24, 2026
1 check passed
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.

1 participant