Skip to content

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

Keep the 503 for a VPS host that answers but can't be verified

AdityaUmaleae0708b5bd60
diff --git a/server/cloud-backend.ts b/server/cloud-backend.ts
index c122a6264e..b74507f4f2 100644
--- a/server/cloud-backend.ts
+++ b/server/cloud-backend.ts
@@ -16,10 +16,12 @@ export function vpsLeftBehindNotice(done: "Moved" | "Deleted", alias: string, co
}
/** What an unreachable old default alias may still run for this installation, and how to find and remove it. */
-export function vpsAliasLeftBehindNotice(done: "Saved" | "Removed", alias: string, environmentFilter: string): string {
+export function vpsAliasLeftBehindNotice(done: "Saved" | "Removed", alias: string, environmentFilter: string, managedFilter: string): string {
return `${done}. ${alias} could not be reached, so this installation's computers there, if any are still there, were left as they are. ` +
`When ${alias} is back, list them with: docker -H ssh://${alias} ps -a --filter ${environmentFilter} ` +
- `and remove any you no longer need with: docker -H ssh://${alias} rm -f <name>`;
+ `and remove any you no longer need with: docker -H ssh://${alias} rm -f <name>. ` +
+ `Computers made by older versions have no installation label: docker -H ssh://${alias} ps -a --filter ${managedFilter} lists every managed one, ` +
+ `so remove one of those only once you know it is this installation's (named openmausbot-vps-<bot>-… for one of its bots).`;
}
/** Why a bot that gets its cloud computer from Boat can't have one while a self-hosted VPS is saved but not chosen for it. */
diff --git a/server/index.test.ts b/server/index.test.ts
index 65fa2e4642..50c0809efc 100644
--- a/server/index.test.ts
+++ b/server/index.test.ts
@@ -11140,11 +11140,23 @@ describe("harness HTTP API", () => {
(candidate: { id: string }) => candidate.id === bot.id,
)).toBe(false);
+ // A server that answers with a list that can't be verified still keeps the alias.
+ rmSync(fakeSshUnavailable, { force: true });
+ writeFileSync(fakeVpsFixture, JSON.stringify({ id: "z".repeat(64), name: containerName }));
+ const unverified = await api("PUT", "/api/config", { vps: { sshAlias: "" } });
+ expect(unverified.status, JSON.stringify(unverified.body)).toBe(503);
+ expect(unverified.body.error).toContain("Keep the current SSH config alias");
+ expect((await api("GET", "/api/config")).body.vps.sshAlias).toBe("fixture-vps");
+ writeFileSync(fakeSshUnavailable, "");
+ writeFileSync(fakeVpsFixture, JSON.stringify({ id: "a".repeat(64), name: containerName }));
+
+ const environmentId = readFileSync(join(home, ".openmausbot", "environment-id"), "utf8").trim();
const cleared = await api("PUT", "/api/config", { vps: { sshAlias: "" } });
expect(cleared.status, JSON.stringify(cleared.body)).toBe(200);
expect(cleared.body.notice).toContain("Removed. fixture-vps could not be reached");
- expect(cleared.body.notice).toContain("docker -H ssh://fixture-vps ps -a --filter label=com.openmausbot.environment=");
+ expect(cleared.body.notice).toContain(`docker -H ssh://fixture-vps ps -a --filter label=com.openmausbot.environment=${environmentId} `);
expect(cleared.body.notice).toContain("docker -H ssh://fixture-vps rm -f <name>");
+ expect(cleared.body.notice).toContain("docker -H ssh://fixture-vps ps -a --filter label=com.openmausbot.vps=1 lists every managed one");
expect((await api("GET", "/api/config")).body.vps.sshAlias).toBe("");
expect(existsSync(fakeVpsFixture)).toBe(true);
} finally {
diff --git a/server/routes/config.ts b/server/routes/config.ts
index 7f053e33f5..7caa3aa9b9 100644
--- a/server/routes/config.ts
+++ b/server/routes/config.ts
@@ -283,8 +283,12 @@ export function createConfigRoutes(deps: ConfigRouteDeps): RouteHandler {
{ vps: { sshAlias: currentVpsAlias } },
managedBoatOwners(),
);
- if (!inventory.available) {
+ if (inventory.unreachable) {
vpsLeftOn = currentVpsAlias;
+ } else if (!inventory.available) {
+ return json(res, 503, {
+ error: `${inventory.problem ?? "VPS computer inventory is unavailable"}. Keep the current SSH config alias and retry`,
+ });
} else {
const resourceError = vpsAliasResourceChangeError(inventory.instances.length);
if (resourceError) return json(res, 409, { error: resourceError });
@@ -685,7 +689,7 @@ export function createConfigRoutes(deps: ConfigRouteDeps): RouteHandler {
);
return json(res, 200, {
...(configForAccess(finalized.value, auth) as object),
- ...(vpsLeftOn ? { notice: vpsAliasLeftBehindNotice(nextVpsAlias ? "Saved" : "Removed", vpsLeftOn, `label=${vps.VPS_ENVIRONMENT_LABEL}=${vps.vpsEnvironmentId()}`) } : {}),
+ ...(vpsLeftOn ? { notice: vpsAliasLeftBehindNotice(nextVpsAlias ? "Saved" : "Removed", vpsLeftOn, `label=${vps.VPS_ENVIRONMENT_LABEL}=${vps.vpsEnvironmentId()}`, `label=${vps.VPS_MANAGED_LABEL}=1`) } : {}),
});
} finally {
for (const provider of transitioningProviders) computerProviderConfigTransitions.delete(provider);
diff --git a/server/vps-computer.test.ts b/server/vps-computer.test.ts
index 64d5ca7430..39824a8835 100644
--- a/server/vps-computer.test.ts
+++ b/server/vps-computer.test.ts
@@ -1363,6 +1363,7 @@ describe("a missing Docker CLI", () => {
const command = dockerCliInstallCommand(process.platform)!;
const inventory = await listManagedVpsComputers(CONFIG, [], runner);
expect(inventory.available).toBe(false);
+ expect(inventory.unreachable).toBeUndefined();
expect(inventory.problem).toContain(command);
expect(inventory.problem).not.toMatch(/ENOENT/);
@@ -1371,3 +1372,24 @@ describe("a missing Docker CLI", () => {
expect(status.problem).not.toMatch(/ENOENT/);
});
});
+
+describe("a VPS inventory that fails", () => {
+ it("is unreachable only when the host gave no list at all", async () => {
+ const silent: VpsCommandRunner = async () => {
+ throw new Error("ssh: connect to host fixture port 22: Connection timed out");
+ };
+ expect(await listManagedVpsComputers(CONFIG, [], silent)).toMatchObject({ available: false, unreachable: true });
+
+ const garbled: VpsCommandRunner = async () => ({ stdout: "not-a-container-id\n", stderr: "" });
+ const unverified = await listManagedVpsComputers(CONFIG, [], garbled);
+ expect(unverified.available).toBe(false);
+ expect(unverified.unreachable).toBeUndefined();
+
+ const answers: VpsCommandRunner = async () => ({ stdout: "", stderr: "" });
+ const both = await listManagedVpsComputers(CONFIG, [], async (args, options) =>
+ args.includes("ssh://other") ? garbled(args, options) : silent(args, options), ["fixture", "other"]);
+ expect(both.available).toBe(false);
+ expect(both.unreachable).toBeUndefined();
+ expect((await listManagedVpsComputers(CONFIG, [], answers)).unreachable).toBeUndefined();
+ });
+});
diff --git a/server/vps-computer.ts b/server/vps-computer.ts
index 0926ebb830..2ec765e7c2 100644
--- a/server/vps-computer.ts
+++ b/server/vps-computer.ts
@@ -144,6 +144,8 @@ export interface ManagedVpsInventory {
vpsAliases: string[];
problem: string | null;
instances: ManagedVpsInventoryInstance[];
+ /** Set when every host that failed gave no list at all (SSH or Docker did not answer), rather than one that could not be verified. */
+ unreachable?: true;
}
function containerNamePart(botId: string): string {
@@ -579,7 +581,7 @@ const VPS_INVENTORY_STATES = new Set<ManagedVpsInventoryInstance["state"]>([
"dead",
]);
-type ManagedVpsAliasScan = Pick<ManagedVpsInventory, "available" | "problem" | "instances"> & { containerIds: Map<string, string> };
+type ManagedVpsAliasScan = Pick<ManagedVpsInventory, "available" | "problem" | "instances" | "unreachable"> & { containerIds: Map<string, string> };
function inventoryFailure(alias: string, error: unknown): ManagedVpsAliasScan {
if (dockerCliMissing(error)) return { available: false, problem: `${dockerCliMissingProblem()} (VPS host: ${alias})`, instances: [], containerIds: new Map() };
@@ -610,16 +612,13 @@ async function scanManagedVpsAlias(
owners: ManagedVpsOwner[],
runner: VpsCommandRunner,
): Promise<ManagedVpsAliasScan> {
+ let listed: { stdout: string };
+ try {
+ listed = await runner(vpsDockerArgs(alias, ["container", "ls", "--all", "--filter", `label=${VPS_MANAGED_LABEL}=1`, "--format", "{{.ID}}"]), { timeoutMs: 20_000 });
+ } catch (error) {
+ return { ...inventoryFailure(alias, error), ...(dockerCliMissing(error) ? {} : { unreachable: true as const }) };
+ }
try {
- const listed = await runner(vpsDockerArgs(alias, [
- "container",
- "ls",
- "--all",
- "--filter",
- `label=${VPS_MANAGED_LABEL}=1`,
- "--format",
- "{{.ID}}",
- ]), { timeoutMs: 20_000 });
const ids = [...new Set(listed.stdout.split(/\r?\n/).map((line) => line.trim()).filter(Boolean))];
if (ids.length > VPS_INVENTORY_LIMIT || ids.some((id) => !CONTAINER_ID.test(id))) {
throw new Error("the VPS returned an invalid or unexpectedly large managed-container list");
@@ -715,7 +714,8 @@ export async function listManagedVpsComputers(
(left.ownerName ?? left.name).localeCompare(right.ownerName ?? right.name) ||
left.vpsAlias.localeCompare(right.vpsAlias),
);
- return { configured: true, available: scans.every((scan) => scan.available), vpsAliases: scanning, problem, instances };
+ const unreachable = scans.some((scan) => scan.unreachable) && scans.every((scan) => scan.available || scan.unreachable);
+ return { configured: true, available: scans.every((scan) => scan.available), vpsAliases: scanning, problem, instances, ...(unreachable ? { unreachable } : {}) };
}
export function vpsContainerRunArgs(
diff --git a/src/components/keys/KeyPanels.tsx b/src/components/keys/KeyPanels.tsx
index ccc3224f40..bb31e5888c 100644
--- a/src/components/keys/KeyPanels.tsx
+++ b/src/components/keys/KeyPanels.tsx
@@ -147,13 +147,14 @@ export function VpsConnection() {
const [notice, setNotice] = useState<string | null>(null);
const configured = Boolean(state.config?.vps?.configured);
const clearing = !alias.trim() && configured;
+ const unchanged = alias.trim() === (state.config?.vps?.sshAlias ?? "");
useEffect(() => {
setAlias(state.config?.vps?.sshAlias ?? "");
}, [state.config?.vps?.sshAlias]);
const save = () => {
- if (saving || (!alias.trim() && !configured)) return;
+ if (saving || (!alias.trim() && !configured) || unchanged) return;
setSaving(true);
setError(null);
setNotice(null);
@@ -193,7 +194,7 @@ export function VpsConnection() {
<button
type="button"
onClick={save}
- disabled={saving || (!alias.trim() && !configured) || alias.trim() === (state.config?.vps?.sshAlias ?? "")}
+ disabled={saving || (!alias.trim() && !configured) || unchanged}
className={cn("ui-button shrink-0", !clearing && "ui-button-primary")}
title={clearing ? t("keys.vps.removeAlias") : undefined}
>