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 <tomb@squareup.com>
Co-authored-by: Tom Brow <tomb@squareup.com>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz>
This commit is contained in:
Tom Brow
2026-11-16 21:12:22 -08:00
committed by GitHub
parent c0ce4982fc
commit 6f1eabe4e8
2 changed files with 42 additions and 1 deletions

View File

@@ -233,7 +233,12 @@ class PresenceCacheNotifier extends Notifier<Map<String, String>> {
_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;

View File

@@ -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();