Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Let the default VPS alias change when its old server can't be reached
AdityaUmale3139706af7b0
diff --git a/docs/byo-vps.md b/docs/byo-vps.mdindex 5e61a536b3..413800d4a6 100644--- a/docs/byo-vps.md+++ b/docs/byo-vps.md@@ -107,7 +107,8 @@ cannot change while any computer it manages still exists: remove the computer fiSelf-hosted VPS computers (or by hand: `docker -H ssh://old-server rm -f openmausbot-vps-<bot>-<hash>`). A serverthat cannot be reached never traps a bot: moving the bot to another server, switching its computer, or deletingit goes ahead, and the app says what may be left on that server and the command that removes it once the server-is back. (Changing the default alias still waits until its server can be listed.) Any alias from your+is back. Changing or clearing the default alias works the same way: the app lists the command that finds this+installation's computers left on that server. Any alias from your`~/.ssh/config`, host key already verified by hand, is all it takes. A new bot starts on the default server.### A server that pauses when idlediff --git a/server/cloud-backend.ts b/server/cloud-backend.tsindex 824529d2c4..c122a6264e 100644--- a/server/cloud-backend.ts+++ b/server/cloud-backend.ts@@ -15,6 +15,13 @@ export function vpsLeftBehindNotice(done: "Moved" | "Deleted", alias: string, co`When ${alias} is back, remove it with: docker -H ssh://${alias} rm -f ${containerName}`;}+/** 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 {+ 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>`;+}+/** 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. */export function vpsNotChosenReason(botName: string, vpsAlias: string | null): string | null {return vpsAlias ? `${botName}'s cloud computer comes from Boat, which is not available here. The self-hosted VPS ${vpsAlias} is set up ` +diff --git a/server/index.test.ts b/server/index.test.tsindex eb21134836..65fa2e4642 100644--- a/server/index.test.ts+++ b/server/index.test.ts@@ -11141,10 +11141,12 @@ describe("harness HTTP API", () => {)).toBe(false);const cleared = await api("PUT", "/api/config", { vps: { sshAlias: "" } });- expect(cleared.status).toBe(503);- expect(cleared.body.error).toContain("fixture SSH is unavailable");- expect(cleared.body.error).toContain("Keep the current SSH config alias");- expect((await api("GET", "/api/config")).body.vps.sshAlias).toBe("fixture-vps");+ 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 rm -f <name>");+ expect((await api("GET", "/api/config")).body.vps.sshAlias).toBe("");+ expect(existsSync(fakeVpsFixture)).toBe(true);} finally {rmSync(fakeSshUnavailable, { force: true });rmSync(fakeVpsFixture, { force: true });diff --git a/server/routes/config.ts b/server/routes/config.tsindex 625a26f77f..7f053e33f5 100644--- a/server/routes/config.ts+++ b/server/routes/config.ts@@ -9,7 +9,7 @@ import type { BrowserCleanupCoordinator, BrowserCleanupRequest } from "../browseimport { finalizeBrowserCleanupMutation, requireBrowserCleanupAcknowledged } from "../browser-lifecycle-cleanup.ts";import type { BrowserLive } from "../browser-live.ts";import type { BrowserRuntime } from "../browser-runtime.ts";-import { boatAccountResourceChangeError, vpsAliasResourceChangeError } from "../cloud-backend.ts";+import { boatAccountResourceChangeError, vpsAliasLeftBehindNotice, vpsAliasResourceChangeError } from "../cloud-backend.ts";import * as composio from "../composio.ts";import {browserProfilePartitionTarget,@@ -277,18 +277,18 @@ export function createConfigRoutes(deps: ConfigRouteDeps): RouteHandler {}for (const provider of transitioningProviders) computerProviderConfigTransitions.add(provider);+ let vpsLeftOn: string | null = null;if (changingVpsAlias && currentVpsAlias) {const inventory = await vps.listManagedVpsComputers({ vps: { sshAlias: currentVpsAlias } },managedBoatOwners(),);if (!inventory.available) {- return json(res, 503, {- error: `${inventory.problem ?? "VPS computer inventory is unavailable"}. Keep the current SSH config alias and retry`,- });+ vpsLeftOn = currentVpsAlias;+ } else {+ const resourceError = vpsAliasResourceChangeError(inventory.instances.length);+ if (resourceError) return json(res, 409, { error: resourceError });}- const resourceError = vpsAliasResourceChangeError(inventory.instances.length);- if (resourceError) return json(res, 409, { error: resourceError });}let boatRecovery = changingBoatToken ? boatCreateRecoverySnapshot() : [];@@ -683,7 +683,10 @@ export function createConfigRoutes(deps: ConfigRouteDeps): RouteHandler {finalized.acknowledgements.every(Boolean),removedBrowserProfileIds.length === 1 ? "The browser profile" : "The browser profiles",);- return json(res, 200, configForAccess(finalized.value, auth));+ return json(res, 200, {+ ...(configForAccess(finalized.value, auth) as object),+ ...(vpsLeftOn ? { notice: vpsAliasLeftBehindNotice(nextVpsAlias ? "Saved" : "Removed", vpsLeftOn, `label=${vps.VPS_ENVIRONMENT_LABEL}=${vps.vpsEnvironmentId()}`) } : {}),+ });} finally {for (const provider of transitioningProviders) computerProviderConfigTransitions.delete(provider);if (changingLocalVmMode) localVmModeChangeBusy.set(false);diff --git a/server/vps-computer.ts b/server/vps-computer.tsindex 314984a0e3..0926ebb830 100644--- a/server/vps-computer.ts+++ b/server/vps-computer.ts@@ -39,7 +39,7 @@ export const VPS_CONTAINER_PREFIX = "openmausbot-vps";export { dockerCliInstallCommand, vpsStartsForTurn, vpsUnavailableHint } from "./vps-hints.ts";// Lazy: index must finish data migration and take the writer lease before this may create the data directory.let vpsEnvironmentIdCache: string | null = null;-function vpsEnvironmentId(): string {+export function vpsEnvironmentId(): string {if (!vpsEnvironmentIdCache) vpsEnvironmentIdCache = loadEnvironmentId(DATA_DIR);return vpsEnvironmentIdCache;}diff --git a/src/components/keys/KeyPanels.tsx b/src/components/keys/KeyPanels.tsxindex 86a25d323d..ccc3224f40 100644--- a/src/components/keys/KeyPanels.tsx+++ b/src/components/keys/KeyPanels.tsx@@ -144,6 +144,7 @@ export function VpsConnection() {const [alias, setAlias] = useState("");const [saving, setSaving] = useState(false);const [error, setError] = useState<string | null>(null);+ const [notice, setNotice] = useState<string | null>(null);const configured = Boolean(state.config?.vps?.configured);const clearing = !alias.trim() && configured;@@ -155,10 +156,12 @@ export function VpsConnection() {if (saving || (!alias.trim() && !configured)) return;setSaving(true);setError(null);+ setNotice(null);api("/api/config", { method: "PUT", body: JSON.stringify({ vps: { sshAlias: alias.trim() } }) })- .then((status: ConfigStatus) => {+ .then(({ notice: savedNotice, ...status }: ConfigStatus & { notice?: string }) => {dispatch({ type: "configStatus", config: status });setAlias(status.vps?.sshAlias ?? "");+ setNotice(savedNotice ?? null);}).catch((e) => setError(e.message)).finally(() => setSaving(false));@@ -197,6 +200,7 @@ export function VpsConnection() {{saving ? <Loader2 size={13} className="animate-spin" aria-hidden="true" /> : clearing ? t("keys.row.remove") : t("common.save")}</button></div>+ {notice && <div role="status" className="text-[12px] leading-4 text-ink-secondary">{notice}</div>}{error && <div role="alert" className="text-[12px] leading-4 text-danger">{error}</div>}</div>);