fix(mcp): a close stops only the work on its own book; each book has its own turn

Closing or opening book A must never block, fail, stop or delay anything on
book B. Two things were server-wide: the stop a close raised for the admin
jobs (a close of one book stopped another's restore, create and adopt, and
refused opens of others while it ran), and the one lifecycle lock a close
held for its whole length (an open of another book waited out the close's
last backup).

Each book now has its own turn and its own stop (Books::lives). A close of X
stops the work on X only: an open of X and a restore that replaces X. A
create, an adoption and a restore that replaces nothing make a new book, which
no close of a book is the close of; only the server's own close stops them
(and every other job: stop_every_job). The stop is lowered while the book's
turn is still held, so an open queued behind a close is not told it was
stopped by a close that is over. The server's close no longer takes a lock:
every admin job has ended by then. "One at a time" remains for making books
(run/books.lock, ledger_store::root INVARIANT 5), where a queued job leaves at
once when stopped.

INVARIANT 10 now names the calls that are neither stoppable nor bounded by one
request, with their worst cases, so the close's bound as written is true:
books.import_bank_csv (a full import of the largest file accepted), a report
over the whole book, and a package after its decision is journaled (one build
over the whole book).

Tests: a restore over beta, a create and an adoption in flight while acme is
closed and opened over and over, its close slow, with another book opened and
closed during each close (mutations: a server-wide stop; one global lock);
a close stops the restore and open of its own book, and the server's close
stops every job; the hammer also makes books and cycles a third book; a close
before a package's decision journals nothing and one after it does not stop it
(mutations: no look before; a stoppable build after). Spec blocks,
docs/mcp-interface.md and docs/testing.md updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-20 19:57:16 -07:00
1 parent d05d1ed7ec
commit a66b56c5c7
4 files changed
+935 -236

No files matched your search

+34 -13
View File
@@ -398,20 +398,41 @@ didn't open, with why). Protocol version 1: the requests are new, the
a commit it had made stands), `books.verify` (once per journal line and
per stored file; a heal of a drifted database is begun only if no stop
was asked before it, then finishes), `books.export_cpa_package` (once per
stored file), a drill, and a format upgrade not yet at its final look (a
stored file, unless it has journaled a decision, below), a drill, and a
format upgrade not yet at its final look (a
stop is honoured up to that look; one that arrives after it still
upgrades and records success). On the admin socket, restore (and its
preview), adopt (and its preview), create and open are stopped by a close
of any book, and by the server's own: before their point of no return
(the rename that puts the books in place; create's making of its folder)
they remove what they wrote and leave the root byte for byte as it was
and answer that they were stopped because the books are closing; after
it they finish (a rename or two and two directory syncs), and the book
is then opened unless that, too, is stopped (it is left closed, and the
answer says so). Every other call does work bounded by the size of one
request and is waited for; `books.import_bank_csv` is the one known
exception (a file of up to 25 MiB is rehearsed whole and then written row
by row, each row journaled: long for a very large file, and not stopped);
upgrades and records success). A stop is scoped to what it concerns. On
the admin socket, a close of the book X stops the work on X only: an open
of X, and a restore that replaces X. A create, an adoption and a restore
that replaces nothing make a new book, which no close of a book is the
close of: a close of one book never stops, fails, refuses or delays them,
nor an open or a close of another book (each book has its own turn; books
are made, adopted and restored one at a time, and a job queued for its
turn leaves at once when asked to stop). The server's own close stops
every job. A stopped job, before its point of no return (the rename that
puts the books in place; create's making of its folder), removes what it
wrote (an adoption also removes the lock file it made in the source
folder, so the original is left as it was) and leaves the root byte for
byte as it was, and answers that it was stopped because the books are
closing; after it the job finishes (a rename or two and two directory
syncs), and the book is then opened unless that, too, is stopped (it is
left closed, and the answer says so). `books.export_cpa_package` with a
reason to export (without an audit, with open drafts) journals that
decision before it builds, because the package counts it (its README and
every footer carry the journal's event count at the build): a close is
looked for once, immediately before the first decision is journaled, and
a stop then journals nothing; after it the package is made whatever a
close does, so no decision is on record for a package that was never
made (every refusal is decided before any decision is journaled). Every
other call does work bounded by the size of one request and is waited
for. Three are the named exceptions to the close's bound, each waited for
in full if a close meets it: `books.import_bank_csv` (a file of up to
25 MiB is rehearsed whole and then written row by row, each row
journaled; worst case, a full import of the largest file accepted),
a report or export over the whole journal (CPU on the ledger in memory,
not stopped; worst case, one report over the whole book), and a package
after its decision is journaled (worst case, one build over the whole
book). Otherwise
the close is bounded by the sum written in the server's INVARIANT 10
(`local.rs`: running calls, the grace, the answers' grace, the stop of a
hurried step, the last backup's 60 s, the stop of what is left of it);