Skip to content

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

fix(local-vm): wait longer for Podman after starting its machine, and say so if it is still not answering (#4252)

Aditya Umaleeea36bdb1cd7
diff --git a/server/podman-machine.test.ts b/server/podman-machine.test.ts
index c9e7875f7e..0d6c38d8b8 100644
--- a/server/podman-machine.test.ts
+++ b/server/podman-machine.test.ts
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import type { CommandRunner } from "./container-computer.ts";
-import { startStoppedPodmanMachine } from "./podman-machine.ts";
+import { NOT_ANSWERING_YET, startStoppedPodmanMachine } from "./podman-machine.ts";
type Status = { runtime: "docker" | "podman" | null; daemonUp: boolean; problem: string | null };
const down: Status = { runtime: "podman", daemonUp: false, problem: "Start podman first" };
@@ -91,6 +91,13 @@ describe("starting a stopped Podman machine on a Mac", () => {
expect(answers).toEqual([]);
});
+ it("says the machine started when Podman still does not answer after the wait, not \"Start podman first\"", async () => {
+ const fake = podman([{ Name: "podman-machine-default", Default: true }]);
+ let checks = 0;
+ await expect(fake.start(down, "darwin", Date.now, async () => { checks++; return down; })).resolves.toEqual({ ...down, problem: NOT_ANSWERING_YET });
+ expect(checks).toBe(20);
+ });
+
it("does not hold a failed status check against later turns", async () => {
const fake = podman([{ Name: "podman-machine-default", Default: true }]);
await expect(fake.start(down, "darwin", Date.now, async () => { throw new Error("inspect failed"); })).rejects.toThrow("inspect failed");
diff --git a/server/podman-machine.ts b/server/podman-machine.ts
index c1d065a54e..1d678a95cb 100644
--- a/server/podman-machine.ts
+++ b/server/podman-machine.ts
@@ -5,7 +5,9 @@ import { sh, type CommandRunner, type ContainerComputerStatus } from "./containe
const MACHINE_START_TIMEOUT_MS = 3 * 60_000;
/** After a failed start, turns get the same message for a while instead of each waiting on another failing start. */
const FAILED_START_BACKOFF_MS = 5 * 60_000;
-const RECHECK_TRIES = 5;
+/** Podman's API socket can answer a while after `machine start` returns: checks once a second for about 20 s. */
+const RECHECK_TRIES = 20;
+export const NOT_ANSWERING_YET = "The Podman machine started, but Podman is not answering yet; try again in a moment";
type MachineEntry = { Name?: unknown; Default?: unknown; Running?: unknown; Starting?: unknown };
type RuntimeStatus = Pick<ContainerComputerStatus, "runtime" | "daemonUp" | "problem">;
@@ -39,13 +41,13 @@ export async function startStoppedPodmanMachine<S extends RuntimeStatus>(
lastFailure = { at: now(), problem: (error as Error).message };
return { ...status, problem: lastFailure.problem };
}
- // Podman's API socket can answer a moment after `machine start` returns.
let fresh = await recheck();
for (let tries = 1; tries < RECHECK_TRIES && !fresh.daemonUp; tries++) {
await pause(1_000);
fresh = await recheck();
}
- return fresh;
+ // Not "Start podman first": it was just started, so say so.
+ return fresh.daemonUp || fresh.runtime !== "podman" ? fresh : { ...fresh, problem: NOT_ANSWERING_YET };
}
async function startMachine(runner: CommandRunner, onStart: () => void): Promise<boolean> {