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(bots): keep account budget exhaustion with the user instead of switching candidates (#5267)

FicoWang2c7d941a2d2c
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botCandidateRecovery.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botCandidateRecovery.test.ts
index 467b58d344..7d013093eb 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/botCandidateRecovery.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/botCandidateRecovery.test.ts
@@ -98,6 +98,36 @@ describe('Bot candidate recovery', () => {
expect(isBotCandidateUnavailable(signals)).toBe(false);
});
+ // Gateway budget exhaustion is account-level: no candidate on the same account can
+ // recover it, so the shared deterministic-exhaustion signal wins over the 429 (#5266).
+ const budgetExceeded = '429: {"message":"ExceededBudget: User=[REDACTED] over budget. Spend=0.0, Budget=0.0","type":"budget_exceeded","code":"429"}';
+ it.each([
+ { errorStatus: 429, message: budgetExceeded },
+ { reason: 'turn-failed', errorStatus: 429, message: budgetExceeded },
+ { sdkError: 'rate_limit', message: 'Request failed: budget_exceeded' },
+ { errorStatus: 429, message: 'You exceeded your current quota, please check your plan and billing details.' },
+ { message: 'insufficient_quota' },
+ ])('keeps the account budget exhaustion with the user instead of switching candidates %j', (signals) => {
+ expect(isBotCandidateUnavailable(signals)).toBe(false);
+ });
+
+ it.each([
+ { errorStatus: 429, message: 'Too Many Requests' },
+ { errorStatus: 429, message: 'rate limit exceeded, retry after 3s' },
+ { sdkError: 'rate_limit', message: 'SDK error: rate_limit' },
+ ])('still switches candidates for transient rate limiting %j', (signals) => {
+ expect(isBotCandidateUnavailable(signals)).toBe(true);
+ });
+
+ it('does not schedule Bot fallback or auto-resume for a gateway budget exhaustion', () => {
+ const h = harness();
+ const signals = { errorStatus: 429, message: budgetExceeded };
+ expect(h.isResumableTurnErrorCandidate(signals, h.item)).toBe(false);
+ expect(h.onResumableTurnError('s', signals, h.item)).toBeNull();
+ expect(h.guard).not.toHaveBeenCalled();
+ expect(h.fallback).not.toHaveBeenCalled();
+ });
+
const drop = { reason: 'pi-gateway-drop', message: 'Connection error.' };
it('takes over an exhausted Pi route only for a host-identified Bot input', async () => {
const ordinary = harness(false);
diff --git a/apps/desktop/src/main/maker-ipc/botCandidateRecovery.ts b/apps/desktop/src/main/maker-ipc/botCandidateRecovery.ts
index 4db3ce09d1..6b3462ebb7 100644
--- a/apps/desktop/src/main/maker-ipc/botCandidateRecovery.ts
+++ b/apps/desktop/src/main/maker-ipc/botCandidateRecovery.ts
@@ -1,8 +1,14 @@
import { isNetworkishErrorMessage, isOverloadErrorMessage } from '@cindy/maker-core';
+import { matchesDeterministicUsageExhaustionText } from '@cindy/maker-shared/error-redaction';
import type { InterruptedTurnErrorSignals } from './interruptedTurnAutoResume.js';
/** A failed provider may be replaced, even when retrying that provider is forbidden. */
export function isBotCandidateUnavailable(signals: InterruptedTurnErrorSignals): boolean {
+ // Account/budget exhaustion is not a property of the failed candidate: every
+ // candidate on the same account fails the same way, so switching or resuming
+ // only hides the real cause. Reuse the shared deterministic signal that the
+ // Codex terminal retry, Cindy AI search and the error banner already honour.
+ if (matchesDeterministicUsageExhaustionText(signals.message ?? '')) return false;
const reason = signals.reason ?? '';
// Explicit product/control failures must never be reinterpreted from their text.
if (reason && ![
@@ -19,7 +25,7 @@ export function isBotCandidateUnavailable(signals: InterruptedTurnErrorSignals):
if ([401, 402, 403, 429, 500, 502, 503, 504, 529].includes(signals.errorStatus ?? 0)) return true;
if (/permission denied/i.test(message)) return false;
return isNetworkishErrorMessage(message) || isOverloadErrorMessage(message, signals.errorStatus)
- || /invalid api key|missing bearer token|no available oauth accounts|credit balance too low|insufficient_quota|quota exceeded|rate.limit exceeded|model.{0,80}(?:not found|does not exist|unavailable)|(?:failed to (?:start|spawn)|could not start) (?:the )?(?:agent|pi|codex|claude)/i.test(message);
+ || /invalid api key|missing bearer token|no available oauth accounts|credit balance too low|rate.limit exceeded|model.{0,80}(?:not found|does not exist|unavailable)|(?:failed to (?:start|spawn)|could not start) (?:the )?(?:agent|pi|codex|claude)/i.test(message);
}
/** The Session reference is only a teardown lease, never proof that a route changed. */