Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

SandyTao520
Copy link
Collaborator

@SandyTao520 SandyTao520 commented Oct 13, 2025

TLDR

Adds configuration and logic to retry API calls when a specific "fetch failed" error occurs, addressing transient network issues.

Dive Deeper

Introduces a --retry-fetch-errors CLI flag (and corresponding config) that, when enabled, allows geminiChat to retry requests that fail with "exception TypeError: fetch failed sending request". This is handled within the existing retryWithBackoff utility in @google/gemini-cli-core.

Reviewer Test Plan

Run the CLI with --retry-fetch-errors in an environment with unstable network connectivity or mock network failures to verify retries occur (disconnect network or set GOOGLE_GEMINI_BASE_URL=http://localhost:9999).

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

@SandyTao520 SandyTao520 requested a review from a team as a code owner October 13, 2025 21:38
Copy link
Contributor

Summary of Changes

Hello @SandyTao520, 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 significantly enhances the resilience of the Gemini CLI by implementing a configurable retry mechanism for specific network-related fetch errors. By introducing a new CLI flag and integrating the logic into the core retry utility, the CLI can now gracefully handle transient network connectivity issues, leading to a more stable and reliable user experience during API interactions.

Highlights

  • New CLI Flag for Retries: Introduced a new --retry-fetch-errors CLI flag that, when enabled, allows the Gemini CLI to automatically retry API calls that fail due to specific 'exception TypeError: fetch failed sending request' errors.
  • Enhanced Retry Logic: The existing retryWithBackoff utility has been updated to incorporate the new retryFetchErrors configuration, specifically targeting and retrying transient network issues indicated by the 'fetch failed' error message.
  • Configuration Integration: The retryFetchErrors option has been integrated into both the CLI's CliArgs and the core library's Config class, ensuring consistent handling and access across the application.
  • Comprehensive Testing: New unit tests have been added to geminiChat.test.ts to verify that the retry mechanism correctly functions when retryFetchErrors is enabled and a 'fetch failed' error occurs, ensuring robustness.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces retry logic for specific 'fetch failed' errors, controlled by a new --retry-fetch-errors flag. The implementation correctly threads the new configuration from the CLI down to the retryWithBackoff utility. However, there are two high-severity issues that should be addressed. First, the retry condition relies on a hardcoded error message string, which is brittle and could lead to silent failures if the error format changes. Second, the new test case intended to validate this feature mocks the retryWithBackoff function, meaning the new retry logic is not actually being tested. The test should be updated to test the real implementation or a new unit test should be added.

packages/core/src/core/geminiChat.test.ts Show resolved Hide resolved
packages/core/src/utils/retry.ts Show resolved Hide resolved
Copy link

github-actions bot commented Oct 13, 2025

Size Change: +926 B (+0.01%)

Total Size: 17.8 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 17.8 MB +926 B (+0.01%)
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB 0 B
./bundle/sandbox-macos-permissive-open.sb 830 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B

compressed-size-action

packages/cli/src/config/config.ts Outdated Show resolved Hide resolved
packages/core/src/core/geminiChat.test.ts Outdated Show resolved Hide resolved
});

describe('Fetch error retries', () => {
const fetchErrorMsg = 'exception TypeError: fetch failed sending request';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we specify the fetch error with a Type rather than a String?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the context, SandyTao520. Given that the SDK discards error details, using error.message.includes() for the specific fetch error message is a pragmatic and reasonable approach to handle these transient network issues. If the SDK evolves to expose more granular error types in the future, we can revisit this to use a more robust type-based check. The linked issue also provides good background on the problem.

packages/core/src/utils/retry.ts Show resolved Hide resolved
Copy link
Collaborator

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved after these comments are addressed.

@SandyTao520
Copy link
Collaborator Author

I've addressed the comments by moving the retry-fetch-errors from a flag to a setting, and updating the test to use the actual retryWithBackoff implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.