Repository navigation
[Bug] Codex Switcher v0.2.8 fails to open on macOS — "Failed to parse accounts file" on startup #113
Description
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
- Install Codex Switcher and log in with at least one ChatGPT OAuth account.
- Use the app normally for a few sessions (refresh / warm-up).
- 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):
- 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. - Legacy
AuthModespelling mismatch —AuthMode::ChatGPTwith#[serde(rename_all = "snake_case")]requires the literalchat_gptin the JSON. Account files written by older versions that usechatgpt,chat_g_pt, orchat_g_p_twill fail to deserialize, even though the JSON itself is well-formed.
Temporary workaround
- Back up the file:
cp ~/.codex-switcher/accounts.json ~/.codex-switcher/accounts.json.bak - Validate the JSON:
cat ~/.codex-switcher/accounts.json | python3 -m json.tool— if it errors, the file is truncated. - 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).
- If the JSON parses but the app still complains, the file likely uses an old
AuthModespelling — replace everychatgpt(and its variants) withchat_gpt, in both the top-levelauth_modefield and the nestedauth_data.typefield.
Suggested fix
- Atomic writes in
save_accounts(): write toaccounts.json.tmpfirst, thenrenameit over the real file, so a crash mid-write cannot leave a truncatedaccounts.jsonbehind. - Backward-compatible deserialization for
AuthMode/AuthData: accept aliaseschatgpt,chat_gpt,chat_g_pt, andchat_g_p_twhile 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 forAccountsStore,AuthMode, andAuthDatadeserialization. - 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 withAccountsStore::default(). The user can then log in again instead of being stuck with an app that "cannot open".
Related issues
- Failed to load accounts Failed to parse accounts file: /Users/jakobgross/.codex-switcher/accounts.json #100 — Failed to parse accounts file (same error on older versions)
- v0.2.2 fails to load legacy accounts.json ChatGPT auth type spelling #58 —
chat_gptspelling mismatch after upgrading to v0.2.2
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