fix(mcp,store): a close stops every call and job that can run long, and says so; an unrecorded refusal never ran

A close waited, unbounded, for a running books.back_up_now (git only Backups::shut
could cancel), for a restore, create or adopt (they hold the one lifecycle lock,
and at the server's close admin_jobs.wait() waited for them before anything was
released), and, through the store lock, for a verification or a package reading
every stored file. The bound's T_calls term was not finite.

Now a close calls hurry at its start, and the stoppable work looks at it:
books.back_up_now and timer-asked backups (git stopped, a stopped run records
'stopped' and no result of its own), books.verify (per journal line and file; a
heal of a drifted database is begun only if no stop came before it: stopped half
way it would leave the live ledger part replayed), books.export_cpa_package (per
stored file). Such a call answers that it was stopped because the books are
closing, and its access record says refused: stopped_by_close. On the admin
socket restore, adopt, create and open take a JobStop: asked at each phase and
file copied, they remove what they wrote and leave the root byte for byte as it
was; the renames that put the books in place are the point of no return, after
which they finish (two renames and two syncs). A close of any book, and the
server's own, raises the flag before it waits for the lifecycle lock.

A close whose last backup had to be killed in the owner's folder now says which
file was left, and the target's backup is marked failed by shut when the run's
future was dropped at its bound. INVARIANT 10 is rewritten so each term of the
bound is enforced by code, and lists the calls that can run long (and the one
known exception, books.import_bank_csv); INVARIANTS 8 and 9 say exactly which
refusals are recorded and why an unrecorded one never ran; the format upgrade's
wording says a stop is honoured up to its final look.

Tests: the close is held to the bound while a backup call, a verification, a
package and each admin job is running and would never end; the stopped job leaves
the root byte for byte as it was; a lock left in a backup folder is reported and
never removed. Sleeps that stood for 'the other side got there' now wait on the
condition (Expect: 100-continue for a half-sent body, a writable named pipe for a
fetch that is reading).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-20 17:15:36 -07:00
1 parent 6f174f3f87
commit aa64df9a25
18 files changed
+1889 -248

No files matched your search

+39 -6
View File
@@ -359,7 +359,8 @@ didn't open, with why). Protocol version 1: the requests are new, the
why), `was_not_open` or `no_such_book`.
In this order: new calls on the book are refused (the door is shut and
the book listed closed); the calls running on it finish, on every route
(nothing is killed, nothing is half-done); the answers on their way out
(an ordinary call: nothing is killed, nothing is half-done; the calls
that can run long are stopped instead, see below); the answers on their way out
are sent, for 10 seconds at most (a client that never reads its answer
doesn't hold the book open); a request whose body has not been read
to its end when that time runs out (counted from the start of the
@@ -374,11 +375,43 @@ didn't open, with why). Protocol version 1: the requests are new, the
(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 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;
a backup still running after that is stopped (git is sent SIGTERM, which
makes it remove its own lock files, and killed with all it started only
if it hasn't ended after 5 seconds) and waited for to end. The program
never writes to or deletes from a backup folder (it is the owner's, and
may be shared with other computers or a sync program): a lock git left
there when it had to be killed is left in place, recorded in
`ops/backup.jsonl` as `lock_left` with its whole path, and the target's
backup is marked failed with words naming the file and saying to remove
it only when nothing else is using the backup folder (`books.backup`
and the close's answer say the same; the next backup that finds the
lock gone goes on). In the book's own archive (`archive.git`, private to
the program; running git by hand inside it is unsupported) it removes
only the locks its own stopped git made, and, at open and when a backup
begins, locks older than ten minutes, each recorded `lock_removed`;
**What a close stops, and what it waits for.** At its start a close
stops the calls and jobs that can do long I/O or loop over a book's
whole journal or files, each at its next look: `books.back_up_now` and
a backup a timer asked for (git is stopped; the call answers that it was
stopped because the books are closing, its access record says
`refused: stopped_by_close`, and nothing it was doing is recorded as done;
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
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);
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);
+8 -1
View File
@@ -33,7 +33,14 @@ easily backupable, journable":
ahead, the commit under the store's lock) and pushes it to the
owner's private repository and backup folder, versioned and
deduplicated, with full history (docs/mcp-interface.md, "Tools —
backups").
backups"). The program stops its git gently (SIGTERM first, so git
removes its own lock files, and a kill only after 5 seconds), and never
writes to or deletes from a backup folder, which is the owner's (shared,
perhaps, with another computer or a sync program): a lock git left
there after a kill is reported with its path, never removed. The book's
own archive (`archive.git`) is private to the program; there it removes
only the locks its own stopped git made, and locks older than ten
minutes found when the books open or a backup begins.
- **Journable.** It literally is a journal: `{seq, ts, type, payload, prev}`.
Greppable, diffable, replayable. The audit trail isn't a feature bolted
on — it's the storage format.
+27 -3
View File
@@ -4326,12 +4326,17 @@ one book never refuses or holds up a call on another.
| `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 |
| `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) stopped inside `init`, a commit and a push to a folder by a close: git is sent SIGTERM and removes its own locks, so none is left in the archive or the folder and the backup's record holds no `lock_removed` or `lock_left` (nothing for the server to clean up), 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_git_stopped_by_sigterm_mid_commit_…`, `…_stopped_mid_add_…`, `a_push_stopped_by_sigterm_…`, `a_git_that_ignores_sigterm_…`, `a_git_that_cannot_end_on_sigterm_…`, `a_lock_left_in_a_folder_target_…`, `a_push_stopped_during_the_pack_transfer_…`, `the_archives_age_rule_at_open`, `removal_after_a_stop_goes_through_the_handle_…`, `git_locks::tests` (3) | REAL git stopped inside a commit (HEAD and ref locks), an add (the index lock) and a push to a folder (the target's ref lock): on SIGTERM it removes its own locks and nothing is noted (the grace is long, so a git that needed the kill would show); a git whose group is frozen (SIGSTOP, so SIGTERM stays pending) is killed only after the grace, and the archive's locks it left (not there when the command began) are removed, noted; the folder target's lock is NEVER removed, reported with its whole path (`LockLeft`, `lock_left` with `path`), a lock that was there before the push is untouched and not named, a later push fails by git's words and removes nothing, the next one passes once the test removes the file; a fake git that traps SIGTERM is sent it first (marker) and killed after the grace with all it started; a 48 MiB pack held in the receiving end's `pre-receive` hook (the target's `incoming-` quarantine present) stopped by SIGTERM and by the kill, `git fsck --strict` on both repositories at once; the archive's locks at open: older than ten minutes removed and noted, younger left and said, non-lock names, folders and links untouched; a swapped `refs` folder or archive path after the handle was opened touches nothing outside; the handle module: exact lock names only, regular files only, no link followed |
| `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_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 |
| `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) |
| `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) |
| `book_open_close::a_close_whose_backup_fails_says_so_and_leaves_nothing_running` | a target whose disk isn't there: `closed_backup_incomplete` naming the failure, quickly, no git run afterwards; the same book with its disk back is answered plainly `closed` |
@@ -4341,6 +4346,25 @@ one book never refuses or holds up a call on another.
| `book_open_close::the_timers_never_touch_a_closed_book` | `--timers 5` (sweep, backup look, drill look every 5 ms) on a book with a backup target, closed and opened 8 times: while closed, with strays planted for a sweep to take, not one file moves; open, it is backed up and drilled; the logs end as whole chains |
| `commands::tests::doctor_says_who_is_connected` | the doctor's lines for sessions |
**Waiting on conditions, not on guesses (review of 2026-11-20).** A test of
this branch that slept for a fixed time to let "the other side get there"
now waits on the condition: `exports::tests::a_close_waits_for_a_fetch_that_is_reading`
(it slept 300 ms assuming its thread had reached the named pipe; it now
opens a non-blocking writer on the pipe, which succeeds only once a reader
has it open); the two MCP bodies that stop half way
(`a_stalled_mcp_body_cannot_hold_a_close_…`, the server's-own-close test, the
second of which slept 200 ms and the first nothing at all) send their head
with `Expect: 100-continue` and their body only on the server's `100
Continue`, which the server sends when its handler first reads the body,
inside the book's door (`raw::Raw::start_inside`); the late-timer test no
longer sleeps 300 ms before its 800 ms window in which nothing may move;
`a_close_whose_backup_fails_…` waits out the backup the opening makes by
asking for one itself (it could be stopped by the close and leave a lock). The
sleeps that remain are negative windows (a close must NOT have been answered;
nothing must move), which can only fail when the property is broken, never
because the machine is slow, and pacing of a stimulus (the hammer's jitter,
a client trickling an upload on purpose).
**For P12 (mutation targets).** `Gate::enter` (count before looking at `shut`),
`Books::release`'s order (the store's close, the gate emptied, sessions ended, the last backup, `Backups::shut`, the logs and files closed, `let_go`) and `Backups::begin`'s count-before-flag, `Backups::shut` (the flag, the turn, the steps drained, the record closed), `ChainLog::close`, `refused_at_door` taking the request's place into its task, the sweep taking the gate, `door`'s entering
before it touches the book, and the gate's riding in the upload and