Files
buzz/mobile/test/shared
Wes 7b8066fb94 fix(mobile): keep the relay session across auth reloads (#9543)
## Summary

`RelaySessionNotifier.build()` watched the whole `authProvider` but only
read the signed-in status. Every `ref.invalidate(authProvider)`
therefore rebuilt the session: the socket and all live subscriptions
were dropped, and every screen resubscribed and republished presence and
read state at once. An invite join invalidates auth twice for the same
identity (3 sockets in about half a second), and each community switch
does it again, producing a REQ burst the relay answers with `CLOSED
rate-limited`.

The session now watches only `(status, community.pubkey)` via `select`,
so it still rebuilds when the user signs in or out, or switches identity
while signed in. Relay URL and signing key changes continue to rebuild
through `relayConfigProvider`, which is unchanged.

### Related issue

None found.

### Testing

- New regression test in `relay_session_test.dart`: with a connected
socket and a live subscription, two auth invalidations for the same
identity keep 1 socket, 0 disposes, `connected` status and a working
subscription; a pubkey change then rebuilds to a second socket, and
signing out disposes it.
- The test fails on `main` without the fix (`Expected: an object with
length of <1>`) and passes with it.
- `just mobile-install mobile-check mobile-test`: format clean, `flutter
analyze` no issues, 4909 tests passed (71 skipped), plus the
native-secp256k1 package suite (27 passed).
### Before and after: first-launch invite join (simulator)

Captured on a freshly erased iPhone 17 simulator with a one-use invite
for each run, counting relay traffic for this identity in the first 5 s
after launch. Before is `main` at `1a5c6939c`; after is this branch at
`8beda6aea`.

| | Before | After |
|---|---|---|
| Relay sockets opened during the join | 3 | **1** |
| Relay frames in the first 5 s | 72 | 57 |
| `OK false` for kinds 20001/30078 | 2 | **0** |
| REQs refused with `quota_exceeded` | 16 | 6 |
| Message posted after the join arrives live | yes | yes, on the same
socket |

The session rebuild is fixed: the join keeps one socket and its
subscriptions. The original target of fewer than 50 frames in 5 s is not
met. The remaining burst is about 31 separate single-document kind 30078
reads (`limit:1`, `authors` = self) at about +1.1 s, and all 6 remaining
`quota_exceeded` refusals are among them. Those reads don't come from
session rebuilds, so they'll be handled in a separate change rather than
in this PR.

- Not yet done: a run on a physical device of the first-launch join
flow.

Signed-off-by: Wes <wesb@block.xyz>
Co-authored-by: Mantis <530af7635ef7d0e1a5189d234338db88cb4ef1ede7119b4ebb4fb05c3eafe3b1@buzz.block.builderlab.xyz>
2026-11-16 12:12:09 -07:00
..