diff --git a/backend/internal/config/config.go b/backend/internal/config/config.go index a7780096..e3dc2109 100644 --- a/backend/internal/config/config.go +++ b/backend/internal/config/config.go @@ -1117,9 +1117,8 @@ type DefaultConfig struct { } type RateLimitConfig struct { - OverloadCooldownMinutes int `mapstructure:"overload_cooldown_minutes"` // 529过载冷却时间(分钟) - RateLimit429CooldownSeconds int `mapstructure:"rate_limit_429_cooldown_seconds"` // 429无重置时间时的默认回避时间(秒) - OAuth401CooldownMinutes int `mapstructure:"oauth_401_cooldown_minutes"` // OAuth 401临时不可调度冷却(分钟) + OverloadCooldownMinutes int `mapstructure:"overload_cooldown_minutes"` // 529过载冷却时间(分钟) + OAuth401CooldownMinutes int `mapstructure:"oauth_401_cooldown_minutes"` // OAuth 401临时不可调度冷却(分钟) } // APIKeyAuthCacheConfig API Key 认证缓存配置 @@ -1579,7 +1578,6 @@ func setDefaults() { // RateLimit viper.SetDefault("rate_limit.overload_cooldown_minutes", 10) - viper.SetDefault("rate_limit.rate_limit_429_cooldown_seconds", 5) viper.SetDefault("rate_limit.oauth_401_cooldown_minutes", 10) // Pricing - 从 model-price-repo 同步模型定价和上下文窗口数据(固定到 commit,避免分支漂移) diff --git a/backend/internal/service/rate_limit_429_cooldown_test.go b/backend/internal/service/rate_limit_429_cooldown_test.go index 35206454..fb7e0dd7 100644 --- a/backend/internal/service/rate_limit_429_cooldown_test.go +++ b/backend/internal/service/rate_limit_429_cooldown_test.go @@ -97,10 +97,9 @@ func TestHandle429_FallbackDisabledSkipsLocalMark(t *testing.T) { require.Zero(t, accountRepo.rateLimitCalls) } -func TestHandle429_FallbackUsesConfigSecondsWhenSettingServiceMissing(t *testing.T) { +func TestHandle429_FallbackUsesDefaultSecondsWhenSettingServiceMissing(t *testing.T) { accountRepo := &rateLimit429AccountRepoStub{} cfg := &config.Config{} - cfg.RateLimit.RateLimit429CooldownSeconds = 9 svc := NewRateLimitService(accountRepo, nil, cfg, nil, nil) account := &Account{ID: 44, Platform: PlatformGemini, Type: AccountTypeAPIKey} @@ -110,5 +109,5 @@ func TestHandle429_FallbackUsesConfigSecondsWhenSettingServiceMissing(t *testing require.Equal(t, 1, accountRepo.rateLimitCalls) require.Equal(t, int64(44), accountRepo.lastRateLimitID) - require.True(t, !accountRepo.lastRateLimitReset.Before(before.Add(9*time.Second)) && !accountRepo.lastRateLimitReset.After(after.Add(9*time.Second))) + require.True(t, !accountRepo.lastRateLimitReset.Before(before.Add(5*time.Second)) && !accountRepo.lastRateLimitReset.After(after.Add(5*time.Second))) } diff --git a/backend/internal/service/ratelimit_service.go b/backend/internal/service/ratelimit_service.go index 293fc528..a53cb0e9 100644 --- a/backend/internal/service/ratelimit_service.go +++ b/backend/internal/service/ratelimit_service.go @@ -955,9 +955,6 @@ func (s *RateLimitService) get429FallbackCooldown(ctx context.Context, account * } seconds := defaultRateLimit429CooldownSeconds - if s.cfg != nil && s.cfg.RateLimit.RateLimit429CooldownSeconds > 0 { - seconds = s.cfg.RateLimit.RateLimit429CooldownSeconds - } seconds = clampRateLimit429CooldownSeconds(seconds) return time.Duration(seconds) * time.Second, true } diff --git a/deploy/config.example.yaml b/deploy/config.example.yaml index 04ebd795..1670699b 100644 --- a/deploy/config.example.yaml +++ b/deploy/config.example.yaml @@ -948,10 +948,6 @@ rate_limit: # 上游返回 529(过载)时的冷却时间(分钟) overload_cooldown_minutes: 10 - # Default cooldown time (in seconds) when upstream returns 429 without a reset time - # 上游返回 429 且无明确重置时间时的默认回避时间(秒) - rate_limit_429_cooldown_seconds: 5 - # ============================================================================= # Pricing Data Source (Optional) # 定价数据源(可选)