mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 08:05:12 +00:00
Merge pull request #9046 from alfadb/fix/zhipu-overload-429-short-cooldown
fix(ratelimit): 智谱平台过载 429 改用秒级冷却
This commit is contained in:
2 files changed
+23
No files matched your search
@@ -15,6 +15,9 @@ import (
|
||||
// 智谱 GLM Coding Plan 实测 429 文案:额度充裕时的「限频」。
|
||||
const zhipuFrequencyLimitedBody = `{"error":{"code":"1302","message":"您的账户已达到速率限制,请您控制请求频率"}}`
|
||||
|
||||
// 智谱错误码 1305 实测 429 文案:平台服务过载,与账号额度无关。
|
||||
const zhipuOverloadLimitedBody = `{"error":{"code":"1305","message":"该模型当前访问量过大,请您稍后再试"}}`
|
||||
|
||||
// newZhipuCodingPlanAccount 构造一个智谱 Coding Plan 账号,Extra 带 5h/weekly
|
||||
// 用量与重置快照(与 CNProviderQuotaService 写入的键一致)。
|
||||
func newZhipuCodingPlanAccount(h5Used, weeklyUsed float64, resetIn time.Duration) *Account {
|
||||
@@ -61,6 +64,23 @@ func TestHandleUpstreamError_ZhipuFrequency429UsesShortCooldown(t *testing.T) {
|
||||
"frequency 429 must cool down seconds, not to the 5h window reset")
|
||||
}
|
||||
|
||||
// 智谱平台过载(1305「该模型当前访问量过大,请您稍后再试」)与账号额度无关,
|
||||
// 也应走秒级 429 兜底,而不是冷却到 5h 窗口结束。
|
||||
func TestHandleUpstreamError_ZhipuOverload1305UsesShortCooldown(t *testing.T) {
|
||||
repo := &rateLimitAccountRepoStub{}
|
||||
service := NewRateLimitService(repo, nil, &config.Config{}, nil, nil)
|
||||
account := newZhipuCodingPlanAccount(12, 4, 4*time.Hour)
|
||||
|
||||
runZhipu429(service, account, zhipuOverloadLimitedBody)
|
||||
|
||||
require.Equal(t, 0, repo.setErrorCalls, "a platform overload 429 must never SetError")
|
||||
require.Equal(t, 1, repo.rateLimitedCalls)
|
||||
require.Equal(t, account.ID, repo.lastRateLimitedID)
|
||||
require.WithinDuration(t, time.Now().Add(defaultRateLimit429CooldownSeconds*time.Second),
|
||||
repo.lastRateLimitedAt, 30*time.Second,
|
||||
"platform overload 429 must cool down seconds, not to the 5h window reset")
|
||||
}
|
||||
|
||||
// 快照显示窗口已耗尽时,即使文案是限频,也仍然冷却到窗口重置点(护栏)。
|
||||
func TestHandleUpstreamError_ZhipuFrequency429WithExhaustedSnapshotKeepsWindowCooldown(t *testing.T) {
|
||||
repo := &rateLimitAccountRepoStub{}
|
||||
|
||||
@@ -126,6 +126,8 @@ const cnFrequencyLimitQuotaGuardPercent = 90
|
||||
|
||||
// cnFrequencyLimitMarkers 是「请求频率/速率限制」类 429 的文案特征(小写比较)。
|
||||
// 智谱实测文案:「您的账户已达到速率限制,请您控制请求频率」。
|
||||
// 智谱平台过载(错误码 1305)的实测文案「该模型当前访问量过大,请您稍后再试」
|
||||
// 与账号额度无关,同样按秒级冷却处理。
|
||||
var cnFrequencyLimitMarkers = []string{
|
||||
"速率限制",
|
||||
"请求频率",
|
||||
@@ -136,6 +138,7 @@ var cnFrequencyLimitMarkers = []string{
|
||||
"rate limit exceeded",
|
||||
"rate_limit_exceeded",
|
||||
"ratelimit exceeded",
|
||||
"访问量过大",
|
||||
}
|
||||
|
||||
// cnQuotaExhaustionMarkers 是额度耗尽类文案;命中任一即认为 429 与额度有关,
|
||||
|
||||
Reference in new issue
Block a user