refactor(core): improve API response error logging when retry#21784
refactor(core): improve API response error logging when retry#21784
Conversation
…lure logic - Simplifies the stream retry loop in GeminiChat by removing the 'lastError' tracking variable in favor of immediate throwing within the catch block. This ensures that logContentRetryFailure is correctly triggered exactly once on the final failure attempt (or initial failure if no retries occur) for Gemini 2 models. - Adds explicit test expectations to verify logContentRetryFailure is not called for non-eligible models or errors
- Updated `streamWithRetries` to track the actual number of `attemptsMade` instead of blindly reporting `maxAttempts` when an `InvalidStreamError` occurs and a retry is not performed (e.g., for non-Gemini-2 models). - Ensure network errors are logged as ContentRetryFailureEvent as well.
|
Hi @yunaseoul, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines. Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. Thank you for your understanding and for being a part of our community! |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refines the content retry mechanism within the GeminiChat component, focusing on accuracy and clarity in error reporting. The changes ensure that retry attempts are precisely counted and logged, providing a more reliable understanding of content delivery failures. By simplifying the retry loop and consolidating error handling, the system becomes more robust and easier to maintain. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors the retry logic in GeminiChat to simplify the implementation and improve the accuracy of failure reporting. The changes remove the lastError tracking variable in favor of a more direct control flow, ensure logContentRetryFailure is called for final failures, and correctly report the number of attempts made. The accompanying test updates correctly validate this new behavior.
My main feedback concerns a subtle inconsistency in the failure logging. For non-retryable errors during the initial connection phase, the failure is not logged, which seems to contradict one of the goals of this PR. I've left a specific comment with more details.
|
Size Change: -2.24 kB (-0.01%) Total Size: 26.1 MB
ℹ️ View Unchanged
|
Summary
This PR refactors the API response error handling and retry logic to improve the accuracy of our telemetry and error logging.
Details
logContentRetryFailureonly capturedInvalidStreamErrorfor Gemini 2 models, missing terminal network failures. Now, it consistently logsContentRetryFailureEventfor all exhausted retryable errors (content and network), with the correct attempt number.GeminiChatby removing thelastErrortracking variable in favor of immediate throwing within the catch block.Related Issues
Fixes #20189
How to Validate
Review the code changes and run
npm run test -w @google/gemini-cli-core. The tests will ensure that retry counts are accurately reported and the logging behaves as expected for both eligible and non-eligible models.Pre-Merge Checklist