Skip to content

fix(core,cli): prevent silent multi-minute loading hangs on network failures - #30182

Merged
DavidAPierce merged 2 commits into
google-gemini:mainfrom
villahernandez-coder:FixBug-cla-572061790
Nov 6, 2026
Merged

DavidAPierce merged 2 commits into
google-gemini:mainfrom
villahernandez-coder:FixBug-cla-572061790

Conversation

@villahernandez-coder

@villahernandez-coder villahernandez-coder commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Prevents Gemini CLI from appearing stuck indefinitely on the loading spinner with no output or error details when outbound API requests encounter network timeouts, unreachable routes, TLS interception errors, or `ALL_PROXY` configurations—particularly under `model: auto` and the default `ui.errorVerbosity: "low"` setting.

Details

When outbound connectivity to the Gemini API failed or stalled on a client machine, several behaviors compounded into a silent 6–20+ minute loading state:

1. **Abort signal propagation in `BaseLlmClient`:** `BaseLlmClient._generateWithRetry` did not pass `signal: abortSignal` to `retryWithBackoff`, preventing `Esc` / cancellation from aborting exponential backoff `delay()` sleeps and allowing background retry attempts to continue after cancellation.
2. **Bounded retries for optional pre-turn `auto` classifiers:** `ClassifierStrategy` and `NumericalClassifierStrategy` invoked `baseLlmClient.generateJson` without `maxAttempts`, running 5 full retry cycles before catching and returning `null` to `DefaultStrategy`, which then started a second full retry loop in `GeminiChat`. Both optional routing strategies now cap `maxAttempts` at `2`.
3. **Fail-fast handling for deterministic network/TLS causes:** `isRetryableError` matched any `TypeError: fetch failed` message when `retryFetchErrors` was `true` (default), retrying deterministic `error.cause` codes across all attempts. Added `NON_RETRYABLE_NETWORK_CODES` (`ENETUNREACH`, `EHOSTUNREACH`, `ENETDOWN`, `EHOSTDOWN`, `EACCES`, `EPERM`, `ERR_INVALID_URL`, `UND_ERR_INVALID_ARG`, `UND_ERR_NOT_SUPPORTED`, and permanent TLS certificate verification errors) so non-transient failures surface immediately on the first attempt.
4. **`ALL_PROXY` / `all_proxy` support:** Extended proxy environment variable resolution in `loadCliConfig` to fall back to `ALL_PROXY` and `all_proxy`.
5. **Network retry visibility in `useLoadingIndicator`:** Added `isNetworkRetry` so network connectivity/timeout retries immediately display `Trying to reach <model> (Attempt X/Y)` even when `ui.errorVerbosity` is `"low"`, while preserving low-verbosity suppression for generic server/content retries.

Related Issues

Fixes #29698

How to Validate

1. Run targeted core and CLI unit tests:
   ```bash
   npm test -w @google/gemini-cli-core -- src/core/baseLlmClient.test.ts src/routing/strategies/classifierStrategy.test.ts src/routing/strategies/numericalClassifierStrategy.test.ts src/utils/retry.test.ts
   npm test -w @google/gemini-cli -- src/ui/hooks/useLoadingIndicator.test.tsx src/config/config.test.ts
   ```
2. Run typecheck and linter:
   ```bash
   npm run typecheck -w @google/gemini-cli-core
   npm run typecheck -w @google/gemini-cli
   npx eslint --max-warnings 0 packages/core/src/core/baseLlmClient.ts packages/core/src/routing/strategies/classifierStrategy.ts packages/core/src/routing/strategies/numericalClassifierStrategy.ts packages/core/src/utils/retry.ts packages/cli/src/config/config.ts packages/cli/src/ui/hooks/useLoadingIndicator.ts
   ```
3. Simulate an unreachable proxy or network failure (e.g., `HTTPS_PROXY=http://127.0.0.1:1 npm run start`) with `model: auto` and default `ui.errorVerbosity: "low"`: verify that retry progress (`Trying to reach ... (Attempt X/Y)`) appears immediately during transient network retries, `Esc` cancels immediately during backoff, and deterministic network/TLS errors fail fast without retrying.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

…ailures

- Pass abortSignal to retryWithBackoff in BaseLlmClient so user cancellation immediately aborts backoff sleeps and prevents background retries.
- Cap optional pre-turn auto-routing classifier attempts to 2 in ClassifierStrategy and NumericalClassifierStrategy so unreachable networks fail fast to DefaultStrategy instead of burning 5 full retry cycles before starting a second chat retry loop.
- Fail fast in isRetryableError on deterministic network/TLS error codes (e.g. ENETUNREACH, EHOSTUNREACH, EACCES, UNABLE_TO_VERIFY_LEAF_SIGNATURE, SELF_SIGNED_CERT_IN_CHAIN, ERR_TLS_CERT_ALTNAME_INVALID) wrapped in TypeError: fetch failed even when retryFetchErrors is true.
- Support ALL_PROXY and all_proxy environment variable fallbacks in CLI proxy configuration.
- Surface network connectivity retry progress immediately in useLoadingIndicator even when ui.errorVerbosity is low.

Fixes google-gemini#29698
@villahernandez-coder
villahernandez-coder requested a review from a team as a code owner November 6, 2026 14:34
@github-actions github-actions Bot added the size/m A medium sized PR label Nov 6, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 addresses silent, long-running hangs in the Gemini CLI caused by network connectivity issues. By implementing better abort signal propagation, introducing fail-fast mechanisms for non-recoverable network errors, and improving user feedback during retries, the CLI now provides a more responsive and transparent experience when encountering network failures.

Highlights

  • Abort Signal Propagation: Updated BaseLlmClient to pass abort signals to retry logic, ensuring that cancellation requests (like pressing Esc) immediately stop pending retry attempts.
  • Fail-Fast Network Handling: Introduced a list of non-retryable network and TLS error codes to prevent unnecessary retries on deterministic failures, improving responsiveness.
  • Proxy Configuration: Extended CLI proxy support to include ALL_PROXY and all_proxy environment variables.
  • UI Feedback: Enhanced the loading indicator to explicitly display network retry progress even when error verbosity is set to low.
  • Strategy Optimization: Capped retry attempts at 2 for classifier strategies to prevent excessive loops during connectivity issues.
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 the 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 counterproductive. 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.

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. ↩

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 204
  • Additions: +184
  • Deletions: -20
  • Files changed: 12

@gemini-cli gemini-cli Bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Nov 6, 2026

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

Copy link
Copy Markdown
Contributor

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 several improvements to proxy configuration, network retry behavior, and LLM client robustness. Specifically, it adds support for the ALL_PROXY and all_proxy environment variables, ensures deterministic network/TLS errors fail fast instead of retrying, and passes abort signals to the retry mechanisms. Additionally, it immediately surfaces retry progress for network failures in low error verbosity mode. Feedback on the changes identifies a bug in the network retry regex within useLoadingIndicator.ts, where normalized FETCH_FAILED errors will not be matched due to a missing underscore in the pattern.

@villahernandez-coder

Copy link
Copy Markdown
Contributor Author

/Gemini review

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

Copy link
Copy Markdown
Contributor

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 several improvements to proxy support, retry mechanisms, and error handling. Specifically, it adds support for the ALL_PROXY and all_proxy environment variables in the CLI configuration and refactors the proxy tests to use vi.stubEnv in accordance with the repository's testing conventions. Additionally, it refines the retry logic by passing abort signals to LLM client retries, limiting classifier strategy attempts to 2, and introducing a list of non-retryable network/TLS error codes (such as ENETUNREACH and certificate errors) to fail fast on deterministic failures. Finally, it updates the loading indicator to immediately surface retry progress for network failures even in low error verbosity mode. I have no further feedback to provide as there are no review comments.

@DavidAPierce
DavidAPierce added this pull request to the merge queue Nov 6, 2026
Merged via the queue into google-gemini:main with commit 33d540e Nov 6, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

loading

2 participants