earendil-works/pi · error · CodexApiError
Codex error
Error message
Codex error: ${message || code || JSON.stringify(event)} What it means
mapCodexEvents converts a 'error' stream event into a CodexApiError, preferring the event's message, then its code, then a JSON dump of the whole event. This is Codex's in-band failure channel: the HTTP request succeeded but the provider reported an error event.
Solutions
- Handle the Codex error event message or code in the payload; retry if transient.
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at packages/ai/src/api/openai-codex-responses.ts:727 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/b79085180006daf6.
Report an issue: GitHub.
Appendix: source
Thrown at packages/ai/src/api/openai-codex-responses.ts:727
typeof event.message === "string"
? event.message
: typeof nested?.message === "string"
? nested.message
: undefined,
};
}
async function* mapCodexEvents(
events: AsyncIterable<Record<string, unknown>>,
output: AssistantMessage,
): AsyncGenerator<ResponseStreamEvent> {
for await (const event of events) {
const type = typeof event.type === "string" ? event.type : undefined;
if (!type) continue;
if (type === "error") {
const { code, message } = extractCodexEventError(event);
throw new CodexApiError(`Codex error: ${message || code || JSON.stringify(event)}`, {
code,
payload: event,
});
}
if (type === "response.failed") {
const response = (event as { response?: { error?: { code?: string; message?: string } } }).response;
const code = response?.error?.code;
const message = response?.error?.message;
throw new CodexApiError(message || "Codex response failed", { code, payload: event });
}
if (type === "response.done" || type === "response.completed" || type === "response.incomplete") {
const response = (event as { response?: { status?: unknown; end_turn?: unknown } }).response;
if (typeof response?.end_turn === "boolean") {
output.endTurn = response.end_turn;
}
const normalizedResponse = responseView on GitHub (pinned to 4af9d21d3b)