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(activity): surface generation failures

Louis Beaumontee91ade94484
diff --git a/apps/screenpipe-app-tauri/components/activity-ledger.test.tsx b/apps/screenpipe-app-tauri/components/activity-ledger.test.tsx
index 0e599c359..df79441dc 100644
--- a/apps/screenpipe-app-tauri/components/activity-ledger.test.tsx
+++ b/apps/screenpipe-app-tauri/components/activity-ledger.test.tsx
@@ -615,6 +615,15 @@ describe("ActivityLedger", () => {
);
});
+ it("keeps the controls but removes the redundant page heading", async () => {
+ render(<ActivityLedger />);
+
+ await screen.findByRole("button", { name: "Generate activities" });
+ expect(screen.queryByRole("heading", { name: "Activity" })).toBeNull();
+ expect(screen.getByLabelText("Time range")).toBeVisible();
+ expect(screen.getByLabelText("AI preset")).toBeVisible();
+ });
+
it("generates through click time when capture starts after Activity opens", async () => {
let summaryCalls = 0;
mocks.localFetch.mockImplementation((path: string) =>
@@ -713,7 +722,7 @@ describe("ActivityLedger", () => {
);
});
- it("bypasses Enhanced AI without exposing ledger rows on AI failure", async () => {
+ it("shows the exhausted AI preset instead of a generic failure", async () => {
mocks.settings.enhancedAI = false;
mocks.runDailySummaryWithPi.mockRejectedValue(
new Error("hosted_ai_allowance_exceeded"),
@@ -723,9 +732,13 @@ describe("ActivityLedger", () => {
await generateActivities();
- expect(
- await screen.findByText("History could not be updated. Try again."),
- ).toBeVisible();
+ expect(await screen.findByRole("alert")).toHaveTextContent(
+ "This AI preset has no usage left. Choose a different AI preset, then try again.",
+ );
+ expect(screen.getByRole("button", { name: "Try again" })).toBeVisible();
+ expect(document.body.textContent).not.toContain(
+ "hosted_ai_allowance_exceeded",
+ );
expect(mocks.runDailySummaryWithPi).toHaveBeenCalledWith(
expect.objectContaining({ sessionPrefix: "activity-history" }),
);
@@ -737,8 +750,74 @@ describe("ActivityLedger", () => {
).toBeNull();
expect(mocks.posthogCapture).toHaveBeenCalledWith(
"activity_generation_failed",
- { range: "today", source: "empty_state" },
+ {
+ range: "today",
+ source: "empty_state",
+ error_kind: "daily",
+ },
+ );
+ });
+
+ it("explains an empty recording range instead of silently returning", async () => {
+ mocks.localFetch.mockImplementation((path: string) =>
+ Promise.resolve({
+ ok: true,
+ status: 200,
+ json: async () =>
+ path.startsWith("/meetings?")
+ ? []
+ : path.startsWith("/activity-ledger?")
+ ? { intervals: [] }
+ : {
+ data_status: "empty_but_recording",
+ total_active_minutes: 0,
+ },
+ }),
+ );
+
+ render(<ActivityLedger />);
+ await generateActivities();
+
+ expect(await screen.findByRole("alert")).toHaveTextContent(
+ "Recording is active, but this range does not have enough activity yet.",
+ );
+ expect(mocks.runDailySummaryWithPi).not.toHaveBeenCalled();
+ expect(screen.getByRole("button", { name: "Try again" })).toBeVisible();
+ });
+
+ it("stops a stalled generation and replaces the spinner with an error", async () => {
+ mocks.runDailySummaryWithPi.mockImplementation(
+ ({ signal }: { signal?: AbortSignal }) =>
+ new Promise((_resolve, reject) => {
+ signal?.addEventListener(
+ "abort",
+ () => {
+ const error = new Error("aborted");
+ error.name = "AbortError";
+ reject(error);
+ },
+ { once: true },
+ );
+ }),
);
+
+ render(<ActivityLedger />);
+ await generateActivities();
+ expect(
+ await screen.findByText("Understanding what you worked on…"),
+ ).toBeVisible();
+
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(120_000);
+ });
+
+ expect(await screen.findByRole("alert")).toHaveTextContent(
+ "Activity generation took too long and was stopped.",
+ );
+ expect(
+ screen.queryByText("Understanding what you worked on…"),
+ ).toBeNull();
+ expect(screen.getByRole("button", { name: "Try again" })).toBeVisible();
});
it("tracks page reach and the activity generation funnel", async () => {
diff --git a/apps/screenpipe-app-tauri/components/activity-ledger.tsx b/apps/screenpipe-app-tauri/components/activity-ledger.tsx
index 93dd84694..82c6564b8 100644
--- a/apps/screenpipe-app-tauri/components/activity-ledger.tsx
+++ b/apps/screenpipe-app-tauri/components/activity-ledger.tsx
@@ -50,6 +50,7 @@ import {
type ActivityHistoryCoverage,
} from "@/lib/activity-history-persistence";
import { localFetch } from "@/lib/api";
+import { presentQuotaError } from "@/lib/chat/quota-errors";
import { showChatWithPrefill } from "@/lib/chat-utils";
import { runDailySummaryWithPi } from "@/lib/daily-summary-pi";
import { useSettings } from "@/lib/hooks/use-settings";
@@ -60,6 +61,7 @@ import type { AIPreset } from "@/lib/utils/tauri";
type RangePreset = "today" | "24h" | "7d" | "custom";
type GenerationSource = "empty_state" | "refresh";
+const ACTIVITY_GENERATION_TIMEOUT_MS = 120_000;
type ActivitySummaryResponse = {
data_status: string;
total_active_minutes: number;
@@ -90,6 +92,21 @@ type ActivityLedgerArtifactInterval = {
type ActivityLedgerArtifactsResponse = {
intervals?: ActivityLedgerArtifactInterval[];
};
+
+function noActivityMessage(dataStatus: string): string {
+ switch (dataStatus) {
+ case "not_recording":
+ return "No recorded activity is available yet. Start recording, then try again.";
+ case "no_capture_in_range":
+ return "No recorded activity was found in this range. Choose another range and try again.";
+ case "empty_but_recording":
+ return "Recording is active, but this range does not have enough activity yet. Keep working for a moment, then try again.";
+ case "unknown":
+ return "Activity data is not ready yet. Check recording status, then try again.";
+ default:
+ return "There is not enough recorded activity in this range to generate a history yet.";
+ }
+}
type ActivityArtifact = ActivityHistoryEvidence & {
browser_url?: string | null;
};
@@ -822,6 +839,11 @@ export function ActivityLedger({
historyLoadingRef.current = true;
setHistoryLoading(true);
setHistoryError("");
+ let timedOut = false;
+ const timeout = window.setTimeout(() => {
+ timedOut = true;
+ controller.abort();
+ }, ACTIVITY_GENERATION_TIMEOUT_MS);
try {
const [summaryResponse, meetingsResponse] = await Promise.all([
localFetch(buildActivitySummaryPath(generationRange), {
@@ -864,11 +886,15 @@ export function ActivityLedger({
persisted.entries.length > 0 ? { entries: persisted.entries } : null,
);
setHistoryCoverage(persisted.coverage);
+ setHistoryError(
+ noActivityMessage(generationSummary?.data_status ?? "unknown"),
+ );
posthog.capture("activity_generation_completed", {
range: preset,
source,
outcome: "no_activity",
activity_count: 0,
+ data_status: generationSummary?.data_status ?? "unknown",
});
return;
}
@@ -970,15 +996,26 @@ export function ActivityLedger({
outcome: "generated",
activity_count: next.entries.length,
});
- } catch {
- if (controller.signal.aborted) return;
- setHistoryError("History could not be updated. Try again.");
+ } catch (reason) {
+ if (controller.signal.aborted && !timedOut) return;
+ const rawError = reason instanceof Error ? reason.message : String(reason);
+ const quota = presentQuotaError(rawError);
+ const friendlyError = timedOut
+ ? "Activity generation took too long and was stopped. Try again."
+ : rawError.toLowerCase().includes("hosted_ai_allowance_exceeded")
+ ? "This AI preset has no usage left. Choose a different AI preset, then try again."
+ : quota.kind !== "none"
+ ? quota.message
+ : "History could not be updated. Try again.";
+ setHistoryError(friendlyError);
posthog.capture("activity_generation_failed", {
range: preset,
source,
+ error_kind: timedOut ? "timeout" : quota.kind,
});
} finally {
- if (!controller.signal.aborted) {
+ window.clearTimeout(timeout);
+ if (historyAbortRef.current === controller) {
historyLoadingRef.current = false;
setHistoryLoading(false);
}
@@ -1070,17 +1107,9 @@ Re-query Screenpipe only inside the cited time range and use the cited frames an
className="flex h-full min-h-0 flex-col bg-background"
data-testid="activity-ledger"
>
- <header className="shrink-0 border-b border-border px-6 pb-5 pt-10">
+ <header className="shrink-0 border-b border-border px-6 pb-4 pt-9">
<div className="mx-auto max-w-4xl">
- <div className="flex flex-wrap items-end justify-between gap-4">
- <div>
- <h1 className="font-sans text-2xl font-medium tracking-tight">
- Activity
- </h1>
- <p className="mt-1 text-sm text-muted-foreground">
- An encrypted record of what you worked on.
- </p>
- </div>
+ <div className="flex flex-wrap items-center justify-end gap-2">
<div className="flex items-center gap-2">
<Select
value={preset}
@@ -1308,15 +1337,17 @@ Re-query Screenpipe only inside the cited time range and use the cited frames an
Generate activities
</h2>
<p className="mt-2 text-sm leading-6 text-muted-foreground">
- {historyError ||
- "Turn this range into a private activity history when you’re ready."}
+ <span role={historyError ? "alert" : undefined}>
+ {historyError ||
+ "Turn this range into a private activity history when you’re ready."}
+ </span>
</p>
<Button
size="sm"
className="mt-5 h-10 px-5 uppercase tracking-wide"
onClick={() => regenerateSelectedRange("empty_state")}
>
- Generate activities
+ {historyError ? "Try again" : "Generate activities"}
</Button>
</div>
</div>
diff --git a/apps/screenpipe-app-tauri/docs/assets/pr/activity-page-reliability.jpg b/apps/screenpipe-app-tauri/docs/assets/pr/activity-page-reliability.jpg
new file mode 100644
index 000000000..6955f709e
Binary files /dev/null and b/apps/screenpipe-app-tauri/docs/assets/pr/activity-page-reliability.jpg differ
diff --git a/apps/screenpipe-app-tauri/lib/daily-summary-pi.test.ts b/apps/screenpipe-app-tauri/lib/daily-summary-pi.test.ts
index e79c8a738..626cde001 100644
--- a/apps/screenpipe-app-tauri/lib/daily-summary-pi.test.ts
+++ b/apps/screenpipe-app-tauri/lib/daily-summary-pi.test.ts
@@ -254,6 +254,77 @@ describe("runDailySummaryWithPi", () => {
expect(mocks.piPrompt).toHaveBeenCalledTimes(2);
});
+ it("preserves a terminal provider error from message_end", async () => {
+ let handler: ((envelope: any) => void) | null = null;
+ mocks.registerForeground.mockImplementation((_sessionId, nextHandler) => {
+ handler = nextHandler;
+ return vi.fn();
+ });
+ mocks.piPrompt.mockImplementation(async () => {
+ queueMicrotask(() => {
+ handler?.({
+ event: {
+ type: "message_end",
+ message: {
+ role: "assistant",
+ stopReason: "error",
+ errorMessage:
+ 'HTTP 429 {"error":{"code":"hosted_ai_allowance_exceeded"}}',
+ content: [],
+ },
+ },
+ });
+ });
+ return { status: "ok", data: null };
+ });
+
+ await expect(
+ runDailySummaryWithPi({
+ date: new Date(2026, 7, 18),
+ range: { start: "start", end: "end" },
+ preset: PRESET,
+ userToken: "user-token",
+ }),
+ ).rejects.toThrow("hosted_ai_allowance_exceeded");
+ expect(mocks.piPrompt).toHaveBeenCalledOnce();
+ });
+
+ it("preserves a terminal provider error carried only by agent_end", async () => {
+ let handler: ((envelope: any) => void) | null = null;
+ mocks.registerForeground.mockImplementation((_sessionId, nextHandler) => {
+ handler = nextHandler;
+ return vi.fn();
+ });
+ mocks.piPrompt.mockImplementation(async () => {
+ queueMicrotask(() => {
+ handler?.({
+ event: {
+ type: "agent_end",
+ messages: [
+ {
+ role: "assistant",
+ stopReason: "error",
+ errorMessage: "rate_limit_exceeded",
+ content: [],
+ },
+ ],
+ },
+ });
+ });
+ return { status: "ok", data: null };
+ });
+
+ await expect(
+ runDailySummaryWithPi({
+ date: new Date(2026, 7, 18),
+ range: { start: "start", end: "end" },
+ preset: PRESET,
+ userToken: "user-token",
+ }),
+ ).rejects.toThrow("rate_limit_exceeded");
+ expect(mocks.piPrompt).toHaveBeenCalledOnce();
+ });
+
it("stops the Pi session when the request is aborted", async () => {
mocks.registerForeground.mockReturnValue(vi.fn());
mocks.piPrompt.mockResolvedValue({ status: "ok", data: null });
diff --git a/apps/screenpipe-app-tauri/lib/daily-summary-pi.ts b/apps/screenpipe-app-tauri/lib/daily-summary-pi.ts
index 60644fd23..649375446 100644
--- a/apps/screenpipe-app-tauri/lib/daily-summary-pi.ts
+++ b/apps/screenpipe-app-tauri/lib/daily-summary-pi.ts
@@ -83,6 +83,35 @@ function finalAssistantText(envelope: AgentEventEnvelope): string {
return "";
}
+type TerminalAssistantMessage = {
+ role?: string;
+ stopReason?: string;
+ errorMessage?: string;
+ error?: string;
+ content?: unknown;
+};
+
+function terminalAssistantError(
+ message: TerminalAssistantMessage | undefined,
+): string | null {
+ if (message?.role !== "assistant" || message.stopReason !== "error") {
+ return null;
+ }
+ const error = message.errorMessage || message.error;
+ return typeof error === "string" && error.trim() ? error : "AI request failed";
+}
+
+function finalAssistantError(envelope: AgentEventEnvelope): string | null {
+ const messages = Array.isArray(envelope.event.messages)
+ ? envelope.event.messages
+ : [];
+ for (let index = messages.length - 1; index >= 0; index -= 1) {
+ const error = terminalAssistantError(messages[index]);
+ if (error) return error;
+ }
+ return null;
+}
+
function abortError(): Error {
const error = new Error("daily summary generation aborted");
error.name = "AbortError";
@@ -129,10 +158,20 @@ export async function runDailySummaryWithPi(
const handler = (envelope: AgentEventEnvelope) => {
const event = envelope.event;
if (event.type === "message_end" && event.message?.role === "assistant") {
+ const terminalError = terminalAssistantError(event.message);
+ if (terminalError && event.willRetry !== true) {
+ fail(new Error(terminalError));
+ return;
+ }
const candidate = contentText(event.message.content).trim();
if (candidate) lastAssistant = candidate;
}
if (event.type === "agent_end") {
+ const terminalError = finalAssistantError(envelope);
+ if (terminalError) {
+ fail(new Error(terminalError));
+ return;
+ }
const finalText = finalAssistantText(envelope) || lastAssistant;
if (finalText) {
settle(finalText);