Skip to content

fix: serialize account store updates - #118

Open
demetrius-skypulse wants to merge 1 commit into
Lampese:mainfrom
demetrius-skypulse:agent/serialize-account-store
Open

fix: serialize account store updates#118
demetrius-skypulse wants to merge 1 commit into
Lampese:mainfrom
demetrius-skypulse:agent/serialize-account-store

Conversation

@demetrius-skypulse

@demetrius-skypulse demetrius-skypulse commented Aug 1, 2026

Copy link
Copy Markdown

Fixes #100.

Summary

  • route every accounts.json mutation through one bounded, guard-owned worker
  • persist updates with same-directory atomic replacement instead of concurrent fs::write calls
  • keep disk I/O off the UI/runtime thread and publish read-only in-memory snapshots
  • serialize account selection and active-account token refresh so stale refresh state cannot overwrite auth.json
  • close update admission and drain accepted writes during desktop or standalone web shutdown

Why

The Refresh flow launches concurrent metadata and token updates. Each update previously performed its own load-modify-write sequence against accounts.json, so writes could race and leave valid JSON followed by a stale duplicated suffix. That makes subsequent refreshes fail with Failed to parse accounts file.

The same stale-state pattern also allowed an in-flight token refresh to rewrite ~/.codex/auth.json for an account that was no longer active.

Scope

This keeps the existing desktop and optional codex-web entrypoints. Each gets the same single-writer behavior when run independently. Coordinating simultaneous desktop and web processes is intentionally out of scope for this fix.

Validation

  • cargo check --manifest-path src-tauri/Cargo.toml
  • cargo test --manifest-path src-tauri/Cargo.toml (37 passed)
  • cargo clippy --manifest-path src-tauri/Cargo.toml --all-targets (passes with existing warnings)
  • pnpm build
  • pnpm tauri build --bundles app --config '{"bundle":{"createUpdaterArtifacts":false}}'
  • git diff --check

New tests exercise concurrent account updates and confirm mutations execute on the dedicated worker thread.

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.

Failed to load accounts Failed to parse accounts file: /Users/jakobgross/.codex-switcher/accounts.json

1 participant