Browse Source

fix: add service unavailable pattern to foreground fallback

The error string 'Service Unavailable' (HTTP 503) from providers was
not matched by any RATE_LIMIT_PATTERNS regex, causing agent sessions
to fail outright instead of falling through to the next model.

Adds /service unavailable/i to RATE_LIMIT_PATTERNS and a test case.

Fixes #623
Michael Henke 1 month ago
parent
commit
7902fcbaa6

+ 4 - 0
src/hooks/foreground-fallback/index.test.ts

@@ -89,6 +89,10 @@ describe('isRateLimitError', () => {
     expect(isRateLimitError({ message: 'Insufficient balance.' })).toBe(true);
   });
 
+  test('returns true for "Service Unavailable"', () => {
+    expect(isRateLimitError({ message: 'Service Unavailable' })).toBe(true);
+  });
+
   test('returns false for non-rate-limit error', () => {
     expect(isRateLimitError({ message: 'invalid API key' })).toBe(false);
   });

+ 3 - 0
src/hooks/foreground-fallback/index.ts

@@ -42,6 +42,9 @@ const RATE_LIMIT_PATTERNS = [
   /insufficient.?(quota|balance)/i,
   /high concurrency/i,
   /reduce concurrency/i,
+  // ponytail: transient server errors mixed in; rename to isRetryableError
+  // and split from rate-limit detection when this list grows further
+  /service unavailable/i,
 ];
 
 export function isRateLimitError(error: unknown): boolean {