n8n-io/n8n · error · Error
Assistant SDK error
Error message
Assistant SDK error: ${remaining.substring(0, 500)} What it means
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.
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.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at packages/@n8n/ai-workflow-builder.ee/src/assistant/assistant-handler.ts:227 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/9b677003522b5981.
Report an issue: GitHub.
Appendix: source
Thrown at packages/@n8n/ai-workflow-builder.ee/src/assistant/assistant-handler.ts:227
continue;
}
await this.processChunkMessages(chunk, state, writer, toolCallId, context);
}
}
} finally {
reader.releaseLock();
}
const remaining = buffer.trim();
if (remaining) {
try {
const chunk = JSON.parse(remaining) as SdkStreamChunk;
await this.processChunkMessages(chunk, state, writer, toolCallId, context);
} catch {
// If the remaining buffer is not JSON, it's likely a plain-text error from the SDK.
// Throw so callers can handle it as a proper error instead of an empty response.
throw new Error(`Assistant SDK error: ${remaining.substring(0, 500)}`);
}
}
const responseText = state.collectedTexts.join('\n');
const summary =
responseText.length > SUMMARY_MAX_LENGTH
? responseText.substring(0, SUMMARY_MAX_LENGTH) + '...'
: responseText;
return {
responseText,
summary,
sdkSessionId: state.sdkSessionId,
hasCodeDiff: state.hasCodeDiff,
suggestionIds: state.suggestionIds,
};
}
View on GitHub (pinned to 5ac6606e81)