Windows Desktop intermittently fails atomic global-state rename with EPERM and leaves large temp files
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 125k
- Forks
- 19.4k
- PR merge metrics
- PR metrics pending
Description
Environment
- Codex Desktop:
OpenAI.Codex 26.825.5331.0 - Bundled CLI:
codex-cli 0.151.0-alpha.7.1 - Windows 11 x64 (
10.0.26200)
What happens
Desktop intermittently logs:
[global-state] Failed to persist global state
errorCode=EPERM
errorMessage="EPERM: operation not permitted, rename '...\.codex\..codex-global-state.json.tmp-<id>' -> '...\.codex\.codex-global-state.json'"
This is not a single startup event. A scan of the retained Codex Desktop logs on this machine found:
- 19
Failed to persist global stateevents; - 19/19 are
EPERMfailures on the atomic rename into.codex-global-state.json; - failures span multiple Desktop sessions/build periods from August 15 through August 29;
- the current August 29 Desktop session logged three failures at
12:22:36Z,15:08:03Z, and15:13:17Z.
The destination file is eventually writable and continues to update, so this is intermittent rather than a permanently invalid ACL/path.
Residue
The failed writes also leave abandoned atomic-write files under %USERPROFILE%\.codex.
At the time of inspection there were 8 ..codex-global-state.json.tmp-* files remaining. The newest two were approximately:
- 2.5 MiB
- 1.5 MiB
Several older zero-byte temp files also remained.
The live .codex-global-state.json exists, is owned by the current user, and had been successfully updated after the latest logged failure.
Expected behavior
Atomic global-state persistence should tolerate transient Windows rename contention and should not leave abandoned temp generations behind.
Potentially appropriate behavior would be a bounded retry/backoff for Windows sharing/rename contention plus exact-temp cleanup once a write is no longer recoverable, while preserving fail-closed behavior for genuine permission errors.
Reproduction / diagnostics
This is intermittent, but the retained logs make it measurable:
- Use Codex Desktop normally on Windows over multiple sessions.
- Search Desktop logs for
Failed to persist global state. - Observe
EPERMon rename from..codex-global-state.json.tmp-*to.codex-global-state.json. - Inspect
%USERPROFILE%\.codexfor stale..codex-global-state.json.tmp-*generations.
No model/provider inference is needed to inspect the failure.
Related issue
#32727 concerns a first-launch ENOENT around .codex-global-state.json.tmp. This report is different: Desktop is already initialized and operational, the destination state file exists and is later updated successfully, but atomic replacement intermittently fails with EPERM and leaves residue.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the global-state persistence path that creates ..codex-global-state.json.tmp-* and renames it to .codex-global-state.json; correlate it with the retained Desktop logs and inspect %USERPROFILE%\.codex residue. Done means transient Windows rename contention is bounded and recoverable, unrecoverable writes clean up their exact temp file, and genuine permission failures still fail closed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- desktop, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100