fix(mcp): a close is bounded, the server's close is the book's close, and the tests prove what they claim

Close bound. A drill ran to its end however large the book, and a format
upgrade counted by the store's close held it, because only git was
cancellable. Now a close hurries them at its start (Backups::hurry): a drill
stops at its next look (git killed, journal line, file, chunk) and its
scratch clone is removed, nothing said of its target (it is due again at
open); a format upgrade is stopped before its journal.format_set line is
appended (reported not done, the books unchanged) and finishes once it is.
The close's last backup, and shut's stop of what is left of it, are not
hurried. INVARIANT 10 now states the bound as the sum of its named parts.
Lock files a stopped git left are removed by the store (previous commit) and
recorded here (lock_removed / lock_left, also those found at open).

Server's own close. It cut a stalled body only after admin jobs, store
closes and the serial 60 s backups, and never shut a gate or closed a log.
It is now Books::release for every open book (gates shut and the cut set for
one grace at the start, books released together, logs, uploads, exports,
backups and store closed), so there is one closing path; INVARIANT 15 says
what is true. A request that finds a shut door during the server's close is
refused as closing, not recorded.

Tests that passed with the fix removed. The timers test now holds a timer
between taking a book's handles and acting on them (--timer-hold), closes the
book in between and requires the tree not to move; the slow-upload test is
driven by conditions (a minute's grace) and has a mirror proving the cut of
an active upload; the line of the cut (a body read to its end is never cut)
has a unit test; a slow drill (--slow-steps) and a format upgrade are held by
the close test; REAL git killed inside init, a commit and a push by a close
leaves no lock and the next backup succeeds (this found that a killed init
left HEAD.lock, fixed in the store); the server's close with a stalled
upload and a stalled call exits 0 with both cut.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-20 13:10:41 -07:00
1 parent 10790d8794
commit f6daba558b
5 files changed
+1071 -126

No files matched your search

+19 -2
View File
@@ -370,9 +370,19 @@ didn't open, with why). Protocol version 1: the requests are new, the
finishes; its MCP sessions end (an agent's next
request on one gets the "isn't open" words above, and after a reopening
a 404 "Session not found", which a client takes as "open a new one"); its
last backup is made, as at the server's close, for 60 seconds at most:
last backup is made, as at the server's close, for 60 seconds at most
(a drill, or a format upgrade not yet journaled, is stopped when the
close begins, at its next look, so it never takes the last backup's
turn; its scratch clone is removed and the books are unchanged):
a backup still running after that is stopped (git is killed with all it
started) and waited for to end; then nothing of the server's can write
started, and any lock file it left, in the book's archive and in a
folder target on this computer, is removed and recorded in
`ops/backup.jsonl` as `lock_removed`; a lock that was there before the
push began is never touched, `lock_left`) and waited for to end;
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);
then nothing of the server's can write
to the book: its access log, uploads, exports and backups are closed
under the locks their writes go in under, so a handle held from before
can never write after a reopening; its store is let go, releasing the
@@ -398,6 +408,13 @@ didn't open, with why). Protocol version 1: the requests are new, the
listed closed from the moment the restore begins, so a call that comes
meanwhile is told the books aren't open (503, as in a close), never that
there are no such books (404).
- **The server's own close** (its standard input ends, or SIGTERM) is the
same path for every open book at once: at its start every book's door
is shut and the cut (above) is set for 10 seconds from that moment; each
book is then released as `close_book` releases it. The server exits 0
once they are all closed (and the HTTP side has ended); a request that
arrives meanwhile is refused as closing (503) and not recorded, the
door being shut.
- `sessions` lists, for each open book, its live MCP sessions: the token's
**name** (never the token, its text or its hash), the client's name and
version from `initialize`, the agent's self-report (`books.start`'s
+10 -1
View File
@@ -4321,7 +4321,16 @@ one book never refuses or holds up a call on another.
| `book_open_close::a_restore_over_an_open_book_is_not_held_by_a_stalled_upload` | a restore over an open book with an upload stalled half way: the upload is cut after the grace, no part file in `legacy/`, the replaced book's log records `cut_by_close`, the restore is answered |
| `book_open_close::a_restore_over_an_open_book_waits_for_what_is_inside_it` | (extended) every call while the restore waits for a half-received upload gets 503 and the closed words, never 404 `no such books` (fails when the restore takes the book out of the list before it shuts the door) |
| `ledger-store` `uploads::tests::a_close_in_the_middle_of_a_file_stops_it_at_the_next_chunk`, `uploads::tests::a_close_between_the_last_byte_and_the_rename_keeps_nothing`, `exports::tests::a_close_waits_for_a_fetch_that_is_reading` | the types' own claims (INVARIANT 6 of uploads, 5 of exports): a close in the middle of a file stops it at the next chunk (no read after, no part left), a close between the last byte and the rename keeps nothing, and a fetch reads under the lock a close takes (a named pipe holds it inside its read; `close` must not return); each fails with its guard removed |
| `book_open_close::a_slow_upload_that_finishes_within_the_grace_is_not_cut` | an upload dripping in over ~600 ms with a 2.5 s grace is kept and answered 200, nothing cut |
| `book_open_close::a_slow_upload_that_finishes_within_the_grace_is_not_cut` | (made deterministic) the grace is a minute and the rest of the bytes go only after the book is listed closed: the cut waits for the grace (fails with the cut set to fire at once) |
| `book_open_close::an_upload_still_arriving_when_the_grace_runs_out_is_cut_however_active_it_is` | the mirror: a client sending 8 KB every 25 ms (not stalled) of a 3 MB body with a 600 ms grace is cut (`cut_by_close`, no part, no bytes kept) and the close answered; driven by the client's condition (it sends until the connection is closed), fails with the cut removed |
| `book_open_close::the_servers_own_close_cuts_stalled_requests_and_exits_zero_in_time` | one upload stalled on one book and one MCP body stalled on another, the server's stdin closed: exit code 0 within the bound, both cut after the grace, no part file, nothing journaled, two `cut_by_close` records, every log whole |
| `book_open_close::a_backup_and_a_sweep_that_took_their_handles_before_a_close_do_nothing_after_it`, `…a_drill_and_a_sweep…` | `--timer-hold` holds a timer between taking a book's handles and acting; the book is closed meanwhile, stray files planted, the timers go on: the closed book's tree doesn't move; opened again the sweep works (fail with the handles' closed state, the gate's check and the backups' shut flag removed) |
| `book_open_close::a_close_stops_a_slow_drill_instead_of_waiting_for_it` | `--slow-steps` makes each phase of a drill wait a minute: the close answers plain `closed` (the last backup was made), within the stated sum, with the drill's scratch clone removed (fails without `hurry`: `closed_backup_incomplete`) |
| `book_open_close::a_close_that_stops_git_in_a_commit_or_a_push_leaves_no_lock_and_the_next_backup_succeeds` | REAL git (a wrapper that points git's hooks at a `reference-transaction` hook that waits) killed inside `init`, a commit and a push to a folder by a close: no lock left in the archive or the folder before the close is answered, each recorded, the reopened book backs up with no step by hand, `git fsck --strict` passes on both |
| `local::tests::a_close_stops_a_format_upgrade_before_it_is_journaled` | an upgrade held in its backup's proof: the close stops it, it says nothing was upgraded, the journal is byte for byte as before |
| `local::tests::a_body_read_to_its_end_is_never_cut_and_one_not_yet_is` | the line of the cut: a body read to its end is never cut (the cut firing, the body asked again), one not read to its end is cut even with bytes on the way |
| `ledger-store` `backup::tests::a_git_killed_mid_commit_…`, `…_mid_add_…`, `…_mid_push_…`, `locks_found_in_the_archive_when_the_books_open_…` | real git killed inside a commit (HEAD and ref locks), an add (the index lock) and a push to a folder (the target's ref lock): locks removed once the group is gone, noted; a lock that was in the target before the push is never removed, and the target's lock is removed only after LOCK_SETTLE; next backup succeeds, `git fsck` passes; the archive's locks are cleared at open |
| `ledger-store` `backup::tests::a_drill_stops_inside_the_phase_it_is_told_to_stop_in` | for each phase (clone, replay, verify, blobs, prefix) a stop set as the phase begins ends the drill inside it (the observer sees no later phase), scratch removed; each case fails when the loop's looks inside that phase are removed |
| `book_open_close::a_running_call_is_never_cut_when_the_grace_runs_out` | `books.back_up_now` held in a stalled `git` past the grace (body whole) is not cut: it finishes, is answered and recorded `ok`, and then the close is answered |
| `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) |