Repository navigation
Conversation
fc4e0de to
578da1e
Compare
yetone
left a comment
There was a problem hiding this comment.
Thanks @Euraxluo, and sorry this waited so long. I reviewed 578da1ea. Nothing in it reaches past its goal (no new hosts, the refresh goes to AutoClaw's own /userapi/v1/refresh). With a sandbox HOME, bun test in packages/autoclaw at your head gives 25 pass, 0 fail. It can't merge as it is:
-
It conflicts with main in
packages/autoclaw/index.mjs,index.test.mjsandREADME.md. main is at autoclaw 0.2.12 since this was opened (#355, #367, #376, #437, #445, #466). Please rebase and bump to 0.2.13 (package.jsonisn't bumped here). -
The 403 quota half is already on main, differently.
quotaRefusal(mainpackages/autoclaw/index.mjs:143-175, plugins#274) turns a 403810000/ quota-words reply into a 429rate_limit_errorwithX-Magpie-Sign-In: kept, so the gateway moves on to the next candidate. A banned account's 401/403 (accountRefusal,bannedSaid) is kept too. Please drop the 403 branch inexplained(index.mjs:105-127at your head) and the README's 403 lines (README.md:86-99,README.md:101), so there aren't two readings of the same reply. -
Renewing on a 401 is still missing on main, so #217 stands, and the host only renews by
expires. The renewal atindex.mjs:598-611needs two fixes before it is safe, because AutoClaw rotates the refresh token (the README's "共用会互踢"):client?.auth?.set?.(…).catch?.(() => {})(index.mjs:605) swallows a failed save. The old refresh token is already spent, so the next start has nothing that works, and the account is signed out for good. If the save fails, don't use the new tokens for this request; say so (X-Magpie-Sign-In: expiredwith the reason) rather than going on.- Concurrent requests that all get a 401 each call
tryRenew. The second refresh spends a token the first already rotated, and one of the writes is lost. Keep one renewal in flight per account (a shared promise), and have the others wait for it. - On main,
refreshTokens(mainindex.mjs:799-826) throwssignIn: "kept"for a banned account andsignIn: "expired"only for a dead grant.tryRenewreturnsfalseon any throw, so a ban becomes the "登录已失效" 401 withexpired. Pass the refresh's ownsignInthrough.
-
Tests: please add a case for two concurrent 401s that refresh once, one where
auth.setrejects, and one where the refresh says banned. Check that each is red with the change taken out, and say so in the PR. -
Please keep the README to what the plugin does. Lines 86-99 ("钱包隔离与会员准入分级", which wallet a model can spend) come from your reading of the wallets API. They can't be checked from here, and they'll go stale. A sentence saying a spent model quota moves to the next candidate and keeps the sign-in is enough.
…ustion 403 - Proactively refresh access token via refreshTokens() and update storage when upstream answers 401 Unauthorized before declaring sign-in expired. - Distinguish HTTP 403 quota exhaustion (code 810000 / quota used up) from auth expiration, returning insufficient_quota and keeping X-Magpie-Sign-In: kept. - Document 5.3 vs 5.3 Flash quota tiering and usage notes in README.md. Fixes magpie-community#217 Co-Authored-By: Claude Code <noreply@anthropic.com>
…passthrough Rebased onto upstream/main (0.2.21). Addresses the review of magpie-community#219: - 401 on both hosts renews the token once and retries both hosts (magpie-community#217); concurrent 401s share one in-flight refresh — the refresh token rotates, so a second concurrent refresh would spend the first one's token and lose one of the writes (test: concurrent-401s) - the new tokens are saved through client.auth.set BEFORE they are used: a failed save answers expired with the reason instead of running on tokens the next start could never reproduce (test: failed-auth.set) - a refresh that comes back banned passes signIn "kept" through, so a banned account is not signed out (test: banned-refresh) - the 403-quota branch in explained is gone — main's quotaRefusal already turns a spent quota into 429 with X-Magpie-Sign-In: kept - README: the wallet-tier section is dropped (unverifiable, goes stale); one line on renewal covers it Tests: HOME=$(mktemp -d) bun test packages/autoclaw — 115 pass, 0 fail. Mutations: single-flight removed → concurrent test red; auth.set failure swallowed → failed-save test red; signIn not passed → banned test red.
578da1e to
ca5e2d4
Compare
|
Rebased onto main (0.2.21) and pushed as ca5e2d4 — all five review points addressed:
|
Summary
Rebased onto main (autoclaw 0.2.21) and reshaped per the review of 578da1e. The plugin now renews the access token reactively on a double-401, safely.
What the rebased branch does
expires; a token revoked upstream used to put the account into backoff forever.client.auth.set()and the save is awaited BEFORE the in-memory token is replaced. If the save fails, the new tokens are not used for the request: the reply is a 401 withX-Magpie-Sign-In: expiredand the reason in the message. Running on tokens that the next start could never reproduce would sign the account out for good.refreshTokensthrowssignIn: "kept"for a banned account andsignIn: "expired"for a dead grant;tryRenewcatches and records which one happened, and the final 401'sX-Magpie-Sign-Inand message reflect it (banned keeps the sign-in, message carries the vendor's words).explainedis dropped (review point 2): main'squotaRefusalalready turns a 403810000/quota-words reply into a 429rate_limit_errorwithX-Magpie-Sign-In: kept. No second reading of the same reply. The README's 403 lines are gone with it.Tests (review point 4)
HOME=$(mktemp -d) bun test packages/autoclaw: 115 pass, 0 fail.bun scripts/check.mjs autoclaw: ok.Three new tests, each verified red with the change taken out (mutation-tested):
concurrent 401s refresh once (single-flight), both requests succeed— refreshCalls becomes 2auth.setswallowed, new tokens used anywaya failed auth.set keeps the new token unused and answers expiredsignInnot passed through (ban becomes expired)a banned refresh surfaces kept, not expiredFixes #217
🤖 Generated with Claude Code