nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] Two processes saving the same session overwrite each other's messages without any error

Open addyCooks opened this issue 2 weeks ago • 2 comments

Description

Reading a session, adding messages and saving it is not protected against another process doing the same. The last writer wins and the other process's messages are lost silently. This happens when the same session is open in two terminals, or in a terminal and the VS Code extension. #1706 fixed the index file, not the session file.

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. Create two SessionManager instances a and b on one directory and create a session with the message A1.
  2. Both read the session. a appends A-reply and saves. b appends B-reply and saves.
  3. Read the session again.

Expected Behavior

Either b's save is rejected (a newer version exists) or the messages are merged. A-reply is not lost.

Actual Behavior

A-reply is gone and no error is shown.

Logs/Screenshots

final messages: ["A1", "B-reply"]

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/session/session-manager.ts:399 (readSession), :413 (loadSession) and the save path: keep a revision number (or the file's modified time) in the session and reject a save if it changed on disk since the read, then reload and merge.
  • source/hooks/useSessionAutosave.ts:240 and :259 (readSession then saveSession) should handle the "changed on disk" result.

Related: #1706 (index file only).

addyCooks avatar Nov 14 '26 06:11 addyCooks

I'd like to take this one — I have the two-SessionManager repro and a fix direction ready, and I've just opened #2207 for #2195 in the same save/index path;

Ember452 avatar Nov 14 '26 07:11 Ember452

is this still open?

acalexanderac avatar Nov 24 '26 17:11 acalexanderac