Skip to content

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

Train K1: MCP startup phase goes to the server log; the notice stays short

milind-soni9f9a8cf95def
diff --git a/server/drivers/chat-host-computer.test.ts b/server/drivers/chat-host-computer.test.ts
index 8932b18e98..ad16354c0a 100644
--- a/server/drivers/chat-host-computer.test.ts
+++ b/server/drivers/chat-host-computer.test.ts
@@ -163,7 +163,7 @@ describe("this desktop's own computer in a chat turn", () => {
const session = await mount(computer(driver, { MODE: "silent" }).server, 150, 600, "c-lost", lines);
expect(names(session)).toEqual(["computer_write"]);
const result = await session.execute("computer_write", { value: "z" }, controller.signal);
- expect(result).toMatchObject({ ok: false, text: expect.stringContaining("did not start this time (MCP startup timed out (server \"computer\"") });
+ expect(result).toMatchObject({ ok: false, text: expect.stringContaining("did not start this time (MCP startup timed out)") });
expect(() => session.validate("computer_write", { value: "z" })).not.toThrow();
await vi.waitFor(() => expect(lines).toEqual([expect.objectContaining({ text: { key: "chat.notice.computerToolsDidNotStart", params: { why: "chat.notice.part.computerToolsTookTooLong" } } })]));
});
diff --git a/server/drivers/chat-mcp-tools.test.ts b/server/drivers/chat-mcp-tools.test.ts
index 1c1b3dac2e..e7396f7068 100644
--- a/server/drivers/chat-mcp-tools.test.ts
+++ b/server/drivers/chat-mcp-tools.test.ts
@@ -497,14 +497,16 @@ describe("Chat MCP session", () => {
const client = new ChatMcpClient(f.server, false, true, "audit");
const id = method === "initialize" ? 1 : 2;
const write = vi.spyOn(spawned.at(-1)!.stdin!, "write");
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
try {
- await expect(client.tools(f.controller.signal, undefined, budget)).rejects.toThrow(new RegExp(
- `^MCP startup timed out.*"audit".*${method}.*request ${id}.*startup budget ${budget}ms.*request budget \\d+ms.*pipe write completed.*matching response absent.*request elapsed \\d+ms.*cleanup confirmed in \\d+ms`,
- ));
+ await expect(client.tools(f.controller.signal, undefined, budget)).rejects.toThrow(/^MCP startup timed out$/);
+ expect(warn).toHaveBeenCalledWith(expect.stringMatching(new RegExp(
+ `^chat-mcp: "audit" startup failed: MCP startup timed out \\(${method} request ${id}, startup budget ${budget}ms, request budget \\d+ms, pipe write completed, matching response absent, request elapsed \\d+ms, cleanup confirmed in \\d+ms\\)$`,
+ )));
const cancels = write.mock.calls.map(([chunk]) => JSON.parse(String(chunk))).filter((frame) => frame.method === "notifications/cancelled");
expect(cancels.map((frame) => frame.params.requestId)).toEqual(method === "initialize" ? [] : [id]);
expect(alive(f.read().pid)).toBe(false);
- } finally { write.mockRestore(); await client.close(); }
+ } finally { write.mockRestore(); warn.mockRestore(); await client.close(); }
});
});
@@ -600,7 +602,7 @@ describe("Chat MCP session", () => {
const session = await mountChatTools({ composio: refused.server, custom: { ready: ready.server } }, ready.controller.signal);
sessions.push(session);
expect(session.definitions.map((definition) => definition.function.name)).toEqual(["ready_write"]);
- expect(session.skipped).toEqual([{ server: "composio", reason: expect.stringContaining('MCP server refused the startup request (server "composio", tools/list request 2') }]);
+ expect(session.skipped).toEqual([{ server: "composio", reason: expect.stringContaining("MCP request failed") }]);
expect(warn).toHaveBeenCalledWith(expect.stringContaining(`"composio"`));
await vi.waitFor(() => expect(alive(refused.read().pid)).toBe(false));
expect(alive(ready.read().pid)).toBe(true);
@@ -825,7 +827,7 @@ describe("Chat MCP shutdown verdict", () => {
killProbe.budgets.length = 0;
});
- it("preserves a startup refusal through unconfirmed cleanup without upstream error text", async () => {
+ it("keeps a startup refusal through unconfirmed cleanup, without upstream error text, and logs the phase", async () => {
const f = fixture(`if (message.method === "tools/list") {
process.stderr.write("private stderr fixture\\n");
send({jsonrpc:"2.0",id:message.id,error:{code:-32602,message:"private upstream fixture"}});
@@ -835,10 +837,10 @@ describe("Chat MCP shutdown verdict", () => {
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
try {
const session = await f.mount();
- expect(session.skipped).toEqual([{ server: "audit", reason: expect.stringMatching(
- /MCP server refused the startup request.*server "audit".*tools\/list request 2.*matching response received.*cleanup unconfirmed in \d+ms/,
- ) }]);
- expect(session.skipped[0]!.reason).not.toMatch(/private|-32602/);
+ expect(session.skipped).toEqual([{ server: "audit", reason: expect.stringContaining("MCP request failed") }]);
+ expect(session.skipped[0]!.reason).not.toMatch(/private|tools\/list request 2/);
+ expect(warn).toHaveBeenCalledWith(expect.stringMatching(/"audit" startup failed: MCP request failed.*tools\/list request 2.*matching response received.*cleanup unconfirmed in \d+ms/));
+ expect(warn.mock.calls.flat().join("\n")).not.toMatch(/private/);
expect(alive(f.read().pid)).toBe(false);
} finally { warn.mockRestore(); }
});
diff --git a/server/drivers/chat-mcp-tools.ts b/server/drivers/chat-mcp-tools.ts
index 167a0800bf..a653b0a41c 100644
--- a/server/drivers/chat-mcp-tools.ts
+++ b/server/drivers/chat-mcp-tools.ts
@@ -155,7 +155,6 @@ export class ChatMcpClient {
private closing?: Promise<void>;
private failure?: string;
private cleanup?: { elapsed: number; stopped: boolean };
- private listed = false;
private stderrTail = "";
private readonly configured: string[];
private readonly label: string;
@@ -179,7 +178,7 @@ export class ChatMcpClient {
this.child.on("error", () => this.fail(new Error("MCP server could not start; check its command and installation")));
// "close" follows the last of its output, so what it said on the way out is read first; a helper still holding stderr doesn't hold this up.
this.child.on("exit", () => {
- const stop = () => this.fail(new Error(`MCP server exited before the session closed.${this.listed ? this.lastWords() : ""}`));
+ const stop = () => this.fail(new Error(`MCP server exited before the session closed.${this.lastWords()}`));
this.child.once("close", stop);
setTimeout(stop, 200).unref();
});
@@ -313,12 +312,13 @@ export class ChatMcpClient {
const atFailure = writeState;
await this.close().catch(() => {});
if (startupMs === undefined || !(error instanceof Error)) throw error;
+ // The phase goes to the server log; the person and the model keep the short reason.
const { elapsed: cleanupMs, stopped } = this.cleanup!;
- const reason = error instanceof McpRequestRefused ? "MCP server refused the startup request" : error.message;
- throw new Error(`${reason} (server ${JSON.stringify(this.label)}, ${method} request ${id}, ` +
+ console.warn(`chat-mcp: "${this.label}" startup failed: ${error.message} (${method} request ${id}, ` +
`startup budget ${startupMs}ms, request budget ${timeout}ms, pipe write ${atFailure}, ` +
`matching response ${matched ? "received" : "absent"}, request elapsed ${elapsed}ms, ` +
`cleanup ${stopped ? "confirmed" : "unconfirmed"} in ${cleanupMs}ms)`);
+ throw error;
}
}
@@ -349,10 +349,7 @@ export class ChatMcpClient {
observer?.listed(result);
tools.push(...result.tools.filter((tool) => modelVisible(tool) && include(tool)));
if (tools.length > SERVER_TOOLS_MAX) throw new Error(`MCP server offers more than ${SERVER_TOOLS_MAX} tools`);
- if (result.nextCursor === undefined) {
- this.listed = true;
- return tools;
- }
+ if (result.nextCursor === undefined) return tools;
if (typeof result.nextCursor !== "string" || !result.nextCursor || cursors.has(result.nextCursor)) throw new Error("MCP tools/list returned an invalid pagination cursor");
cursors.add(result.nextCursor);
cursor = result.nextCursor;