zoecats (Discord #feedback, 10-25): a local aggregator answers 429
insufficient_quota "quota exhausted" for the moment it switches
upstreams, and the agent's retry and every request after it were
answered by magpie itself, "out of its allowance: not asked again
before …", Retry-After 900. v0.1.1488 (c6768f06f) let it through only
when the user unticks the provider's new "Rests" switch; by default it
was still held (checked on origin/main 4dfd88206 below). The owner's
zero-config rule wants it to just work.
Cause: quotaHeld (#1772) answers from the rest, without asking, as soon
as every key left rests out of its allowance or credit, from the first
refusal on, for as long as the rest: 15 minutes (quotaRest) or 30
(creditRest) that magpie guessed when the vendor named no time.
Now (Rest.first, Rest.askAt, Rest.asksAt), for a rest whose length
magpie guessed (creditRest, or quotaRest with no OwnQuotaRest):
- The key is held only once it was refused so twice in a row. The first
refusal still rests it (the order passes it over for a ready
candidate), but the next request, the agent's retry first, asks it
again; served, its rest is cleared as before.
- Held, it is asked again a minute on (fallbackCooldown), once, and
held again if refused.
- A time the vendor named (resets, Retry-After, a window) or the user
set (quotaRest, QuotaResetAt) holds it from the first refusal to
then, as before. A first version gave every refusal one more ask;
the full gateway suite turned it down in TestClineFreeLimitLeaves-
OtherModels and TestZhipuRestsUntilItsReset (a named reset asked
again), so it is limited to the guess.
#1772's keys out for the week are asked at most once a minute each
while requests come, not on every request.
- soonestBack, the Retry-After a 429 without one gets, says when the
first of them is asked again: none after a first refusal, about 60s
for a guessed hold (was 900 or 1800). That narrows #3556 for a
guessed hold; a vendor-named or user-set one is as before.
- A rate limit was already asked again (restLast, retries within the
request) and is unchanged; the new test holds it there, Retry-After
0 and every key resting included.
- The "Rests" switch (LimitRestOff) stays: unticked, nothing rests at
all.
docs/subsystems/gateway-routing.md says so.
Run (worktree at origin/main 4dfd88206 plus this change):
- Reproduced first on the old code with tests:
TestRetryAfterALimitIsAsked (new; 429 insufficient_quota, a usage
limit with no reset, the same with Retry-After: 0, 402, every key of
two; plus two rate-limit cases): the five limit cases red on
4dfd88206 ("request 2 after the refusal: 429 … not asked again before
14:34"), green now; the rate cases green on both.
TestHeldLimitAskedAgainInAMinute (new) red on the old code (Retry-After
900, not asked a minute on), green now. TestAllRestingAnswersFromRest,
TestOwnQuotaRest and TestQuotaHeldOnlyForKeysOutOfAllowance changed to
the new rule (each key asked once more, then held; held Retry-After
about 60s; a user-set week held from the first refusal); red on the
old code. TestRemoteMagpieRestsTheModel (#2077) asks Claude Code once
more before its hold: the other magpie can't read "resets 8:10pm
(America/Los_Angeles)", so its 15 minutes there are a guess.
- Broken by hand, each red, then restored: r.first always false ->
TestRetryAfterALimitIsAsked's five limit cases; askAt never set ->
TestHeldLimitAskedAgainInAMinute and TestAllRestingAnswersFromRest
(Retry-After 900).
- Sandbox HOME, a nogui build of 4dfd88206 and of this tree, `serve` on
127.0.0.1:3481 over a Python fake answering 429 insufficient_quota
"quota exhausted" once, then 200: old: 429, then 429 "not asked again
before 14:41", 429 again, Retry-After 900, 1 upstream POST. New: 429
(no Retry-After), 200, 200, 3 upstream POSTs (rerun on the final tree). The fake refusing every
time, new: 429, 429 Retry-After 60, then held "not asked again before
14:27" Retry-After 60, 2 upstream POSTs.
- go test -tags nogui -count=1 -timeout 45m ./internal/gateway/ at
4dfd88206 plus this tree, through suite-lock (after the DSH run):
ok 446.6s. The first full run, before the rule was limited to a
guess, was red in the three tests named above.
- gofmt -l clean; go vet ./internal/gateway/ (darwin); GOOS=linux go
vet -tags nogui ./...; GOOS=windows go vet -tags nogui
./internal/gateway/: ok.
Not tried: zoecats' own aggregator; a real vendor's out-of-credit key
(OpenAI insufficient_quota) to see the once-a-minute ask in use; the
GUI (no GUI file changed; the Routing page reads the same rests);
Windows box (Windows CI compiles the tests only).