Repository navigation
fix(login): atomically replace file-backed credentials - #1
Open
metacircu1ar wants to merge 1 commit into
Open
metacircu1ar wants to merge 1 commit into
metacircu1ar wants to merge 1 commit into
Conversation
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.
When two Codex processes share file-backed credentials, a save currently truncates
auth.jsonbefore writing its replacement. A process reading during that write can receive empty, partial, or mixed JSON and fail to load credentials. This race is independent of refresh-token reuse grace periods.Reproduced failure
The regression test opens the old credentials file and reads its first half, saves a shorter replacement, then finishes the original read. On upstream base
8f21b7fffbefe77529325fc86c95289371841c6c, it fails deterministically withEOF while parsing a string. It uses temporary directories and synthetic API keys; no real login or token refresh is involved.Fix
codex_utils_path::write_atomicallyto write a temporary file in the destination directory and atomically replace the published file. Existing readers retain the old complete file; new readers see a complete replacement.OpenOptionsinsidetempfile::Builder::make_inand publish withstd::fs::rename. Rust 1.95 can use POSIX rename semantics on Windows when classic replacement is denied, supporting existing open readers.tempfile::persistuses classicMoveFileExWwithout this fallback. Standard creation also avoids retaining the Windows temporary-file attribute. Cleanup stays enabled until publication succeeds.auth.jsonsymlink chains before replacement, including relative links and missing targets. Reject unresolved/cyclic chains instead of overwriting the symlink.0600, including when replacing an existing permissive file).Validation
Tested on macOS arm64 with Rust 1.95.0, using release builds throughout. All post-fix validation applies to this patch atop
8f21b7fffbefe77529325fc86c95289371841c6c; a merge with later fork-main changes has not been tested.cargo +1.95.0 test --release --locked -p codex-login --lib file_storage_save_preserves_an_in_progress_read -- --nocapturefails with the expected JSON parse error.cargo +1.95.0 test --release --locked -p codex-login -p codex-utils-pathpasses all 206 login unit tests, 42 login integration tests, and 8 path-utility tests, including the new regressions.cargo +1.95.0 clippy --release --locked -p codex-login -p codex-utils-path --all-targets -- -D warningspasses.cargo +1.95.0 fmt -p codex-login -p codex-utils-path --checkandgit diff --checkpass.cargo +1.95.0 check --release --locked -p codex-utils-path --all-targets --target x86_64-pc-windows-gnupasses. This checks Windows compilation of the helper and tests; it does not execute them on Windows.Scope
This fixes credential-file publication, not cross-process token refresh serialization or stale-but-valid credentials overwriting newer credentials. It adds no power-loss durability guarantee. Atomic replacement creates a new file: hard-link aliases and custom inode metadata/ACLs are not preserved. On Windows, replacement may still fail when permissions, handle sharing, or filesystem support disallow it; there is no delete-and-recreate fallback. Windows execution has not been validated locally.
This pull request is intentionally opened against the author's fork. Upstream currently does not accept external pull requests.