Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Main green: routines, connector and Windows tests after today's merges (#6231)
Milind Soni676c29f63c40
diff --git a/connector/test/agent.test.ts b/connector/test/agent.test.tsindex 67e2344223..1d74a7cc82 100644--- a/connector/test/agent.test.ts+++ b/connector/test/agent.test.ts@@ -243,8 +243,11 @@ describe("the connector's connection to MausBot", () => {admin.drop();await until(() => Object.keys(record.current.adminKeys).length === 2);admin.signingKid = "k2";+ // Counted from here, and with the Admin's own side open: on a slow runner the agent can still read its dropped+ // connection as open, or have reconnected once more before this drop.+ const before = admin.connections.length;admin.drop();- await until(() => admin.connections.length === 3 && agent.connected);+ await until(() => admin.connections.length > before && admin.connected && agent.connected);expect((await admin.job("host-health", {})).ok).toBe(true);});diff --git a/server/bot-link/link.test.ts b/server/bot-link/link.test.tsindex 96da8acb2a..766def49ac 100644--- a/server/bot-link/link.test.ts+++ b/server/bot-link/link.test.ts@@ -791,7 +791,9 @@ describe("the link between a computer and its Cloud", () => {expect(cloud.runs).toEqual([]);await cloud.listen(cloud.port);computer.dialer.start();- await until(() => computer.said(room.id).length === 4, "the answer is in the room");+ // Waits for the answer itself: on a slow runner the computer's 400 ms stall clock can add a line before it.+ await until(() => computer.said(room.id).some((line) => line.startsWith("Analyst: ")), "the answer is in the room");+ expect(computer.said(room.id).slice(0, 3)).toEqual(["Sam: @Analyst how many orders this week?", "(server.rooms.linkedAway Analyst [My Cloud])", "Sam: @Analyst and split them by country."]);const turns = cloud.runs.filter((run) => run.botId === "cloud-analyst");expect(turns).toHaveLength(1);expect(turns[0]!.text).toContain("Sam: @Analyst how many orders this week?\nSam: @Analyst and split them by country.");diff --git a/server/browser-room.ts b/server/browser-room.tsindex 6284d4a6c9..7a06e3d5a4 100644--- a/server/browser-room.ts+++ b/server/browser-room.ts@@ -1,5 +1,6 @@import { readFileSync } from "node:fs";-import { dirname, join } from "node:path";+// cgroup paths are POSIX paths on every platform this reads them, and in tests run on Windows.+import { posix } from "node:path";import { boxMemory } from "./box-memory.ts";/** One open browser with one page in the server image (Chromium 156, agent-browser 0.37.0): 13 processes, about 160@@ -17,8 +18,8 @@ const readText: Read = (path) => { try { return readFileSync(path, "utf8"); } ca/** The tightest `pids.max` from `at` up to the hierarchy's root under `root`. */function tightest(read: Read, root: string, from: string): number | null {let limit: number | null = null;- for (let at = from.trim(); ; at = dirname(at)) {- const value = Number(read(join(root, at, "pids.max"))?.trim());+ for (let at = from.trim(); ; at = posix.dirname(at)) {+ const value = Number(read(posix.join(root, at, "pids.max"))?.trim());if (Number.isInteger(value) && value > 0) limit = Math.min(limit ?? value, value);if (at === "/" || at === ".") return limit;}diff --git a/server/host/chief-incident-spend.test.ts b/server/host/chief-incident-spend.test.tsindex 80a0d71042..c3de079e4e 100644--- a/server/host/chief-incident-spend.test.ts+++ b/server/host/chief-incident-spend.test.ts@@ -147,11 +147,13 @@ describe("a routine every 5 minutes whose tool server is dead, for a day", () =>});describe("a routine every 5 minutes on a server whose engines cannot start, for a day", () => {- it("tries 9 starts and starts 2 Chief turns", async () => {+ // 9 runs, each started once more 30 s later while it waits for room (#6179); nothing reaches the AI until one starts.+ it("tries 18 starts in 9 runs and starts 2 Chief turns", async () => {const w = world(1, spawnRefused, true);await w.passTo(START + 24 * HOUR);console.log(`requests in 24 hours: ${w.routineTurns.length} routine starts tried + ${w.chiefTurns.length} Chief turns`);- expect(w.routineTurns).toHaveLength(9);+ expect(w.routineTurns).toHaveLength(18);+ expect(new Set(w.routineTurns).size).toBe(9);expect(w.chiefTurns).toHaveLength(2);});});diff --git a/server/index.ts b/server/index.tsindex fdbb518d56..804da32de5 100644--- a/server/index.ts+++ b/server/index.ts@@ -12111,7 +12111,7 @@ ROUTES.push(createThreadRoutes({})); offerAttachmentClear(!CLOUD_TEAM);ROUTES.push(createBotCreateRoutes({store, cfg, presetStore, orgInstallStatuses,- hostedWorkspace: HOSTED_WORKSPACE, hostedFullAccessRefusal: HOSTED_FULL_ACCESS_REFUSAL, desktopManaged: DESKTOP_MANAGED, newBotComputer: (selection) => newBotWorksOn({ desktopApp: DESKTOP_MANAGED && !CLOUD_HOME && !HOSTED_WORKSPACE, platform: process.platform, providerSupportsLocal: registry.get(selection.instanceId)?.adapter.capabilities.localComputerMcp === true }),+ hostedWorkspace: HOSTED_WORKSPACE, hostedFullAccessRefusal: HOSTED_FULL_ACCESS_REFUSAL, desktopManaged: DESKTOP_MANAGED, newBotComputer: (selection) => newBotWorksOn({ desktopApp: DESKTOP_MANAGED && !CLOUD_HOME && !HOSTED_WORKSPACE && desktopComputer.connection() !== null, platform: process.platform, providerSupportsLocal: registry.get(selection.instanceId)?.adapter.capabilities.localComputerMcp === true }),maxWorkspaceBots: MAX_WORKSPACE_BOTS, paused: (botId) => starterAwake.isPaused(botId), cloudOwnerKey: CLOUD_OWNER_KEY,hostedModels, cloudRoutineAuthors,routines: () => routines,diff --git a/server/local-routing.ts b/server/local-routing.tsindex ef17a1a6ea..2a5f228f76 100644--- a/server/local-routing.ts+++ b/server/local-routing.ts@@ -3,7 +3,9 @@ const HOSTS_WITH_AUTO_LOCAL = new Set<NodeJS.Platform>(["darwin", "win32"]);/** Where a new bot works when nothing names a place. On the desktop app on a Mac or a Windows PC, with a model that can use* it: This computer, so a request for the person's own files or apps needs no switch first. Everywhere else (a Cloud,- * a hosted workspace, a server, Linux, where This computer is the server or needs turning on): Auto, as before. */+ * a hosted workspace, a server, Linux, where This computer is the server or needs turning on): Auto, as before.+ * `desktopApp` holds only while the app has handed this server its computer's driver: without it every turn on This+ * computer would fail, and Auto picks This computer by itself once the driver is there. */export function newBotWorksOn(input: { desktopApp: boolean; platform: NodeJS.Platform; providerSupportsLocal: boolean }): "local" | undefined {return input.desktopApp && shouldMountLocalComputer({ requested: undefined, hostPlatform: input.platform, providerSupportsLocal: input.providerSupportsLocal })? "local" : undefined;diff --git a/server/routine-failure-spacing.test.ts b/server/routine-failure-spacing.test.tsindex 592744870f..8dd8911c45 100644--- a/server/routine-failure-spacing.test.ts+++ b/server/routine-failure-spacing.test.ts@@ -157,11 +157,15 @@ describe("a routine every minute by cron whose tool server is dead", () => {});describe("a routine every 5 minutes on a server whose engines cannot start", () => {- it("tries 9 starts in its first day instead of two at every occurrence, and never a second start on the same full server", async () => {+ // Each of the 9 runs waits once for room (#6179) and then fails with the refusal, instead of a spawn every 30 s for an hour.+ it("tries 9 runs in its first day, each started once more 30 s later for room and no more, never its retry", async () => {const h = harness(async () => { throw new Error(SPAWN_REFUSED); });await h.passTo(START + 24 * HOUR, () => {});console.log(`engine starts tried in 24 hours on a server that cannot start one: ${h.started.length}`);- expect(h.started).toHaveLength(9);+ expect(h.started).toHaveLength(18);+ const perThread = new Map<string, number>();+ for (const turn of h.started) perThread.set(turn.threadId, (perThread.get(turn.threadId) ?? 0) + 1);+ expect([...perThread.values()]).toEqual(Array(9).fill(2));expect(h.routine()).toMatchObject({ enabled: true });expect(h.rows().filter((run) => run.status === "failed").every((run) => run.retried === undefined && run.error === SPAWN_REFUSED)).toBe(true);});diff --git a/server/routine-recovery.ts b/server/routine-recovery.tsindex 9fc1c55c0e..57775f3f5a 100644--- a/server/routine-recovery.ts+++ b/server/routine-recovery.ts@@ -218,10 +218,16 @@ export function recoverRun(run: RoutineRun, failure: string, facts: RoutineFailureturn { queued: false, error: line.text, ...(alert === undefined ? {} : { alert }) };};if (verdict.kind === "busy") {+ // A server with no room to start the run's engine is waited for once, 30 s, behind the server's own wait for room; a+ // second refusal fails the run with it. Each recheck is a real spawn, unlike a busy bot's, so a server that stays full+ // is not asked for a process every 30 s for an hour, and the routine's failure spacing counts the run at once.+ const noRoom = outOfProcesses(failure);+ if (noRoom && run.roomWaited) return failed(again);+ if (noRoom) run.roomWaited = true;run.deferredAt ??= now;// A run of checked items waits as long as its bot is busy with the person, which is not a failure; a server with no room// to start it is held to the same hour as any other run.- if (now - run.deferredAt >= ROUTINE_BUSY_WAIT_MS && (run.checkKey === undefined || outOfProcesses(failure))) return failed(codedLine("error", "routines.server.stillBusy", { minutes: ROUTINE_BUSY_WAIT_MS / 60_000, failure }));+ if (now - run.deferredAt >= ROUTINE_BUSY_WAIT_MS && (run.checkKey === undefined || noRoom)) return failed(codedLine("error", "routines.server.stillBusy", { minutes: ROUTINE_BUSY_WAIT_MS / 60_000, failure }));run.status = "queued";run.retryAt = now + ROUTINE_BUSY_RECHECK_MS;attend(run, codedLine("attention", "routines.server.waitingToStart", { failure }));diff --git a/server/routines.ts b/server/routines.tsindex fa344a281c..6e0454ddd7 100644--- a/server/routines.ts+++ b/server/routines.ts@@ -114,6 +114,8 @@ export interface RoutineRun extends RoutineLineCodes, RoutineOwnerMark {status: RoutineRunStatus;manual: boolean;deferredAt?: number;+ /** Set when the run waited once because the server had no room to start its engine (routine-recovery.ts). */+ roomWaited?: true;deferredNoticeAt?: number;/** How long a scheduled run has been seen queued behind its bot's other work, added up pass by pass (routine-bounds.ts `busyWait`). */busyMs?: number;