nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] Autosave re-creates a session without its pinned flag and with a new createdAt when the session file was unreadable

Open addyCooks opened this issue 2 weeks ago • 1 comments

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

  1. Create a session with SessionManager.createSession, then setPinned(id, true).
  2. Overwrite <id>.json with {"truncated":.
  3. Call createSession({id, ...}) with the same data, as autosave does.
  4. 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, copy pinned, titleGenerated and createdAt from 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.

addyCooks avatar Nov 16 '26 09:11 addyCooks

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.

MilindDevX avatar Nov 17 '26 09:11 MilindDevX