Skip to content

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

fix(chat): give the required agents server 20 seconds to start on every desktop

AdityaUmale7779df6625e8
diff --git a/server/drivers/chat-mcp-tools.test.ts b/server/drivers/chat-mcp-tools.test.ts
index f3f4c105f4..e2d53b5fae 100644
--- a/server/drivers/chat-mcp-tools.test.ts
+++ b/server/drivers/chat-mcp-tools.test.ts
@@ -6,7 +6,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import { augmentedPath } from "../env-path.ts";
import { MESSAGE_FILE_MAX_BYTES } from "../message-file.ts";
import { Ajv2020 } from "ajv/dist/2020.js";
-import { ChatMcpClient, ChatToolSessionError, SAVED_RESULTS_FOLDER, SAVED_RESULTS_KEPT, chatToolNotices, directServers, joinLateChatTools, mcpStartupMs, mountChatTools, trimmedToolsNotice, type ChatToolDefinition, type ChatToolSession } from "./chat-mcp-tools.ts";
+import { ChatMcpClient, ChatToolSessionError, SAVED_RESULTS_FOLDER, SAVED_RESULTS_KEPT, agentsStartupMs, chatToolNotices, directServers, joinLateChatTools, mcpStartupMs, mountChatTools, trimmedToolsNotice, type ChatToolDefinition, type ChatToolSession } from "./chat-mcp-tools.ts";
import { EXECUTOR_LIKE_TOOLS } from "../testing/executor-like-tools.ts";
import type { ToolScope } from "../../shared/tool-scope.ts";
import type { SendTurnInput } from "../contracts.ts";
@@ -457,6 +457,13 @@ describe("Chat MCP session", () => {
expect(mcpStartupMs({}, "linux")).toBe(8_000);
});
+ it("gives the agents server twenty seconds on every desktop and never less than a Cloud home's half minute", () => {
+ expect(agentsStartupMs({}, "darwin")).toBe(20_000);
+ expect(agentsStartupMs({}, "linux")).toBe(20_000);
+ expect(agentsStartupMs({}, "win32")).toBe(20_000);
+ expect(agentsStartupMs({ OMB_CLOUD_ROLE: "home" }, "linux")).toBe(30_000);
+ });
+
// tools/list needs a budget that outlasts the child's own start, or the overrun would land in initialize.
it.each([["initialize", 150], ["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; }`);
@@ -1142,6 +1149,24 @@ describe("Chat MCP startup budgets", () => {
}
});
+ it("keeps waiting for a slow agents server past the eight seconds other servers get", async () => {
+ vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
+ try {
+ // Lists its tools only once the test says so, like an agents server still loading on a busy older Mac.
+ const f = fixture(`if (message.method === "tools/list") { const wait = setInterval(() => { if (!existsSync(receipt + ".go")) return; clearInterval(wait);
+ reply(message, {tools:[{name:"write",description:"Fixture write",inputSchema:schema}]}); }, 20); continue; }`);
+ const mounting = watch(mountChatTools({ agents: f.server } as SendTurnInput["integrations"], f.controller.signal));
+ const listed = () => { try { return f.read().calls.some((call) => call.method === "tools/list"); } catch { return false; } };
+ await untilReal(listed);
+ await vi.advanceTimersByTimeAsync(17_000);
+ writeFileSync(`${f.receipt}.go`, "");
+ await untilReal(() => mounting.done);
+ expect(mounting.error).toBeUndefined();
+ sessions.push(mounting.value!);
+ expect(mounting.value!.definitions.map((definition) => definition.function.name)).toEqual(["agents_write"]);
+ } finally { vi.useRealTimers(); }
+ });
+
it("still gives a configured command server 8 seconds, on Windows too", async () => {
vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
try {
diff --git a/server/drivers/chat-mcp-tools.ts b/server/drivers/chat-mcp-tools.ts
index af29a769aa..b695013e8c 100644
--- a/server/drivers/chat-mcp-tools.ts
+++ b/server/drivers/chat-mcp-tools.ts
@@ -78,6 +78,8 @@ const STARTUP_MS = 8_000;
const CLOUD_STARTUP_MS = 30_000;
/** Windows starts each of the app's built-ins as its own Electron process, all at once, and scans each new executable first. */
const WINDOWS_BUILT_IN_STARTUP_MS = 20_000;
+/** A turn can't run without the agents server, so a slow computer (an older Intel Mac) gets this long for it everywhere. */
+const AGENTS_STARTUP_MS = 20_000;
const STARTUP_TIMED_OUT = "MCP startup timed out";
const REQUEST_TIMED_OUT = "MCP request timed out; execution outcome may be uncertain";
/** How much of a server's stderr is kept, and how much of its last line is ever shown. */
@@ -91,7 +93,12 @@ export function mcpStartupMs(env: Record<string, string | undefined> = process.e
return cloudRole(env) ? CLOUD_STARTUP_MS : builtIn && platform === "win32" ? WINDOWS_BUILT_IN_STARTUP_MS : STARTUP_MS;
}
-/** `startupMs` replaces both mcpStartupMs budgets, `hostComputerMs` hostComputerStartupMs. `notice` hears, for the person,
+/** How long the agents server gets to start: never less than the app's other servers. */
+export function agentsStartupMs(env: Record<string, string | undefined> = process.env, platform: NodeJS.Platform = process.platform): number {
+ return Math.max(mcpStartupMs(env, platform), AGENTS_STARTUP_MS);
+}
+
+/** `startupMs` replaces every command server's startup budget (mcpStartupMs, agentsStartupMs), `hostComputerMs` hostComputerStartupMs. `notice` hears, for the person,
* that this computer's tools did not start, worded once per `conversation`. With `background` and the agents server, setup
* waits only for the built-ins a turn acts through (agents, a computer, the browser); the rest are listed by `join` once
* started. `onSettled` hears each server's name once it has listed its tools or failed. */
@@ -557,6 +564,7 @@ export async function mountChatTools(integrations: SendTurnInput["integrations"]
const mustHave = (descriptor: Server) => descriptor === agentsServer || (descriptor === integrations?.localComputer && integrations?.localComputer?.scope !== "local-computer");
const startupMs = options.startupMs ?? mcpStartupMs();
const configuredStartupMs = options.startupMs ?? mcpStartupMs(process.env, process.platform, false);
+ const agentsMs = options.startupMs ?? agentsStartupMs();
const hostComputerMs = Math.max(startupMs, options.hostComputerMs ?? hostComputerStartupMs());
let standIn: { definition: ChatToolDefinition; origin: ToolOrigin; ready?: Promise<unknown[]>; reason?: string } | undefined;
const builtIns = servers.length;
@@ -770,7 +778,7 @@ export async function mountChatTools(integrations: SendTurnInput["integrations"]
const host: HostComputerStart | undefined = hostComputer
? await startHostComputer(hostComputerKey(descriptor), (record) => client.tools(signal, record, hostComputerMs), include, { quickMs: Math.min(startupMs, HOST_COMPUTER_QUICK_MS), firstMs: startupMs }, signal)
: undefined;
- const budgetMs = searchable.has(name) ? REMOTE_MCP_STARTUP_MS : index < builtIns ? startupMs : configuredStartupMs;
+ const budgetMs = searchable.has(name) ? REMOTE_MCP_STARTUP_MS : index < builtIns ? (descriptor === agentsServer ? agentsMs : startupMs) : configuredStartupMs;
const tools = host ? (host.state === "listed" || host.state === "pending" ? host.tools : []) : await client.tools(signal, include, budgetMs, observers.get(name));
if (!tools.length && scope === undefined && descriptor === integrations?.localComputer && (!host || host.state === "listed")) throw new Error("The Local VM listed no tools");
// Harness mounts are known by descriptor, never by a name a configured server could claim. A grant