Files
magpie/internal
yetone 88b4c00ea1 provider: a Codex token refresh, once sent, is waited for even when its caller gives up
willz on Discord: a Codex account that isn't the current one stops showing
its quota after a day or two and asks to be signed in again, while
requests on it still work; moving it to the top "fixes" it.

codexRefresh sent the refresh on the caller's context. OpenAI rotates the
refresh token as it answers, so a refresh whose caller went away mid-flight
(an agent's cancelled request, a usage read's deadline, the keep-alive's
2-minute run) dropped the answer and left magpie holding the spent refresh
token. The next refresh (the keep-alive forces one each day) is refused as
refresh_token_reused, the account is marked lapsed and its row says to sign
in, while the access token it still holds keeps serving requests. Moving it
to the top makes it the active account, whose lapse isn't shown.

Like siwcFresh (the ChatGPT API's refresh) already does, a refresh that has
been sent now runs on context.WithoutCancel with its own 30 s; a caller
already gone sends nothing.

The cause can't be confirmed without willz's log; this is the one path
found where a working account's refresh token is lost.

Run: TestCodexRefreshOutlivesItsCaller fails without the change
("context canceled") and passes with it; -race -count=10; the whole
internal/provider package (sandbox HOME); gofmt -l; go vet darwin,
GOOS=linux -tags nogui, GOOS=windows.
Not tried: a real Codex account.
2026-10-14 14:47:35 +08:00
..
…
…