Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(computer): answers the bridge writes itself carry resultType for 2026-07-28 clients (#4282)

Aditya Umale6df8d555172a
diff --git a/server/local-computer-proxy.test.ts b/server/local-computer-proxy.test.ts
index 529f449eb8..8f8a87db2f 100644
--- a/server/local-computer-proxy.test.ts
+++ b/server/local-computer-proxy.test.ts
@@ -392,6 +392,40 @@ readline.createInterface({input: process.stdin}).on("line", (line) => {
}
});
+ it("win32: a relayed call's answer is marked complete for a client on the 2026-07-28 protocol, and left as it was for an older one", async () => {
+ const server = createServer((_request, response) => {
+ response.writeHead(200, { "content-type": "application/json" });
+ response.end(JSON.stringify({ held: false, helpOpen: false }));
+ });
+ await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
+ const connection = gatedLocalComputer(
+ { command: process.execPath, args: ["-e", PACING_DRIVER], env: {}, platform: "win32", scope: "local-computer" },
+ { url: `http://127.0.0.1:${(server.address() as AddressInfo).port}/control`, token: "relay-result-type-fixture-token" },
+ );
+ const child = spawn(connection.command, connection.args, { env: { ...process.env, ...connection.env }, stdio: ["pipe", "pipe", "pipe"] });
+ try {
+ const lines = createInterface({ input: child.stdout! })[Symbol.asyncIterator]();
+ const typed = async (id: number, protocolVersion: string) => {
+ const params = { name: "type_text", arguments: { pid: 4242, window_id: 0x30a5c, delivery_mode: "foreground", text: "ab" }, _meta: { "io.modelcontextprotocol/protocolVersion": protocolVersion } };
+ child.stdin!.write(JSON.stringify({ jsonrpc: "2.0", id, method: "tools/call", params }) + "\n");
+ const answer = JSON.parse((await lines.next()).value as string);
+ expect(answer.id).toBe(id);
+ return answer.result;
+ };
+ child.stdin!.write(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "initialize", params: {} }) + "\n");
+ await lines.next();
+ const marked = await typed(2, "2026-07-28");
+ expect(marked.isError).toBeUndefined();
+ expect(marked.resultType).toBe("complete");
+ const legacy = await typed(3, "2025-06-18");
+ expect(legacy.isError).toBeUndefined();
+ expect(legacy).not.toHaveProperty("resultType");
+ } finally {
+ child.kill("SIGKILL");
+ await new Promise<void>((resolve) => server.close(() => resolve()));
+ }
+ });
+
it.each(["win32", "darwin"] as const)("%s: a call the bridge answers itself is never journalled, so its request stays incomplete", async (platform) => {
const journal = new ComputerJournal();
let generation = "plain";
diff --git a/server/mcp-bridge.test.ts b/server/mcp-bridge.test.ts
index 70fe45d70c..3355807f6d 100644
--- a/server/mcp-bridge.test.ts
+++ b/server/mcp-bridge.test.ts
@@ -3,6 +3,7 @@ import { describe, expect, it, vi } from "vitest";
import { CONTROL_REFUSAL_PLAIN, CONTROL_UNCONFIRMED, CONTROL_WAITED, type ControlState } from "./control-client.ts";
import {
+ completeFor,
createChildCalls,
createGateInterceptor,
createInactivityWatchdog,
@@ -203,6 +204,16 @@ describe("createGateInterceptor", () => {
expect(answer.result.content[0].text).toBe(CONTROL_REFUSAL_PLAIN);
});
+ it("marks a refusal complete for a client on the 2026-07-28 protocol, which rejects a result without resultType", async () => {
+ const { refused, intercept } = harness(async () => person);
+ const meta = { "io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientCapabilities": {} };
+ intercept(JSON.stringify({ jsonrpc: "2.0", id: 4, method: "tools/call", params: { name: "list_windows", arguments: {}, _meta: meta } }));
+ intercept(frame("tools/call", 5));
+ await drain();
+ expect(JSON.parse(refused[0]!).result).toEqual({ content: [{ type: "text", text: CONTROL_REFUSAL_PLAIN }], isError: true, resultType: "complete" });
+ expect(JSON.parse(refused[1]!).result).toEqual({ content: [{ type: "text", text: CONTROL_REFUSAL_PLAIN }], isError: true });
+ });
+
it("preserves protocol order even though the check is async", async () => {
const order: string[] = [];
let calls = 0;
@@ -369,6 +380,13 @@ describe("createMcpBridgeInterceptor", () => {
expect(forwarded).toEqual([]);
});
+ it("answers a ping from a client on the 2026-07-28 protocol as complete", () => {
+ const answered: string[] = [];
+ const intercept = createMcpBridgeInterceptor({ answer: (line) => answered.push(line), forward: () => {} });
+ intercept(JSON.stringify({ jsonrpc: "2.0", id: 2, method: "ping", params: { _meta: { "io.modelcontextprotocol/protocolVersion": "2026-07-28" } } }));
+ expect(answered).toEqual(['{"jsonrpc":"2.0","id":2,"result":{"resultType":"complete"}}']);
+ });
+
it("treats a ping notification as a silent swallow", () => {
const forwarded: string[] = [];
const answered: string[] = [];
@@ -455,3 +473,19 @@ describe("createReplyQueue", () => {
expect(written).toEqual(["A", "B", "C"]);
});
});
+
+describe("completeFor", () => {
+ const failure = { content: [{ type: "text", text: "Computer-control transport closed" }], isError: true };
+ const on = (version: string) => ({ "io.modelcontextprotocol/protocolVersion": version });
+
+ it("marks the bridge's own answer complete only for a client on the 2026-07-28 protocol or later", () => {
+ expect(completeFor(on("2026-07-28"), failure)).toEqual({ ...failure, resultType: "complete" });
+ expect(completeFor(on("2025-06-18"), failure)).toBe(failure);
+ expect(completeFor(undefined, failure)).toBe(failure);
+ });
+
+ it("keeps a resultType the driver already sent", () => {
+ const asked = { content: [], resultType: "input_required" };
+ expect(completeFor(on("2026-07-28"), asked)).toBe(asked);
+ });
+});
diff --git a/server/mcp-bridge.ts b/server/mcp-bridge.ts
index 89e713a045..75fd56deae 100644
--- a/server/mcp-bridge.ts
+++ b/server/mcp-bridge.ts
@@ -176,7 +176,7 @@ export function createGateInterceptor(options: {
JSON.stringify({
jsonrpc: "2.0",
id: frame.id ?? null,
- result: { content: [{ type: "text", text: state.held ? controlRefusal(state) : CONTROL_WAITED }], isError: true },
+ result: completeFor(frame.params?._meta, { content: [{ type: "text", text: state.held ? controlRefusal(state) : CONTROL_WAITED }], isError: true }),
}),
);
});
@@ -206,7 +206,7 @@ export function createMcpBridgeInterceptor(
if (frame && frame.method === "ping") {
// Notifications have no `id` and require no response.
if (frame.id !== undefined) {
- options.answer(JSON.stringify({ jsonrpc: "2.0", id: frame.id, result: {} }));
+ options.answer(JSON.stringify({ jsonrpc: "2.0", id: frame.id, result: completeFor(frame.params?._meta, {}) }));
}
return;
}
@@ -243,6 +243,16 @@ function failed(text: string): Record<string, unknown> {
return { content: [{ type: "text", text }], isError: true };
}
+const PROTOCOL_VERSION_META = "io.modelcontextprotocol/protocolVersion";
+
+/** A client on protocol revision 2026-07-28 or later rejects a result without resultType (the driver sends one), so an
+ * answer the bridge writes itself says it is complete. Older clients get the result as it was. */
+export function completeFor(meta: unknown, result: unknown): unknown {
+ const version = isObject(meta) ? meta[PROTOCOL_VERSION_META] : undefined;
+ if (typeof version !== "string" || version < "2026-07-28" || !isObject(result) || "resultType" in result) return result;
+ return { ...result, resultType: "complete" };
+}
+
/** A tools/call request the agent waits on, as a relay sees it; anything else is not the relay's to answer. */
function relayableCall(line: string): { id: unknown; call: ToolCall; meta: unknown } | null {
let frame: any = null;
@@ -344,7 +354,7 @@ export function runMcpBridge(options: BridgeOptions): void {
// Fail-closed: a relayed answer is the bridge's, never the driver's, so it is not journalled. The gate check the call
// passed is then left without an entry, which keeps its request's journal incomplete, and an incomplete one never saves.
tap?.leaveOut(frame.id);
- const result = await relayed.catch((error: unknown) => failed(error instanceof Error ? error.message : String(error)));
+ const result = completeFor(frame.meta, await relayed.catch((error: unknown) => failed(error instanceof Error ? error.message : String(error))));
respond(JSON.stringify({ jsonrpc: "2.0", id: frame.id, result }));
};
let sending: Promise<void> = Promise.resolve();