fix(store): one writer at a time; a second is refused, not allowed to corrupt the books
check / check (push) Canceled after 0s

Max-testing pass on ledger-store, found during the survey: nothing
stopped two processes from opening the same books for writing. Two
agent sessions (two MCP servers) on one books dir would each extend the
hash chain from the same last line; one write from each broke the
journal ("seq gap: expected 3, found 2") and the books would not open.

The store now holds an exclusive lock on books-data/wanderbooks.lock
(std's File::try_lock, no new dependency) from before it reads the
journal until it is dropped; the OS releases it if the process dies. A
second writer gets StoreError::Locked saying another process has the
books open. The viewer reads through Snapshot and never takes the lock.
The lock file is git-ignored in the books scaffold.

Regression: a_second_writer_is_refused_while_the_first_has_the_books
(refused while open, allowed after close, books whole).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GWVo7x3UHw5kwCUaWxiejX
This commit is contained in:
swaitsandClaude Opus 5.5 committed 2026-10-13 16:05:59 -06:00
1 parent c539004d1a
commit 8c8ba19471
5 files changed
+78 -1

No files matched your search

+6
View File
@@ -65,6 +65,12 @@ pub enum StoreError {
#[error("store already exists at {0}")]
AlreadyExists(String),
/// Another process has these books open for writing. One writer at a
/// time: two would each extend the hash chain from the same place and
/// break it (found by the max-testing pass, 2026-10-13).
#[error("{0}")]
Locked(String),
/// `open` called where no store exists.
#[error("store not found at {0}")]
NotFound(String),