Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Routines: skip the after-reset replay automatically, with no flag
milind-sonif62b9fdbf996
diff --git a/apps/docs/content/docs/features/automation.mdx b/apps/docs/content/docs/features/automation.mdxindex 2cfe06ce69..c5f6818742 100644--- a/apps/docs/content/docs/features/automation.mdx+++ b/apps/docs/content/docs/features/automation.mdx@@ -38,7 +38,7 @@ If your computer is often off when a routine is due, open the routine's **Advanc### When the AI's usage limit stops a run-If a bot's AI reaches its usage limit during a run and the limit resets within 12 hours, OpenMausBot starts that run once more a minute after the reset, and tells you so. For a repeating routine you can have it wait for its next scheduled run instead: set `"recurringRoutinesSkipLimitReplay": true` under `features` in `~/.openmausbot/config.json`. The stopped run then fails with the usual usage-limit notice. Runs you start with **Run now**, one-time routines and routines that run when a limit resets still start again at the reset, and a bot with a backup AI still switches to it at once.+If a bot's AI reaches its usage limit during a run and the limit resets within 12 hours, OpenMausBot starts that run once more a minute after the reset, and tells you so. A repeating routine's scheduled run is the exception when the routine's next scheduled run comes no later than one of its intervals after the reset (an hour for an hourly routine, a day for a daily one): that next run does the same work, so the stopped run fails with the usual usage-limit notice instead. Runs you start with **Run now**, one-time routines and routines that run when a limit resets still start again at the reset, and a bot with a backup AI still switches to it at once.### Clear a folder's unread dotsdiff --git a/server/config.ts b/server/config.tsindex 10065b8f36..66ff1389b2 100644--- a/server/config.ts+++ b/server/config.ts@@ -244,8 +244,8 @@ const featureConfigSchema = z.object({sharedComputers: z.boolean().optional(),claudeUserMcp: z.boolean().optional(), // Claude bots also load this machine's Claude Code MCP servers. Off unless true: tools cost tokens.claudeUserSkills: z.boolean().optional(), // Claude bots also load the skills in ~/.claude/skills, in place. Off unless true.- llmThreadTitles: z.boolean().optional(), // LLM-generated titles for new threads. Off unless true.- recurringRoutinesSkipLimitReplay: z.boolean().optional(), // A recurring routine run that a usage limit stopped waits for its next scheduled run instead of starting again at the reset. Off unless true.+ /** LLM-generated titles for new threads. Off unless true. */+ llmThreadTitles: z.boolean().optional(),/** A new bot's setup card offers answers its engine writes for it, when there is something to go on. On unless false. */smartSetupChoices: z.boolean().optional(),/** Recall matching passages from the bot's memory into each turn. On unless false. */@@ -514,7 +514,7 @@ export interface AppConfig extends HelperConfig {context?: { rebuildBytes?: number; compactAt?: number; autoCompact?: boolean; roomCompactAt?: number; roomSessions?: boolean; replayToolHistory?: boolean };memory?: { captureQuietMs?: number; tidyHour?: number };localVm?: { mode?: "shared" | "per-bot" | "pool"; maxInstances?: number; idleTimeoutMinutes?: number; preserveInstalledApps?: boolean };- features?: { skillAuthoring?: boolean; skillReview?: boolean; skillReviewSteps?: number; showToolCalls?: boolean; browser?: boolean; sharedComputers?: boolean; claudeUserMcp?: boolean; claudeUserSkills?: boolean; llmThreadTitles?: boolean; recurringRoutinesSkipLimitReplay?: boolean; smartSetupChoices?: boolean; autoRecall?: boolean; skillsLibrary?: boolean; shareLearnedSkills?: "off" | "ask" | "auto"; roomMemoryCapture?: boolean; parallelRoomJobs?: boolean; chiefEscalations?: boolean; acpPlanLines?: boolean; agentsToolBridge?: boolean; savedSteps?: boolean };+ features?: { skillAuthoring?: boolean; skillReview?: boolean; skillReviewSteps?: number; showToolCalls?: boolean; browser?: boolean; sharedComputers?: boolean; claudeUserMcp?: boolean; claudeUserSkills?: boolean; llmThreadTitles?: boolean; smartSetupChoices?: boolean; autoRecall?: boolean; skillsLibrary?: boolean; shareLearnedSkills?: "off" | "ask" | "auto"; roomMemoryCapture?: boolean; parallelRoomJobs?: boolean; chiefEscalations?: boolean; acpPlanLines?: boolean; agentsToolBridge?: boolean; savedSteps?: boolean };onboarding?: { completedAt?: string; version?: number; reelSeen?: boolean; hintsSeen?: string[]; firstTurnAt?: string };browserProfiles?: BrowserProfile[];browserEngine?: BrowserEngineConfig;diff --git a/server/index.ts b/server/index.tsindex 92d434bb49..e8729ef9c1 100644--- a/server/index.ts+++ b/server/index.ts@@ -8811,9 +8811,10 @@ const limitFailovers = new LimitFailovers({ file: join(DATA_DIR, "limit-failoverconst automationDestinations = createAutomationDestinations({ store, mainThread: botMainThread, runs: () => routines?.listRuns() ?? [],cloud: CLOUD_HOME ? { owner: CLOUD_OWNER_KEY!, opener: routineOpener, reportFromOthers: cloudReportFromOthers, opened: (threadId, person) => threadStarters.set(threadId, person), outside: (threadId) => outsideLineage.mark(threadId) } : null });routines = new RoutineManager({- emit: broadcast, limitResetAt: (engine) => limitClock.resetAt(engine), checks: proactive.checks, skipLimitReplay: () => cfg.features?.recurringRoutinesSkipLimitReplay === true,+ emit: broadcast, limitResetAt: (engine) => limitClock.resetAt(engine), checks: proactive.checks,limitBackup: (botId, scope) => { const bot = store.bot(botId); return quotaSwitchEnabled() ? Boolean(bot && limitTakeover.backups(botId, bot.modelSelection, scope, approvalModeFor(bot)).length) : Boolean(bot && startupBackups(bot, cfg.automaticRecovery).length); },- launchId: DESKTOP_MANAGED && /^[\w-]{1,100}$/.test(process.env.OMB_DESKTOP_LAUNCH_ID ?? "") ? process.env.OMB_DESKTOP_LAUNCH_ID : undefined,+ launchId: DESKTOP_MANAGED && /^[\w-]{1,100}$/.test(process.env.OMB_DESKTOP_LAUNCH_ID ?? "")+ ? process.env.OMB_DESKTOP_LAUNCH_ID : undefined,skipStartupRuns: 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,diff --git a/server/routine-recovery.test.ts b/server/routine-recovery.test.tsindex 482898bce8..ac91f7beae 100644--- a/server/routine-recovery.test.ts+++ b/server/routine-recovery.test.ts@@ -6,9 +6,9 @@ import { afterEach, describe, expect, it } from "vitest";import type { RuntimeEvent } from "../shared/runtime-events.ts";import { TRIAL_CREDIT_REFUSED } from "../shared/trial-credit.ts";import {- classifyRoutineFailure, dispatchRefusal, retryNote, ROUTINE_BUSY_RECHECK_MS, ROUTINE_BUSY_WAIT_MS, weekRuns, type RoutineAlert,+ classifyRoutineFailure, dispatchRefusal, nextScheduledRun, retryNote, ROUTINE_BUSY_RECHECK_MS, ROUTINE_BUSY_WAIT_MS, weekRuns, type RoutineAlert,} from "./routine-recovery.ts";-import { RoutineManager, type RoutineManagerOptions, type RoutineRun } from "./routines.ts";+import { RoutineManager, type Routine, type RoutineManagerOptions, type RoutineRun } from "./routines.ts";const dirs: string[] = [];afterEach(() => {@@ -416,35 +416,55 @@ describe("an unattended run only its owner can fix", () => {expect(h.deferred).toHaveLength(1);});- it("with skipLimitReplay on, fails a recurring routine's scheduled run at a usage limit; manual and one-time runs still wait for the reset", async () => {- const h = harness({ skipLimitReplay: () => true });+ it("lets a recurring routine's next scheduled run do the work a usage limit stopped, when it comes within one interval of the reset", async () => {+ const h = harness();const limit = "This Claude account has reached its 5-hour limit, which resets soon. Until then, switch this bot to another AI or Claude account.";const hourly = h.manager.create({ name: "Price check", prompt: "Check the price", botId: "maus-1", schedule: { type: "interval", everyMinutes: 60, anchorAt: START } });+ const daily = h.manager.create({ name: "Brief", prompt: "Write the brief", botId: "maus-2", schedule: { type: "daily", time: "09:00", weekdays: [0, 1, 2, 3, 4, 5, 6] } });+ await h.advance(60 * MINUTE);+ const scheduled = [hourly, daily].map((routine) => h.runs().find((run) => run.routineId === routine.id)!);+ for (const run of scheduled) {+ expect(run).toMatchObject({ status: "running", triggerSource: "schedule" });+ h.fail(run.threadId!, limit, { stopReason: "quota", limitResetsAt: START + 3 * 3_600_000 });+ expect(h.run(run.id)).toMatchObject({ status: "failed", error: limit });+ }+ const action = "This bot's AI reached its usage limit. Its routines work again once it resets, or choose another AI for this bot now.";+ expect(h.failed.map(({ run, alert }) => [run.id, alert])).toEqual(scheduled.map((run) => [run.id, { detail: action }]));+ expect(h.deferred).toEqual([]);+ });++ it("still starts a run again at the reset when its routine's next run is further off, or it was started by hand, or runs once", async () => {+ const h = harness();+ const limit = "This Claude account has reached its 5-hour limit.";+ const resetsAt = START + 3 * 3_600_000;+ const mondays = h.manager.create({ name: "Weekly plan", prompt: "Plan the week", botId: "maus-1", schedule: { type: "daily", time: "09:00", weekdays: [1] } });const once = h.manager.create({ name: "Reminder", prompt: "Remind me", botId: "maus-2", schedule: { type: "once", at: START + 30 * MINUTE } });await h.advance(30 * MINUTE);const oneTime = h.runs().find((run) => run.routineId === once.id)!;- h.fail(oneTime.threadId!, limit, { stopReason: "quota", limitResetsAt: START + 3 * 3_600_000 });- expect(h.run(oneTime.id)).toMatchObject({ status: "queued", retried: "usage_limit" });+ h.fail(oneTime.threadId!, limit, { stopReason: "quota", limitResetsAt: resetsAt });+ expect(h.run(oneTime.id)).toMatchObject({ status: "queued", retried: "usage_limit", retryAt: resetsAt + MINUTE });await h.advance(30 * MINUTE);- const scheduled = h.runs().find((run) => run.routineId === hourly.id)!;- expect(scheduled).toMatchObject({ status: "running", triggerSource: "schedule" });- h.fail(scheduled.threadId!, limit, { stopReason: "quota", limitResetsAt: START + 3 * 3_600_000 });- expect(h.run(scheduled.id)).toMatchObject({ status: "failed", error: limit });- expect(h.failed.map(({ run, alert }) => [run.id, alert])).toEqual([- [scheduled.id, { detail: "This bot's AI reached its usage limit. Its routines work again once it resets, or choose another AI for this bot now." }],- ]);+ const weekly = h.runs().find((run) => run.routineId === mondays.id)!;+ expect(weekly).toMatchObject({ status: "running", triggerSource: "schedule" });+ h.fail(weekly.threadId!, limit, { stopReason: "quota", limitResetsAt: resetsAt });+ expect(h.run(weekly.id)).toMatchObject({ status: "queued", retried: "usage_limit", retryAt: resetsAt + MINUTE });+ const hourly = h.manager.create({ name: "Price check", prompt: "Check the price", botId: "maus-3", schedule: { type: "interval", everyMinutes: 60, anchorAt: START } });const manual = await h.start(hourly.id);- h.fail(manual.threadId!, limit, { stopReason: "quota", limitResetsAt: START + 3 * 3_600_000 });- expect(h.run(manual.id)).toMatchObject({ status: "queued", retried: "usage_limit" });+ h.fail(manual.threadId!, limit, { stopReason: "quota", limitResetsAt: resetsAt });+ expect(h.run(manual.id)).toMatchObject({ status: "queued", retried: "usage_limit", retryAt: resetsAt + MINUTE });+ expect(h.failed).toEqual([]);});- it("starts a recurring routine's scheduled run again at the reset while skipLimitReplay is off", async () => {- const h = harness();- const hourly = h.manager.create({ name: "Price check", prompt: "Check the price", botId: "maus-1", schedule: { type: "interval", everyMinutes: 60, anchorAt: START } });- await h.advance(60 * MINUTE);- const scheduled = h.runs().find((run) => run.routineId === hourly.id)!;- h.fail(scheduled.threadId!, "This Claude account has reached its 5-hour limit.", { stopReason: "quota", limitResetsAt: START + 3 * 3_600_000 });- expect(h.run(scheduled.id)).toMatchObject({ status: "queued", retried: "usage_limit", retryAt: START + 3 * 3_600_000 + MINUTE });+ it("measures a cron routine's interval to the occurrence after its next one, and gives none for a run not its schedule started", () => {+ const routine = (schedule: Routine["schedule"], nextRunAt: number) => ({ id: "routine-1", enabled: true, schedule, nextRunAt }) as Routine;+ const weekdays = { type: "cron" as const, expression: "0 9 * * 1-5", timeZone: "UTC" };+ const thursday = Date.UTC(2026, 7, 20, 9), friday = Date.UTC(2026, 7, 21, 9);+ const scheduled = { routineId: "routine-1", triggerSource: "schedule" } as RoutineRun;+ expect(nextScheduledRun(scheduled, [routine(weekdays, thursday)])).toEqual({ at: thursday, interval: 24 * 60 * MINUTE });+ expect(nextScheduledRun(scheduled, [routine(weekdays, friday)])).toEqual({ at: friday, interval: 3 * 24 * 60 * MINUTE });+ expect(nextScheduledRun({ ...scheduled, triggerSource: "manual" }, [routine(weekdays, thursday)])).toBeUndefined();+ expect(nextScheduledRun({ ...scheduled, triggerSource: "startup" }, [routine(weekdays, thursday)])).toBeUndefined();+ expect(nextScheduledRun(scheduled, [routine({ type: "once", at: thursday }, thursday)])).toBeUndefined();});it("fails a usage limit with no reset time, or one too far off, and tells the owner", async () => {diff --git a/server/routine-recovery.ts b/server/routine-recovery.tsindex 7e4c9546d8..ad0d6b3a22 100644--- a/server/routine-recovery.ts+++ b/server/routine-recovery.ts@@ -7,6 +7,7 @@ import type { RuntimeEvent } from "../shared/runtime-events.ts";import type { RoutineRetryCause } from "../shared/routines.ts";import { engineFailureKind } from "./drivers/engine-errors.ts";import { classifyError } from "./drivers/retry.ts";+import { nextOccurrence } from "./routine-schedules.ts";import type { Routine, RoutineRun } from "./routines.ts";import { hostTimeZone } from "./turn-clock.ts";import { classifyContinuable } from "./turn-continuation.ts";@@ -27,8 +28,8 @@ export interface RoutineFailureFacts {limit?: "engine" | "model" | "credits";/** A backup engine takes over from one whose usage limit refused the run, or that is signed out. */backupReady?: boolean;- /** A usage limit fails the run instead of starting it again at the reset: its routine runs again on its own schedule. */- skipLimitReplay?: boolean;+ /** The next run a recurring routine's schedule starts, for a run that schedule started, and one interval of that schedule. */+ nextScheduled?: { at: number; interval: number };/** The turn's reply came back; only a step it ran failed or wasn't allowed (the runtime error's `partial`). */partial?: boolean;}@@ -53,7 +54,7 @@ export const ROUTINE_BUSY_WAIT_MS = 60 * 60_000;/** Past this, a usage limit fails the run instead: the routine's next scheduled runs come sooner. */const LIMIT_WAIT_MS = 12 * 60 * 60_000;const AFTER_RESET_MS = 60_000;-const WEEK_MS = 7 * 24 * 60 * 60_000;+const DAY_MS = 24 * 60 * 60_000, WEEK_MS = 7 * DAY_MS;/** startTurn's codes for a bot or thread that is busy for now. */const BUSY_CODES = new Set(["thread_busy", "thread_limit", "workspace_busy", "settling"]);/** Stop reasons of a turn someone ended on purpose (Stop, a typed "stop", a settings change that cut it short), the AI@@ -183,7 +184,9 @@ export function recoverRun(run: RoutineRun, failure: string, facts: RoutineFailu}const first = firstNotice(notices, run.botId, verdict.cause, now);const reset = verdict.resetsAt;- if (reset && !facts.skipLimitReplay && reset > now && reset - now <= LIMIT_WAIT_MS && requeueOnce(run, "usage_limit", failure, now, reset + AFTER_RESET_MS)) {+ // A recurring routine's next scheduled run, due within one interval after the reset, does the same work: no start at the reset.+ const nextCovers = reset !== undefined && facts.nextScheduled !== undefined && facts.nextScheduled.at <= reset + facts.nextScheduled.interval;+ if (reset && !nextCovers && reset > now && reset - now <= LIMIT_WAIT_MS && requeueOnce(run, "usage_limit", failure, now, reset + AFTER_RESET_MS)) {return { queued: true, ...(first ? { alert: { detail: `This bot's AI reached its usage limit. This run starts again at ${when(reset + AFTER_RESET_MS)}.` } } : {}) };}const action = verdict.cause === "setup" ? failure : verdict.cause === "credits" && facts.trialCredit ? TRIAL_ACTION : OWNER_ACTION[verdict.cause];@@ -206,9 +209,15 @@ export function weekRuns(runs: readonly RoutineRun[], routineId: string, now: nureturn total ? { ok, total } : undefined;}-/** A run its repeating schedule started: not one started by hand or by an event, and not a one-off or limit-reset routine. */-export function scheduledRecurringRun(run: RoutineRun, routines: readonly Routine[]): boolean {- if ((run.triggerSource ?? (run.manual ? "manual" : "schedule")) !== "schedule") return false;- const type = routines.find((routine) => routine.id === run.routineId)?.schedule.type;- return type !== undefined && type !== "once" && type !== "limit_reset";+/** A scheduled run's next scheduled occurrence and one interval of its schedule; none for a run started by hand, at startup or+ * by an event, or for a one-time or limit-reset routine. */+export function nextScheduledRun(run: RoutineRun, routines: readonly Routine[]): RoutineFailureFacts["nextScheduled"] {+ if ((run.triggerSource ?? (run.manual ? "manual" : "schedule")) !== "schedule") return undefined;+ const routine = routines.find((candidate) => candidate.id === run.routineId);+ if (!routine?.enabled || routine.nextRunAt == null) return undefined;+ const { schedule, nextRunAt: at } = routine;+ const following = schedule.type === "cron" ? nextOccurrence(schedule, at) : null;+ const interval = schedule.type === "interval" ? schedule.everyMinutes * 60_000 : schedule.type === "daily" ? DAY_MS+ : following !== null ? following - at : null;+ return interval === null ? undefined : { at, interval };}diff --git a/server/routines.ts b/server/routines.tsindex 62deb862de..d96b01606f 100644--- a/server/routines.ts+++ b/server/routines.ts@@ -23,7 +23,7 @@ import {routineFailure, routineHostWarning, skipNeedsNotice, supersededBy,} from "./routine-execution.ts";import {- dispatchRefusal, engineFacts, loadOwnerNotices, recoverRun, requeueOnce, weekRuns, type RoutineAlert, type RoutineFailureFacts, type RoutineOwnerNotice, scheduledRecurringRun,+ dispatchRefusal, engineFacts, loadOwnerNotices, nextScheduledRun, recoverRun, requeueOnce, weekRuns, type RoutineAlert, type RoutineFailureFacts, type RoutineOwnerNotice,} from "./routine-recovery.ts";import { activeMs, askOf, settleAsk, waitingFor, type RoutineRunAsk } from "./routine-waits.ts";import { failsLikeLastOutcome, outcomesNewestFirst } from "./routine-outcomes.ts";@@ -264,8 +264,6 @@ export interface RoutineManagerOptions {limitResetAt?: (engine: string) => number | null;/** The bot has a backup engine to continue on when its own engine's usage limit refuses a run, or it is signed out. */limitBackup?: (botId: string, scope?: "engine" | "model" | "credits" | "signed-out") => boolean;- /** A recurring routine run that a usage limit stopped waits for its next scheduled run instead of starting again at the reset. */- skipLimitReplay?: () => boolean;/** Work this thread handed to another bot is still open, so its wait is not only on the person. */handedOffWorkLive?: (threadId: string) => boolean;launchId?: string;@@ -619,7 +617,9 @@ export class RoutineManager {if (!clean.access) delete routine.access;if (!clean.deliver) delete routine.deliver;if (!clean.checks) for (const key of ["checks", "checkedAt", "checkTrouble", "wakeAt"] as const) delete routine[key];- if (Object.hasOwn(patch, "timeoutMinutes") && patch.timeoutMinutes == null) delete routine.timeoutMinutes;+ if (Object.hasOwn(patch, "timeoutMinutes") && patch.timeoutMinutes == null) {+ delete routine.timeoutMinutes;+ }if (patch.enabled === false) {for (const run of this.runs) {if (run.routineId !== routine.id || run.status !== "queued") continue;@@ -1308,7 +1308,7 @@ export class RoutineManager {this.failureFacts.delete(run.id);if (this.closing) return;const held = facts.limit !== undefined || facts.limitResetsAt !== undefined ? facts.limit ?? "engine" : facts.stopReason === "auth_required" ? "signed-out" : undefined, backupReady = held !== undefined && this.options.limitBackup?.(run.botId, held) === true;- const recovery = recoverRun(run, failure, { ...facts, ...(backupReady ? { backupReady } : {}), ...(this.options.skipLimitReplay?.() === true && scheduledRecurringRun(run, this.routines) ? { skipLimitReplay: true } : {}) }, this.now(), this.ownerNotices);+ const recovery = recoverRun(run, failure, { ...facts, ...(backupReady ? { backupReady } : {}), nextScheduled: nextScheduledRun(run, this.routines) }, this.now(), this.ownerNotices);if (!recovery.queued) this.failRun(Object.assign(run, { partial: (facts.partial && Boolean(run.output)) || undefined }), recovery.error, "failed", recovery.alert);else {this.saveLater();