Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

@ammar-agent ammar-agent commented Dec 1, 2025

Non-atomic fs.writeFile can leave truncated/malformed JSON if the app crashes mid-write. This causes 'Unexpected end of JSON input' errors when reading partial.json on the next stream start, leading to amnesia (messages being lost).

Use write-file-atomic which writes to a temp file then renames, ensuring readers always see either the old complete file or the new complete file, never a partial write.

Fixed in:

  • partialService.ts (partial.json)
  • historyService.ts (chat.jsonl rewrites)
  • sessionFile.ts (generic session file utility)

Fixes #803


Generated with mux

Non-atomic fs.writeFile can leave truncated/malformed JSON if the app
crashes mid-write. This causes 'Unexpected end of JSON input' errors
when reading partial.json on the next stream start, leading to amnesia
(messages being lost).

Use write-file-atomic which writes to a temp file then renames,
ensuring readers always see either the old complete file or the new
complete file, never a partial write.

Fixed in:
- partialService.ts (partial.json)
- historyService.ts (chat.jsonl rewrites)
- sessionFile.ts (generic session file utility)

Fixes #803
@ammar-agent ammar-agent force-pushed the fix-malformed-json-partial branch from d938038 to f9846c0 Compare December 1, 2025 18:26
@ammario ammario merged commit 6de7ec2 into main Dec 1, 2025
18 of 19 checks passed
@ammario ammario deleted the fix-malformed-json-partial branch December 1, 2025 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Occasional mild amnesia on queued chat messages

2 participants