GPT-5 finding
Session save uses a single fixed temp filename causing race/lost-update risk across concurrent saves
- src/session.ts:14-15
- src/session.ts:46-49
All writers use the same temp path (latest.tmp). Concurrent calls (from multiple processes or threads) can overwrite each other's temp file and final rename, leading to lost updates or leaving a stray latest.tmp if a crash occurs between write and rename.
Recommendation
Use a unique tmp filename per save (e.g., latest.<pid>.<timestamp>.<random>.tmp) and then rename to latest.json. Optionally fsync the directory after rename for stronger durability and clean up any stale tmp files on startup.