fix(desktop): batch live channel subscriptions and pace reconnect replay under relay rate limits - #5
Merged
Merged
Conversation
The relay's admission control (block#1917) counts EVENT/REQ/COUNT frames per pubkey at 50 per 5s window. The client opened two REQs per member channel (~159 for a 72-channel identity), so cold start and reconnect blew the budget, got the connection rate limited, and replay re-triggered the limiter on every reconnect. - Batch live channel-event and mention subscriptions into multi-channel "#h" filters, 25 channels per REQ (2N REQs -> ~2*ceil(N/25)). - Resolve h-less reactions/deletions to their channel via the referenced event in loaded timeline caches, mirroring the relay's server-side channel resolution (replaces the per-channel withChannelTagFallback). - Allow reconnect history paging for multi-channel "#h" filters. - Raise REPLAY_INTER_BATCH_DELAY_MS 50ms -> 1000ms so replay stays at 8 REQs/sec, under the relay's 10/sec average budget. AGNTOPS-418 Buzz-Message: buzz://message?channel=0c02d73d-f174-4c5f-99a3-cf67ea3d456f&id=19db0642f1adf65a15c7db646a06f0722d11bf3501bd84c78e8916fd0176b9f7 Amp-Thread-ID: https://ampcode.com/threads/T-019fca69-36c1-71d8-b85d-4099ffea48f1 Co-authored-by: Amp <amp@ampcode.com> Signed-off-by: Joah Gerstenberg <joah@squareup.com>
joahg
marked this pull request as ready for review
August 4, 2026 14:54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the rate limiting the dev-mode client has been hitting since the relay's per-pubkey admission control shipped (block#1917, ~2 days ago): 50 EVENT/REQ/COUNT frames per 5 s window (10/sec average) per
(tenant, pubkey).The client opened two REQs per member channel (channel events + mentions) — ~159 REQs on cold start for a 72-channel identity, ~71 for the dev identity. Cold start and every reconnect blew the budget; the reconnect replay then re-blasted all REQs with only 50 ms between batches, re-triggering the limiter and causing the repeated disconnects.
Changes
Batch live subscriptions (
useLiveChannelUpdates.ts)"#h"filters, 25 channels per REQ (LIVE_SUBSCRIPTION_BATCH_SIZE). REQ count drops from2Nto2·⌈N/25⌉— 6 REQs instead of ~144 for 72 channels.buildChannelMentionFilter/subscribeToChannelMentionEventsaccept a channel-ID list.Attribute h-less events client-side (
resolveChannelIdByEventReference)etag; the relay routes them to#hsubscriptions by resolving the target's channel server-side (crates/buzz-core/src/filter.rs). With one channel per subscription the client could inject the known channel (withChannelTagFallback); with batched filters it can't, so the handler now resolves the referenced event in loaded timeline caches instead. Unresolved events are dropped — without a loaded cache the timeline merge was a no-op anyway, and these kinds never hit unread/notification paths.Pace reconnect replay (
relayReconnectReplay.ts)REPLAY_INTER_BATCH_DELAY_MS50 ms → 1000 ms: 8 REQs/sec stays under the relay's 10/sec average with headroom for concurrent publishes.shouldPageReconnectReplaynow accepts multi-channel#hfilters so batched subscriptions keep paged history replay.Validation
pnpm typecheckcleanpnpm test: 4055/4055 pass, including new tests forbatchChannelIds,resolveChannelIdByEventReference, and multi-channel paging eligibilityLinear: AGNTOPS-418