{"record":{"id":"aa441e38ee63b7d5","repo":"Mintplex-Labs/anything-llm","slug":"stream-returned-undefined-chunk-aborting-reply","errorCode":null,"errorMessage":"Stream returned undefined chunk. Aborting reply - check model provider logs.","messagePattern":"Stream returned undefined chunk\\. Aborting reply - check model provider logs\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/ollama/index.js","lineNumber":376,"sourceCode":"      let usage = {\n        prompt_tokens: 0,\n        completion_tokens: 0,\n      };\n\n      // Establish listener to early-abort a streaming response\n      // in case things go sideways or the user does not like the response.\n      // We preserve the generated text but continue as if chat was completed\n      // to preserve previously generated content.\n      const handleAbort = () => {\n        stream?.endMeasurement(usage);\n        clientAbortedHandler(resolve, fullText);\n      };\n      response.on(\"close\", handleAbort);\n\n      try {\n        for await (const chunk of stream) {\n          if (chunk === undefined)\n            throw new Error(\n              \"Stream returned undefined chunk. Aborting reply - check model provider logs.\"\n            );\n\n          if (chunk.done) {\n            usage.prompt_tokens = chunk.prompt_eval_count;\n            usage.completion_tokens = chunk.eval_count;\n            usage.duration = chunk.eval_duration / 1e9;\n            writeResponseChunk(response, {\n              uuid,\n              sources,\n              type: \"textResponseChunk\",\n              textResponse: \"\",\n              close: true,\n              error: false,\n            });\n            response.removeListener(\"close\", handleAbort);\n            stream?.endMeasurement(usage);\n            resolve(fullText);","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/AiProviders/ollama/index.js#L358-L394","documentation":"Stream guard in OllamaAILLM.handleStream: an iteration of the streaming response yielded an undefined chunk, indicating the model provider dropped or corrupted stream data; the stream is aborted early, preserving any text already generated rather than emitting garbage.","triggerScenarios":"Thrown when a streamed chunk is undefined.","commonSituations":"Provider stream interrupted or malformed chunk.","solutions":["Check the model provider logs for stream errors.","Retry the request.","Verify the model supports streaming."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}