Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(limit-takeover): weigh configured backups before the same-account default model
koeria8db3a211bafe
diff --git a/server/host/limit-takeover.test.ts b/server/host/limit-takeover.test.tsindex 0e773a56a4..8af2eaa1d3 100644--- a/server/host/limit-takeover.test.ts+++ b/server/host/limit-takeover.test.ts@@ -68,11 +68,11 @@ const REASONING = { ...TOOLS, effortLevels: ["low", "medium", "high"], modelVariconst REASONING_ENGINES = () => [CLAUDE, CODEX, GO].map((one) => ({ ...one, capabilities: REASONING }));describe("which AI carries on while one is limited", () => {- it("keeps the chosen reasoning when the first backup is also the same account's default model", () => {+ it("keeps the chosen reasoning when a backup is also the same account's default model, in the person's order", () => {const sameAccount = { ...on("codex", "gpt-6"), effort: "medium" } as const;const other = { ...on("opencode", "go-default"), variant: "thinking" };const { instance } = takeover({ engines: REASONING_ENGINES, chosen: () => [other, sameAccount] });- expect(instance.backups("kai", on("codex", "gpt-6-mini"), "model")).toEqual([sameAccount, other]);+ expect(instance.backups("kai", on("codex", "gpt-6-mini"), "model")).toEqual([other, sameAccount]);});it("preserves configured reasoning effort and model variant on chosen backups", () => {@@ -155,9 +155,9 @@ describe("which AI carries on while one is limited", () => {expect(told[0]!.text).toMatch(/^Codex reached its limit until .+, so Kai waits until then: no backup you chose can take over\.$/);});- it("for one model's own limit tries that AI's default model first, and never the limited model", () => {+ it("for one model's own limit offers that AI's default model only after the backups the person chose, and never the limited model", () => {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-sonnet-5"), "model")).toEqual([on("codex", "gpt-6"), on("claude", "claude-opus-5-5")]);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"), "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([]);diff --git a/server/host/limit-takeover.ts b/server/host/limit-takeover.tsindex 35869d50b8..4fde085053 100644--- a/server/host/limit-takeover.ts+++ b/server/host/limit-takeover.ts@@ -193,8 +193,9 @@ export function createLimitTakeover(deps: LimitTakeoverDeps) {return engine.models.default === selection.model || engine.models.options.some((model) => model.id === selection.model) ? null : { why: "unknown-model" };};- /** 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+ /** The AIs that may carry on while `from` is limited or signed out, best first: the backups the person chose, in their+ * order, then for one model's limit or its credits the same AI's own default model, so the person's explicit picks are+ * never overridden. 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. `chosen`: the backups to weigh instead of the bot's and the installation's. `skipped`: each backup* left out, and why. */@@ -217,11 +218,9 @@ export function createLimitTakeover(deps: LimitTakeoverDeps) {else out.push(pick);};const picked = chosen ?? deps.chosen(botId);- if ((scope === "model" || scope === "credits") && picked.length) {- const sameAccountDefault = picked.find((entry) => entry.instanceId === current.instanceId && entry.model === current.models.default);- add(sameAccountDefault ?? { instanceId: current.instanceId, model: current.models.default });- }for (const selection of chosen ?? (scope === "signed-out" ? deps.signedOutChosen?.(botId) ?? picked : picked)) add(selection);+ // The same AI's own default model may carry on for one model's limit or its credits, but only after the backups the person chose, in their order.+ if ((scope === "model" || scope === "credits") && picked.length) add({ instanceId: current.instanceId, model: current.models.default });return { backups: out, skipped: left };}