Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix: recheck reset permission on every try; no reset during workspace maintenance
AdityaUmalef3227a25f186
diff --git a/server/host/cloud-computer-reset-asks.test.ts b/server/host/cloud-computer-reset-asks.test.tsindex 330cd1af27..21a49ca2af 100644--- a/server/host/cloud-computer-reset-asks.test.ts+++ b/server/host/cloud-computer-reset-asks.test.ts@@ -135,6 +135,35 @@ describe("a bot asking for its cloud computer to be reset", () => {expect((await call(chief, { targetBotId: "nobody" })).status).toBe(404);});+ it("checks again on Allow and on every retry whether the bot may still ask, and resets nothing once it may not", async () => {+ let allowed = true;+ const { asks, call, card, reset, flush } = setup({ refusal: () => allowed ? null : "Ada has no cloud computer of its own to reset here." });+ await call(ada, {});+ allowed = false;+ asks.answer(card()!.requestId, "allow");+ await flush();+ expect(reset).not.toHaveBeenCalled();+ expect(card()?.subtitle).toContain("Not reset: Ada has no cloud computer of its own to reset here.");++ let busy = true;+ allowed = true;+ const retry = setup({+ refusal: () => allowed ? null : "not yours",+ reset: async () => { if (busy) throw Object.assign(new Error("this cloud computer is in use — stop its bot's work first"), { status: 409 }); return { ok: true }; },+ });+ await retry.call(chief, { targetBotId: "bot-a" });+ retry.asks.answer(retry.card()!.requestId, "allow");+ await retry.flush();+ expect(retry.reset).toHaveBeenCalledTimes(1);+ allowed = false;+ busy = false;+ retry.timers.shift()!();+ await retry.flush();+ expect(retry.reset).toHaveBeenCalledTimes(1);+ expect(retry.timers).toHaveLength(0);+ expect(retry.card()?.subtitle).toContain("Not reset: not yours");+ });+it("needs a reason, and shows no card without one", async () => {const { call, card, computer } = setup();for (const why of [undefined, "", " "]) {diff --git a/server/host/cloud-computer-reset-asks.ts b/server/host/cloud-computer-reset-asks.tsindex a232890802..a2e8885fda 100644--- a/server/host/cloud-computer-reset-asks.ts+++ b/server/host/cloud-computer-reset-asks.ts@@ -17,7 +17,7 @@ export const RESET_RETRIES = 36;const WHY_LIMIT = 300;type Reset = { ok: boolean; pending?: true; missing?: true };-type Ask = { threadId: string; messageId: string; targetId: string; targetName: string; subtitle: string; boxId: string | null };+type Ask = { threadId: string; messageId: string; fromId: string; targetId: string; targetName: string; subtitle: string; boxId: string | null };type Reply = { status: number; body: Record<string, unknown> };export interface CloudComputerResetAsksDeps {@@ -53,6 +53,10 @@ export function createCloudComputerResetAsks(deps: CloudComputerResetAsksDeps) {async function run(ask: Ask, tries: number): Promise<void> {try {+ // Who may ask can change while the card waits (a moved bot, another computer setting): checked again on every try.+ const from = store.bot(ask.fromId), target = store.bot(ask.targetId);+ const refused = !from || !target ? "the bot is gone" : deps.refusal(from, target);+ if (refused) { show(ask, words(ask.threadId, "server.cloudReset.failed", { reason: refused })); return; }const result = await deps.reset(ask.targetId, ask.boxId);const key = result.missing ? "server.cloudReset.missing" : result.pending ? "server.cloudReset.pending" : "server.cloudReset.done";show(ask, words(ask.threadId, key, { name: ask.targetName }));@@ -93,7 +97,7 @@ export function createCloudComputerResetAsks(deps: CloudComputerResetAsksDeps) {...(room ? { from: { botId: from.id, name: from.name, color: from.color } } : {}),card: { title: words(threadId, "server.cloudReset.title", { name: target.name }), subtitle, options: ["Allow", "Deny"], requestId, requestType: "permission", tool: RESET_CLOUD_COMPUTER_TOOL },});- asks.set(requestId, { threadId, messageId: message.id, targetId: target.id, targetName: target.name, subtitle, boxId });+ asks.set(requestId, { threadId, messageId: message.id, fromId: from.id, targetId: target.id, targetName: target.name, subtitle, boxId });const whose = target.id === from.id ? "your" : `${target.name}'s`;return { status: 200, body: { text: `A card asking the person to reset ${whose} cloud computer is now in this conversation. End this turn now and say in one line that it waits for them. On Allow the computer is deleted once ${target.name} is not working, and ${target.name}'s next turn makes a fresh one. You are not resumed: the card shows how it went.` } };}diff --git a/server/index.ts b/server/index.tsindex edc31970e2..8339343945 100644--- a/server/index.ts+++ b/server/index.ts@@ -9596,7 +9596,7 @@ const ROOM_POST_MAX_CHARS = 4_000;const approvalBus: YourComputerBus = { store, notify };// A bot's ask to reset a stuck cloud computer: its own, or as a Chief one of a bot it manages; Settings' reset on Allow.-const cloudComputerResets = createCloudComputerResetAsks({ language: threadLanguage, store, refusal: (from, target) => target.id !== from.id && !(chiefLevel(from) && canManage(from, target)) ? "You can ask to reset only your own cloud computer; a Chief of Staff can also ask for a bot in a department it manages." : !boat.boatConfigured(cfg) || target.computer !== "cloud" || target.cloudBackend === "vps" || inheritedTeamComputer(target) ? `${target.name} has no cloud computer of its own to reset here.` : null, computer: async (botId) => (await ownCloudComputer(cfg, botId, managedBoatOwners()))?.boxId ?? null, reset: async (botId, boxId) => { if (computerProviderConfigTransitions.has("box")) throw Object.assign(new Error(providerTransitionMessage("box")), { status: 409 }); if (boatLifecycleBusyBots.has(botId)) throw Object.assign(new Error("this bot's cloud computer is being changed — wait for it to finish"), { status: 409 }); return resetBotCloudComputer(cfg, botId, managedBoatOwners(), claimManagedBoatMutation, boxId); } });+const cloudComputerResets = createCloudComputerResetAsks({ language: threadLanguage, store, refusal: (from, target) => target.id !== from.id && !(chiefLevel(from) && canManage(from, target)) ? "You can ask to reset only your own cloud computer; a Chief of Staff can also ask for a bot in a department it manages." : !boat.boatConfigured(cfg) || target.computer !== "cloud" || target.cloudBackend === "vps" || inheritedTeamComputer(target) ? `${target.name} has no cloud computer of its own to reset here.` : null, computer: async (botId) => (await ownCloudComputer(cfg, botId, managedBoatOwners()))?.boxId ?? null, reset: async (botId, boxId) => { if (computerProviderConfigTransitions.has("box")) throw Object.assign(new Error(providerTransitionMessage("box")), { status: 409 }); if (boatLifecycleBusyBots.has(botId)) throw Object.assign(new Error("this bot's cloud computer is being changed — wait for it to finish"), { status: 409 }); return resetBotCloudComputer(cfg, botId, managedBoatOwners(), (instance) => { workspaceMaintenance.assertAvailable(); return claimManagedBoatMutation(instance); }, boxId); } });const { quotaSwitch, harnessCardOutcome } = createQuotaSwitchHost({ store, coordinator, registry, turnStops, hostedModels, providerConfigs, policyModelRefusal, checkedTaskModelSwitch, threadBusy, directRequestOwners, startOrQueueDirectMessage, takeover: limitTakeover, ownCards: (requestId, behavior) => (computerAsks?.asks.answer(requestId, behavior) ?? false) || cloudComputerResets.answer(requestId, behavior) });// Consent cards live only in memory: settle every card still open on disk, or it locks the composer forever.