nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] A truncated prompt-history file is wiped on the next prompt

Open Dhirenderchoudhary opened this issue 1 month ago • 2 comments

Description

loadHistory in source/prompt-history.ts treats any read or parse error the same as a missing file and sets this.history = []. saveHistory writes that array with fs.writeFile, which truncates the file in place. A crash during an earlier save leaves a file that starts with ---JSON_FORMAT--- and then broken JSON.

Steps to Reproduce

  1. Take .nano-coder-history, keep the JSON marker, and cut the JSON off mid-value.
  2. Start nanocoder and submit one prompt.

Expected Behavior

The bad file is left alone, or the previous entries are kept.

Actual Behavior

The parse throws, history becomes empty, and the next save replaces the file with that empty history plus the new prompt.

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently

Dhirenderchoudhary avatar Oct 07 '26 22:10 Dhirenderchoudhary

@addyCooks should i take this one?

Vishesh-Verma-07 avatar Oct 16 '26 14:10 Vishesh-Verma-07

Go ahead @Vishesh-Verma-07 !

addyCooks avatar Oct 16 '26 16:10 addyCooks