gateway: a ZCode trial entry's 3012 rests that entry, not the account

young02036 (Discord, 11-07): on an account with a GLM Coding Plan,
GLM-5.3-Flash-Trial answered 405 code 3012 (ZCode's risk control) while
the account's paid models worked. The plugin's 3012 words read as
failRestricted, which rested the whole account for two hours
(restrictedRest), so magpie stopped sending the paid models the account
still served. A -Trial entry goes to zcode.z.ai's Start Plan, and a dual
account's plain models to its GLM Coding Plan on api.z.ai, so the 3012
is zcode.z.ai's: zcodeTrialRestricted rests the entry alone (restID),
as zcodeTrialBlocked already does for the edge block page. On a
gift-only account the plain model goes to zcode.z.ai too, gets its own
3012 and rests the account, at the cost of that one more refused
request per rest. riskRefused still walls the provider's other accounts
off for the rest of the request.

TestZCodeTrialRefusalRestsTheTrialAlone: "trial risk control" now wants
the entry's rest and the account's GLM-5.3 served after it; new cases
"plain risk control" and "another vendor's risk control" want the
account's rest. docs/subsystems/gateway-routing.md says so.

Run (mote): go test -count=1 -run 'TestZCode|TestRisk|TestRestricted|TestMovedZCode'
./internal/gateway/ ok; gofmt -l clean; GOOS=linux and GOOS=windows go
vet ./internal/gateway/ ok.
Broken by hand: the routing.go check removed, trial_risk_control red
(rested "zcode@api key", want ".../GLM-5.3-Flash-Trial"), then restored.
Not tried: a real 3012 account (the reporter's); the full suite runs
after this push.

Reported-by: young02036
This commit is contained in:
yetone
2026-11-07 15:13:03 +08:00
parent 682d72075a
commit 0978a68681
4 changed files with 27 additions and 5 deletions
+1 -1
View File
@@ -244,7 +244,7 @@ recorded as a prediction failure (`noPrediction`).
- 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.
- 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).
- 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`.
- Only an account is held at a usage cap (`capHeld`) or rested out of one model's pool (`pooled`); a key's windows order it and rest it, nothing more. A key is held only at its own spend cap (below).
- A key at its spend cap ([providers](providers-accounts.md), `provider.SpendCap`) is barred in `perKeyEvery` (`spendHeld`) with a `capHold` whose `spend` is set: it is passed over and the provider's other keys and its fallbacks take the request. Routing's row says what it spent of its cap (`Weighed.SpendCap`, `Spent`, `SpendPeriod`, `SpendSince`). With every candidate held, `cappedError` answers 429 naming each key, what it spent of its cap and when it is back (the next day or month, or not until a cap in all is raised), and the command that changes it, with `Retry-After` at the soonest; a cap in all gives none. A spend hold is not a usage cap: `capHeldOnly` leaves it out, so neither Stop at the caps (`CapStop`) nor Strict's `strictKeep` sends a request to a key past what it may spend. `TestKeySpendCapPassesTheKeyOver`.
+4
View File
@@ -1722,6 +1722,10 @@ func (s *Server) restAfterMarked(c candidate, status int, header http.Header, bo
if why == failQuota && zcodeTrialRefused(c, status, body) {
id = c.restID()
}
// and so is its 3012: zcode.z.ai's, not the GLM Coding Plan's host's
if zcodeTrialRestricted(c, why) {
id = c.restID()
}
// a relay's 429 that names the model whose credentials cooled down is
// that model's: its siblings on the same key still answer upstream,
// and the model's own sentence rests with the model, not on every
+15 -1
View File
@@ -58,10 +58,24 @@ func zcodeTrialRefused(c candidate, status int, body []byte) bool {
// that rests the account (windy_66454 on Discord, 10-31: glm-trial's two
// members, GLM-5.3-Flash and GLM-5.3-Flash-Trial, shared one account rest
// and the plain one was never asked). ZCode's risk control blocking the
// account (code 3012, failRestricted) is the account's, and is read before.
// account (code 3012, failRestricted) is read before, and rests as
// zcodeTrialRestricted says.
func zcodeTrialBlocked(c candidate, status int, body []byte) bool {
if status < 400 || c.p.PluginProvider() != "zcode" || !strings.HasSuffix(strings.ToLower(c.model), "-trial") {
return false
}
return provider.EdgeBlocked(wordsOf(body)) && !restrictedSaid(status, wordsOf(body))
}
// zcodeTrialRestricted says c, a ZCode plugin account asked for one of its
// Start Plan trial entries, was refused by ZCode's risk control (code
// 3012, failRestricted). That is zcode.z.ai's answer, and the entry alone
// rests: a dual account's plain models go to its GLM Coding Plan on
// api.z.ai, which kept serving them (young02036 on Discord, 11-07:
// GLM-5.3-Flash-Trial answered 3012 while the account's GLM-5.3 worked,
// and the account rested whole for two hours). On a gift-only account the
// plain model goes to zcode.z.ai too, gets its own 3012, and that rests
// the account, as zcodeTrialBlocked's block page does.
func zcodeTrialRestricted(c candidate, why string) bool {
return why == failRestricted && c.p.PluginProvider() == "zcode" && strings.HasSuffix(strings.ToLower(c.model), "-trial")
}
+7 -3
View File
@@ -63,11 +63,15 @@ func TestZCodeTrialRefusalRestsTheTrialAlone(t *testing.T) {
// a trial entry goes to zcode.z.ai's Start Plan, and a dual
// account's GLM Coding Plan to api.z.ai: zcode.z.ai's firewall
// blocking the trial says nothing of the plan's host, so the trial
// rests alone and the plan's model is asked. Blocking the plain
// model, or the account's own risk control, rests the account
// rests alone and the plan's model is asked. So does ZCode's risk
// control refusing the trial (3012, young02036 on Discord: the
// gift refused, the plan's models served). Blocking the plain
// model, or its 3012, rests the account
{"trial edge block", "zcode", "GLM-5.3-Flash-Trial", zcodeStartEdge, 405, true, false},
{"plain edge block", "zcode", "GLM-5.3", zcodeStartEdge, 405, false, true},
{"trial risk control", "zcode", "GLM-5.3-Flash-Trial", zcodeStartRisk, 405, true, true},
{"trial risk control", "zcode", "GLM-5.3-Flash-Trial", zcodeStartRisk, 405, true, false},
{"plain risk control", "zcode", "GLM-5.3", zcodeStartRisk, 405, false, true},
{"another vendor's risk control", "factory", "GLM-5.3-Trial", zcodeStartRisk, 405, false, true},
{"another vendor's block", "factory", "GLM-5.3-Trial", zcodeStartEdge, 405, false, true},
} {
t.Run(tc.name, func(t *testing.T) {