summaryrefslogtreecommitdiff
path: root/packages/core/src/utils/retry.ts
diff options
context:
space:
mode:
authorBryan Morgan <[email protected]>2025-06-25 21:45:38 -0400
committerGitHub <[email protected]>2025-06-26 01:45:38 +0000
commitbb797ded7d15003dfec7a68ff82764d7a2c44458 (patch)
treeed7af7f2dae0d9a838610d3248ee957b813b07c3 /packages/core/src/utils/retry.ts
parentb6b9923dc3b80a73fdee3a3ccd6070c8cfb551cd (diff)
429 fix (#1668)
Diffstat (limited to 'packages/core/src/utils/retry.ts')
-rw-r--r--packages/core/src/utils/retry.ts44
1 files changed, 23 insertions, 21 deletions
diff --git a/packages/core/src/utils/retry.ts b/packages/core/src/utils/retry.ts
index ebe18510..372a7976 100644
--- a/packages/core/src/utils/retry.ts
+++ b/packages/core/src/utils/retry.ts
@@ -67,9 +67,9 @@ export async function retryWithBackoff<T>(
maxAttempts,
initialDelayMs,
maxDelayMs,
- shouldRetry,
onPersistent429,
authType,
+ shouldRetry,
} = {
...DEFAULT_RETRY_OPTIONS,
...options,
@@ -93,28 +93,30 @@ export async function retryWithBackoff<T>(
consecutive429Count = 0;
}
- // Check if we've exhausted retries or shouldn't retry
- if (attempt >= maxAttempts || !shouldRetry(error as Error)) {
- // If we have persistent 429s and a fallback callback for OAuth
- if (
- consecutive429Count >= 2 &&
- onPersistent429 &&
- authType === AuthType.LOGIN_WITH_GOOGLE_PERSONAL
- ) {
- try {
- const fallbackModel = await onPersistent429(authType);
- if (fallbackModel) {
- // Reset attempt counter and try with new model
- attempt = 0;
- consecutive429Count = 0;
- currentDelay = initialDelayMs;
- continue;
- }
- } catch (fallbackError) {
- // If fallback fails, continue with original error
- console.warn('Fallback to Flash model failed:', fallbackError);
+ // If we have persistent 429s and a fallback callback for OAuth
+ if (
+ consecutive429Count >= 2 &&
+ onPersistent429 &&
+ authType === AuthType.LOGIN_WITH_GOOGLE_PERSONAL
+ ) {
+ try {
+ const fallbackModel = await onPersistent429(authType);
+ if (fallbackModel) {
+ // Reset attempt counter and try with new model
+ attempt = 0;
+ consecutive429Count = 0;
+ currentDelay = initialDelayMs;
+ // With the model updated, we continue to the next attempt
+ continue;
}
+ } catch (fallbackError) {
+ // If fallback fails, continue with original error
+ console.warn('Fallback to Flash model failed:', fallbackError);
}
+ }
+
+ // Check if we've exhausted retries or shouldn't retry
+ if (attempt >= maxAttempts || !shouldRetry(error as Error)) {
throw error;
}