ac4af582301a4e8a29245dbba767eba31334ddf9
7
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
f5c956b848 |
plugin: a 401 on an access token its refresh token renews makes it due, not the sign-in gone (plugins#618)
jinpy666 (magpie-community/plugins#618): with Copilot plugin 0.1.0, the two Copilot slots that carried no traffic said "sign-in has expired — sign in again" within a day or two, while their GitHub OAuth token still traded at /copilot_internal/v2/token. A plugin's bare 401 (no X-Magpie-Sign-In) marked the account whatever the cause, and a mark is cleared only by a success or a usage read that says so, which an idle slot never gets. The host now judges such a 401 against the sign-in as the request found it (staleAccess in host.js). For an OAuth sign-in with a refresh token whose access token is still the stored one and not due yet, it makes the token due (expires 1, under the auth lock, only while the access token is unchanged), drops the account's loader and says "kept": the gateway fails the request over as before, and the next request renews the token through the plugin's loader (or magpie's auth.refresh) and goes through. Still marked: an access token renewed for this request and turned away, one that was due already and not renewed, an account with no refresh token, and a plugin saying "expired" (a refused refresh). A sign-in that can't be read when the 401 comes is unknown: kept, not marked. A marked account stays routable (pluginAlsoOn doesn't filter marks), so a slot marked before this is renewed on its next request and the success clears it. Copilot isn't a mover; its plugin 0.1.1 (plugins 53d4813, on the dist branch; never on npm) says "expired" for the exchange's own 401 and "renewed" for a quota read GitHub answers, which clears old marks. TestPluginStaleAccessRenewsNotLapses (new, fake plugin + local vendor, no network): idle account kept and due after the 401, renewed and 200 on the next request; a renewed token refused is marked; a refused refresh (signIn "expired") is marked; plugin-auth.json unreadable at the 401 marks nothing; a marked account is still routed. TestPluginFailover's "gone" case asserted one 401 marks; it now asserts no mark after that 401 and the mark once the account's renewed token is refused too. docs/subsystems/provider-plugins.md has the rule. Run at this commit's tree (mote, rebased on |
||
|
|
3dc25a6168 |
tests: a plugin fake's vendor counts only its own test's requests (#3357)
Run 39913278700 at |
||
|
|
2da8fbe488 |
tests: every test that runs plugins on the bun on PATH runs it once first, through testenv.Bun, so a bun that has never run here doesn't time out internal/provider's and internal/plugin's plugin tests (#1306)
|
||
|
|
470d1e71a5 |
provider: a plugin account's usage reading begun before a request was answered no longer overrules the answer, so a 401's lapse mark isn't taken off by a clean reading already out (TestPluginFailover, about 1 run in 90) (waitingsnow) (#1176)
TestPluginFailover failed about 1 run in 90 at "a refused isn't marked". With notePluginLapse logged, a failing run read: a background reading of a's allowance (loginReading, after the "stream" round's StaleAllowance) began at 31.985; the upstream answered a's request 401 at 32.001 and notePluginSaid marked a lapsed at 32.003; the reading ended clean at 32.011 and notePluginLapse(200) took the mark off; the test read the logins at 32.042. Users meet the same: a reading of the Usage page or of routing's allowances that is out when a request is refused clears the mark the refusal left, and routing goes on trying the refused account; one that ends refused marks an account a request has just gone through on. What plugin accounts' sign-ins are told of is now counted under loginsMu (pluginSignInTold, pluginSignInSaid). A request's answer, a sign-in and the plugin's own signIn events are told now and apply as before. pluginLoginQuota takes the count before plugin.AccountUsage, and what its reading found applies only when nothing was told of that account since (notePluginLapseSince), as Allowances leaves out an account renewed while it read. A count rather than a time: Windows' clock moves in ticks of up to 15.6ms, and a reading begun just after an answer would read as begun with it. TestPluginUsageReadOlderThanAnswer holds the fake plugin's usage on an httptest server ($FAKE_USAGE, whose 401 the fake now reads as an expired sign-in) while a request's answer is noted, both ways, and checks that readings begun afterwards still mark and clear. Each direction fails without the fix. TestPluginFailover now reads the allowances the "stream" round left stale before the "gone" round: the fake's usage doesn't ask the upstream that refuses, so a reading that asks after the 401 finds the sign-in good and rightly takes the mark off. A review reproduced that with a delay injected before the count is taken. Left as it is: a reading whose own renewal of the token tells "renewed" before it asks skips the "expired" it then finds; the next 401 marks the account. Not tried with a real plugin account. Under a temp HOME with Go's caches pinned and bun 1.4.2: gofmt, go vet -tags nogui ./..., builds for darwin, GOOS=linux -tags nogui and GOOS=windows (and windows vet of provider and gateway) pass; go test -tags nogui ./... passes; the changed provider tests and TestPluginSaysSignIn/TestPluginFailover pass with -race -count=20; the report's `go test -tags nogui -race -cpu 1,2,4 -count=30 -run '^TestPluginFailover$' ./internal/gateway/` passed 3 rounds (270 runs), where it failed 3 of about 54 runs before the fix on the same loaded machine. |
||
|
|
1fa21850a3 | plugins: a plugin can say its sign-in renewed, and what a usage read means for it (要保证插件跟内置的所有逻辑都要一模一样) — a built-in whose sign-in renewed took the lapse mark off whatever the request then met, and a plugin could only clear it with a success: X-Magpie-Sign-In: renewed now clears it on any status. A usage read marked a plugin account whenever its error said to sign in again and cleared it on any clean read, where Qoder's, Kiro's and others' built-ins marked none from usage: auth.usage may now say signIn: expired, kept or renewed, taken as the header is; one that doesn't say keeps the old reading. TestPluginSaysSignIn and TestPluginUsageLapse fail without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./internal/gateway ./internal/provider ./internal/plugin pass. | ||
|
|
c9d2015e5d | plugins: a plugin says apart what its answer means for the sign-in, so it can fail with its built-in's status (当然要做,要保证插件跟内置的所有逻辑都要一模一样) — magpie took a plugin account for lapsed on a 401 alone, so a plugin had to choose between the built-in's status and its lapse mark: Factory's and MiMo's refused renewals were 401s where the built-in answered 502 and marked the account, and Qoder's 403, Zed's retried 401, Kiro's unreachable refresh and Cursor's expired plan answered other than the built-in so as not to mark one it didn't. An answer's X-Magpie-Sign-In now says: expired marks the account lapsed whatever the status, kept leaves it be; without it a 401 marks it and a success clears it, as before. The agent never sees the header. TestPluginSaysSignIn fails without the change. | ||
|
|
4e63e98359 | gateway: a plugin's provider with several accounts fails over as a built-in's subscription does (别忘了同时添加多个账号、设置路由组、自动故障转移、额度不够时的转移、显示额度) — a test of it end to end, through the plugin host and a fake vendor: three accounts signed in in magpie, all on; one answering a quota 429, a quota error in the stream before any content, or a 401 hands the request to the next and rests, the 401 marking it lapsed; one whose five hours are used up for a model, as the plugin's usage says, is weighed last for that model even while in use, and first for a model its window doesn't count; a routing group of the plugin's model and another provider's answers from the other when every account of the plugin is out. It fails with the account's allowance asked of any agent but the plugin's provider's. |