nanocoder
nanocoder copied to clipboard
[Bug] A corrupt session file is reported as "Session not found" and is silently overwritten by the next autosave
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
- Create a session, then overwrite
<id>.jsonwith{"truncated":. - 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 ofnull.source/session/resolve-session.ts(theloadSessionbranch near the end): say "Session file is unreadable" when the index has the id.source/hooks/useAppHandlers.tsx:688shows a plain "Session not found" too.source/hooks/useSessionAutosave.ts:260: rename the corrupt file to a.corruptbackup before callingcreateSession.- Add tests for the message and the backup.
can you assign this to me @addyCooks