ai-ollama: streamed chat() reports finishReason "stop" when done_reason is "length"
I maintainer di solito rispondono entro 1 giorno
@AlemTuzlak ci sta già lavorando.
Dal 22/10/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 3.2k
- Fork
- 365
- Merge medio
- 1g 11h
- PR unite (30g)
- 278
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TanStack/ai
-
Maintainer sweep: assign a PR to the assignee of the issue it closesForse già presa @tombeckenham l’ha presa oggi. Aperta
TanStack/ai#1889 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Durable resume through withPersistence never fills ctx.inputResponse for mcp_input interruptsForse già presa @tombeckenham l’ha presa oggi. Apertawaiting-on: maintainer
TanStack/ai#1885 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
ai, ai-persistence: a nested subagent that waits runs again from the start under withPersistenceForse già presa @tombeckenham l’ha presa 1 giorno fa. Apertawaiting-on: maintainer
TanStack/ai#1878 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Discriminate status-dependent record and option types (RunRecord, SessionIndexEntry, InputState, durable-only options)Forse già presa @jherr l’ha presa 7 giorni fa. Apertaenhancement waiting-on: maintainer
TanStack/ai#1799 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
move to modelschemasForse già presa @jherr l’ha presa 8 giorni fa. Apertahas-pr waiting-on: maintainer
TanStack/ai#1788 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Nimblesite/SharpLsp#468 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Bundled uv is never updated and trusts the compromised eMudhra certificatesForse già presa @FabienDanieau l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
bg_wait's blocking mode (stopOnAttention: false) is under-documented and effectively undiscoverableAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
nicobailon/pi-subagents#3019 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
db-ux-design-system/core-web#8613 ·
I maintainer di solito rispondono entro 1 giorno