Skip to content

[Bug] Codex Switcher v0.2.8 fails to open on macOS — "Failed to parse accounts file" on startup #113

Closed as not planned

Description

@hoangvu14092005

Environment

  • App version: v0.2.8 (latest)
  • OS: macOS (Apple Silicon / Intel — please confirm)
  • Codex CLI version: (if known)
  • Install method: (DMG / Homebrew / Cargo?)

Describe the bug

After upgrading to v0.2.8 (also reproducible on v0.2.7), Codex Switcher fails to open — the UI does not display the account list, and an error is shown immediately on launch:

Failed to load accounts — Failed to parse accounts file: /Users/<user>/.codex-switcher/accounts.json

The accounts.json file still exists on disk and previously held valid data (the app was working correctly on earlier versions). Reinstalling v0.2.6 does not resolve the issue either.

Steps to reproduce

  1. Install Codex Switcher and log in with at least one ChatGPT OAuth account.
  2. Use the app normally for a few sessions (refresh / warm-up).
  3. Quit the app and relaunch — the parse error appears immediately in the main window.

Expected behavior

The app should open normally, load the account list from accounts.json, and display the management UI.

Actual behavior

The app cannot load any accounts. The UI shows a JSON parse error and there is no way to access the saved accounts without manually editing the file. From a user's perspective, the app "does not open".

Root cause (suspected)

In src-tauri/src/auth/storage.rs, load_accounts() uses serde_json::from_str(&content). Any reason that causes accounts.json to no longer match the AccountsStore schema (a truncated write, or an auth_mode / auth_data variant that does not match the enum) will make the function return Err and the UI will fail to load:

let store: AccountsStore = serde_json::from_str(&content)
    .with_context(|| format!("Failed to parse accounts file: {}", path.display()))?;

The two most likely root causes (also covered in #100 and #58):

  1. File is truncated on write — multiple users have reported the tail of the file is left in a half-written state, e.g. a leftover fragment such as }ount_ids": [] (see comment from Worive in Failed to load accounts Failed to parse accounts file: /Users/jakobgross/.codex-switcher/accounts.json #100). This points to a non-atomic save path where a crash / power loss / quit mid-write leaves the file malformed.
  2. Legacy AuthMode spelling mismatch — AuthMode::ChatGPT with #[serde(rename_all = "snake_case")] requires the literal chat_gpt in the JSON. Account files written by older versions that use chatgpt, chat_g_pt, or chat_g_p_t will fail to deserialize, even though the JSON itself is well-formed.

Temporary workaround

  1. Back up the file: cp ~/.codex-switcher/accounts.json ~/.codex-switcher/accounts.json.bak
  2. Validate the JSON: cat ~/.codex-switcher/accounts.json | python3 -m json.tool — if it errors, the file is truncated.
  3. If the file is malformed, either hand-edit the garbage at the end, or delete it and log in again from scratch (this will lose all saved accounts).
  4. If the JSON parses but the app still complains, the file likely uses an old AuthMode spelling — replace every chatgpt (and its variants) with chat_gpt, in both the top-level auth_mode field and the nested auth_data.type field.

Suggested fix

  • Atomic writes in save_accounts(): write to accounts.json.tmp first, then rename it over the real file, so a crash mid-write cannot leave a truncated accounts.json behind.
  • Backward-compatible deserialization for AuthMode / AuthData: accept aliases chatgpt, chat_gpt, chat_g_pt, and chat_g_p_t while still serializing in the canonical form (as already proposed in v0.2.2 fails to load legacy accounts.json ChatGPT auth type spelling #58). Add regression tests for AccountsStore, AuthMode, and AuthData deserialization.
  • Soft-fail on parse error: instead of bubbling the error up to the UI, rename the broken file to accounts.json.broken-<timestamp> and boot with AccountsStore::default(). The user can then log in again instead of being stuck with an app that "cannot open".

Related issues


Maintenance triage — 2026-09-30

Continue in: #100.

This report describes the same account-file corruption tracked in #100 and the separate legacy ChatGPT enum-spelling compatibility defect tracked in #58. Consolidating the two root causes into those existing issues; both remain open. #182 addresses future atomic writes but does not repair damaged JSON or add the legacy enum aliases.

Activity

  1. added
    bugSomething isn't working
    duplicateThis issue or pull request already exists
    area:storageAccount/settings persistence, data recovery, imports and backups.
    priority:P1Address first: auth, data integrity, security, startup or release validation.
    on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:storageAccount/settings persistence, data recovery, imports and backups.bugSomething isn't workingduplicateThis issue or pull request already existspriority:P1Address first: auth, data integrity, security, startup or release validation.

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions