Skip to content

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

Routines: optional model per routine

Doğukaan Kılıçarslan3ed45bb35d30
diff --git a/apps/docs/content/docs/features/automation.mdx b/apps/docs/content/docs/features/automation.mdx
index cb58290669..40b8eb7630 100644
--- a/apps/docs/content/docs/features/automation.mdx
+++ b/apps/docs/content/docs/features/automation.mdx
@@ -36,6 +36,10 @@ Each run starts fresh by default. For work that builds on last time, such as a Q
If your computer is often off when a routine is due, open the routine's **Advanced** options and turn on **Also run when OpenMausBot starts**. The routine then runs once each time OpenMausBot opens, as well as on its schedule. Its run logs show these runs as **On startup**. A routine that OpenMausBot is already catching up on at startup runs once, not twice, and an occurrence missed by more than 12 hours is covered by the startup run instead of being reported as missed. Switching to another workspace and back, or OpenMausBot recovering from a crash, doesn't count as opening the app again. Pausing a routine stops its startup runs too. It's available for repeating routines, and you can also ask the bot in chat to turn it on.
+### A routine's own model
+
+A routine runs on its bot's model unless it has its own. Give it one through the API with `modelSelection` (the same shape as a bot's: `instanceId`, `model`, and an optional `effort` or `variant`), for example a light hourly check on a smaller model while the bot chats on a stronger one: `PATCH /api/routines/<id>` with `{"modelSelection": {"instanceId": "claude", "model": "claude-haiku-4-5"}}`. Each run's thread then uses that model; if its AI isn't available, the thread falls back to the bot's model. Send `"modelSelection": null` to go back to the bot's model. Room goals always use their bots' own models.
+
### Clear a folder's unread dots
Right-click a folder or open its **…** menu, then choose **Mark folder as read**. This clears unread dots without opening each thread. It does not answer approvals, dismiss questions, or stop any running work.
diff --git a/server/cloud-send-kinds.ts b/server/cloud-send-kinds.ts
index f43e58781c..b64f5de052 100644
--- a/server/cloud-send-kinds.ts
+++ b/server/cloud-send-kinds.ts
@@ -35,7 +35,7 @@ import { restorePaths, validRelative } from "./workspace-backup-paths.ts";
const SHARED_ROOT = "/omb-data";
const FINISHED = new Set(["completed", "failed", "cancelled", "missed"]);
const KIND_BODY_MAX = 8 * 1024 * 1024;
-const ROUTINE_FIELDS = ["name", "prompt", "target", "botId", "groupId", "runOn", "schedule", "durationMinutes", "timeoutMinutes", "attachments", "continuity",
+const ROUTINE_FIELDS = ["name", "prompt", "target", "botId", "groupId", "runOn", "schedule", "durationMinutes", "timeoutMinutes", "attachments", "continuity", "modelSelection",
"overlap", "runOnStartup", "sourceThreadId", "resultsThreadId", "createdAt", "checks", "access", "deliver"] as const;
const CALL_FIELDS = ["name", "description", "botIds", "schedule", "durationMinutes", "attachments", "roomId", "createdAt"] as const;
const WEBHOOK_FIELDS = ["name", "prompt", "botId", "runOn", "delivery", "groupId", "eventTypes", "maxPendingRuns", "resultsThreadId", "createdAt"] as const;
diff --git a/server/index.ts b/server/index.ts
index 8104d276fa..17e564c73b 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -2647,6 +2647,15 @@ function retryComputerEngineMove(): Promise<void> {
return computerEngineMoveRunning;
}
+function routineModelRefusal(body: unknown): { status: number; error: string } | null {
+ const raw = body && typeof body === "object" ? (body as { modelSelection?: unknown }).modelSelection : undefined;
+ if (raw == null) return null;
+ const checked = checkedModelSelection(raw);
+ if (!checked.ok) return checked;
+ (body as { modelSelection: ModelSelection }).modelSelection = checked.selection;
+ return null;
+}
+
function checkedModelSelection(
raw: unknown,
current?: { selection: ModelSelection; busy: boolean },
@@ -8939,7 +8948,8 @@ routines = new RoutineManager({
return groupIsWorking(group) || coordinator.busy ? "busy" : "ready";
},
createTask: (botId, title, run) => {
- const task = store.createTask(botId, title, false);
+ const model = run && routines?.listRoutines().find((routine) => routine.id === run.routineId)?.modelSelection;
+ const task = store.createTask(botId, title, false, undefined, undefined, undefined, model || undefined);
// On a Cloud home the routine's writer opens a run's conversation; a webhook run is the owner's, but its payload never reaches the lent Mac.
if (task && CLOUD_HOME && run) {
threadStarters.set(task.threadId, run.triggerSource === "webhook" ? CLOUD_OWNER_KEY! : routineOpener(run.routineId));
@@ -14865,6 +14875,8 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {
? cloudThreadRefusal(auth, (body as { resultsThreadId: string }).resultsThreadId) : null;
if (path === "/api/routines" && method === "POST") {
const body = await readBody(req);
+ const model = routineModelRefusal(body);
+ if (model) return json(res, model.status, { error: model.error });
const hidden = hiddenRoutineTarget(body, visible);
if (hidden) return json(res, 404, { error: hidden });
const notYours = routineResultsRefusal(body);
@@ -14888,6 +14900,8 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {
routineMatch = path.match(/^\/api\/routines\/([\w-]+)$/);
if (routineMatch && method === "PATCH") {
const body = await readBody(req);
+ const model = routineModelRefusal(body);
+ if (model) return json(res, model.status, { error: model.error });
const hidden = hiddenRoutineTarget(body, visible);
if (hidden) return json(res, 404, { error: hidden });
const notYours = routineResultsRefusal(body);
diff --git a/server/routine-input.ts b/server/routine-input.ts
index 0fc48781e6..b73106d7b9 100644
--- a/server/routine-input.ts
+++ b/server/routine-input.ts
@@ -1,7 +1,7 @@
// A routine as a person, a bot or an import asked for it, checked and cleaned before RoutineManager keeps it.
import { runsOnce } from "../shared/limit-reset.ts";
import { cleanAttachments, cleanTimeoutMinutes } from "./routine-attachments.ts";
-import { loadChecks } from "./routine-load.ts";
+import { loadChecks, loadModelSelection } from "./routine-load.ts";
import { cleanSchedule } from "./routine-schedules.ts";
import type { Routine, RoutineInput } from "./routines.ts";
@@ -35,6 +35,9 @@ export function sanitizeInput(input: RoutineInput, after: number): Omit<Routine,
if (continuity && target === "room-goal") {
throw new Error("Room goals do not carry continuity yet");
}
+ const modelSelection = input.modelSelection == null ? undefined : loadModelSelection(input.modelSelection);
+ if (input.modelSelection != null && !modelSelection) throw new Error("Choose a model: an engine, a model id, and an effort level or a variant, not both");
+ if (modelSelection && target === "room-goal") throw new Error("Room goals run on their bots' own models");
const schedule = cleanSchedule(input.schedule, after);
const asked = Array.isArray(input.checks) && input.checks.length === 0 ? null : input.checks;
const checks = asked == null ? undefined : loadChecks(asked);
@@ -55,6 +58,7 @@ export function sanitizeInput(input: RoutineInput, after: number): Omit<Routine,
...(timeoutMinutes === undefined ? {} : { timeoutMinutes }),
attachments,
...(continuity ? { continuity: true } : {}),
+ ...(modelSelection ? { modelSelection } : {}),
...(input.overlap === "queue" ? { overlap: "queue" as const } : {}),
...(input.runOnStartup === true && !runsOnce(schedule) ? { runOnStartup: true } : {}),
...(checks ? { checks } : {}),
diff --git a/server/routine-load.ts b/server/routine-load.ts
index 58386f5b80..dc15e31cd7 100644
--- a/server/routine-load.ts
+++ b/server/routine-load.ts
@@ -4,6 +4,8 @@ import { z } from "zod";
import type { RoutineRequestOperation } from "../shared/routine-request.ts";
import { ROUTINE_CHECKS, type RoutineCheck } from "../shared/routines.ts";
+import { isEffortLevel, type ModelSelection } from "../shared/wire.ts";
+import { isModelVariant } from "./contracts.ts";
import { ROUTINE_PARTS, type PartPair, type RoutinePart } from "./package-parts.ts";
import { loadAttachments, loadTimeoutMinutes } from "./routine-attachments.ts";
import { isRoutineHoldCause } from "./routine-holds.ts";
@@ -76,6 +78,15 @@ function withoutUndefined<T extends object>(record: T, keys: ReadonlyArray<keyof
}
/** Null when its schedule cannot load: the caller keeps it on disk, unscheduled. */
+export function loadModelSelection(value: unknown): ModelSelection | undefined {
+ if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
+ const { instanceId, model, effort, variant } = value as Record<keyof ModelSelection, unknown>;
+ if (typeof instanceId !== "string" || !instanceId.trim() || typeof model !== "string" || !model.trim()) return undefined;
+ if (effort !== undefined && (!isEffortLevel(effort) || variant !== undefined)) return undefined;
+ if (variant !== undefined && !isModelVariant(variant)) return undefined;
+ return { instanceId: instanceId.trim(), model: model.trim(), ...(effort === undefined ? {} : { effort }), ...(variant === undefined ? {} : { variant }) };
+}
+
export function loadRoutine(routine: Routine, now: number): Routine | null {
const schedule = loadSchedule(routine.schedule, now);
if (!schedule) return null;
@@ -92,6 +103,7 @@ export function loadRoutine(routine: Routine, now: number): Routine | null {
resultsThreadId: persistedSourceThreadId.parse(routine.resultsThreadId),
overlap: routine.overlap === "queue" ? "queue" : undefined,
runOnStartup: routine.runOnStartup === true ? true : undefined,
+ modelSelection: routine.target === "room-goal" ? undefined : loadModelSelection(routine.modelSelection),
skippedRuns: Number.isSafeInteger(routine.skippedRuns) && routine.skippedRuns! > 0 ? routine.skippedRuns : undefined,
lastSkippedAt: Number.isSafeInteger(routine.lastSkippedAt) && routine.lastSkippedAt! >= 0 && routine.lastSkippedAt! <= MAX_DATE_MS ? routine.lastSkippedAt : undefined,
installedPackage: loadInstalledPackage(routine.installedPackage),
@@ -101,7 +113,7 @@ export function loadRoutine(routine: Routine, now: number): Routine | null {
heldFor: isRoutineHoldCause(routine.heldFor) ? routine.heldFor : undefined,
};
delete loaded.failureStreak;
- return withCheckFields(withoutUndefined(loaded, ["timeoutMinutes", "runOnStartup", "installedPackage", "checkedAt", "checkTrouble", "wakeAt", "heldFor"]));
+ return withCheckFields(withoutUndefined(loaded, ["timeoutMinutes", "runOnStartup", "modelSelection", "installedPackage", "checkedAt", "checkTrouble", "wakeAt", "heldFor"]));
}
export function loadRun(run: RoutineRun): RoutineRun {
diff --git a/server/routine-model.e2e.test.ts b/server/routine-model.e2e.test.ts
new file mode 100644
index 0000000000..867942cbaa
--- /dev/null
+++ b/server/routine-model.e2e.test.ts
@@ -0,0 +1,33 @@
+import { expect, it } from "vitest";
+import { launchVerificationServer, runControlOmb } from "../scripts/control-omb.ts";
+
+it("opens each run of a routine with its own model in the run's thread, and refuses a model it cannot check", async () => {
+ const fixture = await launchVerificationServer(process.env, undefined, undefined, undefined, undefined, { scripted: true });
+ const api = async (method: string, path: string, body?: unknown) => {
+ const response = await fetch(`${fixture.info.url}${path}`, { method,
+ headers: { "content-type": "application/json", origin: fixture.info.url },
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
+ });
+ return { status: response.status, body: await response.json() as any };
+ };
+ const cli = (...args: string[]) => runControlOmb([...args, "--url", fixture.info.url]) as Promise<any>;
+ try {
+ const { bot } = await cli("new-bot", "--name", "Routine model fixture");
+ const own = { instanceId: bot.modelSelection.instanceId, model: `${bot.modelSelection.model}-routine` };
+ const created = await api("POST", "/api/routines", { name: "Inbox sweep", prompt: "Sweep the inbox", botId: bot.id,
+ schedule: { type: "daily", time: "09:00", weekdays: [1] }, modelSelection: own });
+ expect(created.status, JSON.stringify(created.body)).toBe(201);
+ expect(created.body.routine.modelSelection).toEqual(own);
+ const run = (await api("POST", `/api/routines/${created.body.routine.id}/run`)).body.run;
+ await expect.poll(async () => (await api("GET", "/api/routines")).body.runs.find((item: any) => item.id === run.id)?.threadId,
+ { timeout: 20_000 }).toBeTruthy();
+ const threadId = (await api("GET", "/api/routines")).body.runs.find((item: any) => item.id === run.id).threadId;
+ const task = (await api("GET", "/api/bots")).body.bots.find((each: any) => each.id === bot.id).tasks.find((item: any) => item.threadId === threadId);
+ expect(task.modelSelection).toEqual(own);
+ const refused = await api("POST", "/api/routines", { name: "Inbox sweep", prompt: "Sweep the inbox", botId: bot.id,
+ schedule: { type: "daily", time: "09:00", weekdays: [1] }, modelSelection: { instanceId: own.instanceId, model: own.model, effort: "galaxy" } });
+ expect(refused).toMatchObject({ status: 400, body: { error: 'effort "galaxy" is not recognized' } });
+ } finally {
+ await fixture.close();
+ }
+}, 120_000);
diff --git a/server/routine-model.test.ts b/server/routine-model.test.ts
new file mode 100644
index 0000000000..d454348a3e
--- /dev/null
+++ b/server/routine-model.test.ts
@@ -0,0 +1,52 @@
+import { mkdtempSync, rmSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { afterEach, describe, expect, it } from "vitest";
+
+import { RoutineManager, type RoutineManagerOptions } from "./routines.ts";
+
+const dirs: string[] = [];
+afterEach(() => {
+ for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });
+});
+
+const START = new Date(2026, 7, 17, 8, 0, 0).getTime();
+const HAIKU = { instanceId: "claude", model: "claude-haiku-4-5" };
+
+function manager() {
+ const dir = mkdtempSync(join(tmpdir(), "omb-routine-model-"));
+ dirs.push(dir);
+ const options: RoutineManagerOptions = {
+ file: join(dir, "routines.json"),
+ now: () => START,
+ botState: () => "ready",
+ createTask: () => ({ threadId: "thread-1" }),
+ startTurn: async () => {},
+ };
+ return { options, routines: new RoutineManager(options) };
+}
+
+const daily = { type: "daily" as const, time: "09:00", weekdays: [1] };
+
+describe("a routine's own model", () => {
+ it("keeps the model it was given across an edit and a restart, and drops it on null", () => {
+ const { options, routines } = manager();
+ const routine = routines.create({ name: "Inbox sweep", prompt: "Sweep the inbox", botId: "maus-1", schedule: daily, modelSelection: { ...HAIKU, effort: "low" } });
+ expect(routine.modelSelection).toEqual({ ...HAIKU, effort: "low" });
+ expect(routines.update(routine.id, { prompt: "Sweep the inbox twice" })?.modelSelection).toEqual({ ...HAIKU, effort: "low" });
+ expect(new RoutineManager(options).listRoutines()[0]!.modelSelection).toEqual({ ...HAIKU, effort: "low" });
+ expect(routines.update(routine.id, { modelSelection: null })?.modelSelection).toBeUndefined();
+ expect(new RoutineManager(options).listRoutines()[0]).not.toHaveProperty("modelSelection");
+ });
+
+ it("refuses a model with no engine or model id, with both an effort and a variant, or on a room goal", () => {
+ const { routines } = manager();
+ const create = (modelSelection: unknown, target: "bot" | "room-goal" = "bot") =>
+ () => routines.create({ name: "Inbox sweep", prompt: "Sweep the inbox", botId: "maus-1", target, schedule: daily, modelSelection } as never);
+ expect(create({ model: "claude-haiku-4-5" })).toThrow(/Choose a model/);
+ expect(create({ instanceId: "claude", model: " " })).toThrow(/Choose a model/);
+ expect(create({ ...HAIKU, effort: "low", variant: "fast" })).toThrow(/Choose a model/);
+ expect(create(HAIKU, "room-goal")).toThrow(/Room goals run on their bots' own models/);
+ expect(routines.listRoutines()).toEqual([]);
+ });
+});
diff --git a/server/routines.ts b/server/routines.ts
index 73132a1e20..da7ae944f8 100644
--- a/server/routines.ts
+++ b/server/routines.ts
@@ -10,6 +10,7 @@ import { activeRunsOf, nextDueOf, schedulerDueOf, wakeHoldOf } from "./routine-d
import { startDueTimer, type DueTimer } from "./due-timer.ts";
import type { GroupGoalRunStatus } from "../shared/group-goal-run.ts";
import type { RoutineRequestOperation } from "../shared/routine-request.ts";
+import type { ModelSelection } from "../shared/wire.ts";
import { intervalAllowsOccurrence, intervalHasRestrictions, isSameLocalDay, latestIntervalOccurrence } from "./routine-intervals.ts";
import { cloneSchedule, limitResetOccurrence, mergeScheduleUpdate, nextOccurrence, RoutineScheduleError, type RoutineSchedule, type RoutineScheduleInput } from "./routine-schedules.ts";
import { runsOnce } from "../shared/limit-reset.ts";
@@ -60,6 +61,7 @@ export interface Routine {
timeoutMinutes?: number;
attachments?: RoutineContextAttachment[];
continuity?: boolean;
+ modelSelection?: ModelSelection;
overlap?: "skip" | "queue";
runOnStartup?: boolean;
checks?: RoutineCheck[];
@@ -175,6 +177,7 @@ export interface RoutineInput {
timeoutMinutes?: number | null;
attachments?: RoutineContextAttachment[];
continuity?: boolean;
+ modelSelection?: ModelSelection | null;
overlap?: "skip" | "queue";
runOnStartup?: boolean;
checks?: RoutineCheck[] | null;
@@ -582,6 +585,7 @@ export class RoutineManager {
timeoutMinutes: Object.hasOwn(patch, "timeoutMinutes") ? patch.timeoutMinutes : routine.timeoutMinutes,
attachments: patch.attachments ?? routine.attachments,
continuity: patch.continuity ?? routine.continuity,
+ modelSelection: Object.hasOwn(patch, "modelSelection") ? patch.modelSelection : routine.modelSelection,
overlap: Object.hasOwn(patch, "overlap") ? patch.overlap : routine.overlap,
runOnStartup: patch.runOnStartup ?? routine.runOnStartup,
checks: Object.hasOwn(patch, "checks") ? patch.checks : routine.checks,
@@ -612,6 +616,7 @@ export class RoutineManager {
});
if (patch.enabled !== undefined) delete routine.heldFor;
if (!clean.continuity) delete routine.continuity;
+ if (!clean.modelSelection) delete routine.modelSelection;
if (clean.overlap !== "queue") delete routine.overlap;
if (!clean.runOnStartup) delete routine.runOnStartup;
if (!clean.access) delete routine.access;
diff --git a/shared/routines.ts b/shared/routines.ts
index caa337747b..81df83bac8 100644
--- a/shared/routines.ts
+++ b/shared/routines.ts
@@ -2,6 +2,7 @@
* snapshot and the `routine` / `routine.run` live frames. */
import type { LimitResetSchedule, LimitResetScheduleInput } from "./limit-reset.ts";
import type { RoutineCronSchedule } from "./routine-schedule.ts";
+import type { ModelSelection } from "./wire.ts";
export interface RoutineIntervalWindow {
start: string;
@@ -131,6 +132,8 @@ export interface Routine {
overlap?: "skip" | "queue";
/** Each run starts with the previous run's report. */
continuity?: boolean;
+ /** The model each run's thread uses instead of its bot's. Missing means the bot's model. */
+ modelSelection?: ModelSelection;
/** Also run once each time OpenMausBot starts. */
runOnStartup?: boolean;
checks?: RoutineCheck[];
@@ -223,6 +226,8 @@ export interface RoutineInput {
overlap?: "skip" | "queue";
/** Each run starts with the previous run's report. */
continuity?: boolean;
+ /** `null` removes it on updates; omission preserves it. */
+ modelSelection?: ModelSelection | null;
runOnStartup?: boolean;
/** `null` explicitly removes them on updates; omission preserves them. */
checks?: RoutineCheck[] | null;