Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/ai/src/changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# AI Source Changes

## 2026-07-25 - Retry transient Codex upstream websocket failures

### What changed and why

- `utils/retry.ts` classifies `upstream_unavailable` provider errors as transient so the existing bounded retry policy
retries Codex websocket proxy disconnects such as `ConnectionClosedOK`.
- The retry classifier and coding-agent event-contract tests pin the exact reported error through the existing retry
lifecycle rather than introducing provider-specific retry behavior.

### Expected merge conflict zones

- LOW: `utils/retry.ts` transient transport error patterns.

## 2026-07-23 - Session-scoped provider resolution via node-only AsyncLocalStorage subpath

### What changed and why
Expand Down
1 change: 1 addition & 0 deletions packages/ai/src/utils/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const RETRYABLE_PROVIDER_ERROR_PATTERN = buildProviderErrorPattern([
"other side closed",
"fetch failed",
"upstream.?connect",
"upstream.?unavailable",
"reset before headers",
"socket hang up",
"socket connection was closed",
Expand Down
10 changes: 10 additions & 0 deletions packages/ai/test/retry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const nvidiaNIMResourceExhaustedMessage = "ResourceExhausted: Worker local total
const bunFetchSocketClosedMessage =
"The socket connection was closed unexpectedly. For more information, pass `verbose: true` in the second argument to fetch()";
const openAIResponsesEarlyEofMessage = "OpenAI Responses stream ended before a terminal response event";
const codexUpstreamUnavailableMessage =
"Error: upstream_unavailable: Codex upstream websocket send failed via proxy endpoint unknown: ConnectionClosedOK";

describe("provider retry classification", () => {
it("matches explicit provider retry guidance", () => {
Expand Down Expand Up @@ -38,6 +40,14 @@ describe("provider retry classification", () => {
).toBe(true);
});

it("matches Codex upstream websocket unavailability", () => {
expect(
isRetryableAssistantError(
fauxAssistantMessage("", { stopReason: "error", errorMessage: codexUpstreamUnavailableMessage }),
),
).toBe(true);
});

it("classifies agent-loop stream idle timeouts as retryable", () => {
// Emitted by @earendil-works/pi-agent-core when a provider stream stops
// delivering events (e.g. a connection that died after a network change).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { createHarness, type Harness } from "./harness.ts";

const primary = "faux/faux-1";
const fallback = "faux/faux-2";
const codexUpstreamUnavailableMessage =
"Error: upstream_unavailable: Codex upstream websocket send failed via proxy endpoint unknown: ConnectionClosedOK";

type EventTranscriptEntry =
| { type: "message_start" | "message_end"; role: string }
Expand Down Expand Up @@ -544,7 +546,7 @@ describe("retry fallback engine", () => {
harness.setResponses([
fauxAssistantMessage("", {
stopReason: "error",
errorMessage: "overloaded_error",
errorMessage: codexUpstreamUnavailableMessage,
}),
fauxAssistantMessage("recovered"),
]);
Expand All @@ -569,7 +571,7 @@ describe("retry fallback engine", () => {
attempt: 1,
maxAttempts: 3,
delayMs: 1,
errorMessage: "overloaded_error",
errorMessage: codexUpstreamUnavailableMessage,
},
{ type: "agent_start" },
{ type: "turn_start" },
Expand Down
Loading