Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(workflows): distinguish catalog loading from empty and failed reads

louis2ab185fe7f17
diff --git a/apps/screenpipe-app-tauri/components/workflows/integrated-workflows.test.tsx b/apps/screenpipe-app-tauri/components/workflows/integrated-workflows.test.tsx
index 180ce4944..8c4b5515a 100644
--- a/apps/screenpipe-app-tauri/components/workflows/integrated-workflows.test.tsx
+++ b/apps/screenpipe-app-tauri/components/workflows/integrated-workflows.test.tsx
@@ -9,8 +9,12 @@ import { SidebarFooter } from "@/components/sidebar-footer";
import { IntegratedWorkflows, workflowAgentTask } from "./integrated-workflows";
vi.mock("@/lib/workflows/desktop-platform", async () => {
- const { createFixtureWorkflowsPlatform } = await import("@screenpipe/workflows-ui/fixture");
- return { desktopWorkflowsPlatform: createFixtureWorkflowsPlatform() };
+ const { createFixtureWorkflowsPlatform, fixtureWorkflowAnalysis } = await import("@screenpipe/workflows-ui/fixture");
+ return { desktopWorkflowsPlatform: {
+ ...createFixtureWorkflowsPlatform(),
+ // jsdom cannot rasterize the browser fixture's SVG screenshots.
+ loadCapturedWork: async () => structuredClone(fixtureWorkflowAnalysis),
+ } };
});
vi.mock("@/components/connected-share-dialog", () => ({
ConnectedShareDialog: ({ open, artifact, onOpenChange, onConnect, connectionsRevision }: any) => open ? <div role="dialog" aria-label="Sharing review"><h2>{artifact.title}</h2><p>{artifact.surface}</p><span>Connections revision {connectionsRevision}</span><button onClick={() => onConnect("slack")}>Connect Slack</button><button onClick={() => onOpenChange(false)}>Close sharing</button></div> : null,
@@ -47,7 +51,7 @@ it("keeps Settings and Help in the footer and opens workspace shortcuts from Hel
it("opens the existing sharing review from the selected workflow in the main app", async () => {
window.history.replaceState(null, "", "/home?mode=workflows");
render(<IntegratedWorkflows active onModeChange={vi.fn()} recordingStatus={null} />);
- fireEvent.click(await screen.findByRole("button", { name: "Build my workflow catalog" }));
+ // Wait for saved data instead of interacting with a transient empty screen.
const card = (await screen.findByRole("heading", { name: "Research synthesis" })).closest("article")!;
fireEvent.click(within(card).getByRole("button", { name: "Open map" }));
expect(screen.queryByRole("dialog", { name: "Sharing review" })).not.toBeInTheDocument();
@@ -70,7 +74,7 @@ it("opens the existing sharing review from the selected workflow in the main app
expect(screen.getByRole("dialog", { name: "Sharing review" })).toHaveTextContent("Connections revision 2");
fireEvent.click(screen.getByRole("button", { name: "Close sharing" }));
expect(screen.queryByRole("dialog", { name: "Sharing review" })).not.toBeInTheDocument();
- expect(screen.getByRole("heading", { name: "Research synthesis" })).toBeVisible();
+ expect(screen.getByRole("textbox", { name: "Workflow title" })).toHaveValue("Research synthesis");
});
vi.mock("@/lib/workflows/rollout", () => ({ useWorkflowsRolloutEnabled: () => true, requireWorkflowsRollout: vi.fn() }));
diff --git a/apps/screenpipe-app-tauri/components/workflows/workflow-loading.test.tsx b/apps/screenpipe-app-tauri/components/workflows/workflow-loading.test.tsx
new file mode 100644
index 000000000..534c94026
--- /dev/null
+++ b/apps/screenpipe-app-tauri/components/workflows/workflow-loading.test.tsx
@@ -0,0 +1,87 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+import React from "react";
+import { act, fireEvent, render, screen, cleanup } from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { WorkflowsApp } from "@screenpipe/workflows-ui";
+import { createFixtureWorkflowsPlatform, fixtureWorkflowAnalysis } from "@screenpipe/workflows-ui/fixture";
+
+beforeEach(() => { vi.useFakeTimers(); window.history.replaceState(null, "", "/home?mode=workflows"); });
+afterEach(() => { cleanup(); vi.useRealTimers(); });
+const mount = async (platform: ReturnType<typeof createFixtureWorkflowsPlatform>, cached = false) => {
+ await act(async () => { render(<WorkflowsApp platform={platform} storageKey={null} initialAnalysis={cached ? fixtureWorkflowAnalysis : null} />); });
+};
+const exhaustRetries = async () => { await act(async () => { await vi.advanceTimersByTimeAsync(3000); }); };
+
+describe("workflow catalog loading", () => {
+ it("shows a skeleton until the catalog arrives, never onboarding during the read", async () => {
+ const platform = createFixtureWorkflowsPlatform();
+ let resolve!: (value: typeof fixtureWorkflowAnalysis) => void;
+ platform.loadCapturedWork = () => new Promise(r => { resolve = r; });
+ await mount(platform);
+ expect(screen.getByRole("region", { name: "Loading workflows" })).toHaveAttribute("aria-busy", "true");
+ expect(screen.queryByText("Your first work map starts here")).not.toBeInTheDocument();
+ await act(async () => resolve(fixtureWorkflowAnalysis));
+ expect(screen.getByRole("heading", { name: "Research synthesis" })).toBeVisible();
+ expect(screen.queryByRole("region", { name: "Loading workflows" })).not.toBeInTheDocument();
+ });
+ it("recovers from a temporary backend restart without showing an error", async () => {
+ const platform = createFixtureWorkflowsPlatform();
+ platform.loadCapturedWork = vi.fn().mockRejectedValueOnce(new Error("Load failed")).mockResolvedValue(fixtureWorkflowAnalysis);
+ await mount(platform);
+ await act(async () => { await vi.advanceTimersByTimeAsync(1000); });
+ expect(screen.getByRole("heading", { name: "Research synthesis" })).toBeVisible();
+ expect(screen.queryByText("Couldn’t load your workflows")).not.toBeInTheDocument();
+ });
+ it("offers read-only retry after failure and shows onboarding only after confirmed empty success", async () => {
+ const platform = createFixtureWorkflowsPlatform();
+ const load = vi.fn().mockRejectedValue(new Error("Load failed"));
+ platform.loadCapturedWork = load;
+ await mount(platform);
+ await exhaustRetries();
+ expect(load).toHaveBeenCalledTimes(3);
+ expect(screen.getByText("Couldn’t load your workflows")).toBeVisible();
+ expect(screen.queryByText("Your first work map starts here")).not.toBeInTheDocument();
+ load.mockResolvedValue(null);
+ await act(async () => fireEvent.click(screen.getByRole("button", { name: "Retry loading" })));
+ expect(screen.getByText("Your first work map starts here")).toBeVisible();
+ });
+ it("keeps previously loaded cards visible after a failed refresh", async () => {
+ const platform = createFixtureWorkflowsPlatform();
+ platform.loadCapturedWork = vi.fn().mockRejectedValue(new Error("Offline"));
+ await mount(platform, true);
+ expect(screen.getByRole("heading", { name: "Research synthesis" })).toBeVisible();
+ await exhaustRetries();
+ expect(screen.getByText("Couldn’t refresh. Your last loaded workflows are still shown.")).toBeVisible();
+ expect(screen.getByRole("heading", { name: "Research synthesis" })).toBeVisible();
+ });
+ it("allows retry when runtime preparation itself fails", async () => {
+ const platform = createFixtureWorkflowsPlatform();
+ const ensure = platform.ensureRuntime;
+ platform.ensureRuntime = vi.fn().mockRejectedValueOnce(new Error("Offline")).mockImplementation(ensure);
+ platform.loadCapturedWork = vi.fn().mockResolvedValue(fixtureWorkflowAnalysis);
+ await mount(platform);
+ expect(screen.getByText("Couldn’t load your workflows")).toBeVisible();
+ await act(async () => fireEvent.click(screen.getByRole("button", { name: "Retry loading" })));
+ expect(screen.getByRole("heading", { name: "Research synthesis" })).toBeVisible();
+ });
+ it("does not show onboarding from an old empty cache while the current read fails", async () => {
+ const platform = createFixtureWorkflowsPlatform();
+ platform.loadCapturedWork = vi.fn().mockRejectedValue(new Error("Offline"));
+ const empty = { ...fixtureWorkflowAnalysis, analysis: { ...fixtureWorkflowAnalysis.analysis, workflows: [] } };
+ await act(async () => { render(<WorkflowsApp platform={platform} storageKey={null} initialAnalysis={empty} />); });
+ await exhaustRetries();
+ expect(screen.getByText("Couldn’t load your workflows")).toBeVisible();
+ expect(screen.queryByText("Your first work map starts here")).not.toBeInTheDocument();
+ });
+ it("cancels scheduled retries when the view unmounts", async () => {
+ const platform = createFixtureWorkflowsPlatform();
+ const load = vi.fn().mockRejectedValue(new Error("Offline"));
+ platform.loadCapturedWork = load;
+ await mount(platform);
+ cleanup();
+ await exhaustRetries();
+ expect(load).toHaveBeenCalledTimes(1);
+ });
+
+});
diff --git a/apps/screenpipe-workflows-web/app/preview/page.tsx b/apps/screenpipe-workflows-web/app/preview/page.tsx
index 5f56023d3..3544367d5 100644
--- a/apps/screenpipe-workflows-web/app/preview/page.tsx
+++ b/apps/screenpipe-workflows-web/app/preview/page.tsx
@@ -3,11 +3,24 @@
"use client";
+import { useEffect, useState } from "react";
import { WorkflowsApp } from "@screenpipe/workflows-ui";
import { createFixtureWorkflowsPlatform, fixtureWorkflowAnalysis } from "@screenpipe/workflows-ui/fixture";
-const previewPlatform = createFixtureWorkflowsPlatform();
+function preview(mode: string | null) {
+ const platform = createFixtureWorkflowsPlatform();
+ const load = platform.loadCapturedWork!;
+ if (mode === "loading") platform.loadCapturedWork = async (...args) => {
+ await new Promise(resolve => setTimeout(resolve, 8000));
+ return load(...args);
+ };
+ if (mode === "error") platform.loadCapturedWork = async () => { throw new Error("Preview unavailable"); };
+ if (mode === "empty") platform.loadCapturedWork = async () => null;
+ return { platform, initialAnalysis: mode ? null : fixtureWorkflowAnalysis };
+}
export default function WorkflowsPreviewPage() {
- return <WorkflowsApp platform={previewPlatform} initialAnalysis={fixtureWorkflowAnalysis} storageKey={null} />;
+ const [state, setState] = useState<ReturnType<typeof preview> | null>(null);
+ useEffect(() => { setState(preview(new URLSearchParams(window.location.search).get("catalog"))); }, []);
+ return state ? <WorkflowsApp platform={state.platform} initialAnalysis={state.initialAnalysis} storageKey={null} /> : null;
}
diff --git a/packages/workflows-ui/src/workflows-app.module.css b/packages/workflows-ui/src/workflows-app.module.css
index c85f69e60..6964b45e2 100644
--- a/packages/workflows-ui/src/workflows-app.module.css
+++ b/packages/workflows-ui/src/workflows-app.module.css
@@ -1022,3 +1022,21 @@
.workflowNotes .bottleneckList article { grid-template-columns: 20px minmax(0, 1fr); }
.workflowNotes .bottleneckTime { grid-column: 2; }
}
+
+/* Loading follows the catalog geometry without pretending the catalog is empty. */
+.skeletonBar { display: block; max-width: 100%; flex-shrink: 0; border-radius: 4px; background: var(--line); animation: catalogPulse 1.8s ease-in-out infinite; }
+.skeletonCard { pointer-events: none; cursor: default; }
+.skeletonTitle { margin: 22px 0 14px; }
+.skeletonLines { display: grid; gap: 7px; min-height: 42px; }
+.skeletonDetail { display: grid; gap: 16px; }
+.skeletonCard .cardMetrics .skeletonBar + .skeletonBar { margin-top: 9px; }
+.catalogLoadStatus, .catalogRefreshNotice { color: var(--muted); font-size: 12px; }
+.catalogRefreshNotice { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
+.catalogRefreshNotice button { color: inherit; background: none; border: 0; text-decoration: underline; cursor: pointer; }
+.catalogLoadError { border: 1px solid var(--line); border-radius: 8px; padding: 40px 24px; text-align: center; }
+.catalogLoadError > svg { color: var(--muted); }
+.catalogLoadError h2 { font-size: 20px; margin: 16px 0 8px; }
+.catalogLoadError p { color: var(--muted); margin: 0 0 24px; font-size: 13px; }
+.catalogLoadError button { margin: auto; }
+@keyframes catalogPulse { 0%, 100% { opacity: .5; } 50% { opacity: 1; } }
+@media (prefers-reduced-motion: reduce) { .skeletonBar { animation: none; } }
diff --git a/packages/workflows-ui/src/workflows-app.tsx b/packages/workflows-ui/src/workflows-app.tsx
index 32af7ae0d..06b02c500 100644
--- a/packages/workflows-ui/src/workflows-app.tsx
+++ b/packages/workflows-ui/src/workflows-app.tsx
@@ -761,6 +761,27 @@ function WorkflowsView({ workflows, knownWorkflowCount, activityPeriod, filters,
);
}
+function CatalogPlaceholder({ detail = false }: { detail?: boolean }) {
+ const ui = useGT();
+ const bar = (width: string, height = 10) => <span className={styles.skeletonBar} style={{ width, height }} />;
+ return <section aria-busy="true" aria-label={ui("Loading workflows")}>
+ <div className={`${styles.pageHeader} ${styles.catalogHeader}`}><h1>{detail ? ui("Workflow") : ui("Your workflows")}</h1><span role="status" className={styles.catalogLoadStatus}>{ui("Loading saved workflows…")}</span></div>
+ <div aria-hidden="true">
+ {!detail && <div className={styles.filterBar}><div>{bar("100px")}{bar("140px", 8)}</div>{bar("85px", 28)}</div>}
+ <div className={detail ? styles.skeletonDetail : styles.workflowGrid}>
+ {Array.from({ length: detail ? 3 : 4 }, (_, i) => <div key={i} className={`${styles.workflowCard} ${styles.skeletonCard}`}>
+ <div className={styles.workflowCardTop}>{bar("20px")}{bar("120px", 18)}</div>
+ <div className={styles.skeletonTitle}>{bar("78%", 20)}</div>
+ <div className={styles.skeletonLines}>{bar("100%")}{bar("91%")}{bar("64%")}</div>
+ <div className={styles.cardPath}>{bar("90%", 28)}<span />{bar("95%", 28)}</div>
+ <div className={styles.cardMetrics}>{[0, 1, 2, 3].map(n => <div key={n}>{bar("70%", 7)}{bar("22px", 12)}</div>)}</div>
+ <div className={styles.cardFooter}>{bar("45%", 8)}{bar("55px", 8)}</div>
+ </div>)}
+ </div>
+ </div>
+ </section>;
+}
+
function readableSkillInstructions(value: string) {
return value
.replace(/^#{1,6}\s+/gm, "")
@@ -1274,6 +1295,9 @@ export function WorkflowsApp({ platform, initialAnalysis = null, storageKey = "s
const [runtime, setRuntime] = useState<WorkflowRuntime | null>(null);
const [analysis, setAnalysis] = useState<WorkflowAnalysis | null>(() => initialAnalysis ? sanitizeWorkflowAnalysis(initialAnalysis) : null);
const [catalogReady, setCatalogReady] = useState(!platform.loadCapturedWork);
+ const [catalogLoading, setCatalogLoading] = useState(Boolean(platform.loadCapturedWork));
+ const [catalogLoadError, setCatalogLoadError] = useState(false);
+ const [catalogLoadRevision, setCatalogLoadRevision] = useState(0);
const [scopeId, setScopeId] = useState(initialScopeId ?? initialAnalysis?.scope?.id ?? "");
const [analyzing, setAnalyzing] = useState(false);
const [analysisJob, setAnalysisJob] = useState<WorkflowAnalysisJob | null>(null);
@@ -1321,18 +1345,24 @@ export function WorkflowsApp({ platform, initialAnalysis = null, storageKey = "s
const selectScope = useCallback((nextScopeId: string) => {
setScopeId(nextScopeId);
+ setCatalogReady(false);
+ setCatalogLoading(true);
+ setCatalogLoadError(false);
setAnalysis(null);
setAnalysisError("");
setSelectedWorkflow(0);
}, []);
const refreshRuntime = useCallback(() => {
+ setCatalogLoading(Boolean(platform.loadCapturedWork));
+ setCatalogLoadError(false);
void platform.ensureRuntime()
.then((nextRuntime) => {
setRuntime(nextRuntime);
+ setCatalogLoadRevision(value => value + 1);
setScopeId((current) => current || nextRuntime.availableScopes?.[0]?.id || "");
})
- .catch((error) => setAnalysisError(error instanceof Error ? error.message : String(error || "Could not prepare your work history.")));
+ .catch(() => { setCatalogLoading(false); setCatalogLoadError(true); });
}, [platform]);
useEffect(() => {
@@ -1359,20 +1389,28 @@ export function WorkflowsApp({ platform, initialAnalysis = null, storageKey = "s
useEffect(() => {
if (!runtime || !platform.loadCapturedWork) return;
setCatalogReady(false);
+ setCatalogLoading(true);
+ setCatalogLoadError(false);
let cancelled = false;
- void platform.loadCapturedWork(WORKFLOW_CATALOG_DAYS, { scope: activeScope ?? undefined })
- .then((nextAnalysis) => {
- if (!cancelled && nextAnalysis) {
- setAnalysis(current => retainNewerWorkflowEdits(current, sanitizeWorkflowAnalysis(nextAnalysis)));
- setCatalogReady(true);
- setSelectedWorkflow(0);
- }
- })
- .catch((error) => {
- if (!cancelled) setAnalysisError(error instanceof Error ? error.message : "Could not load the workflow report.");
- });
- return () => { cancelled = true; };
- }, [activeScope?.id, platform, Boolean(runtime)]);
+ let retryTimer: ReturnType<typeof setTimeout>;
+ const load = async (attempt = 0) => {
+ try {
+ const nextAnalysis = await platform.loadCapturedWork!(WORKFLOW_CATALOG_DAYS, { scope: activeScope ?? undefined });
+ if (cancelled) return;
+ if (nextAnalysis) setAnalysis(current => retainNewerWorkflowEdits(current, sanitizeWorkflowAnalysis(nextAnalysis)));
+ setCatalogReady(true);
+ setCatalogLoading(false);
+ setCatalogLoadError(false);
+ } catch {
+ if (cancelled) return;
+ // Brief backend restarts should not flash onboarding or discard saved cards.
+ if (attempt < 2) retryTimer = setTimeout(() => void load(attempt + 1), 1000 * (attempt + 1));
+ else { setCatalogLoading(false); setCatalogLoadError(true); }
+ }
+ };
+ void load();
+ return () => { cancelled = true; clearTimeout(retryTimer); };
+ }, [activeScope?.id, platform, Boolean(runtime), catalogLoadRevision]);
useEffect(() => {
const refined = (event: Event) => {
@@ -1630,6 +1668,16 @@ export function WorkflowsApp({ platform, initialAnalysis = null, storageKey = "s
case "privacy": content = <PrivacyView runtime={runtime} />; break;
}
+ const catalogView = view !== "profile" && view !== "privacy";
+ if (catalogView && !knownWorkflows.length && (catalogLoading || catalogLoadError)) {
+ content = catalogLoading ? <CatalogPlaceholder detail={view === "workflow"} /> : <>
+ <div className={`${styles.pageHeader} ${styles.catalogHeader}`}><h1>Your workflows</h1></div>
+ <section className={styles.catalogLoadError} role="alert"><AlertTriangle size={20} /><h2>Couldn’t load your workflows</h2><p>Screenpipe may still be starting or reconnecting. Try loading them again.</p><button className={styles.primaryButton} onClick={refreshRuntime}><RefreshCw size={14} />Retry loading</button></section>
+ </>;
+ } else if (catalogView && analysis && (catalogLoading || catalogLoadError)) {
+ content = <><div className={styles.catalogRefreshNotice} role={catalogLoadError ? "alert" : "status"}>{catalogLoadError ? <><span>Couldn’t refresh. Your last loaded workflows are still shown.</span><button onClick={refreshRuntime}>Retry loading</button></> : ui("Refreshing saved workflows…")}</div>{content}</>;
+ }
+
return <>
<AppShell modelControl={platform.modelPreference ? <WorkflowModelControl preference={platform.modelPreference} /> : undefined} composerAccessory={composerAccessory} active={active} fullscreen={fullscreen} navigationFooter={navigationFooter} navigationBrand={navigationBrand} recordingStatus={recordingStatus} view={view} navigate={navigate} runtime={runtime} workflowCount={knownWorkflows.length} query={filters.query} setQuery={(query) => setFilters((current) => ({ ...current, query }))} activityPeriod={activityPeriod} setActivityPeriod={(period) => { setActivityPeriod(period); setSelectedWorkflow(0); }} activeScope={activeScope} scopes={scopes} setScope={selectScope} embedded={embedded} startWindowDrag={platform.startWindowDrag} openCommandPalette={() => setCommandPaletteOpen(true)} assistant={platform.assistant ? { platform: platform.assistant, context: view === "workflow" && activeWorkflow ? { key: `workflow:${activeWorkflow.title}`, title: activeWorkflow.title, workflow: activeWorkflow } : view === "profile" ? { key: "profile", title: ui("Context"), profile: workProfile } : { key: "workflows", title: ui("Your workflows"), catalog: workflows.map(({ title, description }) => ({ title, description })) } } : undefined}>{statusNotice}{content}</AppShell>
<CommandPalette open={active && commandPaletteOpen} commands={paletteCommands} close={() => setCommandPaletteOpen(false)} />