diff options
Diffstat (limited to 'packages/core/src/utils')
| -rw-r--r-- | packages/core/src/utils/nextSpeakerChecker.test.ts | 1 | ||||
| -rw-r--r-- | packages/core/src/utils/retry.test.ts | 2 | ||||
| -rw-r--r-- | packages/core/src/utils/retry.ts | 44 |
3 files changed, 24 insertions, 23 deletions
diff --git a/packages/core/src/utils/nextSpeakerChecker.test.ts b/packages/core/src/utils/nextSpeakerChecker.test.ts index 83ce97fd..475b5662 100644 --- a/packages/core/src/utils/nextSpeakerChecker.test.ts +++ b/packages/core/src/utils/nextSpeakerChecker.test.ts @@ -71,7 +71,6 @@ describe('checkNextSpeaker', () => { chatInstance = new GeminiChat( mockConfigInstance, mockModelsInstance, // This is the instance returned by mockGoogleGenAIInstance.getGenerativeModel - 'gemini-pro', // model name {}, [], // initial history ); diff --git a/packages/core/src/utils/retry.test.ts b/packages/core/src/utils/retry.test.ts index 1988c02a..a0294c31 100644 --- a/packages/core/src/utils/retry.test.ts +++ b/packages/core/src/utils/retry.test.ts @@ -272,7 +272,7 @@ describe('retryWithBackoff', () => { expect(fallbackCallback).toHaveBeenCalledWith('oauth-personal'); // Should retry again after fallback - expect(mockFn).toHaveBeenCalledTimes(4); // 3 initial attempts + 1 after fallback + expect(mockFn).toHaveBeenCalledTimes(3); // 2 initial attempts + 1 after fallback }); it('should NOT trigger fallback for API key users', async () => { 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; } |
