{"record":{"id":"9b677003522b5981","repo":"n8n-io/n8n","slug":"assistant-sdk-error-remaining-substring-0-500","errorCode":null,"errorMessage":"Assistant SDK error: ${remaining.substring(0, 500)}","messagePattern":"Assistant SDK error: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/ai-workflow-builder.ee/src/assistant/assistant-handler.ts","lineNumber":227,"sourceCode":"\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tawait this.processChunkMessages(chunk, state, writer, toolCallId, context);\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\treader.releaseLock();\n\t\t}\n\n\t\tconst remaining = buffer.trim();\n\t\tif (remaining) {\n\t\t\ttry {\n\t\t\t\tconst chunk = JSON.parse(remaining) as SdkStreamChunk;\n\t\t\t\tawait this.processChunkMessages(chunk, state, writer, toolCallId, context);\n\t\t\t} catch {\n\t\t\t\t// If the remaining buffer is not JSON, it's likely a plain-text error from the SDK.\n\t\t\t\t// Throw so callers can handle it as a proper error instead of an empty response.\n\t\t\t\tthrow new Error(`Assistant SDK error: ${remaining.substring(0, 500)}`);\n\t\t\t}\n\t\t}\n\n\t\tconst responseText = state.collectedTexts.join('\\n');\n\t\tconst summary =\n\t\t\tresponseText.length > SUMMARY_MAX_LENGTH\n\t\t\t\t? responseText.substring(0, SUMMARY_MAX_LENGTH) + '...'\n\t\t\t\t: responseText;\n\n\t\treturn {\n\t\t\tresponseText,\n\t\t\tsummary,\n\t\t\tsdkSessionId: state.sdkSessionId,\n\t\t\thasCodeDiff: state.hasCodeDiff,\n\t\t\tsuggestionIds: state.suggestionIds,\n\t\t};\n\t}\n","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/ai-workflow-builder.ee/src/assistant/assistant-handler.ts#L209-L245","documentation":"Stream-trailing error in assistant-handler's consumeSdkStream. It fires when, after the SSE stream ends, the leftover buffer is non-empty but is not valid JSON — interpreted as a plain-text error message from the SDK — so it is raised as an Error with the first 500 characters. Normal parsed chunks are processed inside the loop; this path only handles unparseable residue.","triggerScenarios":"Thrown at packages/@n8n/ai-workflow-builder.ee/src/assistant/assistant-handler.ts:227 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the SDK-side logs; the tail of the stream contained a plain-text error which is surfaced verbatim (first 500 chars).","Handle the error as an assistant/chat failure — the user should retry or the service be investigated.","Verify network stability between n8n and the assistant gateway; truncated streams leave partial buffers that fail JSON.parse."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","contentChangedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}