Repository navigation
fix: retry Gemini 429 rate-limit errors in provider wrapper - #453
Open
lalith0407 wants to merge 1 commit into
Open
lalith0407 wants to merge 1 commit into
lalith0407 wants to merge 1 commit into
Conversation
isTooManyRequestsError only matched the AWS error types and the
"status code: 429" / "rate limit exceeded" text other clients produce.
The genai client behind the Gemini provider returns genai.APIError
("Error 429, Message: ..., Status: RESOURCE_EXHAUSTED"), so a Gemini rate
limit was never retried and failed the call on the first 429. Detect the
typed error by its status code, and its text form, so Gemini gets the same
backoff as the other providers.
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.
Description of the Change
Problem
isTooManyRequestsErrordoesn't recognize Gemini's 429. The genai client returnsgenai.APIErrorby value (Error 429, Message: ..., Status: RESOURCE_EXHAUSTED). So the wrapper's 429 retry never runs for Gemini, and the first rate limit fails the call. Related to #446 / #447, where that unretried 429 hit the task title.Solution
genai.APIErrorand*genai.APIErrorwithCode == 429as a rate limit, the same way the AWS types are checked.error 429, message:andstatus: resource_exhausted.google.golang.org/genaimoves from an indirect to a direct dependency (go mod tidy, same version, go.sum unchanged).Closes #452
Type of Change
Areas Affected
Testing and Verification
Test Configuration
PentAGI Version: 2.2.0-ce (843dfeb)
Docker Version: 29.9.1
Host OS: Linux
LLM Provider: Gemini
Enabled Features: none
Test Steps
go test ./pkg/providers/provider/ -run 'TestRateLimit|TestWrapper_Recognizes'go test ./pkg/providers/...,go vet,golangci-lint run ./pkg/providers/...GEMINI_SERVER_URLat a local proxy that returns Gemini's 429 body for the first 3generateContentcalls and forwards the rest, then start a Gemini flow.Test Results
%w, as text, and with only the code set.context.Canceled,context.DeadlineExceeded, nil, and text with "4290"/"call_429".Security Considerations
None.
Performance Impact
A rate-limited Gemini call now waits through the wrapper backoff (up to 10 tries, 5s plus 1s more each try) instead of failing at once, the same as the other providers.
Documentation Updates
None.
Deployment Notes
None.
Checklist
go fmtandgo vet(for Go code)Additional Notes
Gemini includes a
RetryInforetryDelay(for example11s) inAPIError.Details. The wrapper still uses its fixed backoff, and this PR doesn't change that.HUMAN:
After my task-title PR (#447) I kept digging into why my Gemini free-tier flows died on the very first 429. It turns out the wrapper already retries rate limits, but its check only knows OpenAI-style and AWS errors, so Gemini's 429 never matches. I added a check for Gemini's error type, with a text fallback, and kept everything else the same. Happy to also skip retries on daily-quota 429s or honor Gemini's retry delay if you'd like.