Skip to content

feat(core): increase fetch timeout and fix [object Object] error stringification#20441

Open
bdmorgan wants to merge 15 commits intomainfrom
fix/headers-timeout-pro-models
Open

feat(core): increase fetch timeout and fix [object Object] error stringification#20441
bdmorgan wants to merge 15 commits intomainfrom
fix/headers-timeout-pro-models

Conversation

@bdmorgan
Copy link
Collaborator

Summary

Addresses HeadersTimeoutError (UND_ERR_HEADERS_TIMEOUT) frequently seen with high-latency Gemini 3.0/3.1 Pro models by increasing the default fetch timeout to 60 seconds. Also improves error stringification to prevent [object Object] display for certain non-standard error objects.

Details

  • Increased Timeouts:
    • Added timeout: 60000 to all CodeAssistServer POST and streaming requests in packages/core/src/code_assist/server.ts.
    • Added timeout: 60000 to GoogleGenAI initialization in packages/core/src/core/contentGenerator.ts.
  • Improved Error Handling:
    • Updated getErrorMessage in packages/core/src/utils/errors.ts to check for a .message property on non-Error objects before falling back to String(). This ensures undici timeout errors are human-readable.
  • Tests:
    • Added packages/core/src/utils/errors_timeout.test.ts to verify the fix for HeadersTimeoutError stringification.
    • Updated packages/core/src/code_assist/server.test.ts to reflect the new timeout property in request expectations.

Related Issues

N/A

How to Validate

  1. Run npm test -w @google/gemini-cli-core and verify all tests pass.
  2. Review the new errors_timeout.test.ts which demonstrates the fix for [object Object] error messages.

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 14:11
@gemini-code-assist
Copy link
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 enhances the robustness and user experience of the core library by addressing common issues related to network timeouts and error message clarity. It significantly increases the default fetch timeout for API requests to better accommodate high-latency models, reducing HeadersTimeoutError occurrences. Additionally, it refines the error handling mechanism to provide more descriptive messages for non-standard error objects, preventing generic [object Object] outputs. The changes also ensure that HTTP 499 errors are treated as retryable, improving resilience against transient network issues.

Highlights

  • Increased Fetch Timeout: The default fetch timeout for API requests in CodeAssistServer and GoogleGenAI has been increased to 60 seconds (60000ms) to address HeadersTimeoutError issues, especially with high-latency Gemini models.
  • Improved Error Stringification: The getErrorMessage utility now correctly extracts the message property from non-standard error objects (like undici timeout errors), preventing generic [object Object] outputs and providing more human-readable error messages.
  • Enhanced Retry Logic for HTTP 499: HTTP 499 (Client Closed Request) errors are now recognized as retryable errors within the retryWithBackoff mechanism and classifyGoogleError function, improving resilience against transient network disconnections.
  • Comprehensive Testing: New tests have been added to verify the improved error stringification, and existing tests were updated to reflect the new timeout configurations and the handling of HTTP 499 errors in retry and quota classification logic.
Changelog
  • packages/core/src/code_assist/server.test.ts
    • Updated mock request expectations to include a 60-second timeout for generateContent and streamGenerateContent calls.
  • packages/core/src/code_assist/server.ts
    • Added a timeout property with a value of 60000 milliseconds to the request options for both generateContent and streamGenerateContent methods.
  • packages/core/src/core/contentGenerator.ts
    • Included timeout: 60000 in the httpOptions object passed to the GoogleGenAI constructor.
  • packages/core/src/utils/errors.ts
    • Modified getErrorMessage to explicitly check if an error object has a message property and is a string, returning it if found, before falling back to String().
  • packages/core/src/utils/errors_timeout.test.ts
    • Added a new test file to verify getErrorMessage correctly extracts the message property from plain objects, specifically simulating undici's HeadersTimeoutError.
  • packages/core/src/utils/flashFallback.test.ts
    • Imported the HttpError type.
    • Added a new test case to verify that the onPersistent429 callback is triggered when an HTTP 499 error persists through retry attempts.
  • packages/core/src/utils/googleQuotaErrors.test.ts
    • Updated a test description to include HTTP 499 in the non-retryable error check.
    • Added a test case to confirm that a 499 'Client Closed Request' error is classified as a RetryableQuotaError.
  • packages/core/src/utils/googleQuotaErrors.ts
    • Modified classifyGoogleError to consider HTTP status code 499 (Client Closed Request) as a retryable quota error, alongside 429.
    • Updated logic to use the status code for RetryableQuotaError creation when a specific retry message is not found.
  • packages/core/src/utils/retry.test.ts
    • Added a new test case to confirm that retryWithBackoff successfully retries an operation when it initially fails with an HTTP 499 error.
  • packages/core/src/utils/retry.ts
    • Updated the isRetryableError function to include HTTP status code 499 as a condition for retrying, in addition to 429 and 5xx errors.
  • packages/sdk/src/agent.integration.test.ts
    • Added recordResponses and fakeResponses options to the GeminiCliAgent constructor in the 'propagates errors from dynamic instructions' test, using a golden file path.
Activity
  • Added/updated tests.
  • Validated on MacOS using npm run.
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 increases the fetch timeout to 60 seconds and improves error message stringification, which are valuable changes. However, the introduction of specific logic to treat HTTP 499 errors as retryable, particularly by misclassifying them as a RetryableQuotaError, raises concerns. I've left a comment suggesting a re-evaluation of the necessity of specific 499 handling given existing generic retry mechanisms, and if necessary, to ensure proper classification and separation of concerns.

@github-actions
Copy link

github-actions bot commented Feb 26, 2026

Size Change: +684 B (0%)

Total Size: 25.7 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 25.2 MB +684 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

@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Feb 26, 2026
@bdmorgan bdmorgan enabled auto-merge February 26, 2026 17:29
@bdmorgan bdmorgan disabled auto-merge February 26, 2026 17:29
import { Agent, ProxyAgent, setGlobalDispatcher } from 'undici';

const DEFAULT_HEADERS_TIMEOUT = 60000; // 60 seconds
const DEFAULT_BODY_TIMEOUT = 300000; // 5 minutes
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: might comment that the body timeout is actually unchanged from the default or consider raising it.

Copy link
Contributor

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

lgtm

@bdmorgan bdmorgan requested a review from a team as a code owner February 26, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants