Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai-gemini): keep httpOptions.timeout in geminiImage when a signal is passed #2314 (GitHub #2313)

Openpcbeingused33(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/2313/headopened View on GitHub

pcbeingused33(GitHub profile, opens in a new tab)commented

🎯 Changes

geminiImage() dropped the configured httpOptions.timeout whenever the caller passed an abortSignal. The @google/genai Interactions client applies httpOptions.timeout only when the request has no signal of its own (documented on withHttpTimeout in utils/client.ts). The text and video adapters already handle this with withHttpTimeout (#1975), but the image adapter still passed options.abortSignal straight to client.interactions.create. So an image request with a caller signal could hang past the timeout.

Root cause: generateImages() in packages/ai-gemini/src/adapters/image.ts used { signal: options.abortSignal } without merging in the timeout.

Fix: store config.httpOptions?.timeout in the constructor and pass withHttpTimeout(options.abortSignal, this.timeoutMs) as the signal, the same way video.ts does it. Without a timeout or without a caller signal, the request is unchanged.

Tests: two cases in tests/abort-signal-wire.test.ts, next to the existing text and video ones:

  • image: the timeout aborts fails on main (the request is never aborted) and passes with this change.
  • image: the caller still aborts checks that the caller signal still reaches the request.

No E2E case was added: the aimock setup answers right away, so it cannot show a client-side timeout. The unit tests stub the wire fetch the same way the existing timeout tests do.

Docs: not updated; this makes the image adapter follow the documented httpOptions.timeout behaviour.

Test plan (package-level checks; the full pnpm run test:pr was not run):

  • pnpm --filter @tanstack/ai-gemini exec vitest run (532 passed; the new timeout test fails on main)
  • tsc for packages/ai-gemini, oxlint src --type-aware, oxfmt --check on the changed files

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.
  • Docs: I updated docs/ for this change, or this change is not user-facing.
  • Changeset: I added a changeset (pnpm changeset), or this PR does not change a published package.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

This change was prepared with the assistance of an AI coding assistant.

Summary by CodeRabbit

  • Bug Fixes
    • Gemini image-generation requests now honor the configured HTTP timeout while still responding to caller-triggered cancellation.
    1. tanstack-source added labelsbug

    2. 🦋 Changeset detected

      Latest commit: 29570f3f700faf287c37a74ac8737c2edd70597a

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 2 packages
      NameType
      @tanstack/ai-geminiPatch
      @tanstack/ai-optimize-evalsPatch

      Not sure what this means? Click here to learn what changesets are.

      Click here if you're a maintainer who wants to add another changeset to this PR

    3. tanstack-sourceBotcommented Only here. This is not on GitHub.

      This pull request is useful. It keeps httpOptions.timeout on geminiImage() when the caller passes a signal. Open pull request #2192 does the same timeout-plus-signal fix for OpenRouter. This pull request does not link an issue.

      TanStack Source bot, value agent

    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      The Gemini image adapter now applies httpOptions.timeout when a caller provides an abortSignal. Tests verify that either the configured timeout or the caller’s signal can abort the request.

      Changes: Gemini image timeout handling

      Layer / File(s)Summary
      Apply timeout and verify image request aborts
      packages/ai-gemini/src/adapters/image.ts, packages/ai-gemini/tests/abort-signal-wire.test.ts, .changeset/gemini-image-http-timeout.md
      The adapter combines the caller’s abort signal with the configured timeout for image requests. Tests cover timeout and caller-signal aborts. The changeset declares a patch release.

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Bug fix

      Possibly related PRs

      • TanStack/ai#1975: Adds caller abort-signal handling in Gemini adapters and preserves the HTTP timeout for video requests.

      Suggested reviewers: tombeckenham, alemtuzlak

      Merge Risk: Minimal · up to 29570

      geminiImage() now honors the configured HTTP timeout when a caller supplies an abort signal, which matches the text and video adapters. Requests without a timeout or signal behave as before. The change is small, tested, and easy to revert, so merge risk is minimal.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title names the change: geminiImage() now keeps httpOptions.timeout when a caller passes an abort signal. It matches the fix in image.ts and the new tests, and it follows the conventional commit f…
      Description checkPassedThe description follows the repository template. It has the Changes section with the root cause, fix, and tests. The checklist is filled in. Two items are unchecked: the local test:pr run and the docs…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Title check

      Explanation

      The title names the change: geminiImage() now keeps httpOptions.timeout when a caller passes an abort signal. It matches the fix in image.ts and the new tests, and it follows the conventional commit format. It is specific and concise.

      Full details: Description check

      Explanation

      The description follows the repository template. It has the Changes section with the root cause, fix, and tests. The checklist is filled in. Two items are unchecked: the local test:pr run and the docs update. The author explains the docs choice and says the full test:pr run was skipped. The release impact section is complete and a changeset is included.

      Finishing Touches

      Generate unit tests (beta)

      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      Share

      Recent review info

      Run configuration

      • Source mode: Auto
      • Repository: TanStack/ai
      • Branch: main
      • File: .coderabbit.yaml
      • Commit: 1c55fd5
      • Layers: Repository YAML
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: a5e54076-a7ca-4d47-8172-67b450708f19
      Commits

      Reviewing files that changed from the base of the PR and between 1c55fd51d2fcafb84f59295736bc42f6d2353868 and 29570f3f700faf287c37a74ac8737c2edd70597a.

      Files selected for processing: 3

      • .changeset/gemini-image-http-timeout.md
      • packages/ai-gemini/src/adapters/image.ts
      • packages/ai-gemini/tests/abort-signal-wire.test.ts

      Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

    5. Thanks for the PR, @pcbeingused33! 🙌 @jherr will take a look.

      Automated pre-review checks

      • ✅ CI passing
      • ✅ No merge conflicts
      • ✅ Changeset present
      • ⚠️ No E2E test changes detected — behavior changes need coverage under testing/e2e/ (see CONTRIBUTING)
      Automated triage — a human review follows.
    6. github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer

Sign in to join this conversation.