fix(mcp): a close waits for the answers on their way out, and test it under a hammer

The first run of the hammer (agents calling two books while one is closed and
reopened over and over) found a real race: an MCP request's handler returns
as soon as the session's task has the request, and the tool's answer streams
back afterwards. A close that waited only for handlers and running tools
could end the sessions while an answer was still on its way, so a call that
did not run (refused as closing) reached its client as neither answered nor
refused. The gate now also counts answers on their way out (Answering,
carried in the response body as the server's own close counts them), and a
close waits for them, for ANSWER_GRACE at most, before it ends the sessions.

The hammer (tests/book_open_close.rs) replays both journals afterwards:
every acknowledged draft is there 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 its reopening, the other book never
refused a call and kept answering while the first was closed. Beside it: a
server started with --open, the sessions request over the real socket, the
doctor's lines, and the docs (mcp-interface, architecture, testing).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-20 09:23:39 -07:00
1 parent f7f75fb380
commit 89403a7159
10 files changed
+802 -34

No files matched your search

+9
View File
@@ -287,6 +287,15 @@ re-verifies the journal.
## The local transport and the Windows arms (`ledger-mcp::ipc`, `ledger-store::winsec`, P11c, D-62)
The books server opens the books of the data root at its start (all, or the
ones `--open` names), and opens or closes **one** while it runs (admin
requests `open_book` and `close_book`, `ledger-mcp/src/local.rs`
INVARIANT 10; plan/p15-app-and-relay.md 3.1): each open book has a gate
every request enters before it touches the book, which a close shuts and
waits empty, so the app's tab for a company can be its book's open state.
`sessions.rs` keeps the per-book board of who is connected (the admin
`sessions` request).
The books server, the host and everything that talks to them meet on
channels only this account can open (plan 3.9). `ledger_mcp::ipc` is the
one seam: `Endpoint` (a socket in the root's `run/` on Unix; the pipe