为 Grok 普通 429 增加有限同号重试
This commit is contained in:
@@ -402,6 +402,13 @@ func grokRetryableOnSameAccount(account *Account, statusCode int, responseBody [
|
||||
if statusCode == http.StatusTooManyRequests {
|
||||
return true
|
||||
}
|
||||
case GrokFailureRateLimit:
|
||||
// A transient 429 does not identify a bad credential. Give every Grok
|
||||
// account a bounded same-account retry window before failover; the
|
||||
// failover loop still caps attempts and the client receives 429 after it.
|
||||
if statusCode == http.StatusTooManyRequests {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return account.IsPoolMode() && account.IsPoolModeRetryableStatus(statusCode)
|
||||
}
|
||||
@@ -411,7 +418,7 @@ func grokSameAccountRetryMetadata(account *Account, statusCode int, responseBody
|
||||
return false, 0, time.Time{}
|
||||
}
|
||||
decision := classifyGrokUpstreamFailure(statusCode, responseBody, "")
|
||||
if decision.Class != GrokFailureModelCapacity {
|
||||
if decision.Class != GrokFailureModelCapacity && decision.Class != GrokFailureRateLimit {
|
||||
return true, 0, time.Time{}
|
||||
}
|
||||
return true, 500 * time.Millisecond, time.Now().Add(30 * time.Second)
|
||||
|
||||
@@ -81,7 +81,7 @@ func TestGrokRetryableOnSameAccount_CapacityAndRateLimit(t *testing.T) {
|
||||
account := &Account{ID: 9105, Platform: PlatformGrok, Type: AccountTypeOAuth}
|
||||
require.True(t, grokRetryableOnSameAccount(account, http.StatusTooManyRequests,
|
||||
[]byte(`{"error":{"message":"The model is currently at capacity due to high demand"}}`)))
|
||||
require.False(t, grokRetryableOnSameAccount(account, http.StatusTooManyRequests,
|
||||
require.True(t, grokRetryableOnSameAccount(account, http.StatusTooManyRequests,
|
||||
[]byte(`{"error":{"message":"rate limit exceeded"}}`)))
|
||||
require.False(t, grokRetryableOnSameAccount(account, http.StatusPaymentRequired,
|
||||
[]byte(`{"error":{"message":"You have run out of credits or need a Grok subscription"}}`)))
|
||||
@@ -118,9 +118,9 @@ func TestGrokSameAccountRetryMetadata_CapacityDeadline(t *testing.T) {
|
||||
|
||||
retryable, delay, deadline = grokSameAccountRetryMetadata(account, http.StatusTooManyRequests,
|
||||
[]byte(`{"error":{"message":"rate limit exceeded"}}`))
|
||||
require.False(t, retryable)
|
||||
require.Zero(t, delay)
|
||||
require.True(t, deadline.IsZero())
|
||||
require.True(t, retryable)
|
||||
require.Equal(t, 500*time.Millisecond, delay)
|
||||
require.WithinDuration(t, time.Now().Add(30*time.Second), deadline, 2*time.Second)
|
||||
}
|
||||
|
||||
func TestClassifyGrokUpstreamFailure_ValidationNoCool(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user