SessionIdentities lists the identity in Codex's auth.json (and Claude's
profile), then one per saved login. Once rememberLogins had saved a copy
of the account signed in now, that account was listed twice. QueryPage
keys the request cache on this list, so the save that added the copy
changed the key, and the next Requests page query dropped every cached
chunk and read and priced every session log again, though no identity
had changed. Users could see that as one more slow Requests page after
magpie saved its first copy of an account: one an agent was signed in
to outside magpie (codex login, Claude Code's /login), or the one
already signed in when magpie first ran. Switching between saved
accounts and signing in through magpie never caused it: rememberLogins
replaces a saved account in place, and magpie's own sign-in (addLogin)
writes logins.json together with auth.json. The resolver gets nothing
from the duplicate: an identical entry never changes which email or
login a session resolves to.
SessionIdentities now leaves out a saved identity equal to one already
in the list. One that differs in any field is still listed, such as
another member of the same workspace (the same account id, another
email): sessionResolver.codexUser names no member when two identities
share a workspace and user id but not the email.
TestSessionIdentitiesListTheSavedCurrentAccountOnce saves the account
Codex is signed in to with rememberLogins(true), checks that it was
saved and that the identities are unchanged, then saves a second
member of the same workspace and checks that it is listed.
A scratch test on main (c5a54bc7) showed when the list changed:
switching between two saved Codex accounts changed it once and the save
after that didn't; writing a new account into auth.json changed it, and
the save after that changed it again (3 to 4 identities). With this
change the second change is gone. Found while characterising
TestQueryPageSourceAndIdentityInvalidation: run alone on main with only
this change applied, it gets past request_page_test.go:224 "unchanged
source rebuilt" (the cache is kept) and stops at
request_page_test.go:237, an assumption of the test's own, fixed in
#1045.
Verified on 698da36f (go test -tags nogui under a temp HOME, Go caches
pinned), as first on c5a54bc7:
- -run '^TestSessionIdentities' ./internal/provider: both PASS, also at
local 23:59:59.9, 00:00:30 and 12:00:00.
- go test ./internal/provider ok, and ok with -shuffle=11. With
-shuffle=22 and 33, TestCopilotSignAndModels fails
(account_test.go:403: available after fetch: ...), and at 33
TestPlanQuotas too (planquota_test.go:290: cards: map[]). They fail
the same with this commit's test skipped and session_identity.go as on
main: -shuffle orders every test before -skip leaves one out, so the
others keep their order. Main fails TestCopilotSignAndModels at
-shuffle=33 too. It is an order dependence among the provider tests,
apart from this change.
- Broken on purpose, the new test fails each time. A dedupe on Agent and
AccountID alone: "session_identity_test.go:63: another member of the
workspace was left out: [{Agent:codex AccountID:acct-1 ...
User:me@example.com ...}]". rememberLogins writing nothing:
"session_identity_test.go:49: the signed-in account wasn't saved: 0
saved logins".
Without the change in session_identity.go:
--- FAIL: TestSessionIdentitiesListTheSavedCurrentAccountOnce
session_identity_test.go:53: saving the signed-in account changed its
identities: before [{Agent:codex AccountID:acct-1 ...}], after
[{Agent:codex AccountID:acct-1 ...}
{Agent:codex AccountID:acct-1 ...}]
On this commit: go test -tags nogui ./... ok, go vet ./... ok, gofmt
clean, and -race -count=20 -run '^TestSessionIdentities'
./internal/provider ok.