Repository navigation
fix: pace Discord member subscriptions so a scroll cannot spend the Gateway budget - #52
Conversation
…ateway budget The send loop drained every coalesced subscription snapshot as soon as it was queued, so a burst of viewport changes spent the whole rolling allowance on intermediate positions and the final viewport waited for the minute to roll over. The send queue now owns the rolling window. The first eight subscription frames a minute go at once; past them each waits a spacing of 60 s / (80 - frames this minute), which settles a sustained scroll near forty frames a minute with the last viewport about a second behind. Subscriptions stop at 80 frames a minute, leaving twenty of the queued hundred for commands, and a guild not subscribed this minute skips the spacing. Heartbeats, identify and resume still go straight to the socket. Fixes #44 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@vbmithr this one addresses the budget saturation you measured in #44. What changed (
Tests: these run on a clock the test controls.
Trade-off: if commands themselves run at a high rate, subscriptions get fewer slots. With about 60 commands a minute, I estimate the final viewport could trail by up to about 6 s, but I haven't tested that. To try it: git fetch origin pull/52/head:pr-52 && git checkout pr-52
cargo test -p chatd adapters::discord::gateway
cargo test -p chatd # full daemon suiteYour |
Cause
SendQueuecoalesced subscription snapshots that had not been sent yet, butrundrained each snapshot as soon as it was queued, for as long as the rollingSENDS_A_MINUTE = 100allowance held out. A burst of viewport changes therefore sent one op 37 frame per intermediate position until the allowance ran out. The final viewport then waited up to about 60 s for old frames to age out, and every other queued command waited with it.Fix
The change is limited to the send queue in
crates/chatd/src/adapters/discord/gateway.rs.SendQueuenow records when each frame of the last minute went.pop(now)anddue(now)take the time as an argument, so tests can drive them with their own clock. The socket loop sleeps untildueinstead of until the window frees.60 s / (80 - frames this minute). The wait grows as the allowance runs down. Under a sustained scroll this settles at about 40 frames a minute, and the latest viewport is never more than about 1.3 s behind.Validation
cargo test -p chatd: 290 passed, 0 failed.New and updated unit tests in
send_queue_testsuse a clock the test moves:Fixes #44
🤖 Generated with Claude Code