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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(first-run): keep the learning window alive once the user types (#6225)
Louis Beaumont8cb4d98f36f6
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/chat-main-pane.test.tsx b/apps/screenpipe-app-tauri/components/chat/standalone/chat-main-pane.test.tsxindex 4e0d9c634..2462ed922 100644--- a/apps/screenpipe-app-tauri/components/chat/standalone/chat-main-pane.test.tsx+++ b/apps/screenpipe-app-tauri/components/chat/standalone/chat-main-pane.test.tsx@@ -8,10 +8,23 @@ import { describe, expect, it, vi } from "vitest";import type { Message } from "@/lib/chat/types";import { ChatMainPane } from "./chat-main-pane";-const { messageListUnmounted } = vi.hoisted(() => ({+const { messageListUnmounted, firstRunBannerUnmounted } = vi.hoisted(() => ({messageListUnmounted: vi.fn(),+ firstRunBannerUnmounted: vi.fn(),}));+// The real banner owns the first-run window's ceiling timer. This stand-in+// only has to prove it stays mounted, so it reports its own teardown.+vi.mock("@/components/first-run/learning-banner", async () => {+ const ReactModule = await import("react");+ return {+ FirstRunLearningBanner: () => {+ ReactModule.useEffect(() => () => firstRunBannerUnmounted(), []);+ return <div data-testid="first-run-banner" />;+ },+ };+});+vi.mock("@/components/chat/standalone/inline-chat-history", () => ({InlineChatHistory: () => null,}));@@ -67,6 +80,14 @@ function paneProps(conversationId: string, messages: Message[]) {}describe("ChatMainPane", () => {+ // Testing-library unmounts the tree after each test, which trips both+ // teardown spies. Without this the second test inherits the first test's+ // cleanup and fails on an unmount it never caused.+ beforeEach(() => {+ messageListUnmounted.mockClear();+ firstRunBannerUnmounted.mockClear();+ });+it("remounts the message list when a new blank conversation replaces an old chat", () => {const previousMessage: Message = {id: "previous-message",@@ -87,4 +108,25 @@ describe("ChatMainPane", () => {expect(screen.getByTestId("summary-cards")).toBeInTheDocument();expect(screen.getByTestId("message-list")).toHaveTextContent("0");});++ it("keeps the first-run banner mounted once the user sends a message", () => {+ // The regression this guards. The banner used to render behind+ // `messages.length === 0`, so the first message tore it down along with+ // the ceiling timer it owns: the first-run window then never settled and+ // emitted no event at all. Typing is the behaviour we want, so it must not+ // destroy the first-run summary.+ const { rerender } = render(<ChatMainPane {...paneProps("chat", [])} />);+ expect(screen.getByTestId("first-run-banner")).toBeInTheDocument();++ const sent: Message = {+ id: "sent-message",+ role: "user",+ content: "what did I work on this morning?",+ timestamp: Date.now(),+ };+ rerender(<ChatMainPane {...paneProps("chat", [sent])} />);++ expect(firstRunBannerUnmounted).not.toHaveBeenCalled();+ expect(screen.getByTestId("first-run-banner")).toBeInTheDocument();+ });});diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/chat-main-pane.tsx b/apps/screenpipe-app-tauri/components/chat/standalone/chat-main-pane.tsxindex 6757a01c6..9f21d38c9 100644--- a/apps/screenpipe-app-tauri/components/chat/standalone/chat-main-pane.tsx+++ b/apps/screenpipe-app-tauri/components/chat/standalone/chat-main-pane.tsx@@ -250,10 +250,20 @@ export function ChatMainPane({</div>)}{/* Post-setup learning window. Renders only while the window is- open, so it is inert for everyone else. It sits on the empty- chat because that is where setup now lands and where the- summary chat appears once the window resolves. */}- {messages.length === 0 && !activePipeExecution && (+ open, so it is inert for everyone else. It sits on the chat+ because that is where setup lands and where the summary chat+ appears once the window resolves.++ Deliberately NOT gated on `messages.length === 0`. The window+ owns a ceiling timer, and unmounting the banner kills it: the+ user sends one message, this subtree goes away mid-wait, and+ the window never settles — no summary, and no+ `first_run_learning_resolved`/`_empty` either, so the failure+ is invisible. Typing is the behaviour we want, so it must not+ destroy the first-run summary. Measured 2026-08: 69% of users+ who completed setup produced no learning event at all while+ staying in the app a median of 9.4 hours. */}+ {!activePipeExecution && (<div className="mx-auto w-full max-w-3xl px-4 pb-4"><FirstRunLearningBanneraiPreset={firstRunAiPreset}diff --git a/apps/screenpipe-app-tauri/components/first-run/learning-banner.tsx b/apps/screenpipe-app-tauri/components/first-run/learning-banner.tsxindex 2108ec5c9..481170690 100644--- a/apps/screenpipe-app-tauri/components/first-run/learning-banner.tsx+++ b/apps/screenpipe-app-tauri/components/first-run/learning-banner.tsx@@ -39,6 +39,8 @@ const EMPTY_COPY: Record<FirstRunEmptyReason, string> = {"Only a few screens were captured — not enough to say anything true about your work yet. Keep working and this fills in.",single_app_below_floor:"Everything captured came from a single app, which is too thin to summarize. This fills in as you move between apps.",+ expired_unreported:+ "The first-run summary timed out while Screenpipe was closed. Nothing is lost — it keeps reading in the background as you work.",unknown:"Nothing was captured in that window. Screenpipe keeps reading in the background as you work.",};diff --git a/apps/screenpipe-app-tauri/lib/first-run/learning-window.test.ts b/apps/screenpipe-app-tauri/lib/first-run/learning-window.test.tsindex 99b31ffb1..44f1ac3ab 100644--- a/apps/screenpipe-app-tauri/lib/first-run/learning-window.test.ts+++ b/apps/screenpipe-app-tauri/lib/first-run/learning-window.test.ts@@ -14,6 +14,7 @@ import {buildLearningSummary,capturedAppsFrom,claimLearningSeed,+ clearPendingEmptyReport,formatCountdown,hasEnoughEvidence,learningWindowRemainingMs,@@ -563,3 +564,59 @@ describe("writing phase", () => {expect(writing.startedAt).toBe(anchor);});});++describe("a window that expired while nothing was mounted", () => {+ const seedExpiredLearning = () => {+ window.localStorage.setItem(+ "screenpipe.first-run.learning-window.v1",+ JSON.stringify({+ phase: "learning",+ startedAt: new Date(+ Date.now() - LEARNING_WINDOW_CEILING_MS - 60_000,+ ).toISOString(),+ seededAt: null,+ chatId: null,+ emptyReason: null,+ }),+ );+ };++ it("flags itself for reporting instead of settling silently", () => {+ // The regression: this settle path emits nothing of its own, because the+ // ceiling effect is gated on `phase === "learning"` and normalize has+ // already left it. Without the flag the most common first-run outcome is+ // invisible in analytics.+ seedExpiredLearning();+ const state = readLearningWindow();+ expect(state.phase).toBe("empty");+ expect(state.emptyReason).toBe("expired_unreported");+ expect(state.pendingEmptyReport).toBe(true);+ });++ it("distinguishes 'nobody looked' from 'we looked and could not tell'", () => {+ // `unknown` means the engine was asked and had no answer. Folding an+ // unreported expiry into it makes the two indistinguishable downstream.+ seedExpiredLearning();+ expect(readLearningWindow().emptyReason).not.toBe("unknown");+ });++ it("clears the flag exactly once and is safe to call on every mount", () => {+ seedExpiredLearning();+ expect(readLearningWindow().pendingEmptyReport).toBe(true);+ expect(clearPendingEmptyReport().pendingEmptyReport).toBe(false);+ expect(clearPendingEmptyReport().pendingEmptyReport).toBe(false);+ expect(readLearningWindow().pendingEmptyReport).toBe(false);+ });++ it("leaves a live window alone", () => {+ beginLearningWindow();+ const state = readLearningWindow();+ expect(state.phase).toBe("learning");+ expect(state.pendingEmptyReport).toBe(false);+ });++ it("does not flag a settle the ceiling effect already reported", () => {+ beginLearningWindow();+ expect(markLearningEmpty("no_frames_captured").pendingEmptyReport).toBe(false);+ });+});diff --git a/apps/screenpipe-app-tauri/lib/first-run/learning-window.ts b/apps/screenpipe-app-tauri/lib/first-run/learning-window.tsindex 478c7f1e7..64dcf802a 100644--- a/apps/screenpipe-app-tauri/lib/first-run/learning-window.ts+++ b/apps/screenpipe-app-tauri/lib/first-run/learning-window.ts@@ -67,6 +67,12 @@ export type FirstRunEmptyReason =| "no_frames_captured"| "below_frame_floor"| "single_app_below_floor"+ // The window outlived its ceiling while nothing was mounted to settle it:+ // the app was closed, or the banner's subtree went away mid-wait. Distinct+ // from `unknown`, which means "we looked and could not tell". Here nobody+ // ever looked, and folding the two together hid the largest first-run+ // failure there is.+ | "expired_unreported"| "unknown";export type FirstRunCapturedApp = {@@ -83,6 +89,13 @@ export type FirstRunLearningState = {seededAt: string | null;chatId: string | null;emptyReason: FirstRunEmptyReason | null;+ /**+ * Set when a window is settled by rehydration rather than by the ceiling+ * effect, which is the one settle path that emits nothing. The hook clears+ * it after reporting, so the event fires exactly once no matter how many+ * times the banner remounts.+ */+ pendingEmptyReport: boolean;/** Live-only, never persisted: rehydrating these would show stale apps. */capturedApps: FirstRunCapturedApp[];};@@ -165,6 +178,7 @@ const EMPTY_STATE: FirstRunLearningState = {seededAt: null,chatId: null,emptyReason: null,+ pendingEmptyReport: false,capturedApps: [],};@@ -542,6 +556,12 @@ function normalize(value: unknown): FirstRunLearningState {// A window that outlived its ceiling cannot resume as "learning" — the user// closed the app mid-wait and reopening it to a countdown that already// expired would be a lie. Settle it instead.+ //+ // This is the only settle path with no telemetry of its own: the ceiling+ // effect in `use-learning-window` emits `first_run_learning_empty`, but it+ // never runs here because it is gated on `phase === "learning"` and this+ // function has already moved past it. Flag the settle so the hook reports it+ // once on mount, otherwise the most common first-run outcome is silent.if (phase === "learning") {if (!startedAt) return { ...EMPTY_STATE };if (Date.now() - Date.parse(startedAt) > LEARNING_WINDOW_CEILING_MS) {@@ -549,7 +569,8 @@ function normalize(value: unknown): FirstRunLearningState {...EMPTY_STATE,phase: "empty",startedAt,- emptyReason: "unknown",+ emptyReason: "expired_unreported",+ pendingEmptyReport: true,};}}@@ -568,6 +589,7 @@ function normalize(value: unknown): FirstRunLearningState {seededAt: typeof state.seededAt === "string" ? state.seededAt : null,chatId: state.chatId,emptyReason: null,+ pendingEmptyReport: false,capturedApps: [],};}@@ -576,6 +598,7 @@ function normalize(value: unknown): FirstRunLearningState {phase: "empty",startedAt,emptyReason: "unknown",+ pendingEmptyReport: true,};}@@ -585,6 +608,7 @@ function normalize(value: unknown): FirstRunLearningState {seededAt: typeof state.seededAt === "string" ? state.seededAt : null,chatId: typeof state.chatId === "string" ? state.chatId : null,emptyReason: state.emptyReason ?? null,+ pendingEmptyReport: state.pendingEmptyReport === true,// Always live; see the type comment.capturedApps: [],};@@ -672,9 +696,22 @@ export function markLearningEmpty(phase: "empty",emptyReason: reason,chatId: null,+ // The caller emits `first_run_learning_empty` itself, so there is nothing+ // left for the mount-time reporter to pick up.+ pendingEmptyReport: false,});}+/**+ * Mark the rehydration-settled window as reported. Idempotent, and safe to+ * call from every mount: the flag is already false once the first one wins.+ */+export function clearPendingEmptyReport(): FirstRunLearningState {+ const current = readLearningWindow();+ if (!current.pendingEmptyReport) return current;+ return writeLearningWindow({ ...current, pendingEmptyReport: false });+}+export function markLearningDone(): FirstRunLearningState {const current = readLearningWindow();return writeLearningWindow({diff --git a/apps/screenpipe-app-tauri/lib/first-run/use-learning-window.test.ts b/apps/screenpipe-app-tauri/lib/first-run/use-learning-window.test.tsindex 4234f9d83..ab9480e94 100644--- a/apps/screenpipe-app-tauri/lib/first-run/use-learning-window.test.ts+++ b/apps/screenpipe-app-tauri/lib/first-run/use-learning-window.test.ts@@ -307,3 +307,62 @@ describe("useLearningWindow cross-webview reset", () => {expect(readLearningWindow().phase).toBe("idle");});});++describe("useLearningWindow reports a window that expired unmounted", () => {+ const seedExpiredLearning = () => {+ window.localStorage.setItem(+ "screenpipe.first-run.learning-window.v1",+ JSON.stringify({+ phase: "learning",+ startedAt: new Date(+ Date.now() - LEARNING_WINDOW_CEILING_MS - 60_000,+ ).toISOString(),+ seededAt: null,+ chatId: null,+ emptyReason: null,+ }),+ );+ };++ const emptyEvents = () =>+ capture.mock.calls.filter(([name]) => name === "first_run_learning_empty");++ it("emits first_run_learning_empty on mount, tagged as a rehydrate settle", async () => {+ // Before this, a window that expired while the banner was unmounted — the+ // common case, because sending one chat message used to unmount it —+ // produced no event at all.+ seedExpiredLearning();+ getOnboardingStatus.mockResolvedValue(okStatus(completedAgo(60_000)));++ renderHook(() => useLearningWindow());++ await waitFor(() => expect(emptyEvents()).toHaveLength(1));+ const [, props] = emptyEvents()[0] as [string, Record<string, unknown>];+ expect(props.reason).toBe("expired_unreported");+ expect(props.settled_by).toBe("rehydrate");+ // No live engine read: it would describe now, not the window being reported.+ expect(props.data_status).toBe("not_checked");+ });++ it("reports once, not once per mount", async () => {+ seedExpiredLearning();+ getOnboardingStatus.mockResolvedValue(okStatus(completedAgo(60_000)));++ const first = renderHook(() => useLearningWindow());+ await waitFor(() => expect(emptyEvents()).toHaveLength(1));+ first.unmount();++ renderHook(() => useLearningWindow());+ // Remounting must not double-count: the flag is cleared durably, not in+ // component state.+ await waitFor(() => expect(readLearningWindow().pendingEmptyReport).toBe(false));+ expect(emptyEvents()).toHaveLength(1);+ });++ it("stays quiet for a window that never expired", async () => {+ getOnboardingStatus.mockResolvedValue(okStatus(completedAgo(60_000)));+ renderHook(() => useLearningWindow());+ await waitFor(() => expect(readLearningWindow().phase).not.toBe("idle"));+ expect(emptyEvents()).toHaveLength(0);+ });+});diff --git a/apps/screenpipe-app-tauri/lib/first-run/use-learning-window.ts b/apps/screenpipe-app-tauri/lib/first-run/use-learning-window.tsindex 3c25e7b7f..a0a2fe258 100644--- a/apps/screenpipe-app-tauri/lib/first-run/use-learning-window.ts+++ b/apps/screenpipe-app-tauri/lib/first-run/use-learning-window.ts@@ -19,6 +19,7 @@ import {capturedAppsFrom,claimLearningSeed,classifyEmptyReason,+ clearPendingEmptyReport,hasEnoughEvidence,learningWindowOpening,learningWindowRemainingMs,@@ -332,6 +333,28 @@ export function useLearningWindow(return () => clearTimeout(timer);}, [isLearning, startedAt]);+ // Report a window that rehydration settled. That path is the one settle with+ // no telemetry: the ceiling effect above is gated on `learning`, and+ // `normalize` has already left that phase by the time anything mounts. Until+ // this existed, a window that expired while nothing was mounted produced no+ // event at all, so the outcome was indistinguishable from "user never+ // finished setup" in PostHog.+ const pendingEmptyReport = state.pendingEmptyReport;+ useEffect(() => {+ if (!pendingEmptyReport) return;+ posthog.capture("first_run_learning_empty", {+ reason: state.emptyReason ?? "expired_unreported",+ // No live engine call here: the window is long settled and a status read+ // now would describe the present, not the window it is reporting on.+ data_status: "not_checked",+ frame_count: 0,+ // Separates this from the ceiling-effect emit above, which happens with+ // the banner mounted and a fresh activity read behind it.+ settled_by: "rehydrate",+ });+ setState(clearPendingEmptyReport());+ }, [pendingEmptyReport, state.emptyReason]);+const dismiss = useCallback((options: { opened?: boolean } = {}) => {posthog.capture("first_run_learning_dismissed", {