From c85d2f9bc8b7ad998c7f8095a32895037cda6eb9 Mon Sep 17 00:00:00 2001 From: MoerAI Date: Fri, 8 May 2026 18:31:54 +0900 Subject: [PATCH] fix(model-error-classifier): mark OpenAI server_error patterns as retryable (fixes #3799) OpenAI streaming responses can surface mid-stream errors with type 'server_error' or with the prose message 'An error occurred while processing your request'. Neither matched any entry in RETRYABLE_MESSAGE_PATTERNS, so shouldRetryError returned false and the runtime-fallback / fallback-retry code paths skipped retry. The result was that GPT-5.5 subagent (and main) turns silently stalled until the stale timeout fired. The maintainer's diagnosis on issue #3799 explicitly recommends adding these two patterns to model-error-classifier.ts; this commit does exactly that and adds two regression tests covering the JSON envelope and the prose form. --- src/shared/model-error-classifier.test.ts | 28 +++++++++++++++++++++++ src/shared/model-error-classifier.ts | 5 ++++ 2 files changed, 33 insertions(+) diff --git a/src/shared/model-error-classifier.test.ts b/src/shared/model-error-classifier.test.ts index 0ab40e8eb..172899e64 100644 --- a/src/shared/model-error-classifier.test.ts +++ b/src/shared/model-error-classifier.test.ts @@ -434,6 +434,34 @@ describe("model-error-classifier", () => { //#then expect(result).toBe(true) }) + + test("treats OpenAI streaming server_error envelopes as retryable (issue #3799)", () => { + //#given: OpenAI surfaces its mid-stream error with type 'server_error' + const error = { + name: undefined, + message: "{\"error\":{\"type\":\"server_error\",\"message\":\"server_error\"}}", + } + + //#when + const result = shouldRetryError(error) + + //#then + expect(result).toBe(true) + }) + + test("treats the OpenAI prose 'An error occurred while processing' message as retryable (issue #3799)", () => { + //#given: the human-readable prose surfaced when OpenAI's stream fails + const error = { + name: undefined, + message: "An error occurred while processing your request. Please try again later.", + } + + //#when + const result = shouldRetryError(error) + + //#then + expect(result).toBe(true) + }) }) export {} diff --git a/src/shared/model-error-classifier.ts b/src/shared/model-error-classifier.ts index 787f4825a..a4bbbb9e0 100644 --- a/src/shared/model-error-classifier.ts +++ b/src/shared/model-error-classifier.ts @@ -80,6 +80,11 @@ const RETRYABLE_MESSAGE_PATTERNS = [ "请求过于频繁", // "too many requests" "暂时不可用", // "temporarily unavailable" "服务不可用", // "service unavailable" + // OpenAI streaming server_error events surface either as a literal "server_error" + // type or as the prose error sentence below. Without these patterns subagent + // streams stall instead of being retried (issue #3799). + "server_error", + "an error occurred while processing", ] /**