Skip to content

Commit 18a6091

Browse files
t3dotggclaude
andcommitted
fix(server): ignore output from a replaced Cua driver
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent e99a9b9 commit 18a6091

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎apps/server/src/mcp/CuaMcpProxy.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import * as Effect from "effect/Effect";
1111
import { endCuaSession, ensureCuaMcpProxy } from "./CuaMcpProxy.ts";
1212

1313
// Stands in for `cua-driver mcp`: answers `initialize`, reports its pid and
14-
// whether the handshake finished, and never answers "hang".
14+
// whether the handshake finished, and answers "hang" only as it is stopped.
1515
const FAKE_DRIVER = `
1616
let initialized = false;
17+
let hanging = null;
1718
let input = "";
1819
const reply = (message) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\\n");
1920
process.stdin.on("data", (chunk) => {
@@ -24,11 +25,16 @@ process.stdin.on("data", (chunk) => {
2425
const message = JSON.parse(line);
2526
if (message.method === "initialize") reply({ id: message.id, result: { protocolVersion: "2025-06-18" } });
2627
if (message.method === "notifications/initialized") initialized = true;
28+
if (message.method === "tools/call" && message.params.name === "hang") hanging = message.id;
2729
if (message.method === "tools/call" && message.params.name === "whoami") {
2830
reply({ id: message.id, result: { pid: process.pid, initialized } });
2931
}
3032
}
3133
});
34+
process.on("SIGTERM", () => {
35+
if (hanging !== null) reply({ id: hanging, result: { late: true } });
36+
process.exit(0);
37+
});
3238
`;
3339

3440
const temporaryDirs: Array<string> = [];

‎apps/server/src/mcp/CuaMcpProxy.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ function start() {
6666
let buffer = "";
6767
current.stdin.on("error", () => {});
6868
current.stdout.on("data", (chunk) => {
69+
// A replaced driver can still flush output; its calls were already failed.
70+
if (child !== current) return;
6971
buffer += chunk;
7072
const lines = buffer.split("\\n");
7173
buffer = lines.pop();

0 commit comments

Comments
 (0)