Skip to content

ANCS: some old notifications come back without PreExisting on every reconnect and pop up again #346

Done

Description

@fernando2393

Following up on #339 with the data you asked for.

What happens. On every new ANCS session the iPhone replays its Notification Center. Most entries carry PreExisting (0x04), but a few specific ones never do. They arrive as plain Added events, so tether pops them up as new on every reconnect. I logged each Added event without PreExisting whose Date attribute was more than 2 minutes old (24 sessions, 2026-11-23):

app Date flags category sessions seen
com.burbn.instagram 20261123T094814 0x10 0 Other 19 (over 11 h)
com.ledger.live 20261123T161938 0x10 9 BusinessAndFinance 12
de.zalando.lounge 20261123T180814 0x30 0 Other 7
com.apple.mobilemail 5 different 0x10 / 0x11 6 Email 1–2 each
  • The same entry keeps coming back unflagged session after session, until it's cleared on the phone. It's not random per session.
  • Every one of them has PositiveAction (0x10) set. That's not enough to explain it, though, since plenty of flagged entries have actions too.
  • They arrive in the replay burst right after subscribing, mixed in with the flagged ones.

I saw it live today: I ran a build from main, toggled Bluetooth on the phone, and Instagram, Ledger and Zalando Lounge popped up as "Just now" with content from hours earlier.

Possible rules (I'd like your take before writing code):

  1. By Date: treat an unflagged Added as backlog when its Date is more than ~2 min old. It's simple, but Date is the phone's local wall clock with no zone, so a PC in another timezone or with a skewed clock would misjudge it, and some apps send no Date at all (those would be left as they are).
  2. By replay burst: treat unflagged Added events in the burst right after subscribing as backlog. This needs no clock, but a genuinely new notification that lands in that same second would go to the list without a popup.
  3. Both: suppress only when the event is in the replay burst and its Date is old. That has the fewest false positives, at the cost of a little more state.

I lean towards 3. Locally I've been running 1, and it has removed the repeat popups for me.

Activity

  1. zackb commented on Nov 23, 2026

    @zackb
    Owner

    Thanks, this is exactly the data I was hoping for. It also shows that an assumption we made earlier is wrong: that iOS flags every replayed entry and only those.

    I'd like to avoid a clock-based rule if we can. The Date has no timezone, the two clocks can drift, and the 2-minute cutoff would also hide a notification that was delivered while the link was down for more than 2 minutes. That's the case #339 set out to recover.

    NotificationRegistry::store() already recognises a copy of something we've seen in an earlier session: same app, title, subtitle, body and Date. Right now it uses that only to keep the list free of duplicates, and on_notification still fires, so the popup goes out again. My suggestion:

    • store() returns whether it replaced a copy from an earlier session.
    • handle_response sets pre_existing = true in that case before calling on_notification.
    • The OTP publish in main.cpp should skip those too, so an old code isn't republished on every reconnect.

    This needs no clock and can't hide anything genuinely new, since a new notification won't match on both content and Date. It covers your case: the same Instagram, Ledger or Zalando entry coming back unflagged session after session.

    Two known gaps:

    • The registry lives in memory, so the first session after the daemon starts has nothing to compare against, and those entries would pop up once per login. If that's annoying in practice, your option 2 (treat the replay burst as backlog) makes sense for that first session only, since everything in that replay really is old.
    • Apps that send no Date can't be matched. That's the same as with option 1.

    Could you try this against your log? If it removes the repeat popups the way option 1 did for you, a PR with a registry test would be great: an unflagged copy from an earlier session gets marked pre-existing, and a new one doesn't.

  2. fernando2393 commented on Nov 23, 2026

    @fernando2393
    ContributorAuthor

    Tried it, and it works: after a daemon restart I toggled Bluetooth on the phone, and in the second session the registry caught all 6 unflagged replays (Ledger ×2, Zalando Lounge, WhatsApp, Whoop, Instagram). PR incoming.

    On the first-session gap: in my log, 59 of 64 repeat popups were in the first session after a daemon start. My log is skewed because I restarted a lot while developing, but with #343 the daemon now also restarts at every logout, so it's once per login for everyone. If you're open to it, I'd follow up with your option-2-for-the-first-session idea as a separate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions