Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 不自动重试 OAuth 账号池耗尽错误 (#4337)

Dash369b1d6eee93
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/interruptedTurnAutoResume.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/interruptedTurnAutoResume.test.ts
index 3ef8ab5768..b8dc69be67 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/interruptedTurnAutoResume.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/interruptedTurnAutoResume.test.ts
@@ -274,6 +274,48 @@ describe('isInterruptedTurnError', () => {
);
});
+ it('does not auto-resume when the inference gateway has no available OAuth accounts', () => {
+ const exact =
+ 'API Error: 503 {"error":"No available OAuth accounts in pool","detail":"No available OAuth accounts: 12 cooling down."}';
+ expect(isInterruptedTurnError({ message: exact, errorStatus: 503 })).toBe(false);
+ expect(
+ isInterruptedTurnError({
+ message: '503 Service Unavailable: No available OAuth accounts: 12 cooling down.',
+ }),
+ ).toBe(false);
+ // A stable reason must not override this non-retryable provider signal.
+ expect(
+ isInterruptedTurnError({
+ reason: 'upstream-overload',
+ message: 'No available OAuth accounts in pool',
+ errorStatus: 503,
+ }),
+ ).toBe(false);
+ });
+
+ it('does not broaden the OAuth-pool exception to a different HTTP status', () => {
+ expect(
+ isInterruptedTurnError({
+ message: 'No available OAuth accounts in pool',
+ errorStatus: 400,
+ }),
+ ).toBe(false);
+ // The overload reason normally bypasses message checks. Keeping it retryable
+ // for a non-503 status proves the OAuth exception is scoped to HTTP 503.
+ expect(
+ isInterruptedTurnError({
+ reason: 'upstream-overload',
+ message: 'No available OAuth accounts in pool',
+ errorStatus: 400,
+ }),
+ ).toBe(true);
+ expect(
+ isInterruptedTurnError({
+ message: 'No available OAuth accounts in pool',
+ }),
+ ).toBe(false);
+ });
+
// 第三类:上游没容量。与 #844 的分工靠「本 turn 有没有产出」划清(见判定函数注释),
// 零产出的容量拒绝由 Codex 侧重投,本份只在已有产出时接手,两者互斥。
it('accepts capacity / overload failures', () => {
diff --git a/apps/desktop/src/main/maker-ipc/interruptedTurnAutoResume.ts b/apps/desktop/src/main/maker-ipc/interruptedTurnAutoResume.ts
index 335b28b107..5071f8157c 100644
--- a/apps/desktop/src/main/maker-ipc/interruptedTurnAutoResume.ts
+++ b/apps/desktop/src/main/maker-ipc/interruptedTurnAutoResume.ts
@@ -58,6 +58,20 @@ export interface InterruptedTurnErrorSignals {
const STREAM_TRUNCATION_PATTERN =
/connection closed mid-response|response above may be incomplete|stream (?:closed|ended|interrupted) (?:unexpectedly|mid-response)/i;
+/**
+ * Inference gateways may return 503 while every OAuth account is cooling down.
+ * This is not a transient transport failure: replaying the same turn immediately
+ * only asks the same exhausted account pool again, so it must stay out of the
+ * automatic resume allowlist below.
+ */
+const OAUTH_ACCOUNT_POOL_UNAVAILABLE_PATTERN = /\bno available oauth accounts\b/i;
+
+function isOAuthAccountPoolUnavailableError(signals: InterruptedTurnErrorSignals): boolean {
+ if (signals.errorStatus !== undefined && signals.errorStatus !== 503) return false;
+ return typeof signals.message === 'string' &&
+ OAUTH_ACCOUNT_POOL_UNAVAILABLE_PATTERN.test(signals.message);
+}
+
/**
* SSE 流被中途切断(Claude Code 形态)。三层收紧后才看文案:
* - 没有 HTTP 状态码:上游给了状态码说明它**应答过**,不是流被切断。
@@ -159,6 +173,9 @@ export function shouldPreserveWaitingContinuationOnlyAutoResume(input: {
}
export function isInterruptedTurnError(signals: InterruptedTurnErrorSignals): boolean {
+ // This is a deliberate exception to the broad 503/network allowlist. Check it
+ // first so a future stable reason cannot accidentally re-enable auto-resume.
+ if (isOAuthAccountPoolUnavailableError(signals)) return false;
const reason = typeof signals.reason === 'string' ? signals.reason : '';
// 例外先行:`upstream-overload` 是**已归类为可重试**的 reason,它本身就是比文案更可靠的
// 权威判据(结构化优先于文案,与 overload-error.ts 的论证同源),直接放行、不再看文案。