monater.114514 on Discord: an upstream's TPM 429 was read as out of
quota, and the key rested 15 minutes with balance left.
Cause: failure() read a 429 with rate words as a rate limit only when
plannedWords didn't match, and plannedWords matches the bare word
"quota". Vendors word per-minute limits as quotas: Gemini's "You
exceeded your current quota ... quotaId ...PerMinute", Vertex's "Quota
exceeded for ...requests_per_minute...", Azure's token rate limit whose
link is aka.ms/oai/quotaincrease. Each became failQuota and quotaRest
(15m) when no Retry-After came with it. DashScope (help.aliyun.com
error-code list) words its TPM/TPS limit "Allocated quota exceeded,
please increase your quota limit." and, in OpenAI's shape,
insufficient_quota, which read as quota and credit (30m).
Fix: minuteLimit: a 429 naming a minute-or-less window (per minute,
per second, TPM/RPM, PerMinute, token/call rate limit) and no longer
window, plan limit or money spent is failRate (a minute, or the
vendor's Retry-After / x-ratelimit-reset, via rateRest). Words in a
link no longer turn a rate limit into a plan used up. DashScope's two
TPM wordings are failRate from a DashScope provider only (failureOf);
its "Free allocated quota exceeded." and Coding Plan hour/week/month
stay quota, OpenAI's insufficient_quota stays credit, Zhipu 1113 stays
credit, per-day limits (TPD, PerDay, free-models-per-day) stay quota.
Run at this head: go test ./internal/gateway -count=1 -timeout 45m ok
(550s); new tests TestMinuteLimitIsNotQuota, TestMinuteLimitRestsAMinute,
TestDashScopeAllocationQuotaIsRate with literal vendor bodies; gofmt -l
clean; go vet, GOOS=windows and GOOS=linux go vet ./internal/gateway ok.
Broken by hand: routing.go put back to origin/main (dashScopeRate
stubbed false): all three new tests red, the Vertex 429 rested
14m59s as quota with no header, and as quota (not rate) with
Retry-After 20 or x-ratelimit-reset-tokens 45s.
Not tried: a real vendor 429 (the reporter's upstream and body are not
known yet); the full ./... suite (one suite per machine).