Repository navigation
fix(storage): make state writes atomic and single-writer - #182
Open
squarepots wants to merge 23 commits into
Open
squarepots wants to merge 23 commits into
squarepots wants to merge 23 commits into
Conversation
squarepots
force-pushed
the
fix/durable-state-mutations
branch
from
September 21, 2026 19:04
3014bd7 to
2fadfc7
Compare
This was referenced Sep 21, 2026
This was referenced Sep 30, 2026
This was referenced Sep 30, 2026
[Bug] Codex Switcher v0.2.8 fails to open on macOS — "Failed to parse accounts file" on startup
#113
Closed
Bl0ck154
added a commit
to Bl0ck154/codex-switcher
that referenced
this pull request
Oct 27, 2026
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.
本 PR 同时解决持久状态的两类故障:文件写入中断造成的损坏,以及多个进程并发 read-modify-write 造成的更新丢失。
账号 mutation 统一通过
mutate_accounts,设置 mutation 统一通过mutate_app_settings,并分别使用跨进程锁串行化。accounts、settings 和 Codexauth.json都通过同目录临时文件写入、sync_all和同文件系统原子替换保存;Windows 使用 replace/write-through,Unix secret 临时文件从创建时即为0600。现有文件路径、JSON schema 和 active-account 行为保持不变。新增测试覆盖锁竞争、成功替换、替换前失败时保留旧文件,以及 Unix 限制权限。
验证
rustfmt --edition 2021 --check src-tauri/src/auth/storage.rscargo check --manifest-path src-tauri/Cargo.toml --lockedcargo test --manifest-path src-tauri/Cargo.toml --locked:53 项通过cargo fmt --manifest-path src-tauri/Cargo.toml --all -- --check仅报告现有src-tauri/src/tray.rs格式漂移;本 PR 变更文件通过 targeted rustfmtCloses #159
This PR addresses both durable-state failure modes: corruption from interrupted writes and lost updates when several processes perform read-modify-write operations concurrently.
Account mutations now go through
mutate_accounts, settings mutations go throughmutate_app_settings, and each path is serialized with a cross-process lock. Accounts, settings, and Codexauth.jsonare written to same-directory temporary files, synchronized withsync_all, and atomically replaced on the same filesystem. Windows uses replace/write-through behavior, while Unix secret temporaries have0600permissions from creation. Existing paths, JSON schemas, and active-account behavior remain unchanged.New tests cover lock contention, successful replacement, preservation of the old file when replacement fails, and restrictive Unix permissions.
Validation
rustfmt --edition 2021 --check src-tauri/src/auth/storage.rscargo check --manifest-path src-tauri/Cargo.toml --lockedcargo test --manifest-path src-tauri/Cargo.toml --locked: 53 passedcargo fmt --manifest-path src-tauri/Cargo.toml --all -- --checkreports only pre-existing formatting drift insrc-tauri/src/tray.rs; the changed file passes targeted rustfmtCloses #159
Restores #169 after the source fork was accidentally deleted.
Maintenance triage — 2026-09-30
Prevents future interrupted/concurrent writes; does not repair existing corrupted JSON (#100) or add legacy ChatGPT enum aliases (#58). Preserve both separate acceptance cases.