earendil-works/pi · error · CodexProtocolError

Invalid Codex SSE JSON: ${formatThrownValue(cause)}

Error message

Invalid Codex SSE JSON: ${formatThrownValue(cause)}

What it means

Error "Invalid Codex SSE JSON: ${formatThrownValue(cause)}" thrown in earendil-works/pi.

Source

Thrown at packages/ai/src/api/openai-codex-responses.ts:803

			if (done) break;
			buffer += decoder.decode(value, { stream: true });

			let idx = buffer.indexOf("\n\n");
			while (idx !== -1) {
				const chunk = buffer.slice(0, idx);
				buffer = buffer.slice(idx + 2);

				const dataLines = chunk
					.split("\n")
					.filter((l) => l.startsWith("data:"))
					.map((l) => l.slice(5).trim());
				if (dataLines.length > 0) {
					const data = dataLines.join("\n").trim();
					if (data && data !== "[DONE]") {
						try {
							yield JSON.parse(data) as Record<string, unknown>;
						} catch (cause) {
							throw new CodexProtocolError(`Invalid Codex SSE JSON: ${formatThrownValue(cause)}`, {
								cause,
								payload: data,
							});
						}
					}
				}
				idx = buffer.indexOf("\n\n");
			}
		}
	} finally {
		signal?.removeEventListener("abort", onAbort);
		try {
			await reader.cancel();
		} catch {}
		try {
			reader.releaseLock();
		} catch {}
	}

View on GitHub (pinned to 4af9d21d3b)

Solutions

  1. Log the raw SSE line; the server sent malformed JSON, so retry or update the parser.

When it happens

Trigger: Thrown at packages/ai/src/api/openai-codex-responses.ts:803 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/0e41e0c86d504537. Report an issue: GitHub.