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

+7 -1
View File
@@ -361,7 +361,13 @@ didn't open, with why). Protocol version 1: the requests are new, the
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
are sent, for 10 seconds at most (a client that never reads its answer
doesn't hold the book open); its MCP sessions end (an agent's next
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
close: an upload or a call that began and stopped sending) is cut: its
connection is closed, an upload's part file is removed, nothing of an
MCP call reached the journal, and the access log says `cut_by_close`;
a call whose body arrived whole and is running is never cut, it
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: