fix(mcp): a close cuts a request that never finishes arriving, so a stalled client can't hold a book open

A client that begins an upload or an MCP POST and stops sending is inside
the book's door, and the close waited for it with no bound. Now, when the
close's answer grace runs out, every request inside whose body has not been
read to its end is cut: connection closed, an upload's part file removed by
receive's read error, the access record (written before the answer) says
cut_by_close. A body read to its end is whole and never cut, so a running
call still finishes. Nothing of an MCP call can be journaled by a cut: rmcp
reads the whole body (expect_json) before any message reaches a session or
tool, and the handler checks for the cut again before binding a session.
Holds for a book's close, a restore over an open book (Books::release) and
the server's close. The restore-waits test now uses a grace longer than its
5 s watch: an upload finishing within the grace is still waited for.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-20 11:44:13 -07:00
1 parent 1332c2a576
commit ce636adbb5
5 files changed
+554 -10

No files matched your search

+5
View File
@@ -4316,6 +4316,11 @@ one book never refuses or holds up a call on another.
| `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) |
| `ledger-store` `access::tests::a_closed_log_writes_nothing_and_a_reopened_one_stays_whole`, `uploads::tests::closed_uploads_change_nothing`, `exports::tests::closed_exports_change_nothing_and_give_nothing`, `backup::tests::a_cancelled_git_stops_what_runs_and_starts_nothing` | the closed state of each handle (under the lock its writes go in under), and git's cancel flag (a running command is stopped with all it started, none starts) |
| `book_open_close::a_client_that_never_reads_its_answer_cannot_hold_a_close_nor_break_the_log` | a client asks for the 500 KB tools list and never reads it (the answer is stuck in the socket): the close waits the answer grace (shortened to 700 ms) and then answers; the folder doesn't move afterwards; after the reopening the access log is one whole chain |
| `book_open_close::a_stalled_upload_body_cannot_hold_a_close_and_leaves_no_part_file` | an upload stops sending half way: the close waits the grace (600 ms), cuts it (connection closed, no part file, no bytes kept, record `cut_by_close`) and answers; the folder stands still; one whole access chain across the reopening (hung before the change) |
| `book_open_close::a_stalled_mcp_body_cannot_hold_a_close_and_nothing_of_it_is_journaled` | a `tools/call` whose body stops half way is cut by the close: connection closed, the call is not in the journal, record `cut_by_close` (hung before the change) |
| `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_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_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) |
| `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` |