Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Keep a bot's engine between turns when it works on a cloud computer (#6633)
Milind Soni995ee2cb0353
diff --git a/server/cloud-computer-lazy.e2e.test.ts b/server/cloud-computer-lazy.e2e.test.tsindex e5473481c7..a602d04f00 100644--- a/server/cloud-computer-lazy.e2e.test.ts+++ b/server/cloud-computer-lazy.e2e.test.ts@@ -292,6 +292,29 @@ describe("a cloud computer starts only when the bot uses it", () => {await apiOk("DELETE", `/api/bots/${bot.id}`);}, 30_000);+ it("a second turn on Cloud computer runs in the engine the first one started, and its tools answer only while a turn runs", async () => {+ const bot = await cloudBot("Returner");+ const first = await startTurn(bot.id, "hi");+ await finish(bot.id);+ expect((await computerCall(first, "tools/list")).status).toBe(401);+ const second = await startTurn(bot.id, "again");+ expect(second.pid).toBe(first.pid);+ expect((await computerCall(first, "tools/list")).body.result.tools.map((tool: { name: string }) => tool.name)).toContain("screenshot");+ await finish(bot.id);+ expect((await computerCall(first, "tools/list")).status).toBe(401);+ // A stop ends the engine and the credential with it: the next turn starts its own, with a new one.+ const third = await startTurn(bot.id, "once more");+ expect(third.pid).toBe(first.pid);+ await apiOk("POST", `/api/bots/${bot.id}/interrupt`, { threadId: bot.threadId });+ await idle(bot.id);+ const fourth = await startTurn(bot.id, "after the stop");+ expect(fourth.pid).not.toBe(first.pid);+ expect(fourth.mcpConfig.mcpServers.computer.env.OMB_MCP_TOKEN_COMPUTER).not.toBe(first.mcpConfig.mcpServers.computer.env.OMB_MCP_TOKEN_COMPUTER);+ expect((await computerCall(first, "tools/list")).status).toBe(401);+ await finish(bot.id);+ await apiOk("DELETE", `/api/bots/${bot.id}`);+ }, 60_000);+it("a room message to a member on Cloud computer makes no relay call either", async () => {const bot = await cloudBot("Room member");const { group } = await apiOk("POST", "/api/groups", { name: "Lazy room", memberIds: [bot.id] });diff --git a/server/index.ts b/server/index.tsindex 06497477bb..8bd19b1db9 100644--- a/server/index.ts+++ b/server/index.ts@@ -1684,7 +1684,7 @@ function mintInternalCapability(capability: Omit<InternalCapability, "orphanExpiif (activeInternalGenerationByThread.get(capability.threadId) !== capability.generation) {throw new Error("cannot mint an integration capability for an inactive turn");}- // perTurn: a machine stopped between turns needs a fresh engine, which a new bearer forces.+ // perTurn: an engine whose own process bridges into a machine that can stop between turns needs a fresh start, which a new bearer forces.const token = perTurn ? randomBytes(24).toString("hex") : sessionBearer(capability);// Minted twice in one turn: keep that turn's record and its counters.if (internalCapabilities.get(token)?.generation !== capability.generation) {@@ -2478,7 +2478,7 @@ function controlIntegration(skillAuthoring: false,createdBots: 0,openedThreads: 0,- }, { perTurn: machine !== "this computer" }),+ }, { perTurn: machine !== "this computer" && boxId === undefined }), // a cloud computer's tools are served here per call: nothing in the engine goes stale with the machine};}