Codex Desktop on Windows can leave git diff --numstat readers causing user-mapped section write failures during edits
What version of the Codex App are you using (From “About Codex” dialog)?
26.519
What subscription do you have?
plus
What platform is your computer?
windows 10
What issue are you seeing?
On Windows, Codex Desktop intermittently fails to rewrite files in a Git worktree with:
The requested operation cannot be performed on a file with a user-mapped section open.
In my case this was caused by Codex Desktop background Git diff processes, not by my application code.
Codex was spawning long-running commands like:
git diff --no-ext-diff --no-textconv --color=never ... --find-renames --numstat -z
Observed process chain:
Codex.exe
-> Python313\Scripts\git.exe
-> C:\Program Files\Git\cmd\git.exe
-> mingw64\bin\git.exe
While these Codex-spawned git diff --numstat --find-renames processes were alive, normal source rewrites failed. PowerToys File Locksmith showed no normal file holder, and exclusive-open diagnostics could report exclusive_open=ok.
Killing only those Codex-spawned git diff processes made the same file rewrite succeed immediately.
The issue was amplified because Codex Desktop's Environment / Changes counter was showing about 1.5 million changed lines due to a stale base/ref, while the actual working diff shown elsewhere was small.
What steps can reproduce the bug?
- Open a Git worktree in Codex Desktop on Windows.
- Let Codex Desktop compute the Environment / Changes counter.
- Get into a state where the Environment counter is using a stale or unexpectedly large base/ref. In my case it showed about 1.5 million changed lines, even though the actual working diff was small.
- Observe Codex-spawned background Git processes like:
git diff --no-ext-diff --no-textconv --color=never ... --find-renames --numstat -z
- While those git diff --numstat --find-renames processes are still running, ask the agent to edit or rewrite source files in the worktree.
- The write can fail with:
The requested operation cannot be performed on a file with a user-mapped section open.
- Kill only the Codex-spawned git diff --numstat --find-renames processes.
- Retry the same file edit.
- The rewrite succeeds immediately.
What is the expected behavior?
Codex Desktop should not allow background Git diff readers to block agent file edits on Windows.
Expected behavior:
- Background git diff --numstat scans should be cancelled, sequenced, or avoided before applying patches / rewriting files.
- Codex should avoid holding long-lived mapped reads over files that the agent may rewrite.
- The Environment / Changes counter should not repeatedly compute a stale huge branch/base diff when the actual working diff is small.
- Codex should expose which base/ref the Environment / Changes counter is using, so stale-base problems are diagnosable.
Additional information
This reproduced in Codex Desktop on Windows.
The failing writes included source files such as:
src-tauri/src/lib.rs
src-tauri/src/game_studio/kanban_adapter.rs
Important observations:
- This was not caused by my application code.
- This was not a typical file lock visible in PowerToys File Locksmith.
- File Locksmith showed no normal process holding the file.
- An exclusive-open probe could still report exclusive_open=ok.
- The failure reproduced specifically while Codex background git diff --numstat --find-renames processes were running.
- Killing those diff processes cleared the immediate write failure.
- Fixing the stale Git base/ref so the Environment / Changes counter collapsed also made the issue stop happening during normal work.
The Environment / Changes counter showed about 1.5 million changed lines, while the actual working diff was small. That caused repeated heavy background diff scans and made the Windows mapped-section write failure much more likely.
Suggested mitigation:
Codex Desktop should cancel or sequence background git diff --numstat scans before applying patches on Windows, especially when using --numstat -z --find-renames.
It would also help if Codex showed the base/ref used by the Environment / Changes counter.
6 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
This is related to #23809, but I do not think it is an exact duplicate.
#23809 describes the incorrect Git panel comparison base.
This issue describes the downstream Windows failure mode caused by that behavior: Codex-spawned background
git diff --numstat --find-renamesprocesses can keep mapped reads alive long enough for normal agent file rewrites to fail with:The requested operation cannot be performed on a file with a user-mapped section open.
So even if the stale base/ref problem is fixed, Codex Desktop should also cancel or sequence background Git diff readers before applying patches on Windows.
The lingering
git diff --numstatreaders here are part of the same Git-backed desktop integration surface that this workaround disables.I published a single-file Windows launcher for the original Microsoft Store/MSIX Codex app:
It starts Codex with a process-scoped
GIT_DIR=NUL. On my machine, the stable trace changed from 247 newgit.exeand 137 newtaskkill.exeprocesses per 10 seconds to 0 and 0 over 15 seconds; WMI Provider Host fell from about 6.6% to 0.9%.Usage: fully exit Codex from the Windows system tray, then run the script.
This is an unofficial workaround, not an upstream fix. It deliberately disables or limits Review, Changes, branch detection, commit, and other Git-backed Codex features. It does not patch Codex, modify repositories or Git configuration, write system environment variables, require elevation, terminate processes, or remove chat history. Launching Codex normally restores Git integration.
Additional reproduction: stale Desktop review base blocks external IDE saves
I am seeing the same Windows mapped-section failure, with an additional trigger and user-visible impact: after a branch change, Codex Desktop keeps using an old review base and the resulting background Git work intermittently prevents JetBrains Rider and VS Code from saving source files.
Environment
26200.887526.715.7063.0review-summaryabort pattern remained present locally on26.715.8383.0,26.715.9079.0, and26.715.9868.026.715.10079.0; it is too new for me to claim whether the issue is fixed thereRepository names, branch names, local paths, usernames, and private commit SHAs are redacted below.
Reproduction sequence
review_modelcontinues comparing the worktree against the old fixed SHA from branch A instead of resolving the comparison base for branch B.HEAD, while the correct integration-branch comparison was only 3 commits.``
text
``git diff ... <stale-base-sha> --find-renames --raw --numstat -z
``
text
``Cannot save <redacted-source-file>
Unable to open the file for writing.
The underlying Windows error recorded by Rider was:
``
text
``ERROR_USER_MAPPED_FILE (1224)
The requested operation cannot be performed on a file with a user-mapped section open.
The failure persisted after disabling Copilot, uninstalling the previously suspected endpoint/XDR product, rebooting Windows, and reproducing again. File attributes and ACLs were normal.
Desktop log evidence
The Desktop logs repeatedly contained:
Recent local counts:
| Desktop build | review-summary rows | abort/failure rows |
|---|---:|---:|
| 26.715.8383.0 | 160 | 160 |
| 26.715.9079.0 | 53 | 54 |
| 26.715.9868.0 | 279 | 283 |
Rider logs and Procmon confirmed the mapped-file failure and Git file-mapping activity at save time. Separately, the Codex Desktop logs confirmed the stale-base
review-summaryloop. The combined evidence is consistent with the oversized Codex diff substantially extending the Windows file-mapping conflict window. I am not claiming that every failed save was independently tied to one exact Codex PID in the sanitized capture.Expected behavior
review-summaryrefreshes.Related issues
review-summarysnapshotsThis reproduction connects those stale-base behaviors to the external-editor write failure tracked here: Rider and VS Code can become unable to save ordinary source files while Codex Desktop remains open.
Additional confirmed reproduction for openai/codex#24681.
Environment:
FairyGUI intermittently fails File.WriteAllText with:
Win32 IO returned 1224
The requested operation cannot be performed on a file with a user-mapped section open.
Process Monitor confirmed the source:
ChatGPT.exe
-> C:\Program Files\Git\cmd\git.exe
-> C:\Program Files\Git\mingw64\bin\git.exe
-> git diff ... --find-renames --raw --numstat -z
-> CreateFileMapping(PAGE_READONLY)
During one 26-second capture, Codex started 10 Git diff scans.
Confirmed collision timeline:
All mapped Git processes had ChatGPT.exe as their ancestor. The issue also
reproduced with Fork closed and does not require an extremely large diff.
Please debounce/cancel background diff scans, avoid mapped reads that block
external safe-write/truncate operations on Windows, or provide a workspace
setting to disable background Changes/review refresh.
Additional confirmed reproduction on Codex Desktop 26.803.10989.0 (Unity / HybridCLR)
This issue still reproduces on a current Windows Codex Desktop build.
Environment
26.803.10989.02.52.0.windows.12021.3.57f2GenericReferenceWriter.Write->System.IO.File.WriteAllTextAssets/HybridCLRGenerate/AOTGenericReferences.csFailure
Windows error 1224 corresponds to:
Fresh trace evidence
A fresh 12-second ETW capture immediately after the failure observed
git.exemapping that exact generated C# file three times. The individual mapping intervals lasted approximately 0.68 to 1.25 seconds.The outer Git process was spawned by Codex Desktop's
ChatGPT.exe, using a command shaped like:The target file was tracked and modified. The worktree had approximately 130 tracked changes, so this reproduction did not require the extremely large million-line diff described in the original report.
An earlier capture on the same machine established the stronger timing correlation: the write failure occurred inside Git file-mapping intervals. An isolated A/B test also reproduced error 1224 only when a concurrent Git reader was active; the same writes succeeded 500/500 without it.
This was first confirmed on this machine with Codex Desktop
26.715.9757.0and remains reproducible on26.803.10989.0.Requested mitigation
In addition to coalescing scans, please consider:
No raw ETW trace or private repository path is attached; the values above are sanitized observations.