Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Train K1: name the MCP startup phase on the existing skip line
milind-soni891d7e38392a
diff --git a/server/drivers/chat-mcp-tools.test.ts b/server/drivers/chat-mcp-tools.test.tsindex e7396f7068..97f28d867b 100644--- a/server/drivers/chat-mcp-tools.test.ts+++ b/server/drivers/chat-mcp-tools.test.ts@@ -494,19 +494,18 @@ describe("Chat MCP session", () => {// tools/list needs a budget that outlasts the child's own start, or the overrun would land in initialize.it.each([["initialize", 1_000], ["tools/list", 2_500]] as const)("reports an overrun in %s as a startup timeout, not as a request whose outcome is uncertain", async (method, budget) => {const f = fixture(`if (message.method === "${method}") { return; }`);- const client = new ChatMcpClient(f.server, false, true, "audit");+ const client = new ChatMcpClient(f.server, false, true);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(/^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\\)$`,- )));+ expect(client.startupPhase).toMatch(new RegExp(+ `^${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(); warn.mockRestore(); await client.close(); }+ } finally { write.mockRestore(); await client.close(); }});});@@ -839,7 +838,7 @@ describe("Chat MCP shutdown verdict", () => {const session = await f.mount();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).toHaveBeenCalledWith(expect.stringMatching(/skipping MCP server "audit" for this turn: 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.tsindex a653b0a41c..2ea38b695b 100644--- a/server/drivers/chat-mcp-tools.ts+++ b/server/drivers/chat-mcp-tools.ts@@ -157,12 +157,12 @@ export class ChatMcpClient {private cleanup?: { elapsed: number; stopped: boolean };private stderrTail = "";private readonly configured: string[];- private readonly label: string;+ /** Where a failed start stopped, for the log line that reports it. */+ startupPhase?: string;private pending = new Map<number, { method: string; cancel(): void; resolve(value: unknown): void; reject(error: Error, matched?: boolean): void }>();/** `configured`: a server the person set up, whose own environment passes the bot box as theirs. */- constructor(server: Server, computerUse = false, configured = false, label = "computer") {- this.label = label;+ constructor(server: Server, computerUse = false, configured = false) {this.frameBytes = computerUse ? 32 * 1024 * 1024 : FRAME_BYTES;this.configured = Object.values(server.env).filter((value) => value.length >= 6);try {@@ -312,12 +312,10 @@ 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.+ // Where startup stopped is for the server log; the person and the model keep the short reason.const { elapsed: cleanupMs, stopped } = this.cleanup!;- 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)`);+ this.startupPhase = `${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;}}@@ -689,7 +687,7 @@ export async function mountChatTools(integrations: SendTurnInput["integrations"]const skip = async (server: string, error: unknown, client = started.get(server)) => {const reason = error instanceof Error ? error.message : "MCP server failed to start";skipped.push({ server, reason });- console.warn(`chat-mcp: skipping MCP server "${server}" for this turn: ${reason}`);+ console.warn(`chat-mcp: skipping MCP server "${server}" for this turn: ${reason}${client?.startupPhase ? ` (${client.startupPhase})` : ""}`);await client?.close();};const offeredTools: Array<{ origin: ToolOrigin; tools: CheckedTool[] }> = [];@@ -777,7 +775,8 @@ export async function mountChatTools(integrations: SendTurnInput["integrations"]if (host?.state === "starting" || host?.state === "failed") {const reason = host.state === "failed" ? host.reason : undefined;if (reason !== undefined) {- console.warn(`chat-mcp: this computer's tools did not start for this turn: ${reason}`);+ const phase = mount.value.origin.client.startupPhase;+ console.warn(`chat-mcp: this computer's tools did not start for this turn: ${reason}${phase ? ` (${phase})` : ""}`);options.notice?.(hostComputerNotice(options.conversation, reason));await mount.value.origin.client.close().catch(() => {});}@@ -798,7 +797,7 @@ export async function mountChatTools(integrations: SendTurnInput["integrations"]// Concurrent starts, consumed in config order so names and collision suffixes stay stable.const mounts = servers.map(async ([name, descriptor], index): Promise<Mounted> => {if (signal.aborted || closed) throw aborted();- const client = new ChatMcpClient(descriptor, computerUse, index >= builtIns, name);+ const client = new ChatMcpClient(descriptor, computerUse, index >= builtIns);clients.push(client);started.set(name, client);startedAt[index] = client;