gateway: agy's "Individual quota reached … Resets in" rests the account until then
@Airan_FS on X (11-17): an Antigravity account served through agy-cli answered "⚠ Individual quota reached. Please upgrade your subscription to increase your limits. Resets in …" as the model's reply, and routing never asked the next account. The agy-cli plugin 0.1.87 (magpie-community/plugins afe4c086, on the dist branch) now ends such a turn with a rate_limit_error in agy's words, before or after reply text, so the gateway fails over and rests the account as for any plugin quota error. Here, quotaResetAfter also reads the notice's "Resets in 1h18m40s" (Go's duration form, which resetsInWords can't read since no word ends after its "h"), scoped to the "individual quota reached" line, so the account rests until Google's reset instead of quotaRest's 15 minutes and isn't asked again every quarter hour. gateway-routing.md says so. Tests from the literal notice (discuss.ai.google.dev report, the tweet): TestAgyCLIQuotaNoticeRestsUntilItsResetAndFallsOver (group falls over to the next member, rest "resets" ~1h18m40s, next turn skips it), TestAgyCLIQuotaNoticeMidReplyStillRests (partial text kept, still rests), TestAgyQuotaNoticeResetIsRead. Run (mica, at f33278541 = this change less the doc line): go test ./... -timeout 45m: 102 ok, no FAIL. mote: GOOS=windows go vet ./... ok, GOOS=linux go vet -tags nogui ./... ok; gofmt -l clean. Broken by hand: the old quotaResetAfter with these tests: the account rests 14m59s by "quota" and resetsAfter reads 0, so all three fail. Not tried: a real agy account with its quota used up.
This commit is contained in:
@@ -336,7 +336,7 @@ the key's leaves the call as asked, with a log line (`compactRefused`).
|
||||
- A 5xx is a server error, not quota, unless the vendor's own quota code says so (`quotaCodes`: `usage_limit_reached`, `RESOURCE_EXHAUSTED`, Claude Code's `usage limit reached|<unix>`). A relay's 500 "当前模型 gpt-5.5 负载已经达到上限,请稍后重试" names its load, not the key's allowance: it was read as out of quota by `usedUpWords` (上限), which rested the key till a reset and kept a group's Patience from waiting it out (#1418). The quota words (`usedUpWords`) still apply to a 4xx.
|
||||
- A 429 that names in words when the account is back (WorkBuddy's "将在 2026-10-11 20:16:02 UTC+8重置" and "your usage will reset at 2026-10-11 12:37:53 UTC+8, …", #1669; Volcengine Ark's "You have exceeded the monthly usage quota. It will reset at 2026-10-25 23:59:59 +0800 CST.", #3251, #3276) is out of quota in either language (`resetsWhen`), and rests until that time (`resetsWritten`, read in the offset written). Only the reset phrasing right beside a whole date and time with its UTC/GMT offset, or its offset as Go prints one (four digits, then the zone's name, which isn't read), followed by 重置 or punctuation, is read, so a refusal cut short isn't read as UTC and another vendor's date in passing is no reset; a time past, not a real date, or further off than `longestSaid` isn't read: `longestWritten` (7 days), or `longestMonthly` (35 days) when the refusal says its allowance is a month's (`monthlyWords`: Ark's, Zhipu's 1310 "Weekly/Monthly Limit Exhausted"). Such a reset is the one rest out of quota held past `longestQuota`, to `longestMonthly`; a window read full or the user's own rest is still held to 8 days (`TestMonthlyWrittenResetRestsTheMonth`). Ark's windows as its AccessKey reads them (`volcPlanQuotas`) still reach only its usage card, not routing (#3251). Zhipu's 1308 and 1310 (Z.ai and bigmodel.cn, GLM Coding Plan: "Your limit will reset at 2026-10-15 20:12:13", "您的限额将在 … 重置") write the time with no zone; it is Beijing's, and is read as UTC+8 in those words only (`zhipuResets`, `resetsZhipu`), never when a digit, colon or zone of its own follows (Player on Discord: read by nothing, the key rested `quotaRest` and the refusal said "not asked again before 17:12" while Z.ai said 20:12; `TestZhipuRestsUntilItsReset`). One that points to the account's other models (`otherModels`: "切换其他模型", "switch to the other models") rests that model alone (`restID`). Out of credit or quota on a model that costs credits, where the subscription serves other models free (`catalog.Model.Free`: WorkBuddy's x0.00, Qoder's is_free, Cline's free models; `Provider.PaidBesideFree`), rests that model alone too: the free ones draw on no credits (Creat.wu on Discord, `TestOutOfCreditLeavesFreeModels`). A Credits window leaves the free models out the same way, so an account at 100% isn't ranked spent for them: the WorkBuddy plugin's lists them as `notModels` (0.1.23), and the built-in's scopes itself by the provider's last fetched list (`wbSpareFree`; with no list read, every model counts) (plugins#138, hheei: an account at 560 / 560 was still served deepseek-v4.1-flash; `TestWorkBuddyCreditsSpareFreeModels`). A free model the vendor refuses all the same (WorkBuddy refuses even 0-rate models to an account with no package) rests the account on its own refusal. Cline's daily limit of one free model, 429 "Daily free limit reached on model deepseek/deepseek-v4-flash. Try again in 23h 59m" (the words Cline's own clients read it by, `isClineFreeModelLimitMessage`), rests that model alone (`clineFreeLimit`, `clineModelLimited`, keyed by `restID`) until the time it names (`clineBackIn`, `tryAgainIn`, held to `longestWritten`; `resets`), from a provider whose requests reach Cline's API (`ClinePinnable`: the ClinePass preset, one at cline.bot, the Cline plugin's). The key's other models, free or the plan's, are still served, and the model out of its day is answered with its refusal without asking Cline again (#1398, wuasakura: one free model's 429 sent the whole Cline account to the back; `TestClineFreeLimitRestsTheModel`, `TestClineFreeLimitLeavesOtherModels`). Another vendor's same words, and a Cline 429 that doesn't name the model's limit, rest the key as before. WorkBuddy's 429 14018 "Credits exhausted" is out of credit (`brokeWords`), not a rate limit, on the built-in's raw body and the plugin's `insufficient_quota` alike (`TestCreditsExhaustedIsOutOfCredit`). On the rate-limit branch, a reset time the refusal names (`resetsAt`, or `resetsHeader` as `keepRetry` noted it) is believed up to `longestQuota`, as out of quota believes it, and the Routing page says it rests until then (`resets`); a `Retry-After` or a rate-limit reset header is still held to `longestWait` (an hour) (`rateRest`). The same rest runs for a plugin's requests: the WorkBuddy plugin passes these 429s on as they come (`TestPluginWrittenResetRests`). A JSON error body that escapes what isn't ASCII as `\uXXXX` (Python's json.dumps does by default) has its strings decoded before any word list (`creditWords`, `rateWords`, `plannedWords`, `usedUpWords`, `resetsWhen`, …) is matched (`wordsOf`), so an escaped 余额不足 or 用量 reads as an unescaped one does.
|
||||
- A 429 that names a limit per minute or second (`minuteWords`: per minute, per second, TPM, RPM, `PerMinute` in Gemini's quotaId, Azure's "token rate limit" and "call rate limit") is a rate limit even when it calls itself a quota, unless it also names a longer window or a plan's limit (`longWords`: hour, day, week, month, usage limit, 用量, 套餐) or money spent (`brokeWords`, `insufficient_quota`) (`minuteLimit`). Gemini's "You exceeded your current quota … PerMinute", Vertex's "Quota exceeded for …requests_per_minute…" and Azure's rate limit, whose link is aka.ms/oai/quotaincrease, each rested a key the quarter of an hour of a quota with balance left (monater.114514 on Discord); now they rest as `rateRest` does, a minute or the vendor's `Retry-After`. Words inside a link (`urlWords`) don't make a rate limit a plan used up. DashScope words its TPM/TPS limit as a quota too, `Allocated quota exceeded, please increase your quota limit.` or OpenAI's `insufficient_quota`; from a DashScope provider (`dashScope`) those are rate limits (`dashScopeRate`, in `failureOf`), while its "Free allocated quota exceeded." and a Coding Plan's hour/week/month stay out of quota, and OpenAI's `insufficient_quota` stays out of credit (`TestMinuteLimitIsNotQuota`, `TestMinuteLimitRestsAMinute`, `TestDashScopeAllocationQuotaIsRate`).
|
||||
- Antigravity's 429 for a model's quota used up writes how long until it is back as Go prints a duration: "You have exhausted your capacity on this model. Your quota will reset after 3h19m30s." (`quotaResetAfter`, read by `resetsAfter` beside Factory's "resets in …", held to `longestWritten`). The account (or, as `pooled` says, that model on it) rests that long (`resets`), and the agent's Retry-After says it when no account is left. Unread, it rested `quotaRest`, so the account first in order was asked again, and refused, every 15 minutes while the next ticked account had its quota (Dani Ariyanto on Discord, 10-24; `TestAntigravityQuotaRestsUntilItsReset`). Its other 429, "Resource has been exhausted (e.g. check quota).", names no time and rests `quotaRest` as before.
|
||||
- Antigravity's 429 for a model's quota used up writes how long until it is back as Go prints a duration: "You have exhausted your capacity on this model. Your quota will reset after 3h19m30s." (`quotaResetAfter`, read by `resetsAfter` beside Factory's "resets in …", held to `longestWritten`). The account (or, as `pooled` says, that model on it) rests that long (`resets`), and the agent's Retry-After says it when no account is left. Unread, it rested `quotaRest`, so the account first in order was asked again, and refused, every 15 minutes while the next ticked account had its quota (Dani Ariyanto on Discord, 10-24; `TestAntigravityQuotaRestsUntilItsReset`). agy's own notice for an account's quota used up, "Individual quota reached. Please upgrade your subscription to increase your limits. Resets in 1h18m40s.", is read the same way; the agy-cli plugin (0.1.87) ends such a turn with a `rate_limit_error` in those words, mid-reply or not, where before it went to the client as the reply and the next account was never asked (@Airan_FS on X; `TestAgyCLIQuotaNoticeRestsUntilItsResetAndFallsOver`, `TestAgyCLIQuotaNoticeMidReplyStillRests`, `TestAgyQuotaNoticeResetIsRead`). Its other 429, "Resource has been exhausted (e.g. check quota).", names no time and rests `quotaRest` as before.
|
||||
- A ZCode plugin account's Start Plan trial entry (`<model>-Trial`) that the plugin refuses before sending anything rests that entry alone (`zcodeTrialRefused`, `restID`), not the account: a 400 "ZCode has no active limited quota for GLM-5.3-Trial" when no live plan holds it any more (the trial ended), and a 429 "ZCode's limited quota for glm-5.3 is exhausted or temporarily unavailable" when its bucket is spent (the plugin names the bucket, the entry less `-Trial`). Read as `failQuota` by their words, both rested `zcode@…`, and the account's GLM Coding Plan models were paused with the trial (#3661, orion-nebula-dev; after skygunner's e04a1b994, which covered the 400). Only the plugin's exact words naming the model asked for count: another model named, a model without `-Trial`, the words on another status, the account's own quota or key, and the same words from another vendor still rest the account (`TestZCodeTrialRefusalRestsTheTrialAlone`). An expired trial still kept in a group is asked first and refused locally, as the guessed quota rest is asked again a minute on; the Routing page strikes it as skipped, which the gateway doesn't do for a member no account lists (#3805). ZCode's risk control refusing a trial entry (3012, `failRestricted`) rests that entry alone too (`zcodeTrialRestricted`): the entry goes to zcode.z.ai, a dual account's plain models to its GLM Coding Plan on api.z.ai, which kept serving them (young02036 on Discord, 11-07). The plain model's own 3012 rests the account, as on a gift-only account, where it goes to zcode.z.ai too.
|
||||
- An account resting out of its window (a Claude account by the time Claude Code's refusal named, `resets`, or any by `window`) is back once magpie's reading of its windows (`provider.Allowances`) finds it full till sooner: the window used below `SpentShareOf`, or its reset passed, with no other window over the same models still full. The reading tells `provider.OnRenewed` as the account's `UsageAgent` and user, and `renewed` lifts that account's rests out of quota or by `window`; its rests for a rate limit, its credit, a verification or a failure stay, as a key's do, and so does every rest of other accounts still out of their windows. Planning reads every account candidate's allowance, ordered groups included, so this needs no step of its own in `restingOf`.
|
||||
- An account is held at a usage cap (`capHeld`) or rested out of one model's pool (`pooled`). A key whose windows magpie reads (`provider.TakesUsageCap`: `readsKeyWindows`, OpenCode Go's 5 hours, week and month among them) takes the same cap by its key id (`AccountCaps`, `AccountWindowCaps`; @wanggenjidev on X) and is barred in `perKeyEvery` (`keyCapHeld`, `Provider.KeyCapHeld`) once a window is at it, as an account is, and back when that window renews. Windows not read yet, or a read that failed, hold nothing (`KeyAllowance` keeps the last good reading, `TestKeyUsageCapPassesTheKeyOver`). `CapCareful` and the one-turn-at-a-time rule near a cap are an account's only. A key is also held at its own spend cap (below).
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// @Airan_FS on X (11-17): an agy-cli account out of its quota answered
|
||||
// "⚠ Individual quota reached. Please upgrade your subscription to
|
||||
// increase your limits. Resets in …" as the model's reply, and the next
|
||||
// account was never asked. The agy-cli plugin (plugins packages/agy-cli,
|
||||
// 0.1.87) now ends such a turn with a rate_limit_error in these words,
|
||||
// after the message_start it has already streamed; the reset is Google's,
|
||||
// written as Go prints a duration ("Resets in 1h18m40s.", the words a
|
||||
// user quoted on discuss.ai.google.dev). The account rests until then and
|
||||
// the next member is asked.
|
||||
const agyQuotaNotice = "Individual quota reached. Please upgrade your subscription to increase your limits. Resets in 1h18m40s."
|
||||
|
||||
func agyQuotaStream(text string) string {
|
||||
lines := []string{
|
||||
"event: message_start\ndata: " + `{"type":"message_start","message":{"id":"msg_1","type":"message","role":"assistant","model":"m","content":[],"stop_reason":null,"usage":{"input_tokens":0,"output_tokens":0}}}`,
|
||||
}
|
||||
if text != "" {
|
||||
lines = append(lines,
|
||||
"event: content_block_start\ndata: "+`{"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}`,
|
||||
"event: content_block_delta\ndata: "+`{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"`+text+`"}}`,
|
||||
"event: content_block_stop\ndata: "+`{"type":"content_block_stop","index":0}`)
|
||||
}
|
||||
return sse(append(lines, "event: error\ndata: "+`{"type":"error","error":{"type":"rate_limit_error","message":"agy bridge: Antigravity quota reached: `+agyQuotaNotice+`"}}`)...)
|
||||
}
|
||||
|
||||
func TestAgyCLIQuotaNoticeRestsUntilItsResetAndFallsOver(t *testing.T) {
|
||||
fresh(t)
|
||||
a := &scripted{replies: []reply{{200, "text/event-stream", agyQuotaStream("")}}}
|
||||
b := &scripted{replies: []reply{{200, "", chatOK}}}
|
||||
scriptedOn(t, "a", provider.Anthropic, a)
|
||||
scriptedOn(t, "b", provider.Chat, b)
|
||||
if err := provider.SaveGroup(provider.Group{Name: "G", Members: []string{"a/m", "b/m"}, Routing: provider.Ordered}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s := New()
|
||||
code, body := postAs(t, s, "", `{"model":"group/g","stream":true,"messages":[{"role":"user","content":"hi"}]}`)
|
||||
if code != 200 || !strings.Contains(body, "hello") || strings.Contains(body, "quota") || a.n != 1 || b.n != 1 {
|
||||
t.Fatalf("%d %s (a %d, b %d)", code, body, a.n, b.n)
|
||||
}
|
||||
r := lastRoute(s)
|
||||
if len(r.Tries) != 2 || r.Tries[0].Fail != failQuota || r.Tries[0].Rest == nil {
|
||||
t.Fatalf("the used-up try: %+v", r.Tries)
|
||||
}
|
||||
want := time.Hour + 18*time.Minute + 40*time.Second
|
||||
if d := time.Until(r.Tries[0].Rest.Until); r.Tries[0].Rest.By != "resets" || d < want-time.Minute || d > want {
|
||||
t.Fatalf("a rests %v by %q, not the %v its quota resets in", d, r.Tries[0].Rest.By, want)
|
||||
}
|
||||
// the next turn goes to b without asking a
|
||||
if code, _ := postAs(t, s, "", `{"model":"group/g","messages":[{"role":"user","content":"again"}]}`); code != 200 || a.n != 1 || b.n != 2 {
|
||||
t.Fatalf("next turn %d (a %d, b %d)", code, a.n, b.n)
|
||||
}
|
||||
}
|
||||
|
||||
// A reply that had begun before the quota ran out can't be taken back: the
|
||||
// client keeps its words and is told why it stopped, and the account rests
|
||||
// until its reset all the same.
|
||||
func TestAgyCLIQuotaNoticeMidReplyStillRests(t *testing.T) {
|
||||
fresh(t)
|
||||
a := &scripted{replies: []reply{{200, "text/event-stream", agyQuotaStream("PARTIAL answer")}}}
|
||||
scriptedOn(t, "a", provider.Anthropic, a)
|
||||
s := New()
|
||||
_, body := postAs(t, s, "", `{"model":"a/m","stream":true,"messages":[{"role":"user","content":"hi"}]}`)
|
||||
if !strings.Contains(body, "PARTIAL answer") || !strings.Contains(body, "Individual quota reached") {
|
||||
t.Fatalf("the client got %s", body)
|
||||
}
|
||||
rest, ok := restOf("a")
|
||||
want := time.Hour + 18*time.Minute + 40*time.Second
|
||||
if !ok || rest.By != "resets" {
|
||||
t.Fatalf("a rests %+v (%v)", rest, ok)
|
||||
}
|
||||
if d := time.Until(rest.Until); d < want-time.Minute || d > want {
|
||||
t.Fatalf("a rests %v, not %v", d, want)
|
||||
}
|
||||
}
|
||||
|
||||
// The reset as agy's notice writes it, as Go prints a duration.
|
||||
func TestAgyQuotaNoticeResetIsRead(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
body string
|
||||
want time.Duration
|
||||
}{
|
||||
{agyQuotaNotice, time.Hour + 18*time.Minute + 40*time.Second},
|
||||
{"Individual quota reached. Please upgrade your subscription to increase your limits. Resets in 45m2s.", 45*time.Minute + 2*time.Second},
|
||||
{"Individual quota reached. Please upgrade your subscription to increase your limits. Resets in 26s.", 26 * time.Second},
|
||||
{"Individual quota reached. Please upgrade your subscription to increase your limits. Resets in 120h5m0s.", 120*time.Hour + 5*time.Minute},
|
||||
{"Individual quota reached. Please upgrade your subscription to increase your limits. Resets in 4h.", 4 * time.Hour},
|
||||
{"Individual quota reached. Please upgrade your subscription to increase your limits.", 0},
|
||||
} {
|
||||
if got := resetsAfter([]byte(c.body)); got != c.want {
|
||||
t.Errorf("%s: %v, want %v", c.body, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1275,8 +1275,12 @@ var resetsInWords = lazyre.New(`(?i)\bresets? in (?:(\d+)\s*d(?:ays?)?\b\s*)?(?:
|
||||
// will reset after 3h19m30s." Unread, the account rested the quarter of
|
||||
// an hour of a quota that says nothing, and the account first in order
|
||||
// was asked again, and refused, every 15 minutes for the hours or days
|
||||
// its quota was out (Dani Ariyanto on Discord, 10-24).
|
||||
var quotaResetAfter = lazyre.New(`(?i)\bquota will reset after ((?:\d+h)?(?:\d+m)?(?:\d+(?:\.\d+)?s)?)`)
|
||||
// its quota was out (Dani Ariyanto on Discord, 10-24). agy's own notice
|
||||
// for an account's quota used up says it the same way: "Individual quota
|
||||
// reached. Please upgrade your subscription to increase your limits.
|
||||
// Resets in 1h18m40s." (@Airan_FS on X, through the agy-cli plugin), which
|
||||
// resetsInWords can't read, as no word ends after its "h".
|
||||
var quotaResetAfter = lazyre.New(`(?i)\b(?:quota will reset after|individual quota reached\b[^\n]{0,160}?\bresets in) ((?:\d+h)?(?:\d+m)?(?:\d+(?:\.\d+)?s)?)`)
|
||||
|
||||
// resetsAfter is how long the refusal says until it is back
|
||||
// (resetsInWords, quotaResetAfter, soonWords), held to longestWritten. Zero when it
|
||||
|
||||
Reference in New Issue
Block a user