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:
1 parent
f7f75fb380
commit
89403a7159
10 files changed
+802
-34
No files matched your search
@@ -182,9 +182,18 @@ impl Server {
|
||||
Self::start_in(home, home.dir.path(), &[])
|
||||
}
|
||||
|
||||
/// [`Server::start`], with these arguments after the root (`--open`).
|
||||
pub fn start_with(home: &Home, args: &[&str]) -> Self {
|
||||
Self::spawn(home, home.dir.path(), &[], args)
|
||||
}
|
||||
|
||||
/// [`Server::start`], in the folder `cwd`, with `env` beside the
|
||||
/// home's own (INVARIANT 1).
|
||||
pub fn start_in(home: &Home, cwd: &Path, env: &[(&str, &Path)]) -> Self {
|
||||
Self::spawn(home, cwd, env, &[])
|
||||
}
|
||||
|
||||
fn spawn(home: &Home, cwd: &Path, env: &[(&str, &Path)], args: &[&str]) -> Self {
|
||||
let log = std::fs::OpenOptions::new()
|
||||
.create(true)
|
||||
.append(true)
|
||||
@@ -195,6 +204,7 @@ impl Server {
|
||||
.arg("server")
|
||||
.arg("--root")
|
||||
.arg(home.root())
|
||||
.args(args)
|
||||
.current_dir(cwd);
|
||||
clean_env(&mut command, home.dir.path());
|
||||
let mut child = command
|
||||
|
||||
Reference in new issue
Block a user