earendil-works/pi · error

Request was aborted

Error message

Request was aborted

What it means

iterateSseMessages checks the caller's AbortSignal before each read of the Anthropic SSE body and throws immediately if the request was cancelled. This converts an external cancellation into a regular error so the stream consumer stops draining the HTTP connection promptly.

Solutions

  1. Retry the request; check that no caller-side abort signal fires prematurely.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at packages/ai/src/api/anthropic-messages.ts:413 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24). Data as JSON: /api/errors/676694de93c97466. Report an issue: GitHub.

Appendix: source

Thrown at packages/ai/src/api/anthropic-messages.ts:413

	return {
		line: text.slice(0, lineBreakIndex),
		rest: text.slice(nextIndex),
	};
}

async function* iterateSseMessages(
	body: ReadableStream<Uint8Array>,
	signal?: AbortSignal,
): AsyncGenerator<ServerSentEvent> {
	const reader = body.getReader();
	const decoder = new TextDecoder();
	const state: SseDecoderState = { event: null, data: [], raw: [] };
	let buffer = "";

	try {
		while (true) {
			if (signal?.aborted) {
				throw new Error("Request was aborted");
			}

			const { value, done } = await reader.read();
			if (done) {
				break;
			}

			buffer += decoder.decode(value, { stream: true });
			let consumed = consumeLine(buffer);
			while (consumed) {
				buffer = consumed.rest;
				const event = decodeSseLine(consumed.line, state);
				if (event) {
					yield event;
				}
				consumed = consumeLine(buffer);
			}
		}

View on GitHub (pinned to 4af9d21d3b)