nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] A corrupt session file is reported as "Session not found" and is silently overwritten by the next autosave

Open addyCooks opened this issue 2 weeks ago • 1 comments

Description

readSession returns null both when the file does not exist and when it cannot be parsed. /resume then says "Session not found", although the session is in the index. If that session is still the live one, autosave treats null as "deleted externally" and writes a new file over the corrupt one, so nothing is kept for recovery.

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, then overwrite <id>.json with {"truncated":.
  2. Call resolveSession(id, workingDirectory, {manager}) (what /resume <id> does).

Expected Behavior

A message that says the session file is unreadable (and where it is). The corrupt file is moved aside (for example to <id>.json.corrupt) before anything overwrites it.

Actual Behavior

Session not found: afc1aef0-64f7-4a91-a858-2594ccc1e2d0

although listSessions() still lists that id.

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-410 (readSession): return a distinct result for a parse failure (or throw a typed error) instead of null.
  • source/session/resolve-session.ts (the loadSession branch near the end): say "Session file is unreadable" when the index has the id. source/hooks/useAppHandlers.tsx:688 shows a plain "Session not found" too.
  • source/hooks/useSessionAutosave.ts:260: rename the corrupt file to a .corrupt backup before calling createSession.
  • Add tests for the message and the backup.

addyCooks avatar Nov 16 '26 09:11 addyCooks

can you assign this to me @addyCooks

Vishesh-Verma-07 avatar Nov 17 '26 07:11 Vishesh-Verma-07