Treat retryable Codex errors as runtime warnings

- Map Codex `error` notifications with `willRetry: true` to `runtime.warning`
- Keep active turns/sessions running during reconnect warnings
- Add adapter and ingestion tests for retry-warning behavior
This commit is contained in:
Julius Marminge authored and Julius Marminge committed 2026-03-09 17:21:03 -07:00
1 parent 99dbe4ff02
commit 4ed89e4ba7
3 files changed
+83 -2

No files matched your search

@@ -1091,6 +1091,50 @@ describe("ProviderRuntimeIngestion", () => {
expect(thread.session?.lastError).toBe("runtime exploded");
});
it("keeps the session running when a runtime.warning arrives during an active turn", async () => {
const harness = await createHarness();
const now = new Date().toISOString();
harness.emit({
type: "turn.started",
eventId: asEventId("evt-warning-turn-started"),
provider: "codex",
createdAt: now,
threadId: asThreadId("thread-1"),
turnId: asTurnId("turn-warning"),
payload: {},
});
harness.emit({
type: "runtime.warning",
eventId: asEventId("evt-warning-runtime"),
provider: "codex",
createdAt: now,
threadId: asThreadId("thread-1"),
turnId: asTurnId("turn-warning"),
payload: {
message: "Reconnecting... 2/5",
detail: {
willRetry: true,
},
},
});
const thread = await waitForThread(
harness.engine,
(entry) =>
entry.session?.status === "running" &&
entry.session?.activeTurnId === "turn-warning" &&
entry.activities.some(
(activity: ProviderRuntimeTestActivity) =>
activity.id === "evt-warning-runtime" && activity.kind === "runtime.warning",
),
);
expect(thread.session?.status).toBe("running");
expect(thread.session?.activeTurnId).toBe("turn-warning");
expect(thread.session?.lastError).toBeNull();
});
it("maps session/thread lifecycle and item.started into session/activity projections", async () => {
const harness = await createHarness();
const now = new Date().toISOString();
@@ -407,6 +407,42 @@ lifecycleLayer("CodexAdapterLive lifecycle", (it) => {
}),
);
it.effect("maps retryable Codex error notifications to runtime.warning", () =>
Effect.gen(function* () {
const adapter = yield* CodexAdapter;
const firstEventFiber = yield* Stream.runHead(adapter.streamEvents).pipe(Effect.forkChild);
lifecycleManager.emit("event", {
id: asEventId("evt-retryable-error"),
kind: "notification",
provider: "codex",
threadId: asThreadId("thread-1"),
createdAt: new Date().toISOString(),
method: "error",
turnId: asTurnId("turn-1"),
payload: {
error: {
message: "Reconnecting... 2/5",
},
willRetry: true,
},
} satisfies ProviderEvent);
const firstEvent = yield* Fiber.join(firstEventFiber);
assert.equal(firstEvent._tag, "Some");
if (firstEvent._tag !== "Some") {
return;
}
assert.equal(firstEvent.value.type, "runtime.warning");
if (firstEvent.value.type !== "runtime.warning") {
return;
}
assert.equal(firstEvent.value.turnId, "turn-1");
assert.equal(firstEvent.value.payload.message, "Reconnecting... 2/5");
}),
);
it.effect("preserves request type when mapping serverRequest/resolved", () =>
Effect.gen(function* () {
const adapter = yield* CodexAdapter;
@@ -1192,13 +1192,14 @@ function mapToRuntimeEvents(
if (event.method === "error") {
const message =
asString(asObject(payload?.error)?.message) ?? event.message ?? "Provider runtime error";
const willRetry = payload?.willRetry === true;
return [
{
type: "runtime.error",
type: willRetry ? "runtime.warning" : "runtime.error",
...runtimeEventBase(event, canonicalThreadId),
payload: {
message,
class: "provider_error",
...(!willRetry ? { class: "provider_error" as const } : {}),
...(event.payload !== undefined ? { detail: event.payload } : {}),
},
},