[Bug] Two processes saving the same session overwrite each other's messages without any error
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
- Create two
SessionManagerinstancesaandbon one directory and create a session with the messageA1. - Both read the session.
aappendsA-replyand saves.bappendsB-replyand saves. - 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:240and:259(readSessionthensaveSession) should handle the "changed on disk" result.
Related: #1706 (index file only).
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;
is this still open?