Skip to content

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

Name the per-bot desktop limit when a turn hits it

AdityaUmale632c3b6f5853
diff --git a/server/config.test.ts b/server/config.test.ts
index 12cc042746..092e2f42e9 100644
--- a/server/config.test.ts
+++ b/server/config.test.ts
@@ -23,6 +23,7 @@ import { cacheUntilConfigChanges,
localVmMaxInstances,
localVmMode,
parseConfigPatch,
+ perBotLocalVmLimitProblem,
parseStoredConfig,
persistableInstanceConfigs,
roomTurnTimeoutMinutes,
@@ -637,6 +638,15 @@ describe("configuration boundaries", () => {
expect(localVmMaxInstances({ localVm: { maxInstances: 3 } })).toBe(3);
});
+ it("names the per-bot desktop limit once every allowed desktop exists", () => {
+ const cfg = { localVm: { mode: "per-bot" as const, maxInstances: 8 } };
+ expect(perBotLocalVmLimitProblem(cfg, 7)).toBeNull();
+ expect(perBotLocalVmLimitProblem(cfg, 8)).toBe(
+ "The per-bot Local VM limit is 8 — delete an unused bot VM or raise the limit in App Settings",
+ );
+ expect(perBotLocalVmLimitProblem({}, 2)).toContain("limit is 2");
+ });
+
it("accepts pool mode with the same bounded seat count", () => {
expect(parseConfigPatch({ localVm: { mode: "pool", maxInstances: 4 } })).toEqual({
localVm: { mode: "pool", maxInstances: 4 },
diff --git a/server/index.ts b/server/index.ts
index adffe7d40b..3b93e8f2c1 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -154,7 +154,7 @@ import {
engineLaunches,
localVmIdleTimeoutMinutes,
localVmMaxInstances,
- localVmMode,
+ localVmMode, perBotLocalVmLimitProblem,
localVmPreservesInstalledApps, localVmResources,
roomTurnTimeoutMinutes,
mcpCallTimeoutMinutes,
@@ -11512,8 +11512,8 @@ async function readyLocalVmForTurn(botId: string, target: LocalVmTarget, isCurre
if (action === "run" && !pooled && !ownsProvision) return status;
if (action === "run" && target.key.startsWith("bot:")) {
- const count = await existingPerBotLocalVmCount(status.runtime);
- if (!isCurrent() || count >= localVmMaxInstances(cfg)) return status;
+ const limit = perBotLocalVmLimitProblem(cfg, await existingPerBotLocalVmCount(status.runtime));
+ if (!isCurrent() || limit) return { ...status, problem: limit ?? status.problem };
}
broadcast({ kind: "computer", botId, state: "provisioning" });
diff --git a/server/local-vm-settings.ts b/server/local-vm-settings.ts
index 062dd4c813..4fb1e05f9d 100644
--- a/server/local-vm-settings.ts
+++ b/server/local-vm-settings.ts
@@ -49,6 +49,12 @@ export function localVmMaxInstances(cfg: AppConfig): number {
return cfg.localVm?.maxInstances ?? DEFAULT_LOCAL_VM_MAX_INSTANCES;
}
+/** Why another per-bot desktop can't be created, or null while there is room. */
+export function perBotLocalVmLimitProblem(cfg: AppConfig, existing: number): string | null {
+ const max = localVmMaxInstances(cfg);
+ return existing >= max ? `The per-bot Local VM limit is ${max} — delete an unused bot VM or raise the limit in App Settings` : null;
+}
+
export function localVmIdleTimeoutMinutes(cfg: AppConfig): number {
return cfg.localVm?.idleTimeoutMinutes ?? DEFAULT_LOCAL_VM_IDLE_TIMEOUT_MINUTES;
}
diff --git a/server/routes/computers.ts b/server/routes/computers.ts
index 3fe161194f..47e9bf350e 100644
--- a/server/routes/computers.ts
+++ b/server/routes/computers.ts
@@ -2,7 +2,7 @@ import { z, type ZodString } from "zod";
import * as boat from "../boat.ts";
import { boatHealth } from "../boat-health.ts";
import type { ComputerControl } from "../computer-control.ts";
-import { isValidSshAlias, localVmMaxInstances, localVmMode, localVmResources, type AppConfig } from "../config.ts";
+import { isValidSshAlias, localVmMaxInstances, localVmMode, localVmResources, perBotLocalVmLimitProblem, type AppConfig } from "../config.ts";
import {
containerComputerAction,
containerComputerExists,
@@ -396,12 +396,8 @@ export function createComputerRoutes(deps: ComputerRouteDeps): RouteHandler {
const before = await containerComputerStatus(undefined, undefined, target);
if (!before.runtime) return json(res, 409, { error: before.problem ?? "No container runtime is installed" });
if (!(await containerComputerExists(before.runtime, target))) {
- const count = await existingPerBotLocalVmCount(before.runtime);
- if (count >= localVmMaxInstances(cfg)) {
- return json(res, 409, {
- error: `The per-bot Local VM limit is ${localVmMaxInstances(cfg)} — delete an unused bot VM or raise the limit in App Settings`,
- });
- }
+ const limit = perBotLocalVmLimitProblem(cfg, await existingPerBotLocalVmCount(before.runtime));
+ if (limit) return json(res, 409, { error: limit });
}
}
if (action === "remove") await keepSignInsBeforeRemove(target);