ai-ollama: streamed chat() reports finishReason "stop" when done_reason is "length"
メンテナーはふだん 1 日以内に返信
@AlemTuzlak がすでに取り組んでいます。
2026年10月22日 から。
評価
この issue はまだ評価されていません。
説明
TanStack AI version
@tanstack/ai 0.71.0, @tanstack/ai-ollama 0.12.2 (ollama 0.6.4)
Framework/Library version
Node.js 22, chat() on the server, no framework
Describe the bug and the steps to reproduce it
When Ollama stops at the token limit (options.num_predict), its last stream line has done: true and
done_reason: "length". The streamed chat() path still ends with RUN_FINISHED and finishReason: "stop", so a
cut-off answer looks complete.
The adapter sets the finish from whether tool calls were emitted and never reads done_reason
(packages/ai-ollama/src/adapters/text.ts#L440).
structuredOutput() already checks done_reason === 'length' (L263, from #1548), so only the streamed path is
affected.
Expected: finishReason: "length", as the Chat Completions adapter reports for finish_reason: "length".
Steps: save the script below as repro.mjs, then
npm init -y && npm pkg set type=module
npm install @tanstack/[email protected] @tanstack/[email protected]
node repro.mjs
Output:
RUN_FINISHED stop
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
No Ollama server is needed: a custom fetch returns the NDJSON stream.
import { chat } from '@tanstack/ai';
import { createOllamaChat } from '@tanstack/ai-ollama';
// The last line is what Ollama sends when options.num_predict cuts the answer off.
const lines = [
{ model: 'qwen3.5:0.8b', created_at: '2026-10-21T09:00:00Z', message: { role: 'assistant', content: 'Saturn has more than' }, done: false },
{ model: 'qwen3.5:0.8b', created_at: '2026-10-21T09:00:01Z', message: { role: 'assistant', content: '' },
done: true, done_reason: 'length', prompt_eval_count: 14, eval_count: 5 },
];
globalThis.fetch = async () => new Response(lines.map(line => JSON.stringify(line) + '\n').join(''),
{ headers: { 'content-type': 'application/x-ndjson' } });
for await (const event of chat({
adapter: createOllamaChat('qwen3.5:0.8b'),
messages: [{ role: 'user', content: 'How many moons does Saturn have?' }],
modelOptions: { options: { num_predict: 5 } },
debug: false,
})) {
if (event.type === 'RUN_FINISHED') console.log('RUN_FINISHED', event.metadata?.tanstack?.finishReason);
if (event.type === 'RUN_ERROR') console.log('RUN_ERROR', event.code);
}
Terms & Code of Conduct
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliably reproduced in a debuggable environment, it will probably not be
fixed and this issue may even be closed.
- 主要言語
- TypeScript
- スター
- 3.2k
- フォーク
- 365
- 平均マージ
- 1日 11時間
- マージ済み PR(30日)
- 278
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/ai のほかの issue
-
Maintainer sweep: assign a PR to the assignee of the issue it closes対応中かも @tombeckenham が今日担当しました。 オープン
メンテナーはふだん 1 日以内に返信
-
Durable resume through withPersistence never fills ctx.inputResponse for mcp_input interrupts対応中かも @tombeckenham が今日担当しました。 オープンwaiting-on: maintainer
メンテナーはふだん 1 日以内に返信
-
ai, ai-persistence: a nested subagent that waits runs again from the start under withPersistence対応中かも @tombeckenham が 1 日前に担当しました。 オープンwaiting-on: maintainer
メンテナーはふだん 1 日以内に返信
-
Discriminate status-dependent record and option types (RunRecord, SessionIndexEntry, InputState, durable-only options)対応中かも @jherr が 7 日前に担当しました。 オープンenhancement waiting-on: maintainer
メンテナーはふだん 1 日以内に返信
-
move to modelschemas対応中かも @jherr が 8 日前に担当しました。 オープンhas-pr waiting-on: maintainer
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
Nimblesite/SharpLsp#468 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
Bundled uv is never updated and trusts the compromised eMudhra certificates対応中かも @FabienDanieau が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
bg_wait's blocking mode (stopOnAttention: false) is under-documented and effectively undiscoverableオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
nicobailon/pi-subagents#3019 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
db-ux-design-system/core-web#8613 ·
メンテナーはふだん 1 日以内に返信