Repository navigation
feat(desktop): notifications off by default for all users - #7681
Conversation
Desktop's proactive notifications had ~25% click-through and high dismiss rates (PostHog, 90d). Make them opt-in instead of opt-out, keeping the feature fully intact — users enable via the Settings frequency slider. - NotificationService: default frequency level 3 (Balanced) -> 0 (Off) - One-time launch migration flips existing users to Off once, guarded by a flag so anyone who re-enables is never re-disabled - Backend get_notification_settings default frequency 3 -> 0 (new accounts / unset users); an explicit stored value always wins - Update desktop migration test for the new default Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Greptile SummaryThis PR makes proactive desktop notifications opt-in by changing the default
Confidence Score: 3/5The change is straightforward in intent, but the migration has a logic gap that can silently undo itself for signed-out users or on network failure. For users who are not signed in when the app first launches after the update, or who have a transient network error during the backend push, the migration flag is committed before the push is attempted. The Settings page subsequently reads the un-migrated backend value and writes it back to local UserDefaults, leaving those users at frequency=3 with no way for the migration to self-correct. desktop/Desktop/Sources/ProactiveAssistants/Services/NotificationService.swift — specifically the ordering of the migration flag write relative to the auth check and async backend push. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[applicationDidFinishLaunching] --> B[migrateToOffByDefaultIfNeeded]
B --> C{offByDefaultMigrationKey set?}
C -- Yes --> D[Return — migration already done]
C -- No --> E[Write frequency=0 to UserDefaults]
E --> F[Set offByDefaultMigrationKey=true]
F --> G{AuthService.isSignedIn?}
G -- No --> H[⚠️ Return without backend push\nFlag already committed\nNo retry possible]
G -- Yes --> I[Task: updateNotificationSettings\nfrequency=0 to backend]
I -- Success --> J[Backend updated ✅]
I -- Failure --> K[⚠️ logError only\nFlag already committed\nNo retry]
L[User opens Settings later] --> M[Fetch from backend]
H --> N[Backend still has old value e.g. 3]
K --> N
N --> M
M --> O[Write backend value to UserDefaults\ne.g. frequency=3 again]
O --> P[❌ Migration undone silently]
Reviews (1): Last reviewed commit: "feat(desktop): proactive notifications o..." | Re-trigger Greptile |
| static func migrateToOffByDefaultIfNeeded() { | ||
| guard !UserDefaults.standard.bool(forKey: Self.offByDefaultMigrationKey) else { return } | ||
| UserDefaults.standard.set(0, forKey: Self.frequencyDefaultsKey) | ||
| UserDefaults.standard.set(true, forKey: Self.offByDefaultMigrationKey) | ||
| log("NotificationService: applied notifications-off-by-default migration (frequency=0)") | ||
| guard AuthService.shared.isSignedIn else { return } | ||
| Task { | ||
| do { | ||
| _ = try await APIClient.shared.updateNotificationSettings(enabled: nil, frequency: 0) | ||
| } catch { | ||
| logError( | ||
| "NotificationService: off-by-default migration backend push failed", error: error) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Migration flag set before auth check — backend silently skipped for signed-out users
The offByDefaultMigrationKey guard is set to true synchronously (line 382) before the isSignedIn check, so if the app launches while the user is signed out, the local preference is written to 0 ✅ but the backend push is permanently skipped ❌ and the migration is marked done forever. When the user later signs in and opens Settings, the page reads from the backend (which still carries the old value, e.g. 3), writes it back to frequencyDefaultsKey, and quietly re-enables notifications at Balanced — exactly the state the migration was meant to clear. The same failure mode occurs on any transient network error that rejects the async updateNotificationSettings call: error is logged but the flag has already been committed, so there is no retry path. Consider only setting the flag after a confirmed backend write (moving the set(true…) call inside the Task on success), or scheduling a deferred push on the next sign-in event.
…lt (focus + insights) (#11479) # Re-enable proactive notifications at Balanced by default ## Summary Replaces the notifications-off-by-default migration (`48239de8`, PR #7681) with a one-time balanced-by-default re-enable: - Users at **Off** — and fresh installs with no stored level — move to **frequency 3 (Balanced)** once at launch. Any explicit opt-in level (1–5) is kept. - Turning notifications off *after* the migration sticks: the run-once flag (`notificationsBalancedByDefaultMigrationDone`) guarantees no re-enable on later launches. - Per-assistant toggles are untouched, so only the default-on categories fire: **Live Suggestions** (focus nudges) and **Insight**. Task and Memory notifications stay opt-in. - The backend push rides the existing pending-sync journal (`beginNotificationSettingsSync`) and the shared `NotificationSettingsSyncQueue` (moved from the Settings pane into `NotificationService`, now taking `enabled: Bool?`): a failed PATCH (offline, signed out during onboarding) is retried by the next Settings load, and the launch push is ordered behind any frequency change the user makes right after startup, so a slow migration PATCH can never overwrite a newer user choice. - The backend default (`get_notification_settings` → frequency 0) is deliberately unchanged, so users on current stable builds are unaffected. **Beta picks this up with the next beta release; stable inherits it automatically when that release is promoted to stable** — no backend flip or second change needed. ## Product invariants affected - INV-AUTH-1 — path-matched only (`OmiApp.swift` launch sequence swaps one migration call; `NotificationService.swift` settings-sync statics). No auth/session behavior changes. ## Verification - `xcrun swift test --package-path Desktop --filter UserNotificationCallbackBridgeTests` — 11/11 pass, including two new regression tests: fresh-install/off users migrate to Balanced exactly once and write the key (so backend off-default cannot hydrate 0 over it); explicit user levels are never overridden; a user who re-disables after the migration is never re-enabled. - Real path: built and ran a named dev bundle (`omi-notif-balanced`, dev backend, seeded account). On first launch the migration set `notification_frequency=3`, set the flag, and the backend PATCH completed (pending-sync journal cleared). Settings → Notifications & Privacy shows master ON, Frequency **Balanced**, Live Suggestions ON, Insight ON, Task OFF, Memory OFF — hydrated from the server, confirming the round-trip. State survived two relaunches. Re-verified end-to-end after routing the push through the shared queue (reset migration state, relaunched: frequency=3, flag set, queued PATCH completed). - Independent agent review: approved ("correct, tightly scoped, well-tested"); its one actionable finding — the bare-`Task` push being unordered vs user PATCHes — is fixed in the second commit. Its second note (a fresh install on a second machine pushes Balanced over an explicit non-zero level set elsewhere) is accepted intent: a fresh beta install re-enabling at Balanced is the point of this change. - Server-authoritative hydration observed working: a locally forged frequency (0) with no pending journal entry was corrected back to the server value on Settings load — the identical path that keeps a real user's slider choice authoritative across devices. - UNVERIFIED end-to-end: dragging the slider to Off through the real UI and relaunching (custom SwiftUI slider is not reachable cursor-free); the guard for that path is unit-tested (`testBalancedDefaultMigrationNeverOverridesAnExplicitUserChoice`) and the slider/persistence code is untouched by this PR. ## Rider: unblocks a red main A third commit repairs `APIClientAssistantSettingsTests` (added in 38d3b8e yesterday), which asserted that the shipped default task prompt fits its sync bound — never true (~13.7k chars vs the 10k backend bound since at least June), so the desktop Swift suite was red on main and blocked this PR's gate and the hourly release train. The tests now assert the shipped contract (oversized default prompt is omitted from sync; all three assistants share the 10k bound); the intended bound raise with its backend-deploy sequencing is tracked in #11481.
What
Make proactive desktop notifications opt-in instead of opt-out, for all users. The feature is fully kept — users turn notifications back on anytime via the Settings frequency slider.
Why
PostHog (macOS, 90d): notifications had a ~25% click-through with high dismiss volume (9,153 sent → 2,438 clicked → 8,928 dismissed). They're the noisiest desktop surface relative to engagement.
How
The master
notification_frequencyis the single gate (0 = Offsuppresses all proactive notifications, overriding per-assistant toggles).NotificationService.defaultFrequencyLevel:3(Balanced) →0(Off) — covers fresh installs.migrateToOffByDefaultIfNeeded, called inapplicationDidFinishLaunching): flips existing users to Off once, persisting to the backend. Guarded bynotificationsOffByDefaultMigrationDoneso anyone who later re-enables is never re-disabled.get_notification_settingsfrequency3→0— covers new/unset accounts; an explicit stored value always wins.test_desktop_migrationfor the new default.Reversibility
Per-user, fully reversible: Settings → notification frequency slider re-enables. Existing explicit choices are reset once (by design — "off by default for all users") and can be re-set.
Verification
xcrun swift build -c debug✅ (clean, rebased on latest main)frequency=0 → .infinity interval → droppath.Deploy
desktop/**auto-triggers the desktop release (Codemagic → notarize → Sparkle).backend/database/users.py) deploys separately viagcp_backend.yml.🤖 Generated with Claude Code