Skip to content
Source
Sign inSign up
TanStack/ai

fix(openai-base): report incomplete Chat Completions streams #1604

MergedL-1ngg(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/1604/headmerged by AlemTuzlak View on GitHub

Showing 9 changed files with 10 additions and 1 deletion (loading 5).

x
0 of 9 viewed, 9 left
5 additions and 0 deletions.changeset/short-streams-report-errors.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/openai-base': patch
+---
+​
+Report `incomplete-stream` when a started Chat Completions stream ends without a finish reason or a final usage-only chunk. Keep partial text and close open lifecycles without reporting success or executing pending server tools. Preserve trailing usage and the existing usage-only completion fallback.
4 additions and 0 deletionsdocs/chat/streaming.mdModified
View file
@@ -139,6 +139,10 @@
​
For OpenAI and OpenRouter Responses, a stream that ends without `response.completed` emits `RUN_ERROR` with code `incomplete-stream`. This applies to chat and to structured output. Text received before the error remains available. The run does not call `onFinish`.
​
+Chat Completions adapters built on `@tanstack/openai-base` also check completion in `chat()`. A started stream needs a non-null `finish_reason` or a final usage-only chunk (`choices: []` with `usage`). Otherwise, the adapter closes open lifecycles and emits `RUN_ERROR` with code `incomplete-stream`. Partial text remains available. The run calls `onError`, skips pending server tools, and does not call `onFinish`.
+​
+The usage-only exception preserves provider compatibility. Usage on an earlier chunk or alongside a choice does not satisfy it. The OpenAI SDK hides `[DONE]`, so this check cannot verify that marker. A stream with only `[DONE]` after content still needs a finish reason or usage-only tail to succeed.
+​
## Later
​
- **No HTTP.** Iterate `chat()` yourself. Branch on `chunk.type === "TEXT_MESSAGE_CONTENT"`. Then read `chunk.delta`.
1 addition and 1 deletiondocs/config.jsonModified
View file
@@ -147,7 +147,7 @@
"label": "Streaming",
"to": "chat/streaming",
"addedAt": "2026-04-15",
- "updatedAt": "2026-09-28"
+ "updatedAt": "2026-10-07"