[Bug] atomicWriteFile fails with EPERM on Windows when two writers rename onto the same file
Description
atomicWriteFile writes a temp file and renames it over the target. On Windows, rename onto a file that another rename or read is touching fails with EPERM, and the helper does not retry. PR #2207 added a retry to the session index only; every other user of this helper (artifacts, memory, stats, timeline, lockfile) is still affected.
Environment
- OS: Windows 11 Home 10.0.26300
- Node version: v22.22.3
- Nanocoder version: 1.32.0 (built from main at eb7dee57)
- Provider: Not provider-specific
- Model: Not model-specific
Steps to Reproduce
- In a loop of 20 rounds, call
atomicWriteFile(target, text)16 times at once for the sametarget(Promise.allSettled). - Count the rejected writes.
Expected Behavior
All 320 writes succeed (the last one wins).
Actual Behavior
79 of 320 writes fail.
Logs/Screenshots
EPERM: 79 (241 writes succeeded)
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs with the latest version of nanocoder (main)
Suggested fix:
source/utils/fs/atomic-write.ts:56-72(atomicWriteFile, and the sync variant above it): retryrenamea few times with a short delay (for example 10, 20, 40 ms) when the code isEPERM,EBUSYorEACCES, on Windows only. Thensession-manager.tscan drop its own copy of the retry.- Add a test with concurrent writers like the steps above.
Related: #2195 / PR #2207 (session index only).
I'd like to pick this up. I reproduced it on Windows 11 (16 concurrent writers fail with EPERM in the first round) and have a fix that retries the rename on EPERM/EBUSY/EACCES with a short backoff (10–160 ms, then rethrows), like the session index retry from #2207, plus specs. Could you assign me? I'll open the PR then.
just assigned @seragAhmed, go ahead