Skip to content

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

Check the per-bot desktop limit before waiting on another turn's setup

AdityaUmalea1f67400ccae
diff --git a/server/config.test.ts b/server/config.test.ts
index 092e2f42e9..0edfcb5e76 100644
--- a/server/config.test.ts
+++ b/server/config.test.ts
@@ -641,10 +641,10 @@ describe("configuration boundaries", () => {
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(cfg, 8)).toBe("The per-bot Local VM limit is 8 — delete an unused bot VM");
+ expect(perBotLocalVmLimitProblem({}, 2)).toBe(
+ "The per-bot Local VM limit is 2 — 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", () => {
diff --git a/server/index.ts b/server/index.ts
index 3b93e8f2c1..cf97a40685 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -11509,13 +11509,13 @@ async function readyLocalVmForTurn(botId: string, target: LocalVmTarget, isCurre
if (!isCurrent()) return status;
const action = localVmWakeAction(status);
if (status.ready || !action || !status.runtime) return status;
- if (action === "run" && !pooled && !ownsProvision) return status;
-
if (action === "run" && target.key.startsWith("bot:")) {
const limit = perBotLocalVmLimitProblem(cfg, await existingPerBotLocalVmCount(status.runtime));
if (!isCurrent() || limit) return { ...status, problem: limit ?? status.problem };
}
+ if (action === "run" && !pooled && !ownsProvision) return status;
+
broadcast({ kind: "computer", botId, state: "provisioning" });
try {
status = await containerComputerAction(action, undefined, undefined, target, localVmResources(cfg));
diff --git a/server/local-vm-settings.ts b/server/local-vm-settings.ts
index 4fb1e05f9d..7317c0cf47 100644
--- a/server/local-vm-settings.ts
+++ b/server/local-vm-settings.ts
@@ -52,7 +52,8 @@ export function localVmMaxInstances(cfg: AppConfig): number {
/** 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;
+ const raise = max < MAX_LOCAL_VM_MAX_INSTANCES ? " or raise the limit in App Settings" : "";
+ return existing >= max ? `The per-bot Local VM limit is ${max} — delete an unused bot VM${raise}` : null;
}
export function localVmIdleTimeoutMinutes(cfg: AppConfig): number {