Skip to content

Notify messages stored before the notification handlers subscribe - #2268

Merged
mpretty-cyro merged 1 commit into
session-foundation:devfrom
mpretty-cyro:fix/notify-on-push-cold-start
Nov 17, 2026
Merged

mpretty-cyro merged 1 commit into
session-foundation:devfrom
mpretty-cyro:fix/notify-on-push-cold-start

Conversation

@mpretty-cyro

@mpretty-cyro mpretty-cyro commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Contributor checklist

  • I have tested my contribution on these devices:
  • Two virtual devices: Pixel 7 profile, API 37 (arm64), play flavour, debug, using FCM push
  • My contribution is fully baked and ready to be merged as is
  • I ensure that all the open issues my contribution fixes are mentioned in the commit message of my first commit using the Fixes #1234 syntax

Description

Bug: when a push or a background poll cold-starts the process, the message it stores never notifies. This has been the case since the notification refactor (#2019, first released in 1.33.0). Users see it as "no notifications if I haven't opened the app for a while", because Android kills the cached process and the next message cold-starts it.

Cause: NotificationProcessor is an AuthAwareComponent. AuthAwareComponentsHandler starts it after a random delay of up to a second, and only then do the handlers subscribe to the changeNotification flows of MmsDatabase, SmsDatabase and ThreadDatabase. Those flows keep no replay, so the push stores its message before anyone is listening, and its Added event is dropped.

Fix: each message a notification handler deals with is now marked in the existing notified column of sms and mms, which nothing else uses any more. Each time the handlers subscribe, MissedMessageEvents first sends one Added event for each thread with unread incoming messages that are still unmarked. The replay goes through the normal path, so privacy modes, muted and mentions-only threads, blocked contacts and message requests behave as they do for live events.

  • Ordering: the change flows are subscribed before the database is read, so a message stored in between arrives at least once. The handlers already skip content they've posted.
  • No repeats: messages a handler has already seen aren't replayed, so an unread message the user dismissed doesn't notify again on every cold start.
  • Why per row, not a high-water id: sms has no AUTOINCREMENT; the lokiV46 "add autoincrement" migration recreates it from the same CREATE_TABLE. So deleting its newest rows (expiry, delete-for-me) frees their ids for the next inserts, and a "newer than id N" check would skip those messages.
  • Index: the catch-up query tests read = 0 AND notified = 0, which matches the existing (read, notified, thread_id) index on both tables. Incoming rows are stored with read = 0.
  • First run of this version: before anything has been marked, it marks the unread messages already stored and replays nothing, rather than notifying every unread message once.

Testing:

  • MissedMessageEventsTest runs the real queries against an in-memory database built from SmsDatabase.CREATE_TABLE and MmsDatabase.CREATE_TABLE, plus their is_outgoing columns. It covers:
    • the replay;
    • messages already seen;
    • a new message that reuses a deleted message's sms id;
    • outgoing, deleted and already-read messages;
    • the first run;
    • the subscription happening before the database read.
  • Mutation checks: without the notified filter, 2 tests fail; without the undispatched subscription, 1 fails.
  • On two emulators: the receiver's process was killed with am kill, then the other account sent a message, so the push cold-started the receiver.
    • On dev, the message was stored about 1s before NotificationProcessor subscribed, and no notification was posted.
    • Upgrade: after installing this change over dev, the first launch marked the stored messages and replayed nothing.
    • Cold start: the message was replayed, and a notification was posted with sound.
    • No repeat: a later cold start with no new message posted nothing.
    • Hard delete: after "Clear All Messages" hard-deleted the thread's rows, the next cold-start message was still replayed and notified. Row ids aren't visible on a device, so the id reuse itself is covered only by the SQL test.
  • ShowNoNameOrContent mode wasn't tested on a device.

A push or background poll that cold-starts the process stores its
message before NotificationProcessor subscribes to the database change
flows, which keep no replay, so the message never notified. Since the
notification refactor in 1.33.0 this has hit every message that wakes
a killed process.

Mark each message a handler deals with in the existing, unused
notified column, and have each subscription start by replaying the
unread incoming messages still unmarked as Added events. Messages a
handler already saw aren't replayed, so a dismissed unread message
doesn't notify again on each cold start. The mark is per row because
sms ids are reused after its newest rows are deleted.
@mpretty-cyro
mpretty-cyro force-pushed the fix/notify-on-push-cold-start branch from 8ebb4ce to 012f0c9 Compare November 17, 2026 22:48

@mpretty-cyro mpretty-cyro left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

lgtm

@mpretty-cyro
mpretty-cyro marked this pull request as ready for review November 17, 2026 23:36
@mpretty-cyro
mpretty-cyro merged commit 54689a7 into session-foundation:dev Nov 17, 2026
7 of 9 checks passed
@mpretty-cyro
mpretty-cyro deleted the fix/notify-on-push-cold-start branch November 17, 2026 23:50
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