Skip to content

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

fix: contain routine check receipt failures

Sebastian B1f57644f1806
diff --git a/server/routine-check-failures.test.ts b/server/routine-check-failures.test.ts
new file mode 100644
index 0000000000..155d3c2161
--- /dev/null
+++ b/server/routine-check-failures.test.ts
@@ -0,0 +1,20 @@
+import { spawnSync } from "node:child_process";
+import { mkdtempSync, rmSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { expect, it } from "vitest";
+
+it.each(["manual", "scheduled"])("contains a %s check's rejection after its result was saved", (mode) => {
+ const dir = mkdtempSync(join(tmpdir(), "omb-check-failure-"));
+ try {
+ const child = spawnSync(process.execPath, ["--experimental-strip-types", "server/testing/routine-check-failures.ts", dir, mode], {
+ encoding: "utf8", timeout: 10_000,
+ env: { ...process.env, HOME: dir, USERPROFILE: dir, OMB_DATA_DIR: dir },
+ });
+ expect(child.status, child.stderr).toBe(0);
+ expect(child.stdout).toContain("fixture survived");
+ expect(child.stderr).toContain(mode === "manual" ? "fixture disk full" : "fixture receipt notification failed");
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+});
diff --git a/server/routines.ts b/server/routines.ts
index f1944e5ed2..b2b03df58f 100644
--- a/server/routines.ts
+++ b/server/routines.ts
@@ -1079,7 +1079,7 @@ export class RoutineManager {
for (const run of scheduledRuns) {
if (run.status === "missed") this.options.onRunFailed?.(cloneRun(run));
}
- for (const { id, hold } of checks) void this.runChecks(id, hold);
+ for (const { id, hold } of checks) this.runChecks(id, hold).catch((error) => console.error(`routines: the checks of ${id} failed`, error));
// Oldest first, by id: a rollback across awaits can replace the run objects.
for (const id of this.runs.map((run) => run.id)) {
@@ -1109,7 +1109,7 @@ export class RoutineManager {
}
const checked = triggerSource === "webhook" || run.checkKey ? undefined : this.routines.find((routine) => routine.id === run.routineId && routine.checks);
if (checked) {
- void this.runChecks(checked.id, checkHold(this.runs, checked.id, now, run.id), run.id);
+ this.runChecks(checked.id, checkHold(this.runs, checked.id, now, run.id), run.id).catch((error) => console.error(`routines: the checks of ${checked.id} failed`, error));
continue;
}
const sameRoutineWorking = triggerSource === "schedule" && this.runs.some(other =>
diff --git a/server/testing/routine-check-failures.ts b/server/testing/routine-check-failures.ts
new file mode 100644
index 0000000000..e618a3b95c
--- /dev/null
+++ b/server/testing/routine-check-failures.ts
@@ -0,0 +1,50 @@
+import assert from "node:assert/strict";
+import { setImmediate } from "node:timers/promises";
+import { join } from "node:path";
+
+import { RoutineManager, type RoutineCheckResult } from "../routines.ts";
+
+const [dir, mode] = process.argv.slice(2);
+let resolve!: (result: RoutineCheckResult) => void;
+const pending = new Promise<RoutineCheckResult>((answer) => { resolve = answer; });
+let now = Date.parse("2026-10-28T09:00:00Z");
+const manager = new RoutineManager({
+ file: join(dir!, "routines.json"), now: () => now,
+ botState: () => "ready", createTask: () => ({ threadId: "fixture-thread" }),
+ startTurn: async () => { assert.fail("A failed check must not start a turn"); },
+ checks: { check: async () => pending, release: () => {}, settled: () => {} },
+ emit: (event) => {
+ if (mode === "scheduled" && event.kind === "routine" && (event.routine as { checkTrouble?: string }).checkTrouble) {
+ throw new Error("fixture receipt notification failed");
+ }
+ },
+});
+const routine = manager.create({
+ name: "Fixture checks", prompt: "Check the fixture inbox", botId: "fixture-bot", checks: ["mail"],
+ schedule: { type: "interval", everyMinutes: 15, anchorAt: now + 15 * 60_000 },
+});
+const storage = manager as unknown as { save(): void };
+const save = storage.save.bind(manager);
+storage.save = () => {
+ if (manager.listRuns().some((run) => run.status === "failed")) {
+ throw Object.assign(new Error("fixture disk full"), { code: "ENOSPC" });
+ }
+ save();
+};
+if (mode === "manual") manager.runNow(routine.id);
+else now += 15 * 60_000;
+await manager.tick();
+resolve({ trouble: "Couldn't read Gmail. Reconnect it in Connected apps." });
+await setImmediate();
+assert.equal(manager.listRoutines()[0]!.checkTrouble, "Couldn't read Gmail. Reconnect it in Connected apps.");
+if (mode === "manual") {
+ assert.equal(manager.listRuns()[0]!.status, "queued");
+ storage.save = save;
+ await manager.tick();
+ await setImmediate();
+ assert.equal(manager.listRuns()[0]!.status, "failed");
+ const restored = new RoutineManager({ file: join(dir!, "routines.json"), botState: () => "ready", createTask: () => null, startTurn: async () => {} });
+ assert.equal(restored.listRuns()[0]!.status, "failed");
+} else assert.deepEqual(manager.listRuns(), []);
+manager.close();
+console.log("fixture survived");