Skip to content
Source
Sign inSign up
TanStack/ai

ai-gemini: a stream that ends without finishReason has no terminal event #2130

Send to my agent
Closedkartsan03(GitHub profile, opens in a new tab) opened this issue 0 comments

TanStack AI version

@tanstack/ai 1.4.0, @tanstack/ai-gemini 1.2.1

Framework/Library version

Node.js 22.23.2, server-side chat(), no framework

Describe the bug and the steps to reproduce it

When a Gemini stream ends without any finishReason, chat() yields the partial text and then simply stops: no RUN_FINISHED, no RUN_ERROR, no thrown error. The caller can't tell that the response was cut off.

The adapter emits its terminal event only in the finishReason branch; at the end of the stream it already tracks sawFinishReason, but uses it only to report a blocked prompt. Expected: an incomplete or error outcome that keeps the partial text. #2042 added this for the same case in @tanstack/ai-anthropic 1.1.1.

The fixture is a recorded Gemini stream with its final chunk (the one carrying finishReason) removed. fetch is stubbed to serve it, so no API key or network is needed:

npm install @tanstack/ai@1.4.0 @tanstack/ai-gemini@1.2.1
curl -sLO https://raw.githubusercontent.com/kartsan03/wiretruth/v0.3.0/suite/fixtures/gemini/stream.missing-finish.json
node repro.mjs
import { readFileSync } from 'node:fs'
import { chat } from '@tanstack/ai'
import { createGeminiChat } from '@tanstack/ai-gemini'

const fixture = JSON.parse(readFileSync('stream.missing-finish.json', 'utf8'))
const response = fixture.exchanges[0].response
globalThis.fetch = async () =>
  new Response(response.body.sse.join(''), { status: response.status, headers: response.headers })

const events = []
for await (const event of chat({
  adapter: createGeminiChat(fixture.provenance.requested_model, 'test', { baseURL: 'https://fixture.invalid' }),
  messages: [{ role: 'user', content: fixture.provenance.request.contents[0].parts[0].text }],
  modelOptions: { maxOutputTokens: 16 },
  threadId: 'repro',
})) {
  events.push(event.type)
}
console.log(events.join(' -> '))
console.log('the iterator ended normally')

Output:

RUN_STARTED -> TEXT_MESSAGE_START -> TEXT_MESSAGE_CONTENT -> TEXT_MESSAGE_CONTENT
the iterator ended normally

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

No, because I do not have time to dig into it

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
  1. github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer

  2. tanstack-source added labelsbug

  3. tombeckenham closed this

Sign in to join this conversation.