Skip to content

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

fix: explain unread automation failures

Krishna Dobhal775b4f0a4e67
diff --git a/docs/verification/routines.md b/docs/verification/routines.md
index b9e4699667..7dd88a41c4 100644
--- a/docs/verification/routines.md
+++ b/docs/verification/routines.md
@@ -183,6 +183,16 @@ never kill processes by name or delete a broad temporary root.
## Automated regressions
+The automation notification regression creates a failed run followed by six
+successful runs, restarts the isolated server, and checks that the list explains
+the unread failure and the panel shows it beyond the five newest runs. Opening
+the panel marks the failure seen; a second restart must keep the dot cleared.
+It retains screenshots under `.omb-scratch/automations-journey/notification*`.
+
+```sh
+OMB_UI_E2E=1 pnpm exec vitest run scripts/testing/automations-journey.ui.e2e.test.ts -t explains.an.old.automation.notification
+```
+
In the editor's Advanced section, recurring routines offer **Skip this
occurrence** (the default) or **Queue one run**. The queued scheduled run waits
for the same routine to finish, including the assignments its run still has
diff --git a/scripts/testing/automations-journey.ui.e2e.test.ts b/scripts/testing/automations-journey.ui.e2e.test.ts
index 61a8bec9c7..8a25b6ac38 100644
--- a/scripts/testing/automations-journey.ui.e2e.test.ts
+++ b/scripts/testing/automations-journey.ui.e2e.test.ts
@@ -46,6 +46,54 @@ function plan(bots: Array<{ id: string }>) {
type App = Awaited<ReturnType<typeof openApp>>;
+(enabled ? it : it.skip)("explains an old automation notification and keeps it cleared after restart", async () => {
+ const server = await launchRestartableServer({ scripted: true, dataDirRoot: SHORT_TMP });
+ let app: App | undefined;
+ try {
+ const api = async (method: string, path: string, body?: unknown) => {
+ const response = await fetch(`${server.url}${path}`, { method, headers: { "content-type": "application/json", origin: server.url }, ...(body === undefined ? {} : { body: JSON.stringify(body) }) });
+ expect(response.ok).toBe(true);
+ return response.json();
+ };
+ const bot = (await api("GET", "/api/bots?messages=0")).bots[0];
+ const setReply = (fail: boolean) => writeFileSync(server.planPath, JSON.stringify({ [bot.id]: { script: [{ key: "check", match: ["Check notification history."], repeat: true, steps: [], ...(fail ? { failWith: "Provider disconnected." } : { reply: "Nothing new." }) }] } }));
+ const { routine } = await api("POST", "/api/routines", { name: "Keep an eye on my day", prompt: "Check notification history.", botId: bot.id, schedule: { type: "interval", everyMinutes: 1440, anchorAt: Date.now() + 86_400_000 } });
+ let failedId = "";
+ for (let index = 0; index < 7; index++) {
+ setReply(index === 0);
+ const { run } = await api("POST", `/api/routines/${routine.id}/run`);
+ if (index === 0) failedId = run.id;
+ await expect.poll(async () => (await api("GET", "/api/routines")).runs.find((candidate: { id: string }) => candidate.id === run.id)?.status, { timeout: 30_000 }).toBe(index === 0 ? "failed" : "completed");
+ }
+ await server.stop();
+ await server.start();
+ app = await openApp(server, { shots: join(SHOTS, "notification"), bots: { [bot.name]: bot.id } });
+ await app.openAutomations();
+ await expect.poll(() => app!.rowText(routine.name)).toContain("Provider disconnected.");
+ expect(await app.evaluate('Boolean(document.querySelector(\'[data-testid="routines-attention"]\'))')).toBe(true);
+ await app.screenshot("unread-failure-explained");
+ await app.openRow(routine.name);
+ await expect.poll(app.panel).toContain("Provider disconnected.");
+ await expect.poll(async () => Boolean((await api("GET", "/api/routines")).runs.find((run: { id: string }) => run.id === failedId)?.seenAt)).toBe(true);
+ await expect.poll(() => app!.evaluate('Boolean(document.querySelector(\'[data-testid="routines-attention"]\'))')).toBe(false);
+ await app.screenshot("failure-read");
+ await app.close();
+ app = undefined;
+ await server.stop();
+ await server.start();
+ app = await openApp(server, { shots: join(SHOTS, "notification-restarted"), bots: { [bot.name]: bot.id } });
+ await app.openAutomations();
+ await expect.poll(() => app!.rowText(routine.name)).toContain("Keep an eye on my day");
+ expect(await app.rowText(routine.name)).not.toContain("Provider disconnected.");
+ expect(await app.evaluate('Boolean(document.querySelector(\'[data-testid="routines-attention"]\'))')).toBe(false);
+ await app.screenshot("notification-cleared-after-restart");
+ } finally {
+ await app?.close();
+ console.info(JSON.stringify({ logPath: server.logPath, screenshots: join(SHOTS, "notification") }));
+ await server.close();
+ }
+}, 240_000);
+
/** The real renderer on `server` in headless Chrome, and what a person does with it. */
async function openApp(server: { url: string; port: number; dataDir: string; logPath: string }, options: { shots: string; bots: Record<string, string>; proxyHeaders?: Record<string, string> }) {
mkdirSync(options.shots, { recursive: true });
diff --git a/src/components/TriggersPage.tsx b/src/components/TriggersPage.tsx
index 19144c523f..d830209e92 100644
--- a/src/components/TriggersPage.tsx
+++ b/src/components/TriggersPage.tsx
@@ -2,7 +2,7 @@ import { useEffect, useMemo, useRef, useState, type CSSProperties } from "react"
import { ArrowLeft, Plus, Zap } from "lucide-react";
import { useDesktopCapabilities, windowFramed } from "@/components/DesktopCapabilities";
-import { automationsFrom, automationSentence, automationStatus, orderAutomations, statusLine, type Automation } from "@/lib/automations";
+import { automationsFrom, automationSentence, automationStatus, orderAutomations, runLine, statusLine, type Automation } from "@/lib/automations";
import { cn } from "@/lib/cn";
import { t } from "@/lib/i18n";
import { isRoutineProblemRun } from "@/lib/routines";
@@ -67,11 +67,6 @@ export function TriggersPage({ onBack, onOpenRoom }: { onBack: () => void; onOpe
const open = all.find((automation) => automation.id === openId) ?? null;
const sentenceOf = (automation: Automation) => automationSentence(automation, botName(automation.botId));
- // Opening one marks its failed runs seen, which is what clears the dot on the sidebar row.
- useEffect(() => {
- for (const run of open?.runs ?? []) if (isRoutineProblemRun(run) && !run.seenAt) dispatch({ type: "markRoutineRunSeen", runId: run.id });
- }, [open, dispatch]);
-
const macInset = capabilities.windowChrome === "mac-inset";
const windowDragStyle = macInset ? ({ WebkitAppRegion: "drag" } as CSSProperties) : undefined;
const windowNoDragStyle = macInset ? ({ WebkitAppRegion: "no-drag" } as CSSProperties) : undefined;
@@ -129,6 +124,8 @@ export function TriggersPage({ onBack, onOpenRoom }: { onBack: () => void; onOpe
{listed.map((automation) => {
const status = automationStatus(automation);
const name = automation.name.trim();
+ const unseenProblem = automation.runs.find((run) => isRoutineProblemRun(run) && !run.seenAt);
+ const problemLine = unseenProblem && runLine(unseenProblem);
return (
<li key={automation.id} data-automation={automation.id} data-automation-status={status.state} className={cn("flex items-start gap-3 px-4 py-3.5", openId === automation.id && "bg-raised/60")}>
<StatusMark status={status} className="mt-[5px]" />
@@ -138,6 +135,10 @@ export function TriggersPage({ onBack, onOpenRoom }: { onBack: () => void; onOpe
{status.state === "needs-you"
? <div className="mt-1.5 flex flex-wrap items-center gap-2 text-[13px] text-warning">{t("automations.needsYou", { reason: status.reason ?? "" })}<FixButton automation={automation} status={status} actions={actions} onEdit={() => setEditing({ kind: automation.kind, id: automation.id })} /></div>
: <div className="mt-0.5 text-[13px] text-ink-secondary">{statusLine(automation)}</div>}
+ {problemLine && <button type="button" onClick={() => setOpenId(automation.id)} className="mt-1 flex items-baseline gap-2 text-left text-[13px] text-danger">
+ <span aria-hidden="true" className="size-2 shrink-0 self-center rounded-full bg-danger" />
+ <span>{problemLine.when} {problemLine.mark} {problemLine.text}</span>
+ </button>}
{actions.error && actions.errorFor?.endsWith(`:${automation.id}`) && <p role="alert" className="mt-1 text-[12px] text-danger">{actions.error}</p>}
</div>
{status.state !== "done" && <Switch checked={automation.enabled} disabled={actions.busy === `toggle:${automation.id}`} aria-label={t("automations.toggle", { name: automation.name })} onClick={() => void actions.toggle(automation)} className="mt-0.5 shrink-0" />}
diff --git a/src/components/automations/AutomationPanel.tsx b/src/components/automations/AutomationPanel.tsx
index ef5a2e64a7..3a352c7298 100644
--- a/src/components/automations/AutomationPanel.tsx
+++ b/src/components/automations/AutomationPanel.tsx
@@ -1,10 +1,11 @@
-import { useState } from "react";
+import { useEffect, useState } from "react";
import { Check, Copy, Pause, Pencil, Play, RotateCw, Trash2, X } from "lucide-react";
import { automationStatus, automationSubtitle, capital, lastReceived, lastWhen, runLine, STATUS_WORD, webhookCalls, type Automation } from "@/lib/automations";
import { cn } from "@/lib/cn";
import { copyText } from "@/lib/copy-text";
import { t } from "@/lib/i18n";
+import { isRoutineProblemRun } from "@/lib/routines";
import { loadWebhookCredentials, webhookCredentialStore } from "@/lib/webhook-credentials";
import { useStore } from "@/state/store";
import { AppEventsSection } from "./AppEventsSection";
@@ -14,7 +15,6 @@ import { FixButton, StatusMark } from "./parts";
const RECENT = 5;
const BUTTON = "flex items-center justify-center gap-1.5 rounded-lg px-3 py-2 text-[13px] font-medium disabled:opacity-50";
-/** One automation, simply: its sentence, its status, the last five runs, and what can be done to it. */
export function AutomationPanel({ automation, sentence, onClose, onEdit, onDeleted }: {
automation: Automation;
sentence: string;
@@ -22,7 +22,12 @@ export function AutomationPanel({ automation, sentence, onClose, onEdit, onDelet
onEdit: () => void;
onDeleted: () => void;
}) {
- const { state } = useStore();
+ const { state, dispatch } = useStore();
+ const [unseenRunIds] = useState(() => new Set(automation.runs.filter((run) => isRoutineProblemRun(run) && !run.seenAt).map((run) => run.id)));
+ const visibleRuns = automation.runs.filter((run, index) => index < RECENT || unseenRunIds.has(run.id) || (isRoutineProblemRun(run) && !run.seenAt));
+ useEffect(() => {
+ for (const run of automation.runs) if (isRoutineProblemRun(run) && !run.seenAt) dispatch({ type: "markRoutineRunSeen", runId: run.id });
+ }, [automation.runs, dispatch]);
const actions = useAllAutomationActions();
const status = automationStatus(automation);
const webhook = automation.kind === "webhook" ? state.webhooks.find((candidate) => candidate.id === automation.id) : undefined;
@@ -120,7 +125,7 @@ export function AutomationPanel({ automation, sentence, onClose, onEdit, onDelet
<h3 className="mb-2 text-[12px] font-semibold uppercase tracking-wider text-ink-tertiary">{t("automations.panel.recent")}</h3>
{automation.runs.length === 0
? <p className="text-[13px] text-ink-secondary">{t("automations.panel.noRuns")}</p>
- : <ul className="space-y-1">{automation.runs.slice(0, RECENT).map((run) => {
+ : <ul className="space-y-1">{visibleRuns.map((run) => {
const line = runLine(run);
return (
<li key={run.id}>
diff --git a/src/components/automations/automations.test.ts b/src/components/automations/automations.test.ts
index 20068c6fb2..ddc05e0b21 100644
--- a/src/components/automations/automations.test.ts
+++ b/src/components/automations/automations.test.ts
@@ -99,6 +99,21 @@ describe("+ New", () => {
});
describe("the automation panel", () => {
+ it("explains an unread failure older than the recent runs and keeps it visible after marking it seen", () => {
+ const runs = Array.from({ length: 6 }, (_, index) => ({ id: `success-${index}`, routineId: webhook.id, botId: botA.id, status: "completed", createdAt: now - index * 1_000, scheduledFor: now - index * 1_000, output: "Nothing new." }));
+ const failure = { id: "old-failure", routineId: webhook.id, botId: botA.id, status: "failed", createdAt: now - 60_000, scheduledFor: now - 60_000, error: "Provider disconnected." };
+ const [automation] = automationsFrom({ routines: [], webhooks: [webhook] as never, runs: [...runs, failure] as never });
+ const props = { automation: automation!, sentence: "s", onClose: vi.fn(), onEdit: vi.fn(), onDeleted: vi.fn() };
+ const container = mount(createElement(AutomationPanel, props));
+ expect(container.textContent).toContain("Provider disconnected.");
+ expect(container.querySelectorAll("section ul li")).toHaveLength(6);
+ expect(fixture.dispatch).toHaveBeenCalledExactlyOnceWith({ type: "markRoutineRunSeen", runId: failure.id });
+ const seen = { ...automation!, runs: automation!.runs.map((run) => ({ ...run, seenAt: now })) };
+ flushSync(() => root!.render(createElement(AutomationPanel, { ...props, automation: seen })));
+ expect(container.textContent).toContain("Provider disconnected.");
+ expect(fixture.dispatch).toHaveBeenCalledTimes(1);
+ });
+
it("shows the sentence, the status, an address to paste with Copy address, the recent runs and the four actions, in plain words", () => {
fixture.state.routineRuns = [{ id: "run-1", routineId: "hook-1", botId: "bot-a", status: "completed", scheduledFor: now - 60_000, startedAt: now - 60_000, createdAt: now - 60_000, output: "Drafted a follow-up for Ada.", threadId: "exec-1" }];
const [automation] = automationsFrom({ routines: [], webhooks: [webhook] as never, runs: fixture.state.routineRuns as never });
@@ -235,6 +250,20 @@ describe("the Automations list switch", () => {
expect(row("unnamed").querySelector("button")!.textContent).toContain("sends you a summary of your inbox");
});
+ it("explains an old unread failure on its automation and acknowledges it only when the panel opens", () => {
+ fixture.state.routines = [routine];
+ fixture.state.routineRuns = [
+ ...Array.from({ length: 6 }, (_, index) => ({ id: `success-${index}`, routineId: routine.id, botId: botA.id, status: "completed", createdAt: now - index * 1_000, scheduledFor: now - index * 1_000 })),
+ { id: "old-failure", routineId: routine.id, botId: botA.id, status: "failed", createdAt: now - 60_000, scheduledFor: now - 60_000, error: "Provider disconnected." },
+ ];
+ mountPage();
+ expect(row(routine.id).textContent).toContain("Provider disconnected.");
+ expect(fixture.dispatch).not.toHaveBeenCalledWith(expect.objectContaining({ type: "markRoutineRunSeen" }));
+ flushSync(() => row(routine.id).querySelector("button")!.click());
+ expect(container.querySelector('aside[aria-label="Automation"]')!.textContent).toContain("Provider disconnected.");
+ expect(fixture.dispatch).toHaveBeenCalledWith({ type: "markRoutineRunSeen", runId: "old-failure" });
+ });
+
it("offers no switch for a one-time automation that already happened, and lists no automation whose bot is gone", () => {
fixture.state.routines = [{ ...routine, enabled: false, nextRunAt: null, schedule: { type: "once", at: now - 60_000 } }, { ...routine, id: "orphan", name: "Orphan", botId: "deleted-bot" }];
fixture.state.webhooks = [webhook, { ...webhook, id: "orphan-hook", name: "Orphan hook", botId: "deleted-bot" }];