Skip to content

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

fix: count the saved backup only while Automatic recovery is on

Rino Chengb806f7f73126
diff --git a/server/automatic-recovery.ts b/server/automatic-recovery.ts
index 3c857e8d38..9467f98442 100644
--- a/server/automatic-recovery.ts
+++ b/server/automatic-recovery.ts
@@ -12,6 +12,12 @@ export function startupBackups(bot: { fallback?: Backup[] }, recovery?: { enable
return recovery?.enabled && recovery.backup ? [recovery.backup] : [];
}
+/** Every backup a limited bot may be moved to: its own list, then the installation's one backup, which counts only
+ * while Automatic recovery is on (the backup stays saved while it is off). */
+export function chosenBackups(bot: { fallback?: Backup[] } | null | undefined, recovery?: { enabled: boolean; backup?: Backup }): Backup[] {
+ return [...(bot?.fallback ?? []), ...(recovery?.enabled && recovery.backup ? [recovery.backup] : [])];
+}
+
/** An automatic switch must not strand the task without its tools or move its filesystem to another machine. A USB
* phone is not one of those tools: only Codex and Pi drive one, Claude offers it on every desktop, and no Cloud has a
* USB port, so counting it left a limited Claude bot with no backup but those two. */
diff --git a/server/host/limit-takeover.test.ts b/server/host/limit-takeover.test.ts
index f844ab2e85..019f1d2895 100644
--- a/server/host/limit-takeover.test.ts
+++ b/server/host/limit-takeover.test.ts
@@ -1,3 +1,4 @@
+import { chosenBackups } from "../automatic-recovery.ts";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
@@ -112,6 +113,16 @@ describe("which AI carries on while one is limited", () => {
expect(takeover().instance.backups("kai", on("claude", "claude-sonnet-5"), "credits"), "no backup chosen: none for credits either").toEqual([]);
});
+ it("counts the installation's saved backup only while Automatic recovery is on", () => {
+ const backup = on("codex", "gpt-6");
+ const off = takeover({ chosen: () => chosenBackups(undefined, { enabled: false, backup }) }).instance;
+ for (const scope of ["model", "credits", "engine"] as const) {
+ expect(off.backups("kai", on("claude", "claude-sonnet-5"), scope), `recovery off, backup saved: none for ${scope}`).toEqual([]);
+ }
+ expect(chosenBackups({ fallback: [] }, { enabled: true, backup })).toEqual([backup]);
+ expect(chosenBackups({ fallback: [on("claude", "claude-opus-5-5")] }, { enabled: false, backup }), "the bot's own list always counts").toEqual([on("claude", "claude-opus-5-5")]);
+ });
+
it("leaves out an AI that is signed out, held by its own limit, short of this AI's tools, or another sign-in to the same plan", () => {
const signedOut = engine("claude", "claudeAgent", ["claude-opus-5-5"], { snapshot: { state: "available", authenticated: false } });
const claudeChosen = { chosen: () => [on("claude", "claude-opus-5-5"), on("opencode", "go-default")] };
diff --git a/server/index.ts b/server/index.ts
index 36d0d7c3b8..86d3d4cc61 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -210,7 +210,7 @@ import {
newId,
} from "./contracts.ts";
import { RETRY_MAX_ATTEMPTS } from "./drivers/retry.ts";
-import { recoveryCapabilityError, startupBackups } from "./automatic-recovery.ts"; import { outOfProcesses } from "./process-shortage.ts";
+import { chosenBackups, recoveryCapabilityError, startupBackups } from "./automatic-recovery.ts"; import { outOfProcesses } from "./process-shortage.ts";
import { createQuotaSwitchHost } from "./host/quota-switch.ts"; import { quotaSwitchEnabled } from "./quota-switch.ts"; import { createPeerLimitResend } from "./host/peer-limit-resend.ts";
import { decodeGeneratedImage } from "./generated-image.ts";
import { createMcpServersHost } from "./host/mcp-servers-host.ts"; import { createMcpKeys } from "./vault/mcp-keys.ts"; import { createLimitTakeover, signedOutStop } from "./host/limit-takeover.ts";
@@ -8734,7 +8734,7 @@ async function stopBotForEmergencyApprovalDowngrade(botId: string): Promise<void
const engineName = (engine: string) => engineLabel(engine, registry.get(engine) ?? undefined);
const limitClock = new LimitResetClock({ file: join(DATA_DIR, "limit-holds.json"), accounts: () => planAccountsFromInstances(instanceConfigs(cfg)), onChange: () => routines?.retimeLimitResets(),
- waiting: () => Boolean(routines?.listRoutines().some((routine) => routine.enabled && routine.schedule.type === "limit_reset")) }); const limitTakeover = createLimitTakeover({ file: join(DATA_DIR, "limit-notices.json"), holdsFile: join(DATA_DIR, "limit-takeover-holds.json"), configs: () => instanceConfigs(cfg), context: selectionContext, blockedUntil: (engine, model) => limitClock.blockedUntil(engine, model), resetAt: (engine, model) => limitClock.resetAt(engine, model), enabled: () => quotaSwitchEnabled(), where: CLOUD_HOME ? "on the Cloud" : "on this computer", signedOutNow: (id) => registry.knownSnapshot(id)?.authenticated === false, signedOutNoticed: () => registry.forgetSnapshots(), botsOn: (id) => store.bots.filter((bot) => !bot.hidden && bot.modelSelection.instanceId === id), engineName, engines: () => selectableInstances(registry.instances().map((engine) => ({ instanceId: engine.instanceId, driverKind: engine.driverKind, displayName: engine.displayName, enabled: engine.enabled, access: registry.access(engine.instanceId), models: engine.models, snapshot: registry.knownSnapshot(engine.instanceId) ?? { state: "unavailable" as const, reason: "not read yet" }, capabilities: engine.adapter.capabilities }))), chosen: (botId) => [...(store.bot(botId)?.fallback ?? []), ...(cfg.automaticRecovery?.backup ? [cfg.automaticRecovery.backup] : [])], signedOutChosen: (botId) => { const bot = store.bot(botId); return bot ? startupBackups(bot, cfg.automaticRecovery) : []; }, tell: (about, text) => notify(buildNoticeNotification(about, store.bot(about.id)?.threadId ?? "", text)), record: (failover) => { limitFailovers.record(failover); perf.noteFailover(failover.threadId, failover.why === "signed-out" ? "signed-out" : "limit"); } }); registry.onSignedIn((instanceId) => limitTakeover.signedIn(instanceId));
+ waiting: () => Boolean(routines?.listRoutines().some((routine) => routine.enabled && routine.schedule.type === "limit_reset")) }); const limitTakeover = createLimitTakeover({ file: join(DATA_DIR, "limit-notices.json"), holdsFile: join(DATA_DIR, "limit-takeover-holds.json"), configs: () => instanceConfigs(cfg), context: selectionContext, blockedUntil: (engine, model) => limitClock.blockedUntil(engine, model), resetAt: (engine, model) => limitClock.resetAt(engine, model), enabled: () => quotaSwitchEnabled(), where: CLOUD_HOME ? "on the Cloud" : "on this computer", signedOutNow: (id) => registry.knownSnapshot(id)?.authenticated === false, signedOutNoticed: () => registry.forgetSnapshots(), botsOn: (id) => store.bots.filter((bot) => !bot.hidden && bot.modelSelection.instanceId === id), engineName, engines: () => selectableInstances(registry.instances().map((engine) => ({ instanceId: engine.instanceId, driverKind: engine.driverKind, displayName: engine.displayName, enabled: engine.enabled, access: registry.access(engine.instanceId), models: engine.models, snapshot: registry.knownSnapshot(engine.instanceId) ?? { state: "unavailable" as const, reason: "not read yet" }, capabilities: engine.adapter.capabilities }))), chosen: (botId) => chosenBackups(store.bot(botId), cfg.automaticRecovery), signedOutChosen: (botId) => { const bot = store.bot(botId); return bot ? startupBackups(bot, cfg.automaticRecovery) : []; }, tell: (about, text) => notify(buildNoticeNotification(about, store.bot(about.id)?.threadId ?? "", text)), record: (failover) => { limitFailovers.record(failover); perf.noteFailover(failover.threadId, failover.why === "signed-out" ? "signed-out" : "limit"); } }); registry.onSignedIn((instanceId) => limitTakeover.signedIn(instanceId));
const limitFailovers = new LimitFailovers({ file: join(DATA_DIR, "limit-failovers.json"), blockedUntil: (engine, model) => limitClock.blockedUntil(engine, model), signedOut: (engine) => limitTakeover.stillSignedOut(engine), engineName,
threadModel: (botId, threadId) => store.projectBotForTask(botId, threadId)?.modelSelection ?? null,
note: (threadId, line, text) => store.appendMessage(threadId, { role: "bot", kind: "activity", tool: { name: `recovery: ${line}`, ok: true, ...(text ? { nameCode: text.key, nameParams: text.params } : {}) } }),