From 29057ece3ef9b649b233dfc1fbcece94712f17df Mon Sep 17 00:00:00 2001 From: David Brailovsky Date: Wed, 21 Oct 2026 11:54:47 +0200 Subject: [PATCH] fix(ai): retry Codex CLI stream disconnect errors relayed by proxies closes #11057 --- packages/ai/CHANGELOG.md | 1 + packages/ai/src/utils/retry.ts | 3 +++ 2 files changed, 4 insertions(+) diff --git a/packages/ai/CHANGELOG.md b/packages/ai/CHANGELOG.md index 79b819682..6c95a3e5f 100644 --- a/packages/ai/CHANGELOG.md +++ b/packages/ai/CHANGELOG.md @@ -22,6 +22,7 @@ - Fixed whitespace-only tool output (for example a bare `\r\n` from bash) being sent as-is to OpenAI Completions, OpenAI Responses, and Google providers; it now uses the same placeholder as empty output, since some providers reject whitespace-only tool content with a 400 ([#8720](https://github.com/earendil-works/pi/issues/8720)) - Fixed automatic retry not triggering for gateway upstream failures such as `upstream_error: Upstream request failed`, `upstream_stream_read_error`, and `Upstream HTTP/2 stream failed` ([#10920](https://github.com/earendil-works/pi/issues/10920)) +- Fixed automatic retry not triggering for `stream disconnected before completion` errors relayed by proxies that wrap the Codex CLI ([#11057](https://github.com/earendil-works/pi/issues/11057)) - Fixed OpenAI Responses deferred tool loads rewriting the top-level tool list, and losing the prompt cache, on every load after a tool removal. Models with `additional_tools` now declare all tools in `additional_tools` items, starting with one at the head of the input, so removals (announced as text) and redefinitions no longer rewrite the prefix. Tool search and Kimi tool messages rewrite the top-level tools once per removal or redeclaration and keep later loads anchored ([#10940](https://github.com/earendil-works/pi/issues/10940)) ## [1.3.0] - 2026-10-15 diff --git a/packages/ai/src/utils/retry.ts b/packages/ai/src/utils/retry.ts index ca5eb7d68..af71de78f 100644 --- a/packages/ai/src/utils/retry.ts +++ b/packages/ai/src/utils/retry.ts @@ -99,6 +99,9 @@ const RETRYABLE_PROVIDER_ERROR_PATTERN = buildProviderErrorPattern([ "stream ended before message_stop", "stream ended before a terminal response event", "http2 request did not get a response", + // Codex CLI mid-stream disconnect, relayed by proxies that wrap the Codex CLI, + // e.g. "stream disconnected before completion: stream closed before response.completed" (#11057). + "stream disconnected before completion", // Node ERR_HTTP2_STREAM_CANCEL: the HTTP/2 session died before the request was // sent, e.g. after the Bedrock SDK's 5-minute session timeout (#10379). "pending stream has been canceled",