fix(api): retry on 429 rate-limit with exponential backoff (QUA-645)#106
Merged
Desperado merged 1 commit intoMay 24, 2026
Conversation
Free-tier Anthropic keys hit per-minute token limits on the first call when the system prompt + tool catalog is large. Previously the 429 was surfaced raw with no retry, blocking any trial user on a free key. Adds doWithRetry() in internal/agent/retry.go: - Retries up to 3 times on HTTP 429 (1 s → 2 s → 4 s backoff) - Parses Retry-After header when present to use the server-suggested delay - Respects context cancellation during sleep (Ctrl+C exits immediately) - Prints "rate limited — retrying in Xs (N/3)…" via term or stdout Wired into callStreamingAPI() (with terminal + context) and callAPI() (background context, no terminal). Both rebuild the request body from the already-marshaled []byte slice, so no double-read issue. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
✅ QualityMax Pipeline
Powered by QualityMax — AI-Powered Test Automation |
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
Free-tier Anthropic keys hit per-minute token limits on the very first call because qmax-code's system prompt + tool catalog is large. The 429 was surfaced raw with no retry — blocking any trial user on a free key.
doWithRetry()ininternal/agent/retry.goRetry-Afterheader to use the server-suggested delay when present● rate limited — retrying in 2s (1/3)…via the terminal status linecallStreamingAPI()andcallAPI(); request body is rebuilt from the already-marshaled[]byteslice each attempt (no double-read issue)Closes QUA-645
Test plan
🤖 Generated with Claude Code