Skip to content

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

Bound initial status reads during waits

WAI LOK HO6e93d31512a0
diff --git a/server/cloud-computer-background.test.ts b/server/cloud-computer-background.test.ts
index df856dae32..628057ef73 100644
--- a/server/cloud-computer-background.test.ts
+++ b/server/cloud-computer-background.test.ts
@@ -162,6 +162,16 @@ describe.each([
server.closeAllConnections();
});
+ it("bounds a stalled initial status read by the requested wait", async () => {
+ const processId = await start();
+ hold = true;
+ const began = Date.now();
+ const result = await call("exec_status", { process_id: processId, wait_seconds: 1 }).done;
+ expect(Date.now() - began).toBeLessThan(3_000);
+ expect(result).toMatchObject({ isError: true, content: [{ text: expect.stringContaining("Nothing was changed; call exec_status again") }] });
+ server.closeAllConnections();
+ });
+
it("propagates cancellation during a follow-up status read", async () => {
const processId = await start();
holdStatusAfterFirst = true;
diff --git a/server/cloud-computer-background.ts b/server/cloud-computer-background.ts
index f320fb5dae..49023b4284 100644
--- a/server/cloud-computer-background.ts
+++ b/server/cloud-computer-background.ts
@@ -138,11 +138,11 @@ export async function backgroundStatus(
): Promise<CloudComputerResult> {
const processId = processIdFrom(boxId, args.process_id);
if (processId === null) return text(OTHER_COMPUTER, true);
- const until = Date.now() + Math.min(args.wait_seconds ?? 0, STATUS_WAIT_MAX_SECONDS) * 1_000;
- let firstRead = true;
+ const waitMs = Math.min(args.wait_seconds ?? 0, STATUS_WAIT_MAX_SECONDS) * 1_000;
+ const until = Date.now() + waitMs;
for (;;) {
assertBoatNotDeleting(boxId);
- const deadline = firstRead ? null : AbortSignal.timeout(Math.max(1, until - Date.now()));
+ const deadline = waitMs ? AbortSignal.timeout(Math.max(1, until - Date.now())) : null;
const readSignal = deadline ? AbortSignal.any([signal, deadline]) : signal;
let response: Response, body: any;
try {
@@ -161,7 +161,6 @@ export async function backgroundStatus(
const remaining = until - Date.now();
if (!body.running || remaining <= LAST_READ_WINDOW_MS) return describeStatus(args.process_id, body);
await delay(Math.min(POLL_MS, remaining - LAST_READ_WINDOW_MS), undefined, { signal });
- firstRead = false;
}
}