Handle Claude rate limits and throttle provider fetches#102
Merged
Conversation
Contributor
|
Claude API Rate Limit(429) 대응하려고 Provider 요청 스로틀링이랑 중복 호출 제거 로직 추가하고, UI에 에러 상태 표시 기능 넣었네. 야, 코드는 전체적으로 꽤 잘 짰다. 특히 이건 맛보기 리뷰고, 버그나 보안 이슈 포함한 깐깐한 전체 리뷰 마렵다 싶으면 댓글로 |
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.
Summary
Claude usage fetches were failing with 429 responses from the Anthropic usage endpoint, but the app surfaced those failures as generic errors and kept retrying on the normal refresh cadence. That left users without a clear explanation in the menu and increased the chance of repeated rate-limited requests.
Root Cause
The Claude provider treated 429 responses like any other network failure, so the UI could only show a generic failure state. The provider manager also had no provider-specific minimum fetch interval, which meant Claude could be retried on the standard auto-refresh cadence even immediately after a rate-limit response. In parallel, the refresh path needed an explicit guard against overlapping startup refresh scheduling and concurrent provider fetches.
Fix
This change adds a provider-level minimum fetch interval to the shared protocol and sets Claude to a ten minute cooldown. Claude now parses API error payloads, classifies 429 responses as rate limits, and surfaces a user-facing
Rate limitedstate instead of collapsing into a generic failure. The provider manager now tracks in-flight fetches per provider, deduplicates concurrent requests, and returns throttled cooldown messages instead of issuing another network call while the cooldown window is active. The status bar menu was updated to render rate-limited providers explicitly, including an error submenu and cached details when available. The refresh timer startup path now cancels any previous initial refresh task before scheduling a new one.User Impact
Users will now see Claude marked as
Rate limitedwhen Anthropic rejects usage requests with 429, instead of seeing a vague failure. Subsequent refreshes during the cooldown window do not hit the Claude usage API again, which reduces unnecessary retries and avoids amplifying the rate-limit condition. The runtime fetch path also resists duplicate refreshes more cleanly by joining concurrent provider requests instead of spawning duplicate network work.Validation
I validated the change with
swiftlint lint CopilotMonitor/CopilotMonitor CopilotMonitor/CopilotMonitorTests,xcodebuild test -project CopilotMonitor/CopilotMonitor.xcodeproj -scheme CopilotMonitor -destination 'platform=macOS', andxcodebuild clean build -project CopilotMonitor/CopilotMonitor.xcodeproj -scheme CopilotMonitor -destination 'platform=macOS'. I also launched the rebuilt debug app, confirmed that Claude rendered asRate limitedin the menu, and observed that the next three-minute refresh returnedRate limited. Retrying in 7m.from the throttled path instead of issuing another Claude network request.