Skip to content

fix(accounts): back up snapshots before codex; restore after symlink clobber#25

Merged
NagyVikt merged 1 commit into
mainfrom
fix/snapshot-backup-recovery
May 13, 2026
Merged

fix(accounts): back up snapshots before codex; restore after symlink clobber#25
NagyVikt merged 1 commit into
mainfrom
fix/snapshot-backup-recovery

Conversation

@NagyVikt
Copy link
Copy Markdown
Collaborator

Summary

  • Pre-codex backup vault: restoreSessionSnapshotIfNeeded copies every saved snapshot into accounts/.snapshot-backups/ before codex runs.
  • Post-codex repair: syncExternalAuthSnapshotIfNeeded walks the vault before name resolution; restores any snapshot whose on-disk identity no longer matches its backup (codex wrote through a stale auth.json symlink) or whose file is missing.
  • Vault is cleared after the new account is saved.

This survives the case where the shell hook is shadowed (e.g., a competing codex() GH_TOKEN-export function) and restore-session never runs — the backup taken on any prior shell hook firing still protects future syncs that detect the clobber.

Why this case existed

Without the vault, identity-based name resolution kept matching the clobbered file's new identity and silently overwrote the previous account's registry entry, removing it from codex-auth list.

Test plan

  • npm run build
  • npm test — 77/77 pass
  • New regression: auth.json is a symlink, restore-session backs up snapshots, simulated codex login overwrites the previous snapshot through the symlink, sync recovers the original tokens and saves the new account under its own name

🤖 Generated with Claude Code

…link clobber

restoreSessionSnapshotIfNeeded now copies every saved snapshot into a
hidden .snapshot-backups vault before codex runs. syncExternalAuthSnapshotIfNeeded
walks that vault before name resolution and restores any snapshot whose
on-disk identity no longer matches the backup (codex wrote through a
stale auth.json symlink) or whose file was removed entirely. After the
new account is saved, the vault is cleared.

Without this, identity-based name resolution kept reusing the clobbered
file's *new* identity and silently overwrote the previous account's name
in the registry, deleting it from the user's list. Notably this fires
even when the shell hook is shadowed by a competing `codex()` function
(e.g., a GH_TOKEN export wrapper) and restore-session never runs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@NagyVikt NagyVikt merged commit 21ce898 into main May 13, 2026
1 check passed
@NagyVikt NagyVikt deleted the fix/snapshot-backup-recovery branch May 13, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant