Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Cloud computer: after a recovery wait, only look at the screen; keep the installation limit
milind-soni343a74d2ab36
diff --git a/server/boat-health.ts b/server/boat-health.tsindex 7211a07584..0a1d1024d3 100644--- a/server/boat-health.ts+++ b/server/boat-health.ts@@ -20,7 +20,7 @@ export const DEAD_COMPUTER = {/** And in a day, so a provider that keeps handing out broken computers cannot use up the plan's computers or hours. */replacementsPerDay: 3,/** And at most this many automatic deletes per installation in an hour, whoever's computers they are. */- installationDeletesPerHour: 3,+ installationDeletesPerHour: 1,/** The provider's `error` must be seen on two reads at least this far apart before a computer is deleted for it. */deadConfirmMs: process.env.OMB_CLOUD_COMPUTER_DEAD_CONFIRM_MS?.trim() ? Math.max(0, Number(process.env.OMB_CLOUD_COMPUTER_DEAD_CONFIRM_MS) || 0) : 30 * 60_000,/** At most one automatic restart per installation in this long. */diff --git a/server/boat-recovery.test.ts b/server/boat-recovery.test.tsindex ff873aae82..e5b135957f 100644--- a/server/boat-recovery.test.ts+++ b/server/boat-recovery.test.ts@@ -250,18 +250,20 @@ describe("a cloud computer the provider reports in error", () => {expect(deletes()).toHaveLength(2);});- it("is deleted by itself at most three times an hour for the whole installation, whoever's computers they are", async () => {- const dead = [await botWith("error"), await botWith("error"), await botWith("error"), await botWith("error")];- for (const { botId } of dead) await boat.findBoat(cfg, botId);- for (const { botId } of dead) await expect(boat.provisionBoat(cfg, botId, "Bot")).rejects.toThrow(words.CLOUD_COMPUTER_DEAD_WAITING);+ it("is deleted by itself at most once an hour for the whole installation, whoever's computer it is", async () => {+ const first = await botWith("error");+ const second = await botWith("error");+ await boat.findBoat(cfg, first.botId);+ await boat.findBoat(cfg, second.botId);+ await expect(boat.provisionBoat(cfg, first.botId, "Bot")).rejects.toThrow(words.CLOUD_COMPUTER_DEAD_WAITING);+ await expect(boat.provisionBoat(cfg, second.botId, "Bot")).rejects.toThrow(words.CLOUD_COMPUTER_DEAD_WAITING);at += DEAD_CONFIRM;- for (const { botId } of dead.slice(0, 3)) await expect(boat.provisionBoat(cfg, botId, "Bot")).rejects.toMatchObject({ code: journal.BOAT_DELETION_FINISHED });- const last = dead[3]!;- await expect(boat.provisionBoat(cfg, last.botId, "Bot")).rejects.toThrow(words.CLOUD_COMPUTER_NEEDS_PERSON);- expect(deletes().map((request) => request.headers["x-ascii-confirm-delete"])).toEqual(dead.slice(0, 3).map(({ box }) => box.id));+ await expect(boat.provisionBoat(cfg, first.botId, "Bot")).rejects.toMatchObject({ code: journal.BOAT_DELETION_FINISHED });+ await expect(boat.provisionBoat(cfg, second.botId, "Bot")).rejects.toThrow(words.CLOUD_COMPUTER_NEEDS_PERSON);+ expect(deletes().map((request) => request.headers["x-ascii-confirm-delete"])).toEqual([first.box.id]);at += 61 * 60_000;- await expect(boat.provisionBoat(cfg, last.botId, "Bot")).rejects.toMatchObject({ code: journal.BOAT_DELETION_FINISHED });- expect(deletes()).toHaveLength(4);+ await expect(boat.provisionBoat(cfg, second.botId, "Bot")).rejects.toMatchObject({ code: journal.BOAT_DELETION_FINISHED });+ expect(deletes()).toHaveLength(2);});it("finishes after a crash between the delete and the new computer, telling each side once", async () => {diff --git a/server/boat-recovery.ts b/server/boat-recovery.tsindex c576a800c7..5b62000e14 100644--- a/server/boat-recovery.ts+++ b/server/boat-recovery.ts@@ -88,8 +88,9 @@ type Dead = { boxId: string; name: string };type ReplaceOutcome = "confirmed" | "pending" | "kept" | "held" | "waiting" | "capped" | "failed";/** What became of a computer that was woken for a turn and stayed silent past the wake's patience. `answers`: a last probe- * got through after all. `gone`: it no longer exists, so the next start makes a new one. `off`: automatic replacement is- * switched off, so nothing was done. `kept`: it was left as it is, and `why` says so in a few words for the turn. */+ * got through after all. `gone`: it no longer exists, so the next start makes a new one. `off`: nothing was done, as+ * automatic replacement is switched off (or the computer answered moments ago), and the turn's wait fails as a passing+ * failure, as before. `kept`: it was left as it is, and `why` says so in a few words for the turn. */export type WakeTimeoutOutcome = { kind: "answers" | "replaced" | "gone" | "off" } | { kind: "kept"; why: string };const KEPT_WHY: Partial<Record<ReplaceOutcome | "unreachable", string>> = {@@ -424,7 +425,8 @@ export function createBoatRecovery(deps: BoatRecoveryDeps) {}deps.log(`cloud computer ${owner}: ${boxId} did not answer within ${Math.round(READY_WAIT.wakePatienceMs / 60_000)} minutes of waking; replacing it`);const outcome = await replace(owner, seen.identity, seen.identity.state === "error" ? { dead: true } : {});- return outcome === "confirmed" || outcome === "pending" ? { kind: "replaced" } : outcome === "kept" ? { kind: "answers" } : keptWhy(outcome);+ // "kept": it answered a command moments ago by the record, though not this probe; left as it is, as when switched off.+ return outcome === "confirmed" || outcome === "pending" ? { kind: "replaced" } : outcome === "kept" ? { kind: "off" } : keptWhy(outcome);}const unsubscribe = health.onNotResponding((boxId) => {@@ -512,6 +514,9 @@ export function createBoatRecovery(deps: BoatRecoveryDeps) {},/** A start the Admin turned away for computers at once, right after this owner's computer was replaced: the old one's* place is still being given back. */+ /** This owner's computer was replaced by itself in the last fifteen minutes: its turns may make the new one even+ * where they would never make a first one. */+ replacedRecently: (owner: string): boolean => entries.some((entry) => entry.owner === owner && !entry.manual && now() - entry.at < 15 * 60_000),claimSentence(owner: string, error: unknown): string | undefined {const recent = entries.some((entry) => entry.owner === owner && now() - entry.at < 15 * 60_000);return recent && cloudFailureOf(error).limit?.reason === "at_once" ? CLOUD_COMPUTER_NOT_RESPONDING : undefined;diff --git a/server/cloud-computer-tools.ts b/server/cloud-computer-tools.tsindex 8127ea1175..b2b4b6d6de 100644--- a/server/cloud-computer-tools.ts+++ b/server/cloud-computer-tools.ts@@ -13,7 +13,7 @@ import { controlRefusal, type ControlState } from "./control-client.ts";import { COMPUTER_COPY_BUDGET_MS, HARNESS_CALL_BUDGET_MS } from "./harness-budget.ts";import { compileToolSchema } from "./mcp-schema-validator.ts";import {- CLOUD_COMPUTER_ANSWER_LOST, CLOUD_COMPUTER_EXEC_ANSWER_LOST, CLOUD_COMPUTER_NO_ANSWER, CLOUD_COMPUTER_REPLACEMENT_STARTING, CLOUD_COMPUTER_STILL_RESTORING,+ CLOUD_COMPUTER_ANSWER_LOST, CLOUD_COMPUTER_ANSWERS_AGAIN, CLOUD_COMPUTER_EXEC_ANSWER_LOST, CLOUD_COMPUTER_NO_ANSWER, CLOUD_COMPUTER_REPLACEMENT_STARTING, CLOUD_COMPUTER_STILL_RESTORING,CLOUD_COMPUTER_STILL_WAKING, CLOUD_COMPUTER_UNREACHABLE,} from "../shared/cloud-computer-recovery.ts";@@ -66,6 +66,8 @@ const QUICK_CALL_MS = 25_000;* so the call itself, or the line that says to repeat it, still gets through. */const RECOVERY_WAIT_RESERVE_MS = 30_000;const COPY_TOOLS = new Set(["copy_from_computer", "copy_to_computer"]);+/** Calls that change nothing on the computer: the only ones made after the call waited out a restart or replacement. */+const LOOKS = new Set(["screenshot", "get_screen_size"]);export const cloudComputerCallBudgetMs = (name: unknown): number =>typeof name === "string" && COPY_TOOLS.has(name) ? COMPUTER_COPY_BUDGET_MS : HARNESS_CALL_BUDGET_MS;const quote = (value: string) => "'" + value.replace(/'/g, "'\\''") + "'";@@ -226,7 +228,10 @@ export async function cloudComputerRpc(return text ? { isError: true, content: [{ type: "text", text }] } : null;};let before = refused("before");+ let waited = false;+ let noticeOwed: string | null = null;if (before && deps.recovery?.settle) {+ waited = true;// A restart or replacement under way is waited for here, not refused at once: a bot refused straight away repeats// the call, is refused again, and gives up while its computer is still being brought back.const until = deadline - RECOVERY_WAIT_RESERVE_MS;@@ -242,6 +247,19 @@ export async function cloudComputerRpc(before = refused("before");}if (before) { deps.settled?.(false); return before; }+ if (waited) {+ // The computer came back, or was replaced, while this call waited: anything but a look at the screen is handed back+ // unperformed, as a call that waited through a person's hold is, and a look goes through the control gate again.+ const notice = deps.recovery?.notice(boxId);+ const again = LOOKS.has(String(params.name)) ? await deps.gate() : null;+ if (again?.held) return { isError: true, content: [{ type: "text", text: controlRefusal(again) }] };+ if (!again) {+ deps.settled?.(false);+ return { isError: true, content: [...(notice ? [{ type: "text" as const, text: notice }] : []), { type: "text", text: CLOUD_COMPUTER_ANSWERS_AGAIN }] };+ }+ deps.assertActive();+ if (notice) noticeOwed = notice;+ }const late = AbortSignal.timeout(Math.max(1, deadline - Date.now()));deps.disk?.began(deps.cfg, boxId);let result: CloudComputerResult;@@ -262,6 +280,6 @@ export async function cloudComputerRpc(if (unanswered) result = refused("after") ?? result;deps.settled?.(!unanswered);if (disk) result = { ...result, content: [...result.content, { type: "text", text: disk }] };- const notice = deps.recovery?.notice(boxId);+ const notice = noticeOwed ?? deps.recovery?.notice(boxId);return notice ? { ...result, content: [{ type: "text", text: notice }, ...result.content] } : result;}diff --git a/server/cloud-computer-wake.test.ts b/server/cloud-computer-wake.test.tsindex 2412322549..e6030bf2e9 100644--- a/server/cloud-computer-wake.test.ts+++ b/server/cloud-computer-wake.test.ts@@ -152,9 +152,9 @@ const ready = (bot: BotRecord) => power.ready(bot, turn(), {});const deletes = () => requests.filter((request) => request.method === "DELETE");const creates = () => requests.filter((request) => request.method === "POST" && request.path === "/boxes");-/** One computer call as the bot makes it, through the same route a turn's calls take. */-const call = (boxId: () => string, extra: Partial<Parameters<typeof tools.cloudComputerRpc>[1]> = {}) =>- tools.cloudComputerRpc({ method: "tools/call", params: { name: "exec", arguments: { command: "echo hi" } } }, {+/** One computer call as the bot makes it, through the same route a turn's calls take: by default an exec of `echo hi`. */+const call = (boxId: () => string, extra: Partial<Parameters<typeof tools.cloudComputerRpc>[1]> = {}, name = "exec") =>+ tools.cloudComputerRpc({ method: "tools/call", params: { name, arguments: name === "exec" ? { command: "echo hi" } : {} } }, {cfg, signal: new AbortController().signal, boxId, gate: async () => ({ held: false }), assertActive: () => {}, recovery, ...extra,});const ranEcho = () => requests.filter((request) => request.command?.includes("echo hi")).length;@@ -183,6 +183,7 @@ describe("a woken cloud computer that never answers", () => {expect(deletes().map((request) => request.path)).toEqual([`/boxes/${box.id}`]);expect(creates()).toHaveLength(1);expect(told).toEqual([[bot.id, "replaced"]]);+ expect(recovery.replacedRecently(bot.id)).toBe(true);const first = await call(() => machine!.id as string);expect((first as { isError?: boolean }).isError).toBeFalsy();@@ -268,30 +269,57 @@ describe("a woken cloud computer that never answers", () => {});describe("a computer call made while its computer is being replaced", () => {- it("waits for the replacement and runs on the new computer, instead of being refused again and again", async () => {+ /** A computer the recovery is replacing, slowly, while the turn still names it. */+ async function replacing() {const { bot, box } = await asleep(Infinity);box.state = "ready";await boat.findBoat(cfg, bot.id);deleteDelayMs = 300;- const replacing = recovery.wakeTimedOut(bot.id, box.id);- await vi.waitFor(() => expect(recovery.refusal(box.id, "before")).not.toBeNull());+ const done = recovery.wakeTimedOut(bot.id, box.id);+ await vi.waitFor(() => expect(recovery.refusal(box.id, "before")).not.toBeNull(), { timeout: 10_000 });let current = box.id;let reclaims = 0;- const result = await call(() => current, {- reclaim: async (replacedBoxId) => {- reclaims++;- expect(replacedBoxId).toBe(box.id);- const machine = await power.ready(bot, turn(), { budgetMs: 30_000 });- current = machine!.id as string;- return current;- },- });- await replacing;- expect(reclaims).toBe(1);- expect(current).not.toBe(box.id);+ const reclaim = async (replacedBoxId: string) => {+ reclaims++;+ expect(replacedBoxId).toBe(box.id);+ const machine = await power.ready(bot, turn(), { budgetMs: 30_000 });+ current = machine!.id as string;+ return current;+ };+ return { box, done, reclaim, current: () => current, reclaims: () => reclaims };+ }++ it("waits for the replacement instead of being refused again and again, and a look at the screen then runs on the new computer", async () => {+ const r = await replacing();+ let gates = 0;+ const result = await call(r.current, { reclaim: r.reclaim, gate: async () => { gates++; return { held: false }; } }, "get_screen_size");+ await r.done;+ expect(r.reclaims()).toBe(1);+ expect(r.current()).not.toBe(r.box.id);+ expect(gates).toBe(2);expect((result as { isError?: boolean }).isError).toBeFalsy();expect((result as { content: unknown[] }).content[0]).toEqual({ type: "text", text: words.CLOUD_COMPUTER_REPLACED });- expect(ranEcho()).toBe(1);+ expect(requests.some((request) => request.command?.includes("getdisplaygeometry") && request.path.includes(r.current()))).toBe(true);+ });++ it("hands back a call that would change something, unperformed, once the new computer answers: the bot looks first", async () => {+ const r = await replacing();+ const result = await call(r.current, { reclaim: r.reclaim });+ await r.done;+ expect(r.reclaims()).toBe(1);+ expect(result).toEqual({ isError: true, content: [+ { type: "text", text: words.CLOUD_COMPUTER_REPLACED }, { type: "text", text: words.CLOUD_COMPUTER_ANSWERS_AGAIN },+ ] });+ expect(ranEcho()).toBe(0);+ });++ it("is refused after the wait when a person took the computer meanwhile", async () => {+ const r = await replacing();+ let gates = 0;+ const result = await call(r.current, { reclaim: r.reclaim, gate: async () => (++gates === 1 ? { held: false } : { held: true, reason: "person" as const }) }, "get_screen_size");+ await r.done;+ expect((result as { isError?: boolean }).isError).toBe(true);+ expect(requests.some((request) => request.command?.includes("getdisplaygeometry"))).toBe(false);});it("says the new computer is still starting, and that the call was not performed, when it is not up in time", async () => {diff --git a/server/host/cloud-computer-users.test.ts b/server/host/cloud-computer-users.test.tsnew file mode 100644index 0000000000..0ddcf7ecc6--- /dev/null+++ b/server/host/cloud-computer-users.test.ts@@ -0,0 +1,28 @@+import { describe, expect, it } from "vitest";++import { usedByAnotherBot } from "./cloud-computer-users.ts";++const deps = (holders: Record<string, string>, bots: Record<string, string>) => ({+ holder: (resource: string) => (holders[resource] ? { threadId: holders[resource]! } : undefined),+ botOfThread: (threadId: string) => bots[threadId] ?? null,+});++describe("a bot's cloud computer held by a running turn", () => {+ it("is free when no turn holds it", () => {+ expect(usedByAnotherBot("bot-a", "bx_1", deps({}, {}))).toBe(false);+ });++ it("is not counted as someone else's when the holder is the bot's own turn, in its chat or a task", () => {+ expect(usedByAnotherBot("bot-a", "bx_1", deps({ "computer:box-bot:bot-a": "chat-a" }, { "chat-a": "bot-a" }))).toBe(false);+ expect(usedByAnotherBot("bot-a", "bx_1", deps({ "computer:box:bx_1": "task-a" }, { "task-a": "bot-a" }))).toBe(false);+ });++ it("is not counted as someone else's when the holder is a room's turn, which only the bot itself can be", () => {+ expect(usedByAnotherBot("bot-a", "bx_1", deps({ "computer:box-bot:bot-a": "room-1" }, {}))).toBe(false);+ });++ it("is someone else's when another bot's turn holds the computer or the machine", () => {+ expect(usedByAnotherBot("bot-a", "bx_1", deps({ "computer:box:bx_1": "chat-b" }, { "chat-b": "bot-b" }))).toBe(true);+ expect(usedByAnotherBot("bot-a", "bx_1", deps({ "computer:box-bot:bot-a": "chat-b" }, { "chat-b": "bot-b" }))).toBe(true);+ });+});diff --git a/server/host/cloud-computer-users.ts b/server/host/cloud-computer-users.tsnew file mode 100644index 0000000000..1c31ce953a--- /dev/null+++ b/server/host/cloud-computer-users.ts@@ -0,0 +1,21 @@+// Whether a bot's own cloud computer is held by a running turn of some other bot, so it is never replaced by itself from+// under that turn. A turn takes a bot's computer through two resources, the bot's and the machine's, and only a turn of+// that same bot binds them; a holder whose bot cannot be told (a room's turn, say) is that bot's own turn acting in+// the room, and does not stop a replacement its own silence asked for.+export interface CloudComputerUsersDeps {+ /** The running turn that holds this resource, if one does. */+ holder(resource: string): { threadId: string } | undefined;+ /** The bot whose turn runs in this thread; null when the thread is not one bot's (a room's). */+ botOfThread(threadId: string): string | null;+}++export const computerResources = (owner: string, boxId: string): string[] => [`computer:box-bot:${owner}`, `computer:box:${boxId}`];++export function usedByAnotherBot(owner: string, boxId: string, deps: CloudComputerUsersDeps): boolean {+ return computerResources(owner, boxId).some((resource) => {+ const holder = deps.holder(resource);+ if (!holder) return false;+ const bot = deps.botOfThread(holder.threadId);+ return bot !== null && bot !== owner;+ });+}diff --git a/server/index.ts b/server/index.tsindex a52390c1fa..e95b00ea6c 100644--- a/server/index.ts+++ b/server/index.ts@@ -428,7 +428,7 @@ import { createLocalVmUpdater, LOCAL_VM_UPDATING_PROBLEM, recoverLocalVms, VPS_Oimport { keepInstalledAppsBeforeRemove } from "./local-vm-profiles.ts";import { localVmStopReason, recordLocalVmIdleStop } from "./local-vm-stop-reason.ts";import { ComputerIdleTimer } from "./computer-idle.ts";-import { CLOUD_COMPUTER_DID_NOT_START, CLOUD_COMPUTER_START_BUDGET_MS, CLOUD_COMPUTER_STARTING, createCloudComputerPower, type CloudComputerReadyHooks } from "./host/cloud-computer-power.ts"; import { ownCloudComputer, resetBotCloudComputer } from "./host/cloud-computer-reset.ts"; import { createCloudComputerResetAsks, noOwnCloudComputer } from "./host/cloud-computer-reset-asks.ts";+import { CLOUD_COMPUTER_DID_NOT_START, CLOUD_COMPUTER_START_BUDGET_MS, CLOUD_COMPUTER_STARTING, createCloudComputerPower, type CloudComputerReadyHooks } from "./host/cloud-computer-power.ts"; import { usedByAnotherBot } from "./host/cloud-computer-users.ts"; import { ownCloudComputer, resetBotCloudComputer } from "./host/cloud-computer-reset.ts"; import { createCloudComputerResetAsks, noOwnCloudComputer } from "./host/cloud-computer-reset-asks.ts";import { LocalVmLease, LocalVmLeasePool } from "./local-vm-lease.ts";import { LocalVmSeatPool, type LocalVmSeatHolder } from "./local-vm-seat-pool.ts";import { loopGuardSettings } from "./host/loop-guard.ts"; import { createUnattendedTurns, personDriven } from "./host/unattended-turns.ts"; import { createPersonFirst } from "./host/person-first.ts"; import { createRunOwners, runActorOf } from "./host/run-owner.ts";@@ -5633,7 +5633,7 @@ const meetingsHost = createMeetingsHost({ cfg, dataDir: DATA_DIR, store, startTuroutineComputer: routine => { const bot = store.bot(routine.botId); return bot && turnProvider(bot, routine.runOn) === "box" ? botComputerControlKey(bot) : null; },busy: owner => computerProviderConfigTransitions.has("box") || boatLifecycleBusyBots.has(owner) || managedBoatOwners().some(entry => entry.botId === owner && entry.inUse) || meetingsHost.keepsAwake(owner),claim: owner => { const team = teamComputers.list().find(entry => teamComputerOwner(entry.id) === owner); return team ? claimTeamComputerLifecycle(team) : claimBotComputerLifecycle(owner); },-}); const boatRecovery = createBoatRecovery({ cfg: () => cfg, log: line => console.warn(line), eligible: owner => { const bot = store.bot(owner); return Boolean(bot) && botComputerControlKey(bot!) === owner; }, personActive: owner => computerControl.snapshot(owner).held || desktopViewer.viewing(owner) > 0, usedByOther: (owner, boxId) => [`computer:box-bot:${owner}`, `computer:box:${boxId}`].some(resource => { const holder = turnResources.holder(resource); return holder !== undefined && store.botByThread(holder.threadId)?.id !== owner; }), tell: (owner, key) => { const team = teamComputers.list().find(entry => teamComputerOwner(entry.id) === owner); if (team) { teamComputers.setProblem(team.id, serverLine(appLanguage(), CLOUD_COMPUTER_PERSON_LINES.teamNotResponding, { name: team.name })); return; } const bot = store.bot(owner); if (!bot) return; const text = serverLine(conversationLanguage(bot.threadId), CLOUD_COMPUTER_PERSON_LINES[key], { name: bot.name }); store.appendMessage(bot.threadId, { role: "bot", kind: "activity", tool: { name: `recovery: ${text}`, ok: true } }); notify(buildNoticeNotification(bot, bot.threadId, text)); } }); const runComputers = createRunComputerGate({ computerOf: (run) => { const bot = store.bot(run.botId); return bot && turnProvider(bot, run.runOn as RoutineRunOn | undefined) === "box" ? botComputerControlKey(bot) : null; }, find: (owner) => boat.findBoat(cfg, owner), wake: (owner, budgetMs) => boat.readyBoat(cfg, owner, budgetMs), awaitAnswer: (boxId, opts) => boatReadiness.awaitAnswer(cfg, boxId, opts), verdict: (owner, since) => boatRecovery.verdict(owner, since), recoveryState: (owner) => boatRecovery.status(owner)?.state ?? null, used: (owner) => cloudComputerPower.used(owner), disk: (boxId, signal) => cloudComputerDisk.beforeRun(cfg, boxId, signal), remember: runComputerMemory(join(DATA_DIR, "routine-computers.json")), routineOf: (botId, threadId) => { const run = routines?.activeRunForBot(botId); return run?.threadId === threadId ? run.routineId : null; }, log: (line) => console.warn(line) });+}); const boatRecovery = createBoatRecovery({ cfg: () => cfg, log: line => console.warn(line), eligible: owner => { const bot = store.bot(owner); return Boolean(bot) && botComputerControlKey(bot!) === owner; }, personActive: owner => computerControl.snapshot(owner).held || desktopViewer.viewing(owner) > 0, usedByOther: (owner, boxId) => usedByAnotherBot(owner, boxId, { holder: resource => turnResources.holder(resource), botOfThread: threadId => store.botByThread(threadId)?.id ?? null }), tell: (owner, key) => { const team = teamComputers.list().find(entry => teamComputerOwner(entry.id) === owner); if (team) { teamComputers.setProblem(team.id, serverLine(appLanguage(), CLOUD_COMPUTER_PERSON_LINES.teamNotResponding, { name: team.name })); return; } const bot = store.bot(owner); if (!bot) return; const text = serverLine(conversationLanguage(bot.threadId), CLOUD_COMPUTER_PERSON_LINES[key], { name: bot.name }); store.appendMessage(bot.threadId, { role: "bot", kind: "activity", tool: { name: `recovery: ${text}`, ok: true } }); notify(buildNoticeNotification(bot, bot.threadId, text)); } }); const runComputers = createRunComputerGate({ computerOf: (run) => { const bot = store.bot(run.botId); return bot && turnProvider(bot, run.runOn as RoutineRunOn | undefined) === "box" ? botComputerControlKey(bot) : null; }, find: (owner) => boat.findBoat(cfg, owner), wake: (owner, budgetMs) => boat.readyBoat(cfg, owner, budgetMs), awaitAnswer: (boxId, opts) => boatReadiness.awaitAnswer(cfg, boxId, opts), verdict: (owner, since) => boatRecovery.verdict(owner, since), recoveryState: (owner) => boatRecovery.status(owner)?.state ?? null, used: (owner) => cloudComputerPower.used(owner), disk: (boxId, signal) => cloudComputerDisk.beforeRun(cfg, boxId, signal), remember: runComputerMemory(join(DATA_DIR, "routine-computers.json")), routineOf: (botId, threadId) => { const run = routines?.activeRunForBot(botId); return run?.threadId === threadId ? run.routineId : null; }, log: (line) => console.warn(line) });function inheritedTeamComputer(bot: Pick<BotRecord, "section" | "computer" | "cloudBackend">): TeamComputerRecord | undefined {return teamComputers.forBot(bot);@@ -5860,7 +5860,7 @@ function mountBotBoat(try {attached = await attachBotBoat(bot, owner, {budgetMs: CLOUD_COMPUTER_START_BUDGET_MS,- onSeated: () => { slot.pendingReason = CLOUD_COMPUTER_STARTING; }, onRestoring: () => { slot.pendingReason = CLOUD_COMPUTER_RESTORING; }, existingOnly: opts.existingOnly, onWaking: () => { slot.pendingReason = CLOUD_COMPUTER_WAKING; }, onReplacing: () => { slot.pendingReason = CLOUD_COMPUTER_REPLACING; },+ onSeated: () => { slot.pendingReason = CLOUD_COMPUTER_STARTING; }, onRestoring: () => { slot.pendingReason = CLOUD_COMPUTER_RESTORING; }, existingOnly: opts.existingOnly && !boatRecovery.replacedRecently(bot.id), onWaking: () => { slot.pendingReason = CLOUD_COMPUTER_WAKING; }, onReplacing: () => { slot.pendingReason = CLOUD_COMPUTER_REPLACING; },});if (!attached) throw new Error(opts.existingOnly ? "this bot no longer has a cloud computer of its own" : "the cloud computer could not be created or reached");} catch (error) {diff --git a/shared/cloud-computer-recovery.ts b/shared/cloud-computer-recovery.tsindex 78ee82fc14..13efa89ffb 100644--- a/shared/cloud-computer-recovery.ts+++ b/shared/cloud-computer-recovery.ts@@ -46,6 +46,10 @@ export const CLOUD_COMPUTER_REPLACING =/** The turn's computer was replaced while this call waited, and the new one is not up yet. */export const CLOUD_COMPUTER_REPLACEMENT_STARTING ="This bot's cloud computer stopped responding and was replaced with a new one, which is still starting. This call was not performed. Repeat it in a minute.";+/** A call that waited out its computer's restart or replacement: only a look at the screen is made after such a wait,+ * since the bot has not seen what the computer is like now. */+export const CLOUD_COMPUTER_ANSWERS_AGAIN =+ "The cloud computer answers again. This call was not performed while MausBot waited for it: take a fresh screenshot, then repeat it.";/** Woken and not answering yet, inside the wake's patience: the call is not counted against the computer. */export const CLOUD_COMPUTER_WAKING ="The cloud computer is awake but not answering yet; MausBot keeps waiting for it. This call was not performed. Repeat it in a moment.";