{"record":{"id":"5867923a1ed6946a","repo":"Stirling-Tools/Stirling-PDF","slug":"stream-ended-without-a-result","errorCode":null,"errorMessage":"Stream ended without a result","messagePattern":"Stream ended without a result","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/editor/src/proprietary/components/chat/ChatContext.tsx","lineNumber":705,"sourceCode":"            }\n          },\n          onError: (data) => {\n            receivedResult = true;\n            dispatch({ type: \"SET_PROGRESS\", progress: null });\n            dispatch({\n              type: \"ADD_MESSAGE\",\n              message: {\n                id: generateId(),\n                role: ChatRole.ASSISTANT,\n                content: data.message || \"Something went wrong.\",\n                timestamp: Date.now(),\n              },\n            });\n          },\n        });\n\n        if (!receivedResult) {\n          throw new Error(\"Stream ended without a result\");\n        }\n      } catch (e) {\n        if ((e as Error).name === \"AbortError\") return;\n        const err = e as Error;\n        const isEngineError =\n          err.message.startsWith(\"AI engine request failed:\") ||\n          err.message === \"Stream ended without a result\";\n        const content = isEngineError\n          ? \"Failed to get a response. The AI engine may not be available yet.\"\n          : (err.message ??\n            \"Failed to get a response. The AI engine may not be available yet.\");\n        dispatch({ type: \"SET_PROGRESS\", progress: null });\n        dispatch({\n          type: \"ADD_MESSAGE\",\n          message: {\n            id: generateId(),\n            role: ChatRole.ASSISTANT,\n            content,","sourceCodeStart":687,"sourceCodeEnd":723,"githubUrl":"https://github.com/Stirling-Tools/Stirling-PDF/blob/9ef20dcab80b85041912f045e17a6aea1d08f969/frontend/editor/src/proprietary/components/chat/ChatContext.tsx#L687-L723","documentation":"Thrown after consumeSSEStream completes without ever invoking the onResult handler (receivedResult stayed false). This means the SSE stream closed normally but no terminal result event was emitted by the engine — the stream ended prematurely or only emitted progress/error events without a final result.","triggerScenarios":"The AI engine stream closed mid-run (connection dropped, server timeout, incomplete orchestration) without sending a result event. The onError handler may have fired (which sets receivedResult=true), but if only progress events arrived and the stream closed, receivedResult remains false.","commonSituations":"The AI engine crashed mid-inference. A proxy/load-balancer cut the long-running SSE connection on a timeout (e.g. nginx proxy_read_timeout). The engine emitted a partial stream then closed without a terminal event.","solutions":["Increase proxy/server read timeouts for the streaming endpoint (nginx proxy_read_timeout, gateway timeout).","Check AI engine logs for mid-run crashes or unhandled exceptions.","Verify the engine always emits a terminal result or error event before closing the stream.","Add a client-side timeout/watchdog that surfaces a clearer message if no result arrives within N seconds."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Add a watchdog that surfaces a clear error if no result arrives in time\nconst watchdog = setTimeout(() => {\n  if (!receivedResult) controller.abort();\n}, STREAM_TIMEOUT_MS);","typeGuard":null,"tryCatchPattern":"// Distinguish premature stream close from an explicit error event\nif (!receivedResult) {\n  throw new Error(\"Stream ended without a result\");\n}","preventionTips":["Configure proxy/server timeouts long enough for inference (disable buffering, raise read timeout).","Ensure the engine always emits a terminal result or error event.","Add a client-side watchdog so a silent close becomes an actionable timeout."],"tags":["network","sse","streaming","ai-engine","timeout"],"backgroundTag":null,"analyzedSha":"9ef20dcab80b85041912f045e17a6aea1d08f969","analyzedAt":"2026-08-13T22:11:39.827Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}