[Bug] Autosave re-creates a session without its pinned flag and with a new createdAt when the session file was unreadable
Description
Autosave reads the session before saving. If the file cannot be read (for example it is truncated), readSession returns null, autosave assumes the session was deleted and calls createSession with the same id. createSession builds a new record, so pinned is lost and createdAt is reset.
Environment
- OS: Windows 11 Home 10.0.26300
- Node version: v22.22.3
- Nanocoder version: 1.32.0 (built from main at 5df35b3a)
- Provider: Not provider-specific
- Model: Not model-specific
Steps to Reproduce
- Create a session with
SessionManager.createSession, thensetPinned(id, true). - Overwrite
<id>.jsonwith{"truncated":. - Call
createSession({id, ...})with the same data, as autosave does. - List the sessions.
Expected Behavior
The session is still pinned and keeps its original createdAt.
Actual Behavior
pinned: true -> undefined
createdAt: 2026-11-16T07:59:22.051Z -> 2026-11-16T07:59:22.098Z
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:156-168(createSession): when a session with the same id is already in the index, copypinned,titleGeneratedandcreatedAtfrom the index entry.source/hooks/useSessionAutosave.ts:260-270: only take the "deleted externally" branch when the index no longer has the id.- Add a test for the sequence above.
Related: the next issue (corrupt session reported as "not found"), which has the same cause.
Hi @addyCooks, I'd like to take this one. I checked main: createSession builds a fresh session without pinned or titleGenerated and with a new createdAt, and saveSession then replaces the index entry with it, so the pin is lost. I'll follow your suggestion: when the index already has the id, createSession keeps pinned, titleGenerated and createdAt, and autosave only takes the "deleted externally" path when the id is gone from the index. I'll add a test for the truncated-file sequence and leave the related "not found" issue for its own PR.