Skip to content

feat(core): add HTTP 499 to retryable errors and map to RetryableQuotaError#20432

Merged
bdmorgan merged 5 commits into
mainfrom
fix/retry-499-errors
Feb 26, 2026
Merged

feat(core): add HTTP 499 to retryable errors and map to RetryableQuotaError#20432
bdmorgan merged 5 commits into
mainfrom
fix/retry-499-errors

Conversation

@bdmorgan

Copy link
Copy Markdown
Collaborator

Summary

Adds HTTP 499 (Client Closed Request) to the list of retryable errors in packages/core, and correctly classifies it as a RetryableQuotaError so that it triggers the exponential backoff mechanism and eventually the onPersistent429 fallback dialog (e.g., offering to fall back to a Flash model) if the transient infrastructure failure persists. This is especially helpful for timeouts occurring when talking to models like Gemini 3.1 Pro via proxy servers.

Details

  • Added HTTP 499 to the isRetryableError status check in packages/core/src/utils/retry.ts.
  • Updated classifyGoogleError in packages/core/src/utils/googleQuotaErrors.ts to map HTTP 499 to RetryableQuotaError.
  • Added unit tests to retry.test.ts and googleQuotaErrors.test.ts.
  • Added an integration test to flashFallback.test.ts to ensure persistent 499 errors trigger the correct fallback intent logic.
  • Included a fix for a flaky test in packages/sdk/src/agent.integration.test.ts that was failing due to missing fakeResponses configurations during the run.

Related Issues

N/A

How to Validate

  1. Run npm test -w @google/gemini-cli-core and verify all tests pass.
  2. Review the added test cases in retry.test.ts, googleQuotaErrors.test.ts, and flashFallback.test.ts which mock the 499 failure condition.

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

@bdmorgan bdmorgan requested a review from a team as a code owner February 26, 2026 13:14
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @bdmorgan, 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 improves the resilience of the core package by explicitly recognizing and handling HTTP 499 "Client Closed Request" errors. By classifying these errors as retryable quota errors, the system can now intelligently apply exponential backoff and trigger appropriate fallback mechanisms when transient infrastructure issues persist. This enhancement is particularly beneficial for interactions with AI models via proxy servers, where such timeouts can occur, leading to a more robust and user-friendly experience.

Highlights

  • HTTP 499 Handling: Added HTTP 499 (Client Closed Request) to the list of retryable errors within the core package.
  • Quota Error Classification: Mapped HTTP 499 to RetryableQuotaError to ensure it triggers exponential backoff and appropriate fallback mechanisms, such as onPersistent429.
  • Enhanced Test Coverage: Introduced new unit tests for retry logic and Google quota error classification, and an integration test specifically for persistent 499 errors triggering the fallback intent logic.
  • Flaky Test Fix: Resolved a flaky integration test in the SDK by correctly configuring fakeResponses for dynamic instructions.
Changelog
  • packages/core/src/utils/flashFallback.test.ts
    • Imported HttpError type for use in tests.
    • Added a new integration test case to verify that persistent HTTP 499 errors correctly trigger the onPersistent429 fallback callback.
  • packages/core/src/utils/googleQuotaErrors.test.ts
    • Updated the description for a test case to reflect that 499 is now considered a retryable error.
    • Added a new test case to confirm that classifyGoogleError correctly identifies HTTP 499 as a RetryableQuotaError.
  • packages/core/src/utils/googleQuotaErrors.ts
    • Modified the classifyGoogleError function to include HTTP 499 status code when determining if an error is a retryable quota error, ensuring proper handling and retry logic.
  • packages/core/src/utils/retry.test.ts
    • Added a new unit test to confirm that the retryWithBackoff utility successfully retries operations when encountering an HTTP 499 error.
  • packages/core/src/utils/retry.ts
    • Updated the isRetryableError function to explicitly include HTTP 499 status code as a condition for retrying, alongside 429 and 5xx errors.
  • packages/sdk/src/agent.integration.test.ts
    • Modified an existing integration test to include recordResponses and fakeResponses configurations, addressing a previous flakiness issue.
Activity
  • The author, bdmorgan, initiated this pull request to enhance error handling for HTTP 499 responses.
  • New unit and integration tests were developed and added to thoroughly validate the implemented changes.
  • A previously flaky integration test within the SDK was identified and fixed as part of this work.
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.

@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 correctly adds HTTP 499 (Client Closed Request) to the set of retryable errors. The changes are consistently applied across the retry logic and error classification utilities, and are well-supported by new unit and integration tests. Classifying the 499 error as a RetryableQuotaError is a logical choice that allows it to leverage the existing exponential backoff and fallback mechanisms. The included fix for a flaky test is also a good addition. The changes are of high quality and I have no further recommendations.

@@ -144,14 +144,14 @@ describe('GeminiCliAgent Integration', () => {
});

it('propagates errors from dynamic instructions', async () => {
const goldenFile = getGoldenPath('agent-static-instructions');

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.

is this change needed?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

where is the file been attach bro??

@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label Feb 26, 2026
@github-actions

github-actions Bot commented Feb 26, 2026

Copy link
Copy Markdown

Size Change: +125 B (0%)

Total Size: 25.7 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 25.2 MB +125 B (0%)
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 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
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B

compressed-size-action

@bdmorgan bdmorgan added this pull request to the merge queue Feb 26, 2026
Merged via the queue into main with commit 9c2fd5a Feb 26, 2026
27 checks passed
@bdmorgan bdmorgan deleted the fix/retry-499-errors branch February 26, 2026 15:56
heaventourist pushed a commit to heaventourist/gemini-cli that referenced this pull request Feb 26, 2026
BryanBradfo pushed a commit to BryanBradfo/gemini-cli that referenced this pull request Mar 5, 2026
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026

@marsam2489-lang marsam2489-lang left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Try the best merge

warrenzhu25 pushed a commit to warrenzhu25/gemini-cli that referenced this pull request Apr 9, 2026
@sripasg sripasg added the size/m A medium sized PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m A medium sized PR status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants