Skip to content

Add resetBudget() to LeakyBucketRateLimit#369

Merged
darshkpatel merged 1 commit into
mainfrom
darsh/add-reset-budget
Apr 7, 2026
Merged

Add resetBudget() to LeakyBucketRateLimit#369
darshkpatel merged 1 commit into
mainfrom
darsh/add-reset-budget

Conversation

@darshkpatel

@darshkpatel darshkpatel commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds resetBudget() public method to LeakyBucketRateLimit that zeros out consumed budget and stops any active restore interval
  • Needed by river-manager to reset retry budget when a client transitions from background → foreground

Why

When mobile users background the app, the OS kills WebSocket connections (close code 1006). The retry budget accumulates failures during this time. When the user returns, the budget is already exhausted, causing all River services to immediately go fatal and show the "Please Refresh" modal — even though the network is fine.

With resetBudget(), river-manager can give the client a fresh budget on foreground, allowing reconnection to be retried.

Adds a public method to fully reset the retry budget (zero consumed
budget and stop any active restore interval). This is needed by
river-manager to reset the budget when a client transitions from
background to foreground — previous failures during OS backgrounding
shouldn't count against the fresh reconnection attempt.
@darshkpatel darshkpatel marked this pull request as ready for review April 7, 2026 17:22
@darshkpatel darshkpatel requested a review from a team as a code owner April 7, 2026 17:22
@darshkpatel darshkpatel requested review from daweifeng-replit and removed request for a team April 7, 2026 17:22

@jackyzha0 jackyzha0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm this was explicit when we first started to avoid allowing retry spam on reload but i think time has shown us this is too aggressive

lets roll this out and watch the sessions per client metric

@darshkpatel darshkpatel merged commit 1e0007b into main Apr 7, 2026
8 checks passed
@darshkpatel darshkpatel deleted the darsh/add-reset-budget branch April 7, 2026 17:24
darshkpatel added a commit that referenced this pull request Apr 7, 2026
## Summary
- Bumps version to 0.216.0 (includes `resetBudget()` from #369)
- Adds test for `resetBudget`: verifies it zeroes consumed budget,
resets backoff to 0, and stops the restore interval

## Test plan
- All rate limit tests pass (9/9)

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants