Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Chief retries: queue only a retry of an idle thread whose bot is busy elsewhere
milind-sonid84b29142641
diff --git a/server/host/chief-notices-retry.test.ts b/server/host/chief-notices-retry.test.tsindex 1963537904..67d22d85d4 100644--- a/server/host/chief-notices-retry.test.ts+++ b/server/host/chief-notices-retry.test.ts@@ -80,7 +80,7 @@ describe("a Chief's retry of a teammate's busy thread", () => {}it("queues the retry while its bot is mid-turn elsewhere, and the queue starts it when the bot frees up", async () => {- const f = fixture({ threadBusy: (botId) => botId === "ada", groupTurnActive: (botId) => botId === "ada" });+ const f = fixture({ groupTurnActive: (botId) => botId === "ada" });const queued = await f.notices.retryThread({ chief: f.chief as never, bot: f.ada as never, threadId: "ada-job", unattended: true, note: "The service was down." });expect(queued).toEqual({ queued: true });expect(f.startTurn).not.toHaveBeenCalled();@@ -95,7 +95,7 @@ describe("a Chief's retry of a teammate's busy thread", () => {});it("queues with the capacity reason at its bot's turn limit, answering queued rather than failed", async () => {- const f = fixture({ threadQueued: () => true, botAtThreadCapacity: () => true });+ const f = fixture({ botAtThreadCapacity: () => true });const queued = await f.notices.retryThread({ chief: f.chief as never, bot: f.ada as never, threadId: "ada-job", unattended: false });expect(queued).toEqual({ queued: true });const snapshot = queuedSteerSnapshot(() => true);@@ -103,11 +103,23 @@ describe("a Chief's retry of a teammate's busy thread", () => {cancelSteeredMessage("ada", snapshot["ada-job"]![0]!.queueId, "ada-job");});- it("still refuses while the thread only shuts down, or when its bot has room and no room turn", async () => {- const settling = fixture({ threadBusy: () => true, threadSettling: () => true, groupTurnActive: () => true });- await expect(settling.notices.retryThread({ chief: settling.chief as never, bot: settling.ada as never, threadId: "ada-job", unattended: true })).rejects.toThrow(RETRY_BLOCKED.settling);- const withRoom = fixture({ threadBusy: () => true });- await expect(withRoom.notices.retryThread({ chief: withRoom.chief as never, bot: withRoom.ada as never, threadId: "ada-job", unattended: true })).rejects.toThrow(RETRY_BLOCKED.running);+ it("still refuses a thread that runs, shuts down or already waits, even while its bot is at its turn limit", async () => {+ for (const [over, refusal] of [+ [{ threadBusy: () => true }, RETRY_BLOCKED.running],+ [{ threadBusy: () => true, threadSettling: () => true }, RETRY_BLOCKED.settling],+ [{ threadQueued: () => true }, RETRY_BLOCKED.queued],+ ] as const) {+ const f = fixture({ ...over, botAtThreadCapacity: () => true, groupTurnActive: () => true });+ await expect(f.notices.retryThread({ chief: f.chief as never, bot: f.ada as never, threadId: "ada-job", unattended: true })).rejects.toThrow(refusal);+ expect(f.startTurn).not.toHaveBeenCalled();+ }+ expect(_queuedCount("ada-job")).toBe(0);+ });++ it("starts OpenMausBot's own retry at once, never from the queue", async () => {+ const f = fixture({ botAtThreadCapacity: () => true });+ await f.notices.retryThread({ chief: f.chief as never, bot: f.ada as never, threadId: "ada-job", unattended: true, automatic: true });+ expect(f.startTurn).toHaveBeenCalledTimes(1);expect(_queuedCount("ada-job")).toBe(0);});diff --git a/server/host/chief-notices.ts b/server/host/chief-notices.tsindex 93ed9f162c..103f2bbc70 100644--- a/server/host/chief-notices.ts+++ b/server/host/chief-notices.ts@@ -120,24 +120,22 @@ export function createChiefNotices(deps: ChiefNoticeDeps) {}/** The one way a teammate's stopped thread runs again: a Chief's retry_thread and OpenMausBot's automatic retry both- * start it here, after the same refusal checks. Throws the refusal, or why the start failed. A busy refusal queues the- * retry instead when the bot is mid-turn elsewhere or at its turn limit: the steer queue starts it when the bot frees up. */+ * start it here, after the same refusal checks. Throws the refusal, or why the start failed. A Chief's retry of an idle+ * thread whose bot is busy elsewhere (at its turn limit, or in a room's turn) waits in that thread's queue instead, and+ * the queue starts it when the bot frees up. A thread that still runs, shuts down or already waits is refused as before. */async function retryThread(input: { chief: BotRecord; bot: BotRecord; threadId: string; unattended: boolean; note?: string; automatic?: true }): Promise<{ queued: true } | undefined> {const refused = retryRefusal(input.bot.id, input.threadId);+ if (refused) throw new Error(refused);const chief = peerName(input.chief.name);const lead = input.automatic? `${AUTO_RETRY_LEAD}, once, before telling ${chief}, your Chief of Staff, that this thread's last run failed.`: `${RETRY_LEAD}${chief}, your Chief of Staff, after this thread's last run stopped.${input.note ? ` Note from ${chief}: ${quoteInNote(input.note, 300)}` : ""}`;const text = `${lead} Continue the request above from where it stopped and finish it. If the same problem comes back, say exactly what is blocking and stop.]`;const peerAsk = { botId: input.chief.id, name: input.chief.name, ...(input.unattended ? { unattended: true } : {}) };- if (refused) {- const atCapacity = deps.botAtThreadCapacity(input.bot.id);- const groupTurn = deps.groupTurnActive(input.bot.id);- if ((refused === RETRY_BLOCKED.running || refused === RETRY_BLOCKED.queued) && (atCapacity || groupTurn)) {- queueSteeredMessage(input.bot.id, input.threadId, text, { reason: atCapacity ? "capacity" : "group-turn", unattended: input.unattended, peerAsk });- return { queued: true };- }- throw new Error(refused);+ const atCapacity = !input.automatic && deps.botAtThreadCapacity(input.bot.id);+ if (atCapacity || (!input.automatic && deps.groupTurnActive(input.bot.id))) {+ queueSteeredMessage(input.bot.id, input.threadId, text, { reason: atCapacity ? "capacity" : "group-turn", unattended: input.unattended, peerAsk });+ return { queued: true };}await deps.startTurn(input.bot.id, text, { threadId: input.threadId, unattended: input.unattended, peerAsk });}