Skip to content

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

Open
pcbeingused33 wants to merge 1 commit into
TanStack:mainfrom
pcbeingused33:fix/gemini-image-http-timeout
Open

pcbeingused33 wants to merge 1 commit into
TanStack:mainfrom
pcbeingused33:fix/gemini-image-http-timeout

Conversation

@pcbeingused33

@pcbeingused33 pcbeingused33 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

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

… is passed

The Interactions client only applies httpOptions.timeout when the request
has no signal. The image adapter passed the caller's abortSignal as is, so
the configured timeout was dropped. Combine both with withHttpTimeout, as
the text and video adapters already do.
@changeset-bot

changeset-bot Bot commented Dec 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 29570f3

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

This PR includes changesets to release 2 packages
Name Type
@tanstack/ai-gemini Patch
@tanstack/ai-optimize-evals Patch

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

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

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 name Status Explanation
Title check Passed 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 f…
Description check Passed 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…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check 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 1c55fd5 and 29570f3.

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.

@github-actions
github-actions Bot requested a review from jherr December 3, 2026 02:22
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the waiting-on: maintainer The ball is in the maintainers’ court label Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-on: maintainer The ball is in the maintainers’ court

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants