Skip to content

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

Honor short background status waits

WAI LOK HOfe2b99ab801e
diff --git a/server/cloud-computer-background.test.ts b/server/cloud-computer-background.test.ts
index 8efb0efb44..2fa8bb71a5 100644
--- a/server/cloud-computer-background.test.ts
+++ b/server/cloud-computer-background.test.ts
@@ -93,6 +93,7 @@ describe.each([
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("check its exit code and output");
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);
@@ -135,6 +136,16 @@ describe.each([
const processId = await start();
processes.get(`${BOX}:${processId.split("-")[1]}`)!.runningFor = 100;
expect(json(await call("exec_status", { process_id: processId, wait_seconds: 3 }).done)).toMatchObject({ status: "running", exitCode: null });
+ expect(calls.filter(entry => entry.method === "GET")).toHaveLength(3);
+ });
+
+ it.each([true, false])("honors a one-second wait and reports whether the command finished: %s", async (finishes) => {
+ const processId = await start();
+ Object.assign(processes.get(`${BOX}:${processId.split("-")[1]}`)!, { runningFor: finishes ? 1 : 100, exitCode: 3 });
+ const began = Date.now();
+ const result = json(await call("exec_status", { process_id: processId, wait_seconds: 1 }).done);
+ expect(Date.now() - began).toBeGreaterThanOrEqual(900);
+ expect(result).toMatchObject({ status: finishes ? "finished" : "running", exitCode: finishes ? 3 : null });
expect(calls.filter(entry => entry.method === "GET")).toHaveLength(2);
});
diff --git a/server/cloud-computer-background.ts b/server/cloud-computer-background.ts
index 8ea7c96a4b..bf92063297 100644
--- a/server/cloud-computer-background.ts
+++ b/server/cloud-computer-background.ts
@@ -146,8 +146,9 @@ export async function backgroundStatus(
if (!response.ok) return text(boatErrorMessage(response.status, "Reading the command's status", body, included(cfg)), true);
if (typeof body?.running !== "boolean") return text("The cloud computer gave an unreadable answer about this command. Call exec_status again.", true);
if (!body.running) untrack(boxId, processId);
- if (!body.running || Date.now() + POLL_MS > until) return describeStatus(args.process_id, body);
- await delay(POLL_MS, undefined, { signal });
+ const remaining = until - Date.now();
+ if (!body.running || remaining <= 0) return describeStatus(args.process_id, body);
+ await delay(Math.min(POLL_MS, remaining), undefined, { signal });
}
}
diff --git a/server/cloud-computer-tools.test.ts b/server/cloud-computer-tools.test.ts
index a352ba4c0e..80df7f72ed 100644
--- a/server/cloud-computer-tools.test.ts
+++ b/server/cloud-computer-tools.test.ts
@@ -57,6 +57,7 @@ describe("cloud computer tools", () => {
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("check its exit code and output");
expect(exec.description).toContain("report the work as unfinished with the process_id");
});