fix(accounts): preserve saved snapshots on codex login from a fresh terminal#24
Merged
Merged
Conversation
…erminal restoreSessionSnapshotIfNeeded materialized the auth symlink only after the session-pin lookups. In a fresh terminal with no pinned session, it early-returned without materializing, leaving ~/.codex/auth.json as a symlink into accounts/<name>.json from older installs. The shell hook then ran `codex login`, which wrote through the symlink and overwrote the previously-active snapshot in place; syncExternalAuthSnapshotIfNeeded afterward saw the corrupted file matched the incoming identity and renamed it, wiping the previous account. Move the materialize step above all early returns so the symlink is flattened before `codex login` ever sees auth.json. Also exclude update-check.json (the npm version cache) from listAccountNames so it stops appearing as a phantom account in `codex-auth list`. Realign the email-shaped-duplicate test with the refresh-by-email behavior introduced in #23: same-email re-login now refreshes the canonical snapshot in place with forceOverwrite=true, instead of spawning a --dup-2 entry. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
materializeAuthSymlinkabove the early returns inrestoreSessionSnapshotIfNeededso a stale~/.codex/auth.jsonsymlink (from older installs) is flattened beforecodex loginruns. Previously, in a fresh terminal with no pinned session, the function returned early andcodex loginwrote through the symlink, overwriting the previously-active saved snapshot — the nextcodex-auth listshowed only the freshly-logged-in account.update-check.json(npm version cache) fromlistAccountNamesso it no longer appears as a phantom "account".Test plan
npm run buildnpm test— 76/76 pass (was 75/76 on main; the--dup-2test was outdated since fix(accounts): refresh snapshot by email even when not active #23)update-check.jsonin accounts dir is excluded fromlistAccountNames🤖 Generated with Claude Code