Skip to content

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

Never pick another model for a bot that has no backup chosen

Rino Cheng9c0e7438b5f3
diff --git a/server/host/limit-takeover.test.ts b/server/host/limit-takeover.test.ts
index f37f787212..f844ab2e85 100644
--- a/server/host/limit-takeover.test.ts
+++ b/server/host/limit-takeover.test.ts
@@ -108,7 +108,8 @@ describe("which AI carries on while one is limited", () => {
const { instance } = takeover({ chosen: () => [on("codex", "gpt-6")] });
expect(instance.backups("kai", on("claude", "claude-sonnet-5"), "model")).toEqual([on("claude", "claude-opus-5-5"), on("codex", "gpt-6")]);
expect(instance.backups("kai", on("claude", "claude-opus-5-5"), "credits")).toEqual([on("codex", "gpt-6")]);
- expect(takeover().instance.backups("kai", on("claude", "claude-sonnet-5"), "model"), "the same AI's default model, with no backup chosen").toEqual([on("claude", "claude-opus-5-5")]);
+ expect(takeover().instance.backups("kai", on("claude", "claude-sonnet-5"), "model"), "no backup chosen: no other model is picked").toEqual([]);
+ expect(takeover().instance.backups("kai", on("claude", "claude-sonnet-5"), "credits"), "no backup chosen: none for credits either").toEqual([]);
});
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", () => {
@@ -138,6 +139,16 @@ describe("a model's own limit", () => {
type: "runtime.error", message: "limit", limit, ...(limitResetsAt ? { limitResetsAt } : {}),
}) as RuntimeEvent;
+ it("starts a no-backup bot's turn on its own model while that model is held, and a bot with a backup on the same AI's default", () => {
+ const opus = on("claude", "claude-sonnet-5");
+ const none = takeover();
+ none.instance.noteRuntimeEvent("kai", opus, error("model", NOW + 2 * HOUR));
+ expect(none.instance.heldAtStart(KAI, opus), "no backup chosen: the turn is tried as usual and the limit shows").toBeNull();
+ const chosen = takeover({ chosen: () => [on("codex", "gpt-6")] });
+ chosen.instance.noteRuntimeEvent("kai", opus, error("model", NOW + 2 * HOUR));
+ expect(chosen.instance.heldAtStart(KAI, opus), "a backup chosen: it carries on as before").toMatchObject({ scope: "model" });
+ });
+
it("holds that model alone until the reset it named, at most six hours, an hour when it named none, and not once it works", () => {
const { instance, now } = takeover({ chosen: () => [on("claude", "claude-opus-5-5"), on("opencode", "go-default")] });
instance.noteRuntimeEvent("kai", on("claude", "claude-opus-5-5"), error("model", NOW + 2 * HOUR));
diff --git a/server/host/limit-takeover.ts b/server/host/limit-takeover.ts
index 768a5700e0..9f3864c3da 100644
--- a/server/host/limit-takeover.ts
+++ b/server/host/limit-takeover.ts
@@ -174,9 +174,9 @@ export function createLimitTakeover(deps: LimitTakeoverDeps) {
return engine.models.default === selection.model || engine.models.options.some((model) => model.id === selection.model);
};
- /** The AIs that may carry on while `from` is limited or signed out, best first: for one model's limit the same AI's own
- * default model, then the backups the person chose. No other AI is picked for them: with none of those usable the bot
- * waits for the reset or a sign-in. `approval`: the thread's level, when known. */
+ /** The AIs that may carry on while `from` is limited or signed out, best first: for one model's limit, when the person chose
+ * any backup, the same AI's own default model first, then the backups the person chose. A bot with no backup chosen gets
+ * none, and no other AI is picked for it: with none usable the bot waits for the reset or a sign-in. `approval`: the thread's level, when known. */
function backups(botId: string, from: ModelSelection, scope: TakeoverScope = "engine", approval?: ApprovalMode): ModelSelection[] {
const engines = deps.engines();
const current = engines.find((engine) => engine.instanceId === from.instanceId);
@@ -187,8 +187,9 @@ export function createLimitTakeover(deps: LimitTakeoverDeps) {
if (out.some((known) => known.instanceId === selection.instanceId && known.model === selection.model)) return;
if (usable(engines, current, selection, scope, approval)) out.push({ instanceId: selection.instanceId, model: selection.model });
};
- if (scope === "model" || scope === "credits") add({ instanceId: current.instanceId, model: current.models.default });
- for (const selection of scope === "signed-out" ? deps.signedOutChosen?.(botId) ?? deps.chosen(botId) : deps.chosen(botId)) add(selection);
+ const chosen = deps.chosen(botId);
+ if ((scope === "model" || scope === "credits") && chosen.length) add({ instanceId: current.instanceId, model: current.models.default });
+ for (const selection of scope === "signed-out" ? deps.signedOutChosen?.(botId) ?? deps.chosen(botId) : chosen) add(selection);
return out;
}