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);
+9 -3
View File
@@ -4084,7 +4084,8 @@ it checks are already theorems.
a medium effort, no claim, a lowered bar read retroactively),
`a_period_is_attested_on_a_standing_audit`,
`cpa_package_refuses_without_a_counted_audit_unless_a_reason_is_given`
(refused, a reason journaled as a decision, an audit alone not enough, a
(refused, a reason journaled as a decision, and none journaled when an open
draft then refuses the same package, an audit alone not enough, a
year attested below the whole bar not enough, the whole bar, an entry
since, `warn`), `audits_wait_for_the_upgrade` (the fixture over the
wire; the package is not held up by an audit it cannot ask for).
@@ -4310,7 +4311,7 @@ one book never refuses or holds up a call on another.
| `book_open_close::books_left_closed_at_the_start_say_so_and_open_when_asked` | a real server started with `--open BOOK`: the other book is listed closed and says so on the MCP, download, export and upload routes; a name that is no book is 404; opening serves |
| `book_open_close::the_open_option_takes_none_and_refuses_a_book_that_doesnt_exist` | `--open none` leaves every book closed; `--open nobody` exits 2 before opening anything |
| `book_open_close::the_sessions_request_names_each_connection_and_never_its_token` | over the real socket: two tokens, two clients, an agent's report, neither token's text nor SHA-256 in the answer, an ended session gone, a close ends the book's sessions |
| `book_open_close::closing_and_opening_a_book_over_and_over_loses_and_duplicates_nothing` | the hammer: 6 agents on one book (which has a backup target, every timer at 10 ms, and two clients sending bad tokens so refusals are being recorded) and 4 on another make journaled drafts and reads while the first is closed and reopened 12 times; every file of the closed book (journal, access log, every ops log, stored files, the backup's repository) is hashed when the close is answered and compared just before the reopening, every cycle; "the other book progressed" waits on that condition, not a sleep; the logs end as whole chains; both journals are replayed afterwards: every acknowledged draft is in its journal exactly once under the id it was told, no refused call left anything, the closed book's journal and access log never moved between the close answer and the reopening, the other book never refused a call and kept answering while the first was closed, and the books replay with gapless ids |
| `book_open_close::closing_and_opening_a_book_over_and_over_loses_and_duplicates_nothing` | the hammer: 6 agents on one book (which has a backup target, every timer at 10 ms, and two clients sending bad tokens so refusals are being recorded) and 4 on another make journaled drafts and reads while the first is closed and reopened 12 times, and a maker thread creates up to eight new books and closes and opens a third over and over (every one must be answered as asked: a close of the first never stops, refuses or fails an admin job on another book; a probabilistic check, the deterministic one is `closing_and_opening_one_book_never_…`); every file of the closed book (journal, access log, every ops log, stored files, the backup's repository) is hashed when the close is answered and compared just before the reopening, every cycle; "the other book progressed" waits on that condition, not a sleep; the logs end as whole chains; both journals are replayed afterwards: every acknowledged draft is in its journal exactly once under the id it was told, no refused call left anything, the closed book's journal and access log never moved between the close answer and the reopening, the other book never refused a call and kept answering while the first was closed, and the books replay with gapless ids |
| `book_open_close::a_close_doesnt_wait_for_a_clients_open_event_stream` | a client keeps its standalone event stream (a GET) open (known open: its response head has come; no sleep): closing its book still answers at once, not after the grace for answers on their way out (it took 12 s while the stream was counted as an answer, which stalled the bridge in a hand demonstration) |
| `local::tests::a_refusal_being_recorded_keeps_its_place_when_its_client_hangs_up` | a request refused at the door has its access record written by a task that keeps its place inside the book's door: with the only blocking thread held and the request's future dropped, the door stays counted, a close waits, and the record is written before it empties (it was uncounted: the record could land after the close, and after a reopening) |
| `local::tests::handles_from_before_a_close_do_nothing_after_the_book_is_open_again` | the access log, uploads, exports and backups taken before a close, used after the same book is opened again (a late record, a sweep, a grant, an export, a run, a drill, a format upgrade), write nothing: the reopened book's tree is byte for byte what its own upgrade left, and its backup record is a whole chain (fails when the backups' shut flag and record close are removed) |
@@ -4334,8 +4335,13 @@ one book never refuses or holds up a call on another.
| `book_open_close::a_running_call_is_never_cut_when_the_grace_runs_out` | an ordinary call (`books.attach_receipt`, held inside its read of its file, a named pipe) past the grace (body whole) is not cut: it finishes when fed, is answered and recorded `ok`, and then the close is answered (a backup asked for is no longer this call: it is stoppable) |
| `book_open_close::a_close_stops_a_running_backup_call_and_says_so` | `books.back_up_now` held in a stalled `git` (never lifted until the call answers): the close stops it, the call is answered that it was stopped because the books are closing, its access record is `refused: stopped_by_close` with no head, the backup record holds `stopped` and no result of its own for the run, git and all it started are gone, the close's last backup is made and the close answers `closed` |
| `book_open_close::a_close_stops_a_running_verification_and_a_running_package_and_says_so` | `books.verify` and `books.export_cpa_package` held as they begin by `--timer-hold` (`call:...`), which the close releases: each is stopped at its first look, answers it was stopped, is recorded `refused: stopped_by_close`, the journal is unchanged |
| `book_open_close::a_close_stops_a_running_restore_adopt_create_and_open_leaving_the_root_as_it_was` | each admin job held inside a phase (`restore:copy`, `adopt:open`, `create:start`, `open:start`): its scratch or staging folder is there while held; a close of another book stops it, it answers it was stopped, the root's `books/` and `legacy/` are byte for byte as before; asked again it goes through |
| `book_open_close::a_close_stops_the_restore_and_the_open_of_its_own_book_leaving_the_root_as_it_was` | a restore over a book and the open of a book, each held inside a phase (`restore:copy`, `open:start`): its scratch or staging folder is there while held; a close of THAT book stops it, it answers it was stopped, the root's `books/` and `legacy/` are byte for byte as before; asked again it goes through |
| `book_open_close::the_servers_close_stops_every_running_admin_job_leaving_the_root_as_it_was` | restore (a new book, and over `acme`), adopt, create and open, each held inside a phase, the server closed with nothing lifting the hold: each answers it was stopped, the root as it was, exit 0; asked again on a new server the first goes through |
| `book_open_close::closing_and_opening_one_book_never_stops_waits_for_or_refuses_another_books_jobs` | a restore over `beta`, a create of `epsilon` and an adoption of `delta` in flight (they make books one at a time, so the later two queue for their turn, and each is held in its phase in its time), `acme` closed (its backup's git stalled, so the close is slow) and opened again around each; during each close `cedar` is opened and closed and answers while the close of `acme` is still not answered; all three finish (`Restored`, `Created`, `Adopted`, no problem), none was stopped. Mutations: a close that raises a server-wide stop fails it (a queued job stopped); one global lock around open and close fails it (the open waits for the close) |
| `book_open_close::a_close_never_leaves_a_decision_on_record_for_a_package_that_was_not_made` | `books.export_cpa_package` with `allow_open_drafts`: held as it begins and the book closed, it is stopped and the journal holds no decision; held right after its decision is journaled and the book closed, it is made, handed over (`ok`), one decision. Mutations: no look before the journaling fails the first; a build still stoppable after it fails the second |
| `ledger-store` `tests/root.rs::a_job_stopped_at_any_phase_before_its_point_of_no_return_leaves_the_root_as_it_was` | create, adopt, restore (over existing books) and the restore preview stopped at each phase they ask: `Stopped`, the root (`books/`, `legacy/`) byte for byte as before; never stopped, `place` is the last phase asked (nothing after the point of no return) |
| `ledger-store` `tests/root.rs::an_adoption_that_does_not_finish_leaves_no_lock_file_in_the_source` | a source with no lock file: the adoption stopped at each of its seven phases, refused after taking the lock (a stale preview head), and panicking in the middle leaves the source folder name for name, byte for byte and mode for mode as it was; a lock file swapped in by someone else during the adoption is not removed; a source that had its lock keeps it (stopped or adopted, `source_lock_created` false); a success of a source with none leaves the one it made and says so. Mutation: no removal fails it |
| `ledger-store` `tests/root.rs::a_job_waiting_for_its_turn_stops_when_asked_and_otherwise_waits_for_it` | the turn at making books held (as another process would): a create that isn't asked to stop waits, and stops within seconds once asked (`Stopped`, nothing made); not asked, it goes through when the turn is let go. Mutation: a blocking wait for the turn fails it |
| `book_open_close::a_lock_a_kill_leaves_in_the_backup_folder_is_reported_and_never_removed_by_the_server` | REAL git in a push to a folder with its group frozen, so only the kill after the grace ends it: the lock it leaves is still there after the close, recorded `lock_left` with its whole path, no `lock_removed` for the folder, the close's answer and `books.backup` name the file and say when it may be removed, a lock that was there before is neither touched nor named, a later backup fails by git's words and removes nothing, and once the file is removed the backup goes on, `git fsck --strict` on both |
| `book_open_close::a_call_whose_answer_was_never_read_is_on_record_as_having_run` | a journaled draft whose client goes without reading: after the close the access log has its record, outcome `ok`, with the head it wrote (INVARIANT 14: a retry isn't made safe by anything; the record says it ran) |
| `book_open_close::a_close_is_not_answered_while_its_backup_still_runs` | a book with a folder target and a stand-in `git` on the server's PATH that waits: the close isn't answered before its backup bound (1.2 s), then answers `closed_backup_incomplete`, git and all it started are gone, and lifting the stall makes nothing resume; the reopened book's backup record is a whole chain and it backs up (fails when `shut` is removed: git still runs after the answer) |