Skip to content

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

Clarify cloud background command handoff limits

WAI LOK HO1ad835cb51c6
diff --git a/server/cloud-computer-background.test.ts b/server/cloud-computer-background.test.ts
index c828f070e0..8efb0efb44 100644
--- a/server/cloud-computer-background.test.ts
+++ b/server/cloud-computer-background.test.ts
@@ -91,6 +91,9 @@ describe.each([
const result = await started.done;
expect(result.isError).not.toBe(true);
expect(json(result)).toMatchObject({ processId: expect.stringMatching(new RegExp(background.PROCESS_ID_PATTERN)), status: "running" });
+ expect(json(result).next).toContain("completion will not automatically resume this turn or notify a delegator");
+ expect(json(result).next).toContain("use exec_status with wait_seconds in this turn");
+ expect(json(result).next).toContain("report it as unfinished with the process_id");
expect([started.gated(), started.checks()]).toEqual([1, 2]);
expect(calls).toHaveLength(1);
expect(calls[0]).toMatchObject({ method: "POST", path: `${root}/${BOX}/commands`, authorization, body: { detached: true } });
@@ -111,6 +114,14 @@ describe.each([
expect(reads.map(entry => [entry.path, entry.query, entry.authorization])).toEqual(Array(2).fill([`${root}/${BOX}/commands/${processId.split("-")[1]}`, "?tailBytes=12000", authorization]));
});
+ it.each([0, 3])("keeps one background command through terminal exit %i", async (exitCode) => {
+ const processId = await start();
+ Object.assign(processes.get(`${BOX}:${processId.split("-")[1]}`)!, { runningFor: 1, exitCode, stdout: "receipt" });
+ expect(json(await call("exec_status", { process_id: processId }).done)).toMatchObject({ status: "running", exitCode: null });
+ expect(json(await call("exec_status", { process_id: processId, wait_seconds: 1 }).done)).toMatchObject({ status: "finished", exitCode, stdout: "receipt" });
+ expect(calls.filter(entry => entry.method === "POST")).toHaveLength(1);
+ });
+
it("waits for the command to finish when asked, polling the computer rather than the bot", async () => {
const processId = await start();
Object.assign(processes.get(`${BOX}:${processId.split("-")[1]}`)!, { runningFor: 2, stdout: "loaded\n" });
diff --git a/server/cloud-computer-background.ts b/server/cloud-computer-background.ts
index 8933561df2..8ea7c96a4b 100644
--- a/server/cloud-computer-background.ts
+++ b/server/cloud-computer-background.ts
@@ -113,7 +113,7 @@ export async function startInBackground(cfg: AppConfig, boxId: string, command:
if (Number.isInteger(body?.exitCode) && processId === undefined) return ranInForeground(body);
if (!Number.isSafeInteger(processId) || processId < 1) return text(`The cloud computer did not say which process it started. The command may have started. ${CHECK_BEFORE_RERUN}.`, true);
track(boxId, processId);
- return text(JSON.stringify({ processId: processIdOn(boxId, processId), status: "running", next: "It keeps running after this call. Follow it with exec_status." }));
+ return text(JSON.stringify({ processId: processIdOn(boxId, processId), status: "running", next: "It keeps running after this call, but its completion will not automatically resume this turn or notify a delegator. If its result is needed for this task, use exec_status with wait_seconds in this turn until it finishes, then check its exit code and output. If you cannot finish checking in this turn, report it as unfinished with the process_id; do not start another copy blindly." }));
}
function describeStatus(processId: string, body: any): CloudComputerResult {
diff --git a/server/cloud-computer-tools.test.ts b/server/cloud-computer-tools.test.ts
index 1f7a894c0b..a352ba4c0e 100644
--- a/server/cloud-computer-tools.test.ts
+++ b/server/cloud-computer-tools.test.ts
@@ -48,12 +48,16 @@ const rpc = (request: unknown, gate: { held: boolean; reason?: "person"; blocked
describe("cloud computer tools", () => {
it("lists the same thirteen tools for every engine", async () => {
- const listed = await rpc({ method: "tools/list", params: {} }).done as { tools: Array<{ name: string }> };
+ const listed = await rpc({ method: "tools/list", params: {} }).done as { tools: Array<{ name: string; description: string }> };
expect(listed.tools.map(tool => tool.name)).toEqual([
"screenshot", "get_screen_size", "click", "move", "drag", "type_text", "key_press", "scroll", "open_url", "exec", "exec_status",
"copy_from_computer", "copy_to_computer",
]);
expect(calls).toEqual([]);
+ const exec = listed.tools.find(tool => tool.name === "exec")!;
+ expect(exec.description).toContain("Completion does not automatically resume this turn or notify a delegator");
+ expect(exec.description).toContain("use exec_status with wait_seconds in this turn");
+ expect(exec.description).toContain("report the work as unfinished with the process_id");
});
it.each([
diff --git a/server/cloud-computer-tools.ts b/server/cloud-computer-tools.ts
index 79f8f76d42..61793b59d4 100644
--- a/server/cloud-computer-tools.ts
+++ b/server/cloud-computer-tools.ts
@@ -24,7 +24,7 @@ export const CLOUD_COMPUTER_TOOLS = [
tool("key_press", "Press an X11 key or shortcut.", { key: { type: "string", pattern: "^[A-Za-z0-9_+]+$", minLength: 1, maxLength: 100 } }, ["key"]),
tool("scroll", "Scroll at a point on the cloud desktop.", { x: coordinate, y: coordinate, direction: { type: "string", enum: ["up", "down", "left", "right"] }, amount: { type: "integer", minimum: 1, maximum: 30 } }, ["x", "y", "direction"]),
tool("open_url", "Request opening an HTTP or HTTPS URL in the cloud desktop browser; inspect the screen to confirm it loaded.", { url: { type: "string", pattern: "^https?://", maxLength: 2000 } }, ["url"]),
- tool("exec", "Run a shell command on the assigned cloud computer and wait for its result. For a command that may run long (downloads, installs, builds, data jobs), set background: true: it starts the command and answers at once with a process_id to follow with exec_status, and the computer stays on for it for up to two hours.", {
+ tool("exec", "Run a shell command on the assigned cloud computer and wait for its result. For a command that may run long (downloads, installs, builds, data jobs), set background: true: it starts the command and answers at once with a process_id to follow with exec_status, and the computer stays on for it for up to two hours. Completion does not automatically resume this turn or notify a delegator. If the result is needed for this task, use exec_status with wait_seconds in this turn until it finishes, then check its exit code and output. If you cannot finish checking in this turn, report the work as unfinished with the process_id; do not claim completion or start another copy blindly.", {
command: { type: "string", minLength: 1, maxLength: 4000 },
background: { type: "boolean", description: "Start the command and answer at once with a process_id, instead of waiting for it to finish." },
}, ["command"]),
diff --git a/server/hosted-desktop.e2e.test.ts b/server/hosted-desktop.e2e.test.ts
index 79f8d75e37..aa339b1cd4 100644
--- a/server/hosted-desktop.e2e.test.ts
+++ b/server/hosted-desktop.e2e.test.ts
@@ -139,7 +139,10 @@ it("keeps the bot's own engine on the cloud computer, and a failed place never b
const client = mcpClient(computer);
try {
expect((await client.request("initialize", { protocolVersion: "2024-11-05", capabilities: {}, clientInfo: { name: "fixture", version: "1" } })).result.serverInfo.name).toBe("openmausbot-computer");
- expect((await client.request("tools/list")).result.tools).toHaveLength(13);
+ const listed = (await client.request("tools/list")).result.tools;
+ expect(listed).toHaveLength(13);
+ expect(listed.find((tool: { name: string }) => tool.name === "exec").description)
+ .toContain("Completion does not automatically resume this turn or notify a delegator");
const shot = await client.request("tools/call", { name: "screenshot", arguments: {} });
expect(shot.result.content[0]).toMatchObject({ type: "image", mimeType: "image/jpeg" });
const exec = await client.request("tools/call", { name: "exec", arguments: { command: "printf hosted-desktop" } });