fix(core): Improve API error retry logic#9763
Merged
Merged
Conversation
|
Size Change: +58 B (0%) Total Size: 17.4 MB ℹ️ View Unchanged
|
geoffdowns
pushed a commit
to geoffdowns/gemini-cli
that referenced
this pull request
Sep 26, 2025
jkcinouye
pushed a commit
that referenced
this pull request
Sep 29, 2025
thacio
added a commit
to thacio/auditaria
that referenced
this pull request
Oct 4, 2025
giraffe-tree
pushed a commit
to giraffe-tree/gemini-cli
that referenced
this pull request
Oct 10, 2025
cocosheng-g
pushed a commit
that referenced
this pull request
May 6, 2026
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.
TLDR
This pull request refactors the API error handling and retry mechanism within the core chat functionality. Previously, we relied on string-matching error messages to decide whether to retry an API call. This update switches to using the structured
ApiErrorfrom the GenAI SDK, checking the HTTP status code directly. This makes our retry logic more robust and reliable, ensuring we correctly retry on transient errors like rate limits (429) and server errors (5xx) while failing fast on client-side issues like bad requests (400).Dive Deeper
The previous implementation of our retry logic was brittle because it parsed the text of an error message to find status codes. This approach can easily break if the upstream SDK changes its error message formatting.
This change improves our resilience by:
instanceof ApiErrorfrom@google/genai.error.statusproperty to make decisions, which is a much more stable API than the error message.shouldRetryfunction is now more explicit:400 Bad Requesterrors.429 Rate Limit Exceedederrors.5xxserver-side errors.This ensures the CLI is more predictable when interacting with the Gemini API, leading to a better user experience during transient network or server issues.
Reviewer Test Plan
Validating this change manually is difficult as it requires forcing the backend to produce specific HTTP error codes.
The most effective way to review this PR is to:
what's in @packages/, this would exceed token limit and get 400 bad request.Testing Matrix