From 6f1eabe4e8969084b0f79fde67115349421e0fea Mon Sep 17 00:00:00 2001 From: Tom Brow Date: Mon, 16 Nov 2026 21:12:22 -0800 Subject: [PATCH] fix(mobile): read presence for a person shown again while still covered (#9595) ## Context Follow-up to [#9480 stop following off-screen presence](https://github.com/block/buzz/pull/9480), from [Wes's review comment](https://github.com/block/buzz/pull/9480#discussion_r4591994023). When a person is retired, presence narrows the live subscription to the people still shown. If that narrowing fails, the old wide stream stays live and still covers the retired person. If that person is then shown again, the tracked set matches the live stream's keys, so `_subscribe` returned early without reading their snapshot. Their dot stayed empty until a live event or the next 60 second poll. The same gap happened when a person was shown again before the retirement's resubscribe ran. `_subscribe` now schedules the pending snapshot read before returning in that case, so a person shown again gets their current presence right away. ## Validation - New test: `a key shown again while a failed narrowing left it covered is read`. It failed before the fix (no snapshot read for the re-shown key) and passes after it. - `flutter analyze` clean; full mobile `flutter test` suite passes. - Automated app test (iOS 27 simulator, signed-in debug build): Home Team filter DM rows show presence dots, and they are still correct after switching to Solo for 70 s and back. The Team list stays mounted offstage while hidden, so that run is a smoke check of the presence flows; the retire and re-show path itself is covered by the new unit test. ## Regressions None expected. The extra read happens only when a newly tracked key is already covered by the live stream. `_schedule` already dedupes and skips while a retry is pending, so it adds at most one small snapshot query per re-shown key. Signed-off-by: Tom Brow Co-authored-by: Tom Brow Co-authored-by: studio --- .../profile/presence_cache_provider.dart | 7 +++- .../profile/presence_cache_provider_test.dart | 36 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/mobile/lib/features/profile/presence_cache_provider.dart b/mobile/lib/features/profile/presence_cache_provider.dart index fa8ef8f56c..6b2f3b6e02 100644 --- a/mobile/lib/features/profile/presence_cache_provider.dart +++ b/mobile/lib/features/profile/presence_cache_provider.dart @@ -233,7 +233,12 @@ class PresenceCacheNotifier extends Notifier> { _subscribeAttempted = _retrying = false; return; } - if (_presenceUnsub != null && _covered) return; + if (_presenceUnsub != null && _covered) { + // A key shown again while a stream from before its retirement still + // covers it needs only its read. + _schedule(generation); + return; + } // One subscription opens at a time. A replacement holds this until it is // promoted or abandoned, so tracking bursts widen it in later rounds. _opening = true; diff --git a/mobile/test/features/profile/presence_cache_provider_test.dart b/mobile/test/features/profile/presence_cache_provider_test.dart index cdf3a04117..7542057f5b 100644 --- a/mobile/test/features/profile/presence_cache_provider_test.dart +++ b/mobile/test/features/profile/presence_cache_provider_test.dart @@ -345,6 +345,42 @@ void main() { }); }); + test( + 'a key shown again while a failed narrowing left it covered is read', + () { + fakeAsync((time) { + final relaySession = _RecordingRelaySessionNotifier(); + final container = _buildContainer(relaySession: relaySession); + addTearDown(container.dispose); + final notifier = container.read(presenceCacheProvider.notifier); + + container.read(presenceCacheProvider); + notifier.track(['alice']); + final bob = notifier.track(['bob']); + time.elapse(Duration.zero); + final wide = relaySession.subscriptions.single; + + // Bob is retired, but the narrower stream fails, so the wide one stays. + bob(); + relaySession.autoReady = false; + time.elapse(PresenceCacheNotifier.releaseDelay); + relaySession.subscriptions.last.retrying(); + time.elapse(Duration.zero); + expect(relaySession.subscriptions, [wide]); + expect(container.read(presenceCacheProvider), isNot(contains('bob'))); + + // Shown again before the next poll, Bob is read right away. + relaySession.queried.clear(); + relaySession.snapshot['bob'] = 'online'; + notifier.track(['bob']); + time.elapse(Duration.zero); + expect(relaySession.subscriptions, [wide]); + expect(relaySession.queried.expand((keys) => keys), ['bob']); + expect(container.read(presenceCacheProvider)['bob'], 'online'); + }); + }, + ); + test('releasing everyone closes the stream until someone is shown', () { fakeAsync((time) { final relaySession = _RecordingRelaySessionNotifier();