Commit Graph
1 Commits
Author SHA1 Message Date
yetone 4683a0382c provider: a saved ChatGPT account Codex is signed in to is refreshed in Codex's auth.json, not in its copy
A ChatGPT account switched in to Codex is one sign-in in two places:
logins.json's copy and Codex's auth.json hold one refresh token.
renewSaved refreshed the copy whenever it was asked to: a provider made
for the account while another was Codex's, held over a switch
(SwitchWhenSpent, keep-first), a usage or models read, keep-alive or a
revoked-token check decided "not the live one" just before a switch.
OpenAI rotates the refresh token as it answers, so auth.json was left
with a spent one. The Codex app of an edu or business workspace fetches
its workspace config bundle (/backend-api/wham/config/bundle) at start
with it; the refresh is refused (refresh_token_reused), app-server
answers configRequirements/read with -32603 "failed to read
configuration layers: Your access token could not be refreshed ...",
and the app stays paused on "无法加载组织设置". Reinstalling the app or
changing the preferred account doesn't help: auth.json stays.

renewSaved now asks, under savedTokenMu (which a switch holds too),
whether the saved account is the one Codex is signed in to (sameLogin,
or the same refresh token) and renews it through codexTokenRenewing on
Codex's own store instead.

Reported by 万贤凯 on Discord (two edu_plus accounts, "Codex 始终登录首选
账号" on, both used up).

Run:
- TestSavedRefreshOfCodexOwnRenewsCodexOwn: red on the old code (auth.json
  kept refresh token "r" after it was spent), green with the fix.
- Codex app-server 0.163.0-alpha.10.2 in a sandbox CODEX_HOME, edu_plus
  auth.json, fake bundle (401) and token endpoint (refresh_token_reused):
  configRequirements/read gives the -32603 above, the reply the desktop
  shows as the org-settings dialog. magpie's openai_base_url and
  [model_providers.magpie] don't move the bundle request (it goes to
  chatgpt_base_url, which magpie never writes).
- gofmt -l; go vet darwin, linux -tags nogui, windows.
- Full suite (go test -tags nogui -timeout 45m ./..., through suite-lock,
  at dd1e8822d plus this change): every package ok except internal/gui's
  TestRestartHandsTheGatewayOver (one request during the handover got
  EOF, 12 of 13). It passes 5 of 5 alone and this change doesn't reach
  it; filed as #3451.

Not tried: the reporter's own auth.json and logins.json, so which caller
spent their token isn't known; a real edu account; the GUI (unchanged).
2026-10-24 14:37:39 +08:00