Repository navigation
fix(ancs): process replies as they arrive, fetch the newest first - #339
Conversation
zackb
left a comment
There was a problem hiding this comment.
Thanks for digging into this, and for the antenna and connection parameter stuff. That must have taken you some real time and will save someone else (probably me :)) theirs.
Before going further, I want to make sure we agree on what's actually slow.
- Where does the "about a second each" come from? In your logs, is the phone taking ~1s to answer each GetNotificationAttributes, or is the daemon waiting? My suspicion is the
AncsClient::tickonly running once per second. Replies get buffered and only drained on the next tick, and that's also when the next request goes out. btmon trace would show for sure. If the phone responds in a ms or few, the replay is slow because of our loop, and draining on arrival would turn ~170s into a few seconds. Most of the reordering wouldn't be needed then. - Did you see the drop at client.cpp:471? Once 32 requests are queued, further pre-existing events are dropped without being remembered. The chron ordering means the newest entries never get fetched. Is that the "a session that ended early never reached it" you saw, or were sessions really ending mid replay?
- "Some old ones come back unflagged": do you have an example (app, Date attribute, flags)? I've had reports of this from others but have never been able to repro it myself. I'd like to see what you hit before changing live behaviour.
- The front-of-queu eviction: when the queue is full,
submit(..., front = true)drops queue_.back(). That entry could be a user's libnotify reply/dismiss action or an app-name lookup, not only backlog. The dropped UID also stays in in_progress and the registry's seen_, so it won't be fetched again this session. Was that intended? - "UIDs only grow" is only true in a single session, UIDs restart on each connection (see AI notes in BLUETOOTH.md).
Also, the build.log and build-cfg.log files should not be in source control.
If 1 turns out to be the bottleneck, I think the "drain on arrival" change is the way.
We could then see what's left of 2-5 with the replay running at full speed, and keep the fetch_order.
The ANCS client only ran on the supervisor's one-second tick, so each reply from the phone waited for the next tick before it was processed and the next request went out. Measured on an iPhone: the phone answers a GetNotificationAttributes in about 180 ms, then the daemon waited 1000 ms. A replay of Notification Center (about 170 entries here) took minutes. The D-Bus thread now wakes the supervisor when something lands in the ANCS inbox (a Data Source reply, a Notification Source event or a desktop action), and the supervisor runs only the ANCS drain until the next full tick. The daemon's wait between a reply and the next request went from 1000 ms to 0. A replay also brings more entries than the client queues, and the ones beyond the limit are never fetched. Within a session UIDs grow, so additions that arrive together are now fetched newest first (fetch_order, with unit tests). Also adds two BLUETOOTH.md troubleshooting rows for causes of a flapping LE link that are easy to miss: a Wi-Fi/Bluetooth combo card with no antenna, and stale per-device connection parameters. Co-Authored-By: Claude Opus 5.5 <[email protected]>
dfe5282 to
b21fb26
Compare
|
Thanks for the careful review, you were right on the main point. I've reworked the PR around it and force-pushed.
Sorry about the build logs. They're gone. |
|
"the same 36 entries arrived without PreExisting every time" this is huge. and explains a lot of issues users are having with replay! |
Problem (iPhone, iOS 26, BlueZ 5.85)
When a notification session starts, iOS replays all of Notification Center (about 170 entries here) and the client fetches each one:
Change
AncsClient::pump), still on the tick thread. The wait between a reply and the next request went from 1000 ms to 0: 33 fetches took 6 s instead of 33 s.fetch_order), so the queued 32 are the newest.BLUETOOTH.md: two troubleshooting rows for a flapping LE link (a combo Wi-Fi/Bluetooth card with no antenna; stale per-device connection parameters).Testing
fetch_order; the whole suite passes (650).🤖 Generated with Claude Code