fix(openai): preserve other platforms' capacity handling

This commit is contained in:
r266-tech committed 2026-11-07 21:35:48 +08:00
1 parent 88b7090a35
commit a1395eeaf2
3 files changed
+17 -1

No files matched your search

@@ -202,3 +202,16 @@ func TestOpenAICapacityShedModelRule_ErrorFieldsOnly(t *testing.T) {
})
}
}
func TestOpenAICapacityShedModelRule_OtherPlatformKeepsDefault(t *testing.T) {
repo := &modelNotFoundAccountRepoStub{}
svc := &OpenAIGatewayService{rateLimitService: &RateLimitService{accountRepo: repo}}
account := openAICapacityShedModelRuleAccount(AccountTypeOAuth)
account.Platform = PlatformGrok
payload := []byte(`{"type":"error","error":{"code":"server_is_overloaded","message":"overloaded"}}`)
failover := svc.newOpenAIStreamFailoverErrorWithModel(nil, account, false, "", payload, "overloaded", "grok-4")
require.Empty(t, repo.modelRateLimitCalls)
require.Zero(t, repo.tempCalls)
require.True(t, failover.RetryableOnSameAccount)
require.True(t, failover.RequestScopedTransient)
}
@@ -1644,6 +1644,9 @@ func (s *OpenAIGatewayService) handleOpenAIStreamTerminalAccountSideEffects(
canonicalModel ...string,
) (int, bool) {
statusCode := openAIStreamFailureStatus(payload, message)
if statusCode == http.StatusServiceUnavailable && (account == nil || account.Platform != PlatformOpenAI) {
return statusCode, false
}
switch statusCode {
case http.StatusForbidden:
if !openAIStream403AccountFailure(payload, message) {
@@ -455,7 +455,7 @@ func (s *OpenAIGatewayService) newOpenAIAccountFailoverErrorWithClassificationHe
upstreamMsg,
retryableOnSameAccount || oauth429Retry,
)
if shouldDisable && failoverErr.RequestScopedTransient {
if shouldDisable && account != nil && account.Platform == PlatformOpenAI && failoverErr.RequestScopedTransient {
// A configured model cooldown takes precedence over capacity-shed replay.
failoverErr.RetryableOnSameAccount = false
}