Skip to content

Eliminate rate limiting by removing spend API and staggering requests - #7

Merged
stevensouza merged 2 commits into
mainfrom
stevensouza/stagger-api-requests
Mar 2, 2026
Merged

stevensouza merged 2 commits into
mainfrom
stevensouza/stagger-api-requests

Conversation

@stevensouza

Copy link
Copy Markdown
Owner

Summary

Fixes persistent HTTP 429 rate limiting by removing the spend API call (overage_spend_limit) which was silently getting rate-limited while still consuming the server's rate limit budget. Decouples plan tier fetch from usage polling—it now fires once at startup with a 2-second stagger instead of on every poll cycle. Adds refreshAll() method so the Refresh button updates both usage % and plan tier with staggered timing.

Changes

  • Remove SpendResponse struct and fetchSpendData() entirely
  • Remove spend fields from UsageData and all spend-related UI/logging
  • Add fetchPlanIfNeeded() method (fires once at startup with 2s delay)
  • Add refreshAll() method for manual refresh via Refresh button
  • Reduce normal poll cycles from 2-3 simultaneous requests to 1 request
  • Add planFetchDelaySeconds constant for stagger timing

Result

Each poll cycle now sends exactly one API request (usage only) instead of two-three simultaneous requests, preventing rate limit hammering. The Refresh button updates both metrics with 2-second stagger to avoid simultaneous API calls.

🤖 Generated with Claude Code

Steven Thomas Souza and others added 2 commits March 2, 2026 16:17
Removes the spend API call (overage_spend_limit) which was silently getting
429'd and consuming rate limit budget. Decouples plan tier fetch from usage
polling so it only fires once at startup with a 2s delay. Adds refreshAll()
method for manual refresh (Refresh button) to update both usage and plan
staggered by 2s. Reduces normal poll cycles from 2-3 simultaneous requests
to 1, preventing 429 rate limit hammering.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Ping completion (StatusBarController) and reset ping (SchedulerService)
were calling fetchUsage() directly, bypassing the backoff timer and
sending requests while the server was still rate-limiting. Added
isBackingOff property to UsageService so these callers skip the fetch
when consecutive 429 errors are active.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@stevensouza
stevensouza merged commit a923d42 into main Mar 2, 2026
2 checks passed
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.

1 participant