gateway: a reading that finds a vendor-timed quota rest's window renewed has the vendor asked once
RookieRicardoR on X: a GLM Coding Plan key ran out, they used a reset card (重置卡) on Zhipu's side, and magpie kept answering "limit reached" without asking Zhipu. Zhipu's 1308/1310 names the reset time, so the key rests by "resets" till it and timedHeld answers every request locally. Since #2718 a reading that finds the window less than full (renewed) doesn't lift a rest the vendor timed, only a window truly started again (restarted) does, because a vendor's usage can read low while its refusal stands. A reset bought on the vendor's side moves neither, so it was never noticed before the named time. Now liftRests, on renewal, lets such a hold go once for its named time (askOnRenewalLocked: askAt = now, the rest itself kept, recorded in restingUntil.renewAsked). The next request asks the vendor: an answer clears the rest as any answer does; refused again with the same time, it is held till then whatever later readings say, so #2718's repeated refusals don't come back. This applies to every provider whose windows magpie reads (Zhipu/Z.ai plan quota, sub2api balance URLs, subscriptions) and to quota and credit rests, not rate rests. Where no windows are read, the rest line's "Try now" (Unrest) already asks at once. The same tweet said the same prompt from Pi got Claude Code's earlier DeepSeek reply word for word. magpie keeps no reply to give a later request (classify caches routing verdicts, vision_cache image descriptions, prev_response rebuilds input; held answers are errors only), and magpie sets no temperature or seed for DeepSeek. TestSameRequestIsAskedEveryTime now holds that: the same bytes from Claude Code's and an OpenAI client's protocol, twice each, reach the vendor four times and get its four answers. Run (mote, at this commit on origin/main9494a38b4): - go test ./internal/gateway/ ./internal/provider/ -count=1 -timeout 45m: provider ok (150s); gateway FAIL (987s) on one test only, TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes, red the same alone at origin/main9494a38b4(3 of 3) and filed as #7117. The log also has doneHold's "close of closed channel" panic, filed as #6690. - go test ./internal/gateway/ -run 'TestSameRequestIsAskedEveryTime| TestRenewalAsksAVendorTimedRestOnce' -count=2: ok - go test ./internal/gateway/ -run 'TestRenewalAsksAVendorTimedRestOnce| TestReadingKeepsARefusalsRest|TestAutoVisionKeepsOffARefusedAccount| TestKeyBackOnceItsWindowIsNotFull|TestZhipuRestsUntilItsReset|Held|Rest': ok - GOOS=linux and GOOS=windows go vet ./internal/gateway/ ./internal/provider/: ok - gofmt -l: clean Broken by hand: - askOnRenewalLocked's call taken out: TestRenewalAsksAVendorTimedRestOnce red ("the window read renewed, and the key is still held"). - its once-per-time guard taken out: red ("asked again for the same named time"). - a reply cache keyed by path and body wrapped round Handler: TestSameRequestIsAskedEveryTime red ("the vendor was asked 2 times for 4 requests"). Not tried: a real Zhipu reset card or a real GLM account; the test uses a sub2api window and Zhipu's reset wording. Bug 2 was not reproduced with real DeepSeek; the reporter's Requests trace would show both calls.
This commit is contained in:
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user