mirror of
https://github.com/block/buzz.git
synced 2026-11-28 04:01:45 +00:00
6b0dfc1957fb6cb87d40b5c3bd6570aa7e8a896e
2 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
61c070d591 |
perf(mobile): derive Active filter activity from the channel list, with no per-channel relay reads (#9832)
The Active section filter needs to know when each channel last had a message. Since #8479 (saved channel section filters) and #9796 (section filter refinements), the app has looked that up with its own relay history read per channel in every section that uses the filter. Since #9885, main caches what the channel list's read and live delivery saw for each channel (its latest post, or that it has none), and looks a channel up only while the list has no cached evidence for that channel. The lookup's own answer is not cached, so it runs again on every resume while that lasts. A failed lookup shows the notice with Retry at once and is also retried automatically up to three times. Channels the list's batched read misses (for example when it fails or hits its deadline) and every channel after a channel list rebuild, which clears the cache, all go through that lookup. With many channels, those reads compete with the channel list's own reads and the read-state sync for the relay's request budget. When they time out or get rate limited, the app shows an "activity couldn't load" notice, and the same pressure can delay other requests such as read-state sync. The channel list already reads each channel's latest messages in one batched request when it loads. This change records the newest message time from that read (self-authored and muted messages included, unlike `lastMessageAt`) and keeps it current from live delivery and from the unread catch-up the list already sends after a reconnect. Where that catch-up starts after posts no read has covered yet (for example, a post that arrived while offline and was read on another device), a separate small request sent after the catch-up asks for the newest one with a single `limit: 1` filter per such channel. It is sent only for channels an Active section is showing, only when the gap could hold a newer post than the one already known (including one the catch-up itself just verified), and without the per-channel websocket fallback, so a failure there leaves only that channel's activity unknown and never delays unread state. A successful refresh replaces a channel's time, so a deleted latest post stops counting, while keeping any newer message that arrived during the read. Only messages whose signature verifies count, and the app verifies only a message that would change a channel's activity. When a channel's latest post is deleted, live or while offline, the app forgets that channel's activity, so it reads as unknown (and stays visible) until the next background list read re-reads it on resume, reconnect or a list change, if an Active section shows it. A channel the last list read missed is asked for again the same way. The Active filter reads that value, so it sends no relay requests of its own. This replaces main's cache together with its fallback lookup, the lookup's retries and Retry. Because the filter can no longer fail on a lookup, the "activity couldn't load" notice is removed too. ### Validation - **Network impact.** Before: one history read for each channel in an Active-filtered section while the list has no cached evidence for that channel, again on each resume while that lasts, with up to three automatic retries plus a manual Retry when it fails. After: no reads of its own. The filter reuses the list's existing batched read. Only for channels an Active section shows, the next background list read asks again for a channel whose latest post was deleted or failed verification, and a reconnect may send the gap read below. - Provider tests check that activity comes from the list read, live delivery and a reconnect's catch-up; ignores a message with a bad signature; includes self-authored messages; counts a future-dated post as now; leaves `lastMessageAt` untouched and sends no extra requests; stays unknown (the channel stays visible) when a read or catch-up fails; survives a same-community rebuild; picks up a post read on another device while offline, including after an offline rebuild resets the unread cursor; drops a deleted latest post on refresh, and forgets it until the next list read on a live deletion or a deletion the catch-up returns; skips the gap read for a channel no Active section shows, or one whose catch-up found a newer verified post; asks again for a channel whose list read had no verifiable post; and keeps a live post that arrives during a refresh. - Simulator run on a signed-in community: set a section to Active (7 days), then backgrounded and resumed the app and pulled to refresh. Inactive channels stayed collapsed under Show more, and no notice appeared. ### Regressions - Signature checks for read and catch-up results run in a background isolate and check only each channel's newest message, so only those messages are copied off the UI isolate. A channel whose newest message fails verification is not updated by that read (unknown after a catch-up or gap read, so it stays visible) instead of falling back to an older one. Unread state from a catch-up is published first; its activity lands once those checks finish. A live message is checked on the UI isolate, and only when it is newer than the known activity. - Channels the batch doesn't cover (for example non-member or archived channels, or a batch that hits its deadline) have unknown activity. The filter fails open for them, so they stay visible, which matches how it treated a failed lookup before. - A catch-up that finds only newer self-authored, muted or already-read messages now republishes the list once, so the filter sees them. Before, it published nothing. - After a reconnect, channels an Active section shows, whose catch-up would skip posts no read has covered, get one `limit: 1` filter each in one small extra request, sent after the unread catch-up. It adds at most one event per such channel, against main's per-channel lookup (with its retries) for every Active channel the list has no cached evidence for. A rate-limit refusal of either request still pauses the session's reads, since the relay's quota covers every request this client makes. - A channel with a gap to read reads as unknown, so it stays visible, until that read answers. - A channel no Active section shows, whose catch-up would skip uncovered posts, reads as unknown until a later catch-up runs while it is shown. - A channel whose catch-up or gap read fails (including a catch-up that fails before sending) reads as unknown, so it shows unfiltered until a later read succeeds. A failed gap read is not retried by itself; the next list read's catch-up asks again, so it adds no retry traffic. - A post dated ahead of the device clock (the relay accepts up to 15 minutes) counts as activity now. --------- Signed-off-by: Tom Brow <tomb@block.xyz> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost> |
||
|
|
8f3f4e266a |
test(mobile): run push tests without a gateway dart-define (#9423)
A plain `cd mobile && flutter test` failed 11 push and notification tests on a clean checkout of main, while CI passed. Agents running the full suite kept reporting them as "pre-existing, also fails on main", which hides real regressions in the same files. ### Root cause Push is gated on the compile-time `BUZZ_PUSH_GATEWAY_URL` define (`Env.pushGatewayConfigured`, since [#7261 configurable gateway](https://github.com/block/buzz/pull/7261) made the gateway optional). Without it the app is a push-less build: `readBuzzPushEndpointGrants()` returns no grants and `buzzPushLifecycleEnabled()` is false. CI's mobile shards, `just mobile-test` and the lefthook pre-push lane (which runs `just mobile-test`) all pass `--dart-define=BUZZ_PUSH_GATEWAY_URL=https://push.example`; a bare `flutter test` passes nothing. Each of the 11 was checked against that: - `notification_toggle_test` (5 cases) and `push_lease_revocation_outbox_test` "hosted relay assertion": no endpoint grants without a gateway (`Bad state: No element` at the grant lookup, `No endpoint grant exists for push lease tombstone`). - `push_bridge_test` "reads and exposes persisted endpoint grants" and "debug enrollment carries the configured relay and gateway URLs": the bridge returns `[]` before calling native (`Expected: an object with length of <1>, Actual: []`). - `push_bootstrap_test` "default push requires relay capability" and "new community starts registration": the lifecycle is disabled, so registration never starts (`Expected <1>, Actual <0>`). - `push_bridge_test` "development push gateway matches the compiled configuration": a stale test. It expected a `https://push.buzz.xyz` default that [#7261 configurable gateway](https://github.com/block/buzz/pull/7261) removed from the app; under CI's define both sides equal `push.example`, so it could never fail there. The same files pass on the same Mac with the define, so nothing is environmental. The `Unexpected native call takePendingNotificationResponse` log is unrelated noise: the toggle test's native mock didn't answer that call, which logs (and is caught) in CI too. ### Fix Tests get the gateway from a test hook instead of the define. `Env.pushGatewayUrl` becomes a getter over the compiled value with a `@visibleForTesting` `debugPushGatewayUrlOverride` (the same pattern as `debugUriStreamOverride`), and `test/flutter_test_config.dart` sets it for every test file. `push_unconfigured_build_test` sets it to `''`, so it runs in the main suite instead of being skipped there and run separately. CI, the Justfile, `scripts/flake-check.mjs` and the AGENTS/README check commands drop the define, so CI, `just mobile-test`, pre-push and a bare `flutter test` run the same thing. I chose this over documenting a canonical command because the define can't be made automatic: `flutter test` has no config file for defines, so any doc fix still leaves the obvious command red. A test hook makes every invocation agree. The stale test is replaced by one in the push-less file that binds the production read: with the override cleared, `Env.pushGatewayUrl` must equal the compiled `BUZZ_PUSH_GATEWAY_URL`. Now that CI compiles without the define, it fails if the app regains a built-in gateway default, which the old test never could. The toggle test's mock answers `takePendingNotificationResponse` with no pending response. What gets better: one test mode everywhere, and the push-less tests run in every run. Nothing gets worse: production reads the same compiled value (the override is never set outside tests, and an `aot-snapshot` probe shows AOT still folds the getter to the compiled constant and drops push-only code when the define is absent), and every test still runs in the push-capable mode CI used before. ### Validation - On a fresh origin/main worktree with the Hermit toolchain, a bare `flutter test` failed exactly these 11; the same files passed on the same machine with the define. - After the fix, the pre-push `just mobile-check` and `just mobile-test` (now a bare `flutter test` plus the recipe and secp256k1 checks) pass, with the push-less tests running instead of skipped. `scripts/flake-check.test.mjs` passes. - Falsifiability: re-adding a `defaultValue` to the compiled gateway fails the new no-default test, and removing `flutter_test_config.dart` brings back the other 10 failures. - Unrelated: an earlier full run also failed `community_provider_test` "discard orphan snapshots and image caches", which waits 500 ms for a background directory delete. The Mac was running other full suites at the time; the file passed 8 of 8 runs alone, with and without the define. It is not touched here. 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> |