Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai-gemini): report a chat stream that ends without a finishReason #2124

Mergedjaeminbird(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/2124/headmerged by tombeckenham View on GitHub

Showing 8 changed files with 7 additions and 1 deletion (loading 4).

x
0 of 8 viewed, 8 left
5 additions and 0 deletions.changeset/gemini-truncated-stream.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/ai-gemini': patch
+---
+​
+Report `truncated-stream` when a Gemini chat stream ends without a `finishReason`. Before, the run had no terminal event and `onFinish` got the partial text as a success. The adapter now closes the open tool calls, reasoning, and text, then emits `RUN_ERROR`. Structured output already reported this case. An abort is not reported.
1 addition and 0 deletionsdocs/chat/streaming.mdModified
View file
@@ -199,6 +199,7 @@
- **An OpenAI or OpenRouter Responses stream ends without `response.completed`.** The adapter emits `RUN_ERROR` with code `incomplete-stream`. This applies to chat and to structured output. The text that arrived stays available. The run does not call `onFinish`.
- **A Chat Completions stream ends without a finish.** See below.
- **An Anthropic stream ends before a stop reason.** No `message_delta` with `stop_reason` and no `message_stop` arrived. The adapter emits `RUN_ERROR` with code `incomplete-stream`. The text that arrived stays available. The run does not call `onFinish`.
+- **A Gemini chat stream ends without a `finishReason`.** The adapter closes the open tool calls, reasoning, and text, then emits `RUN_ERROR` with code `truncated-stream`. Gemini structured output already uses this code. The text that arrived stays available. The run does not call `onFinish`.
​
Chat Completions adapters built on `@tanstack/openai-base` also make sure that the stream finished. A started stream needs one of these:
​
1 addition and 1 deletiondocs/config.jsonModified
View file
@@ -192,7 +192,7 @@
"label": "Streaming",
"to": "chat/streaming",
"addedAt": "2026-04-15",
- "updatedAt": "2026-11-04"
+ "updatedAt": "2026-11-09"
"label": "Stream Events",