changed 429 failover from 3 consecutive to 2 for OAuth users (#1579)
This commit is contained in:
parent
4b5ca6bc77
commit
eacbb3551c
|
@ -50,16 +50,15 @@ describe('Flash Fallback Integration', () => {
|
||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should trigger fallback after 3 consecutive 429 errors for OAuth users', async () => {
|
it('should trigger fallback after 2 consecutive 429 errors for OAuth users', async () => {
|
||||||
let fallbackCalled = false;
|
let fallbackCalled = false;
|
||||||
let fallbackModel = '';
|
let fallbackModel = '';
|
||||||
|
|
||||||
// Mock function that simulates exactly 3 429 errors, then succeeds after fallback
|
// Mock function that simulates exactly 2 429 errors, then succeeds after fallback
|
||||||
const mockApiCall = vi
|
const mockApiCall = vi
|
||||||
.fn()
|
.fn()
|
||||||
.mockRejectedValueOnce(createSimulated429Error())
|
.mockRejectedValueOnce(createSimulated429Error())
|
||||||
.mockRejectedValueOnce(createSimulated429Error())
|
.mockRejectedValueOnce(createSimulated429Error())
|
||||||
.mockRejectedValueOnce(createSimulated429Error())
|
|
||||||
.mockResolvedValueOnce('success after fallback');
|
.mockResolvedValueOnce('success after fallback');
|
||||||
|
|
||||||
// Mock fallback handler
|
// Mock fallback handler
|
||||||
|
@ -69,9 +68,9 @@ describe('Flash Fallback Integration', () => {
|
||||||
return fallbackModel;
|
return fallbackModel;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Test with OAuth personal auth type, with maxAttempts = 3 to ensure fallback triggers
|
// Test with OAuth personal auth type, with maxAttempts = 2 to ensure fallback triggers
|
||||||
const result = await retryWithBackoff(mockApiCall, {
|
const result = await retryWithBackoff(mockApiCall, {
|
||||||
maxAttempts: 3,
|
maxAttempts: 2,
|
||||||
initialDelayMs: 1,
|
initialDelayMs: 1,
|
||||||
maxDelayMs: 10,
|
maxDelayMs: 10,
|
||||||
shouldRetry: (error: Error) => {
|
shouldRetry: (error: Error) => {
|
||||||
|
@ -89,8 +88,8 @@ describe('Flash Fallback Integration', () => {
|
||||||
AuthType.LOGIN_WITH_GOOGLE_PERSONAL,
|
AuthType.LOGIN_WITH_GOOGLE_PERSONAL,
|
||||||
);
|
);
|
||||||
expect(result).toBe('success after fallback');
|
expect(result).toBe('success after fallback');
|
||||||
// Should have: 3 failures, then fallback triggered, then 1 success after retry reset
|
// Should have: 2 failures, then fallback triggered, then 1 success after retry reset
|
||||||
expect(mockApiCall).toHaveBeenCalledTimes(4);
|
expect(mockApiCall).toHaveBeenCalledTimes(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not trigger fallback for API key users', async () => {
|
it('should not trigger fallback for API key users', async () => {
|
||||||
|
|
|
@ -426,7 +426,7 @@ describe('retryWithBackoff', () => {
|
||||||
|
|
||||||
await expect(promise).resolves.toBe('success');
|
await expect(promise).resolves.toBe('success');
|
||||||
|
|
||||||
// Should trigger fallback after 4 consecutive 429s (attempts 2-5)
|
// Should trigger fallback after 2 consecutive 429s (attempts 2-3)
|
||||||
expect(fallbackCallback).toHaveBeenCalledWith('oauth-personal');
|
expect(fallbackCallback).toHaveBeenCalledWith('oauth-personal');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -97,7 +97,7 @@ export async function retryWithBackoff<T>(
|
||||||
if (attempt >= maxAttempts || !shouldRetry(error as Error)) {
|
if (attempt >= maxAttempts || !shouldRetry(error as Error)) {
|
||||||
// If we have persistent 429s and a fallback callback for OAuth
|
// If we have persistent 429s and a fallback callback for OAuth
|
||||||
if (
|
if (
|
||||||
consecutive429Count >= 3 &&
|
consecutive429Count >= 2 &&
|
||||||
onPersistent429 &&
|
onPersistent429 &&
|
||||||
(authType === AuthType.LOGIN_WITH_GOOGLE_PERSONAL ||
|
(authType === AuthType.LOGIN_WITH_GOOGLE_PERSONAL ||
|
||||||
authType === AuthType.LOGIN_WITH_GOOGLE_ENTERPRISE)
|
authType === AuthType.LOGIN_WITH_GOOGLE_ENTERPRISE)
|
||||||
|
|
Loading…
Reference in New Issue