Repository navigation
Fix HTTP 429 rate limiting in usage API polling - #6
Merged
Merged
Conversation
Replace the repeating timer with a self-rescheduling one-shot timer to enable adaptive backoff. When a 429 (Too Many Requests) error or network failure occurs, the next poll is delayed with exponential backoff (capped at 10 minutes). Success resets backoff to normal. Also prevent the session key update feedback loop: API-driven session key rotations no longer trigger the Combine observer that restarts polling. Only user-initiated credential changes restart polling. Additionally, add sleep/wake handling: polling stops before system sleep and resumes after a 15-second delay on wake, preventing "connection offline" errors. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
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
Fixed the HTTP 429 rate-limiting errors shown in Event Log by addressing two root causes:
Session key feedback loop: API-driven session key rotations were triggering the Combine observer that restarted polling, causing 9-18+ requests/minute in bursts. Now only user-initiated credential changes restart polling.
No rate-limit handling: Added exponential backoff for 429 and network errors, with the next poll delayed by
min(interval * 2^consecutive_errors, 10 min). Backoff resets on success.Post-sleep connection errors: Added sleep/wake observers to pause polling before sleep and resume after a 15-second delay, preventing "connection offline" errors.
Changes
Sources/PingClaude/UsageService.swift: AddedisUpdatingSessionKeyflag,consecutiveErrorstracking, replaced repeating timer with self-rescheduling one-shot timer, added explicit 429 handling, added sleep/wake observersSources/PingClaude/Constants.swift: AddedusageMaxBackoffSecondsconstantTesting
make build✓make lint✓make bundle✓Manual verification recommended: launch app and monitor Event Log for steady 60s polling without restart bursts.
🤖 Generated with Claude Code