ZCode's account-wide 429 "[1302][您的账户已达到速率限制,请您控制请求频率][id]"
read as a rate limit that passes: the same-one retries (passing) asked it
again 1/2/4s apart and a patience's rounds sent the whole request again
every 2s..30s — "magpie keeps asking, so the 429 comes back in a loop"
(#5406, erlinerd; two further accounts on v0.1.3216). Rested and retried,
the 429 came back: no moment clears it.
walled now also matches the ZCode plugin's own naming of the refusal,
the vendor's three-part label [1302][its words][its request id] (its
words whole, a 16-hex id). The next account is asked, or the agent has
the error at once, as wallCodes says.
Review change: the patch also added the bare code "1302" to wallCodes,
for every vendor. Zhipu's own API answers 1302 for a concurrency or
minute limit ("并发数过高", or "您的账户已达到速率限制" with no label),
which a moment does clear, so a GLM key would have lost its in-place
retries. The bare code stays a rate limit that passes; only the label's
shape walls. The comment's claim that the 并发数过高 reading "never
reaches here" is gone. Two Zhipu bodies are added to the test's
"still passes" cases.
Run (wsl-run, magpie-desktop, Go 1.26.8):
- go test -count=1 -run 'Wall|MinuteLimit|RateLimit|RestRetry|Patience|Busy|FailureReads|PassErrors|Zhipu|ZCode' ./internal/gateway: ok 21.9s
- the same Wall|RateLimit|Patience|Busy set with -race: ok
- gofmt -l: clean
Broken by hand:
- main's fallback.go: TestZCodeWallIsNotRetriedInPlace red ("the wall
passes: asked again in place", "the wall is busy") on both labelled bodies.
- the patch's own fallback.go (bare 1302 in wallCodes): red on both
Zhipu bodies ("doesn't pass", "not busy").
Not tried: a real ZCode account's 429, and whether the next account is
asked on a live rotation.
Reported-by: erlinerd
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
SenseTime Raccoon answers an account whose token throughput is used up
with 429 {"error":{"code":"user_model_rate_limited","message":"您的模型请
求频率超限,请稍后重试","type":"rate_limit_error"}} and no Retry-After.
Its words read as a short rate limit, so the lone account was asked again
by the same-one retries (passing: 1, 2, 4s) and then by the plain
provider's patience (busy/replan: 2, 4, 8, 16s): eight asks in ~38s,
each one resending the whole ~88k-token request into the bucket it was
waiting on (cycocyco's numbers in plugins#512).
A 429 whose error.code is in wallCodes (only user_model_rate_limited) is
now neither passing nor busy. It still reads as failRate and rests as one
(a minute, doubled each time it comes back, up to 30 min, rateRest), so a
group's next member or the provider's next account is asked, and a lone
one hands the agent the vendor's error after one ask. The code is matched
at error.code only, not as words anywhere in the body. Other rate limits,
the same Chinese words under another code included, are retried as
before. The plugin passes the vendor's body through unchanged, so this is
the place for it.
Run (mote, at this change on origin/main 244d80e23):
- go test ./internal/gateway -run 'TestTokenWall|TestRateLimitIsWaitedOut|TestShortReset|TestLastOneLeft|TestGroup': ok
- gofmt -l internal cmd: clean; GOOS=linux go vet -tags nogui ./... and
GOOS=windows go vet ./...: ok
- go test -timeout 45m -count=1 ./...: every package ok except
internal/gui, whose ten real-window AppKit tests (dock, panel, tray,
titlebar, plugin page) were killed at their deadlines, mote's known
state (#4125, #2645); this change touches no GUI code.
Rebased on origin/main 88e6fb9cf: go test -timeout 45m ./internal/gateway
./internal/usage: ok. Rebased again on 88e6fb9cf (routing.go's credit
rests changed, not the rate path): go test ./internal/gateway -run
'TestTokenWall|TestRateLimitIsWaitedOut|TestShortReset|TestLastOneLeft|
TestGroup|Rest|Credit': ok; the whole package not rerun there.
Broken by hand: with both !walled(body) guards taken out,
TestTokenWallIsNotRetriedInPlace is red (passes, busy) and
TestTokenWallFailsFast is red with "429 after 16 tries".
Not tried: the real Raccoon API (no account here), nor the reporter's
Hermes on Windows.