Skip to content

feat(desktop): notifications off by default for all users - #7681

Merged
kodjima33 merged 1 commit into
mainfrom
desktop-notifications-off-by-default
Jun 7, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
desktop-notifications-off-by-default

Conversation

@kodjima33

Copy link
Copy Markdown
Collaborator

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_frequency is the single gate (0 = Off suppresses all proactive notifications, overriding per-assistant toggles).

  • Client default NotificationService.defaultFrequencyLevel: 3 (Balanced) → 0 (Off) — covers fresh installs.
  • One-time launch migration (migrateToOffByDefaultIfNeeded, called in applicationDidFinishLaunching): flips existing users to Off once, persisting to the backend. Guarded by notificationsOffByDefaultMigrationDone so anyone who later re-enables is never re-disabled.
  • Backend default get_notification_settings frequency 3 → 0 — covers new/unset accounts; an explicit stored value always wins.
  • Updated test_desktop_migration for 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)
  • Backend default + test updated.
  • ⚠️ Runtime suppression not exercised end-to-end (would require triggering a proactive assistant). Logic is the documented frequency=0 → .infinity interval → drop path.

Deploy

  • Merging desktop/** auto-triggers the desktop release (Codemagic → notarize → Sparkle).
  • Python backend (backend/database/users.py) deploys separately via gcp_backend.yml.

🤖 Generated with Claude Code

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]>
@kodjima33
kodjima33 merged commit 230c1bb into main Jun 7, 2026
3 checks passed
@kodjima33
kodjima33 deleted the desktop-notifications-off-by-default branch June 7, 2026 05:03
@greptile-apps

greptile-apps Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes proactive desktop notifications opt-in by changing the default notification_frequency from 3 (Balanced) to 0 (Off) on both the macOS client and the Python backend, and introduces a one-time launch migration that flips existing users to Off once.

  • Client change: NotificationService.defaultFrequencyLevel drops to 0; migrateToOffByDefaultIfNeeded() is called at launch to write frequency=0 locally and push it to the backend, guarded by a UserDefaults flag so re-enabled users are never forcibly re-disabled.
  • Backend change: get_notification_settings default frequency falls from 3 to 0 for both missing-doc and unset-field paths; tests updated to match.
  • Migration flag race: the offByDefaultMigrationKey guard is committed synchronously before the auth check, so users who are signed out at migration time (or hit a network error) have the backend push silently skipped with no retry path — when Settings later hydrates from the backend (which still carries the old value), frequencyDefaultsKey is overwritten, quietly undoing the migration.

Confidence Score: 3/5

The 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

Filename Overview
desktop/Desktop/Sources/ProactiveAssistants/Services/NotificationService.swift Adds migrateToOffByDefaultIfNeeded() and changes defaultFrequencyLevel to 0; migration flag is committed before the async backend push, so signed-out users and network-error cases silently skip the backend update while the guard prevents any retry.
desktop/Desktop/Sources/OmiApp.swift Calls migrateToOffByDefaultIfNeeded() early in applicationDidFinishLaunching, before assistants can fire — placement looks correct.
backend/database/users.py Changes default frequency from 3 to 0 for both missing-doc and unset-field cases; correctly aligns backend default with new client default.
backend/tests/unit/test_desktop_migration.py Updates two assertions to expect frequency=0; test coverage matches the backend default change correctly.
desktop/CHANGELOG.json Adds an unreleased changelog entry describing the opt-in notifications change.

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]
Loading

Reviews (1): Last reviewed commit: "feat(desktop): proactive notifications o..." | Re-trigger Greptile

Comment on lines +379 to +393
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)
}
}
}

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.

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

kodjima33 added a commit that referenced this pull request Aug 13, 2026
…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.
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