diff --git a/docs/README.md b/docs/README.md index 1450099f..140f92d0 100644 --- a/docs/README.md +++ b/docs/README.md @@ -28,7 +28,7 @@ the [retired](./retired/) notes now. | [marmot-direct-messages.md](./marmot-direct-messages.md) | a one-to-one message inside a group as a stock NIP-59 gift wrap — what its MIP-03 carve-out costs, why the sender cannot read their own, and the one query that would broadcast it | | [mls-skipped-keys.md](./mls-skipped-keys.md) | why a group event that arrives a moment late was dropped for good, which flows triggered it, the fix as it landed in mls-kmp, and the one word of the diagnosis that was wrong | | [long-running-sync.md](./long-running-sync.md) | the chat subscriptions that stay open instead of pulling once per screen — why the request queue could not simply hold one, and how the group filter follows the room list | -| [notifications-and-background-sync.md](./notifications-and-background-sync.md) | notifications, and the background sync they need: a phased plan, not built. Read state per room, then notifications for as long as the process lives, then a bounded background pass on WorkManager, BGTaskScheduler and the desktop tray. Covers why notifications come from the table rather than the wire, why the cursor is a row id and never a timestamp, why the object graph has to leave the composition first, what each platform can honestly offer, and real-time push (MIP-05) as the owner's decision rather than a phase | +| [notifications-and-background-sync.md](./notifications-and-background-sync.md) | notifications, and the background sync they need: a phased plan, built on Android and desktop but for its device run, written but not compiled on iOS, with the background half behind a flag that is off in release. Read state per room, then notifications for as long as the process lives, then a bounded background pass on WorkManager, BGTaskScheduler and the desktop tray. Covers why notifications come from the table rather than the wire, why the cursor is a row id and never a timestamp, why the object graph has to leave the composition first, what each platform can honestly offer, and real-time push (MIP-05) as the owner's decision rather than a phase | | [dead-code.md](./dead-code.md) | code in the sync and relay stack that nothing calls, why each piece is still there, and which of it is a bug rather than a leftover | | [nsec-sign-in.md](./nsec-sign-in.md) | signing in with an existing nostr key — why an nsec can never have a wallet behind it, the ten call sites that make it small, and the sign-in machine that was already built and unreachable | | [npub-sign-in.md](./npub-sign-in.md) | signing in with only a public key — what a key that cannot sign can still see here, why that is a preview rather than a browser, and the four decisions the word settles | diff --git a/docs/notifications-and-background-sync.md b/docs/notifications-and-background-sync.md index c58d64a1..16da63b8 100644 --- a/docs/notifications-and-background-sync.md +++ b/docs/notifications-and-background-sync.md @@ -21,7 +21,56 @@ the table rather than from the places that write to it, and never put a `since` filter. Then read [multiple-profiles.md](./multiple-profiles.md) for why a profile switch is a restart, which is why the background sync serves one profile (D6). -**Not built.** Written against `2563572e`, on 2026-11-22. Paths starting `K/` are under +**Built** on `claude/giza-notifications-background-sync-1a8e0b`, against `2563572e`, on +2026-11-22, one commit per phase (`5683199c` to the commit that adds this header; Phase 10 is two). +The background half is behind `ExperimentalFeatures.backgroundSync`, on in development builds and +off in release; read state and notifications while the app runs are not flagged. jvmTest 1,774, all +passing; `m3Audit`, `brandAudit` and `walletAudit` at their budgets; `compileDebugKotlinAndroid` +builds and the debug manifest merges; `./gradlew check` passes. The phases are kept as written, because they are the +reasoning. Where the build chose differently: + +| what the plan said | what it turned out to be | +|---|---| +| Phase 2: `SyncEngine` and `OutboundEngine` moved out of their view models | **the view models stay, built once by `GizaRuntime`.** Neither ever used `viewModelScope` -- both run on the scope they are given -- so constructing them outside a `ViewModelStore` changed nothing about how they run, and a 950-line move bought nothing. `GizaRuntime.synchronization` and `.notary` are them | +| (not in the plan) | **`SovereignWalletViewModel` resets the identity to null when it is created.** The flow it writes is the runtime's now and outlives an activity, so an activity recreated over a living process would otherwise start with the last one's identity set and skip the startup that chooses it | +| Phase 2: `IdentityStore`, extracted from `listIdentities` | `DefaultIdentity.load` (Phase 9), the reading half only: no key-file migration and no credential repair, which belong to a launch somebody is watching. A seed missing its credential is still found by derivation | +| Phase 3: a manual `Migration(46, 47)` | an `AutoMigration` with `ReadMarkMigrationSpec`, whose `onPostMigrate` runs the `UPDATE`. Room generates the shape | +| Phase 5: the switches in the identity's `UserPrefs` | **on `NotificationLedger`**, folded into schema 47 (which has not shipped) in Phase 5. `UserPrefs` lives in the wallet library's submodule. Before an identity is armed there is no row, and the settings screen says why there is nothing to set | +| D7: approval lines are someone else's | **they are written as the user's own** (`isUserMessage = true`, from `announce`'s actor), so the classifier exempts Needs you from the own-line rule, and the policy never drops one as already read. `NotificationClassifierJvmTest` pins both | +| D9: hide every line's text when Show message text is off | only a message's. A Needs you or Group activity line is the app's own sentence, never what anybody wrote | +| D3: armed after the first sync settles | armed once the identity's negentropy queue has been empty for **30 seconds without a break** -- the only signal that a first sync is over. Arming also marks every room read up to its newest line, so a new device starts with nothing unread | +| D6: a notification names the profile when there are several | **not done**: `RoomNotification.profileName` is always null | +| Phase 6: sender names from the room's participants | and, for a sender who is not a participant row (a NIP-17 peer), from their `Profile`. `NotificationDispatcherJvmTest` found the gap | +| Phase 0, check 4 | a group message filed first as a placeholder and decrypted later keeps the placeholder's id, which the cursor may have passed: it counts as unread and posts nothing. Kept as a known gap | +| Phase 7: a Notifications screen pushed from settings | from the **Profile tab**, the only list of settings the app has; shown only for a profile that can sign | +| Phase 8: `isVisible` and `holdConnections` | as planned; `holdConnections` is visible, or any of a set of named reasons to keep connected (`desktop`, `grace`, `stayConnected`, `backgroundPass`) | +| D5: a quick pass of REQs to EOSE and a full pass of negentropy | **one pass that runs the app's own engines**: it activates the default profile when no screen has and holds the connections, which makes `LiveSubscriptionManager` reconnect, open its subscriptions (whose `limit` is the quick catch-up) and queue the negentropy reconciliation (the full one), exactly as returning to the foreground does. Quick and full differ in their minimum wait and their deadline. The second fetch after a Welcome is the live tier's own room-list loop | +| D5: wait for the outbound queue to empty | wait for it to **stop moving** for five seconds. A row that can never be sent would otherwise hold every pass to its deadline -- nine minutes on Android | +| (not in the plan) | a `Disabled` outcome: a profile whose notifications are off is not synced in the background | +| (not in the plan) | **Android's application starts not visible**, until an activity's `ON_START` says otherwise. A process started for the worker has no activity, and the pass declines to run while the app is "visible" | +| Phase 10: the worker returns at once while Stay connected runs | it runs anyway; the reconciliation it queues is the one thing the live tier cannot do, and holding the connections twice is harmless | +| Phase 10: Stay connected's switch | stored in Android `SharedPreferences` -- a device's choice, not a profile's -- and the service started only from `MainActivity`, because Android refuses a foreground service started from the background | +| Phase 12: Open Giza, Mute all for an hour, Quit | **Open window** and **Quit**. `m3-title-case.py` reads "Open Giza" as title case; muting everything for an hour is the master switch already | +| Phase 13: a reply runs the outbound engine | through `BackgroundSyncPass.withProfile`, under the pass's own lock so a reply and a sync never activate and deactivate the profile under each other. A reply for a profile other than the default, or than the one open, is refused, not sent as somebody else | +| Phase 15 | not built | +| (not in the plan) | the worktree's build needed `lightning-kmp-app` and its nested submodules initialised from the main checkout's copies, with their `local.properties` and the prebuilt native secp256k1 | + +**Not done:** + +- **Nothing on iOS has been compiled.** The iosMain actuals (`PlatformNotifier.ios.kt`, + `BackgroundSync.ios.kt`, `BackgroundTime.ios.kt`, `BackgroundSyncSection.ios.kt`), the + `MainViewController` change and `iOSApp.swift` were written on linux, where the iOS targets are not + declared. The likeliest breaks are the Kotlin spellings of the UIKit and UserNotifications + enums (`UNAuthorizationStatus…`, `UIApplicationState…`, `UIBackgroundRefreshStatus…`, the + `…OptionNone` constants) and the Swift names of Kotlin's top-level functions + (`PlatformNotifier_iosKt`, `BackgroundSync_iosKt`). +- **Phase 14's device run**, on every platform: nothing here has posted a notification on a phone, + run a WorkManager period, been woken by BGTaskScheduler, or closed to a real tray. +- **Phase 0, check 3** (iOS file protection), which needs a device. +- **`ExperimentalFeatures.backgroundSync` stays**, as D12 says it must until the device run. +- **Part C**, which is the owner's decision. + +Written against `2563572e`, on 2026-11-22. Paths starting `K/` are under `composeApp/src/commonMain/kotlin/mobi/giza/compose/`. ---