Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Let a paused bot's routine and webhook runs go quietly instead of failing into To review (#5947)
milind-soni0d21b1814374
diff --git a/docs/pausing-bots.md b/docs/pausing-bots.mdindex 499767a780..681566d934 100644--- a/docs/pausing-bots.md+++ b/docs/pausing-bots.md@@ -14,8 +14,8 @@ Right away, for every bot it pauses:Until it is resumed, a paused bot takes no new work:- a message to it is refused with a line saying it is paused and how to resume it;-- its routines and webhooks don't run: each run that comes due fails with the same line, and the routine's card says- its bot is paused;+- its routines and webhooks don't run: each run that comes due is let go quietly, with the same line in its run log,+ so nothing lands under To review; the routine's card says its bot is paused. A run started by hand fails with the line;- another bot that tries to hand it work is told it is paused, and not to route around it;- in a room it is skipped, and the room goes on with its other members;- the bot API and the headless CLI get `409` with code `bot_held`.diff --git a/server/index.ts b/server/index.tsindex 57246892dc..5cda955dc4 100644--- a/server/index.ts+++ b/server/index.ts@@ -8785,7 +8785,7 @@ routines = new RoutineManager({skipStartupRuns: (startedFromSleep = Boolean(CLOUD_HOME) && wokeFromSleep(DATA_DIR)), // a Cloud home waking from a sleep it was stopped forhasPendingDelegations: runtimeWorkPending, refusedHandoff: refusedHandoffs.take, handedOffWorkLive: (threadId) => coordinator.outstandingFor(threadId).length > 0,routineTurn: (threadId) => directRequestOwners.get(threadId)?.automation !== undefined, personTurn: (threadId) => directRequestOwners.get(threadId)?.origin?.kind === "user",- botState: unattendedDispatchState, pausedText: (botId) => botHolds.text(botId, threadLanguage(store.bot(botId)?.threadId ?? "")) ?? starterCaps.pausedText(botId, threadLanguage(store.bot(botId)?.threadId ?? "")),+ botState: unattendedDispatchState, pausedText: (botId) => botHolds.text(botId, threadLanguage(store.bot(botId)?.threadId ?? "")) ?? starterCaps.pausedText(botId, threadLanguage(store.bot(botId)?.threadId ?? "")), held: (botId) => botHolds.held(botId),goalState: (groupId, coordinatorBotId) => {if (!groupId) return unattendedDispatchState(coordinatorBotId);const group = store.group(groupId);diff --git a/server/routines.test.ts b/server/routines.test.tsindex 93506b01ad..10a5af100b 100644--- a/server/routines.test.ts+++ b/server/routines.test.ts@@ -4086,6 +4086,25 @@ describe("turning a schedule back on, and a deleted bot's schedules", () => {h.manager.create(once(start + 120_000));expect(h.manager.nextDueAt()).toBe(start + 120_000);});++ it("lets a bot the person paused skip its scheduled and webhook runs quietly, and fails only a run they started by hand", async () => {+ const h = harness(start);+ const paused = "Ada is paused, so it takes no new work.";+ h.options.pausedText = (botId) => (botId === "maus-1" ? paused : null);+ h.options.held = (botId) => botId === "maus-1";+ const routine = h.manager.create(once(start + 60_000));+ h.setNow(start + 60_000);+ await h.manager.tick();+ h.manager.enqueueWebhook({ webhookId: "hook", webhookName: "New lead", prompt: "Handle it", botId: "maus-1", runOn: "maus", deliveryId: "d1", receivedAt: start });+ await h.manager.tick();+ expect(h.manager.listRuns().map((run) => [run.status, run.error])).toEqual([["cancelled", paused], ["cancelled", paused]]);+ expect([h.taskTitles, h.started, h.failed]).toEqual([[], [], []]);++ h.manager.runNow(routine.id);+ await h.manager.tick();+ expect(h.manager.listRuns().at(-1)).toMatchObject({ status: "failed", error: paused });+ expect(h.failed).toHaveLength(1);+ });});describe("runs that report into a chat", () => {diff --git a/server/routines.ts b/server/routines.tsindex 4593fb20cd..fb360dbc73 100644--- a/server/routines.ts+++ b/server/routines.ts@@ -226,7 +226,7 @@ export interface RoutineManagerOptions {/** Every payload must be `{ kind, … }`: the server numbers and replays frames by it. */emit?: (payload: Record<string, unknown>) => void;botState: (botId: string) => "ready" | "busy" | "missing";- /** Why this bot takes no runs now, in the person's words (a Starter Cloud keeps only so many bots awake); null when it does. */ pausedText?: (botId: string) => string | null;+ /** Why this bot takes no runs now, in the person's words (a Starter Cloud keeps only so many bots awake); null when it does. */ pausedText?: (botId: string) => string | null; /** The person paused this bot: its runs are let go quietly, not failed into To review. */ held?: (botId: string) => boolean;goalState?: (groupId: string | undefined, coordinatorBotId: string) => "ready" | "busy" | "missing";createTask: (botId: string, title: string, run?: RoutineRun) => { threadId: string } | null;joinConversation?: (run: RoutineRun) => string | null;@@ -1113,7 +1113,7 @@ export class RoutineManager {}if (state === "missing") { this.failRun(run, this.missingTargetMessage(run.target)); continue; }const paused = run.target === "room-goal" ? null : this.options.pausedText?.(run.botId);- if (paused) { this.failRun(run, paused); continue; }+ if (paused) { if (triggerSource !== "manual" && this.options.held?.(run.botId)) void this.cancelRun(run.id, paused); else this.failRun(run, paused); continue; }const startedAt = this.now();const suffix = ` · ${new Date(startedAt).toLocaleString("en-US", { month: "short", day: "numeric", hour: "numeric", minute: "2-digit" })}`;const title = `${run.routineName.slice(0, 80 - suffix.length).trimEnd()}${suffix}`;