nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] Session save fails with EPERM on Windows when another process is reading sessions.json

Open addyCooks opened this issue 2 weeks ago • 2 comments

Description

On Windows, saving a session throws EPERM: operation not permitted, rename ... sessions.json.<id>.tmp if another process is reading sessions.json at that moment. The session file is written but the index update fails, so the session is missing from /resume until the next start. This is a follow-up to #1706 / PR #1732: the cross-process lock covers writers but not readers.

Environment

  • OS: Windows 11 Home 10.0.26300
  • Node version: v22.22.3
  • Nanocoder version: 1.32.0 (built from main at f92cce9c)
  • Provider: Not provider-specific
  • Model: Not model-specific

Steps to Reproduce

  1. Write a worker script using SessionManager on one shared directory that loops createSession (writer) or listSessions (reader).
  2. Start 4 writers (40 saves each) and 1 reader (400 listSessions calls) at the same time.
  3. Count errors, session files and index entries.

Expected Behavior

No errors. The index lists every session file.

Actual Behavior

Several saves throw EPERM, and the index misses sessions.

Logs/Screenshots

ERR w EPERM: operation not permitted, rename 'C:\...\sessions.json.<uuid>.tmp'   (5 in one run, 48 in another)
session files: 121, index entries: 100

With 4 writers and no reader: 0 errors, 100 files, 100 index entries. After a restart (initialize() then listSessions()) all 121 sessions show again.

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently (intermittent under load)
  • [x] This issue occurs with the latest version of nanocoder (main)

Suggested fix:

  • source/session/session-manager.ts:55-63 (atomicWriteFile): retry the rename a few times with a short delay when it fails with EPERM, EBUSY or EACCES (Windows only).
  • Optionally read the index under the same lock (listSessions, line 385).
  • Add a test with a concurrent reader.

Related: #1706 (closed), PR #1732.

addyCooks avatar Nov 14 '26 06:11 addyCooks

@addyCooks May I take this issue? I’m new to the repo and will try to fix it, will update here if I have questions

Ember452 avatar Nov 14 '26 06:11 Ember452

Go ahead @Ember452 !

addyCooks avatar Nov 14 '26 06:11 addyCooks