GPT-5 finding
Read-only state access rewrites the state file on every read (unnecessary disk I/O)
- src/state/db.ts:147-150
- src/state/db.ts:128-141
readLocked uses withLockedState with a no-op mutator that returns the same state, but withLockedState always calls writeUnsafe. This causes a full JSON rewrite to disk for getSession/getIdempotent calls that should be read-only, updating mtime and incurring unnecessary I/O under lock.
Recommendation
- Introduce a read-only code path that acquires/releases the lock without writing (e.g., a withReadOnlyLock that just returns readUnsafe(path)). - Alternatively, change withLockedState to only call writeUnsafe when state has actually changed (e.g., pass a flag from mutator or deep-equal compare). Update readLocked to use the read-only path.