Commit Graph
2 Commits
Author SHA1 Message Date
yetone 954977d1a4 provider: the workspace-switch test's fake counts its asks under a lock (#5819)
LoginUsage reads every account at once, so TestCodexAppWorkspaceSwitch-
ReadsEachWorkspace's fake handled ws-personal and ws-team together and
wrote asked[ws]++ from two handlers unguarded. That is #5819's red
("workspaces read: map[ws-personal:1]", no per-account error: the
team's reading was right, its count was lost) and, in the full run at
d3fc6f2bf on mote, "fatal error: concurrent map writes" at
codex_workspace_switch_test.go:90, which took the whole provider
package down. The count is now taken under a mutex.

Run on mote: go test -race -count=3 on the old test, DATA RACE at :90
and FAIL; with this change -race -count=20 -cpu 1,4 ok, gofmt and vet
clean. The full ./... run at d3fc6f2bf had two more reds, both filed
already: gui TestOpenInRexSelectsTheTab/remote_control_off (#5565,
asked []) and plugin TestCancelledSignInEndsItsFetch (#5264).
2026-11-10 04:23:37 +08:00
yetone 2d1b7c1b6c codex: a workspace sharing Codex's sign-in reads and sends as its own workspace
JdAZzzzzz (X) has a personal Pro and a Team seat of one ChatGPT login in
magpie, and switches workspace in the Codex app. Both cards read the
same plan ("Prolite"), week, reset time, pace and two reset cards; only
the token counts (local sessions) differed.

Cause: one ChatGPT sign-in reaches every workspace of its login with
one refresh token. Codex's workspace routing (codex-rs
login/src/auth/manager/workspace_routing.rs, /wham/accounts/check)
changes which one auth.json names in tokens.account_id. rememberLogins
saved each workspace as an account (codexWho goes by account_id), both
with that refresh token. renewSaved found the account not in use "held
by Codex" (heldByCodex: same refresh token), renewed through Codex's
store as it should, and returned that store's account id too: the
workspace Codex is on. So the other account's usage, plan, resets and
the gateway's requests for it named the workspace in use, and spent it.

- renewSaved returns the saved account's own workspace for a token read
  where Codex holds the sign-in, in ~/.codex and in another Codex folder
  (codexOwnWorkspace).
- A sign-in sync put Codex's auth.json on every record sharing its
  refresh token, so the other workspace's record was carried as the one
  in use. liveCodex and applyLogins no longer match by refresh token
  when the workspaces are known apart (codexWorkspacesApart).

TestCodexAppWorkspaceSwitchReadsEachWorkspace: one sign-in (same
refresh token, the real token's claim layout), the app's switch with
only account_id rewritten or with the tokens naming the new workspace,
Codex left on either one. On the old code all 4 cases are red with the
report's picture ("jd@example.com · ws-team (ws-team) reads plan
"prolite" ... 2 resets; its workspace has "team" ... 0 resets"), the
account's requests signed for the other workspace, and CollectSignIns
carrying each record as the other workspace. Green with the change.

Run at 9a00bfed1 (origin/main) plus this change, on mote (macOS):
- gofmt -l internal/provider: nothing
- go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet of
  internal/provider; go build, GOOS=linux go build -tags nogui,
  GOOS=windows go build: ok
- go test -count=1 ./internal/provider: ok (134s)
Not run: go test ./... (mote's suite.lock queue had five suites ahead;
shipped without holding behind it).
Not tried: a real Team seat (no such account here); that ChatGPT's
backend honours chatgpt-account-id for a token whose claim names the
other workspace is what Codex's routing does, not checked by hand.
Not changed: once Codex rotates the shared refresh token, the other
workspace's saved copy holds a spent one (#5779).
2026-11-09 17:13:17 +08:00