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(sidebar): restore automation pagination
Louis Beaumonta9fdfadef13c
diff --git a/apps/screenpipe-app-tauri/components/__tests__/chat-sidebar-grouping.test.ts b/apps/screenpipe-app-tauri/components/__tests__/chat-sidebar-grouping.test.tsindex 039abc989..eeb28d507 100644--- a/apps/screenpipe-app-tauri/components/__tests__/chat-sidebar-grouping.test.ts+++ b/apps/screenpipe-app-tauri/components/__tests__/chat-sidebar-grouping.test.ts@@ -10,6 +10,8 @@ import {buildGroupedRecents,buildSidebarRecentsSections,latestSidebarPipeRunTimes,+ mergeSidebarPipeInventory,+ SIDEBAR_AUTOMATION_PAGE_SIZE,sortSidebarPipeRuns,visibleSidebarPipeNames,listMoveTargetGroups,@@ -226,6 +228,81 @@ describe("visibleSidebarPipeNames", () => {),).toEqual(["new-pipe", "older-pipe", "oldest-pipe"]);});++ it("does not let saved history bypass an authoritative inventory page", () => {+ expect(+ visibleSidebarPipeNames(+ [+ {+ name: "visible-pipe",+ executionCount: 2,+ latestExecutionId: 20,+ lastRun: "2026-08-26T08:00:00.000Z",+ },+ ],+ [+ {+ ...s("older", "older run", "older-pipe"),+ kind: "pipe-run",+ updatedAt: Date.parse("2026-08-25T08:00:00.000Z"),+ },+ ],+ true,+ ),+ ).toEqual(["visible-pipe"]);+ });+});++describe("mergeSidebarPipeInventory", () => {+ const inventory = (start: number, count: number) =>+ Array.from({ length: count }, (_, index) => ({+ name: `pipe-${start - index}`,+ executionCount: 1,+ latestExecutionId: start - index,+ lastRun: null,+ }));++ it("keeps the initial automation page compact", () => {+ expect(SIDEBAR_AUTOMATION_PAGE_SIZE).toBe(8);+ expect(+ mergeSidebarPipeInventory(+ [],+ inventory(20, SIDEBAR_AUTOMATION_PAGE_SIZE),+ "replace",+ ),+ ).toHaveLength(8);+ });++ it("refreshes visible rows without growing past the requested page", () => {+ const firstPage = inventory(20, SIDEBAR_AUTOMATION_PAGE_SIZE);+ const refreshed = mergeSidebarPipeInventory(+ firstPage,+ inventory(21, SIDEBAR_AUTOMATION_PAGE_SIZE),+ "refresh",+ );++ expect(refreshed).toHaveLength(SIDEBAR_AUTOMATION_PAGE_SIZE);+ expect(refreshed.map((pipe) => pipe.latestExecutionId)).toEqual([+ 21, 20, 19, 18, 17, 16, 15, 14,+ ]);+ });++ it("recovers the initial page on the first successful heartbeat", () => {+ expect(+ mergeSidebarPipeInventory(+ [],+ inventory(20, SIDEBAR_AUTOMATION_PAGE_SIZE),+ "refresh",+ ),+ ).toHaveLength(SIDEBAR_AUTOMATION_PAGE_SIZE);+ });++ it("grows only after an explicit append", () => {+ const firstPage = inventory(20, SIDEBAR_AUTOMATION_PAGE_SIZE);+ expect(+ mergeSidebarPipeInventory(firstPage, inventory(12, 8), "append"),+ ).toHaveLength(16);+ });});describe("sortSidebarPipeRuns", () => {diff --git a/apps/screenpipe-app-tauri/components/chat-sidebar.tsx b/apps/screenpipe-app-tauri/components/chat-sidebar.tsxindex 238537346..b8e51f212 100644--- a/apps/screenpipe-app-tauri/components/chat-sidebar.tsx+++ b/apps/screenpipe-app-tauri/components/chat-sidebar.tsx@@ -151,10 +151,13 @@ import {buildGroupedRecents,latestSidebarPipeRunTimes,listMoveTargetGroups,+ mergeSidebarPipeInventory,recurringPipeGroupKeys,+ SIDEBAR_AUTOMATION_PAGE_SIZE,sortSidebarPipeRuns,visibleSidebarPipeNames,sessionGroupKey,+ type SidebarPipeInventoryItem,type SidebarItem,type SidebarRecentsSection,validateSidebarGroupName,@@ -163,7 +166,6 @@ import {/** Max top-level rows shown in recents. Pipes use the authoritative inventory. */const SIDEBAR_CAP = 8;const PIPE_RUNS_PER_GROUP = 10;-const PIPE_INVENTORY_PAGE_SIZE = 20;const DELETED_PIPE_EXECUTIONS_KEY = "screenpipe:deleted-pipe-executions";const RECENTS_SOURCE_FILTER_KEY = "screenpipe:recents-hidden-sources";const RECENTS_LAYOUT_KEY = "screenpipe:recents-layout";@@ -266,13 +268,6 @@ function syncExternalChatsIfNeeded(force = false): Promise<void> {return externalChatSyncPromise;}-interface SidebarPipeInventoryItem {- name: string;- executionCount: number;- latestExecutionId: number;- lastRun: string | null;-}-interface SidebarPipeExecution {id: number;pipe_name: string;@@ -707,6 +702,7 @@ export function ChatSidebar({ className, onViewAll }: ChatSidebarProps) {const [pipeInventory, setPipeInventory] = useState<SidebarPipeInventoryItem[]>([]);const [pipeInventoryLoaded, setPipeInventoryLoaded] = useState(false);const [pipeInventoryAuthoritative, setPipeInventoryAuthoritative] = useState(false);+ const pipeInventoryAuthoritativeRef = useRef(false);const [pipeInventoryLoadingMore, setPipeInventoryLoadingMore] = useState(false);const [pipeInventoryHasMore, setPipeInventoryHasMore] = useState(false);const pipeInventoryCursorRef = useRef<number | null>(null);@@ -741,6 +737,7 @@ export function ChatSidebar({ className, onViewAll }: ChatSidebarProps) {setPipeInventory([]);setPipeInventoryLoaded(false);setPipeInventoryAuthoritative(false);+ pipeInventoryAuthoritativeRef.current = false;setPipeInventoryHasMore(false);pipeInventoryCursorRef.current = null;}, []);@@ -760,10 +757,12 @@ export function ChatSidebar({ className, onViewAll }: ChatSidebarProps) {preserveExisting = false,) => {const generation = pipeDataGenerationRef.current;+ const recoveringInitialPage =+ preserveExisting && !pipeInventoryAuthoritativeRef.current;if (append) setPipeInventoryLoadingMore(true);try {const params = new URLSearchParams({- limit: String(PIPE_INVENTORY_PAGE_SIZE),+ limit: String(SIDEBAR_AUTOMATION_PAGE_SIZE),});if (append && pipeInventoryCursorRef.current != null) {params.set("before_id", String(pipeInventoryCursorRef.current));@@ -786,21 +785,25 @@ export function ChatSidebar({ className, onViewAll }: ChatSidebarProps) {lastRun: typeof pipe.last_run_at === "string" ? pipe.last_run_at : null,});}- setPipeInventory((previous) => {- if (!append && !preserveExisting) return page;- const merged = new Map(previous.map((pipe) => [pipe.name, pipe]));- for (const pipe of page) merged.set(pipe.name, pipe);- return Array.from(merged.values()).sort(- (a, b) => b.latestExecutionId - a.latestExecutionId,- );- });+ setPipeInventory((previous) =>+ mergeSidebarPipeInventory(+ previous,+ page,+ append+ ? "append"+ : preserveExisting && !recoveringInitialPage+ ? "refresh"+ : "replace",+ ),+ );// A heartbeat refreshes only the newest page. Preserve the pagination// cursor and older inventory rows the user explicitly loaded.- if (!preserveExisting) {+ if (!preserveExisting || recoveringInitialPage) {setPipeInventoryHasMore(payload.has_more === true);pipeInventoryCursorRef.current =typeof payload.next_before_id === "number" ? payload.next_before_id : null;}+ pipeInventoryAuthoritativeRef.current = true;setPipeInventoryAuthoritative(true);} catch {// Keep recent in-memory pipe groups available if the engine is still@@ -956,7 +959,11 @@ export function ChatSidebar({ className, onViewAll }: ChatSidebarProps) {else sessionsByPipe.set(name, [session]);}- const orderedNames = visibleSidebarPipeNames(pipeInventory, pipes);+ const orderedNames = visibleSidebarPipeNames(+ pipeInventory,+ pipes,+ pipeInventoryAuthoritative,+ );return orderedNames.map((name) => {const inventoryItem = pipeInventory.find((pipe) => pipe.name === name);@@ -993,7 +1000,13 @@ export function ChatSidebar({ className, onViewAll }: ChatSidebarProps) {sessions,};});- }, [pipeInventory, pipes, loadedPipeRuns, storeSessionIds]);+ }, [+ pipeInventory,+ pipeInventoryAuthoritative,+ pipes,+ loadedPipeRuns,+ storeSessionIds,+ ]);const pipeLastRuns = useMemo(() => latestSidebarPipeRunTimes(pipeInventory, pipes),diff --git a/apps/screenpipe-app-tauri/lib/utils/chat-sidebar-grouping.ts b/apps/screenpipe-app-tauri/lib/utils/chat-sidebar-grouping.tsindex 7e14213c4..956567471 100644--- a/apps/screenpipe-app-tauri/lib/utils/chat-sidebar-grouping.ts+++ b/apps/screenpipe-app-tauri/lib/utils/chat-sidebar-grouping.ts@@ -4,6 +4,36 @@import type { SessionRecord } from "@/lib/stores/chat-store";+export interface SidebarPipeInventoryItem {+ name: string;+ executionCount: number;+ latestExecutionId: number;+ lastRun: string | null;+}++export const SIDEBAR_AUTOMATION_PAGE_SIZE = 8;++export function mergeSidebarPipeInventory(+ previous: SidebarPipeInventoryItem[],+ page: SidebarPipeInventoryItem[],+ mode: "replace" | "append" | "refresh",+): SidebarPipeInventoryItem[] {+ if (mode === "replace") return page;++ const merged = new Map(previous.map((pipe) => [pipe.name, pipe]));+ for (const pipe of page) merged.set(pipe.name, pipe);+ const sorted = Array.from(merged.values()).sort(+ (a, b) => b.latestExecutionId - a.latestExecutionId,+ );++ // A heartbeat may replace rows in the pages already requested, but it must+ // not silently reveal another row. Only an explicit "show more" append can+ // increase the visible inventory. If the initial request failed, the first+ // successful heartbeat becomes the initial page instead of staying empty.+ const visibleCount = previous.length > 0 ? previous.length : page.length;+ return mode === "refresh" ? sorted.slice(0, visibleCount) : sorted;+}+export function latestSidebarPipeRunTimes(inventory: Array<{ name: string; lastRun: string | null }>,sessions: SessionRecord[],@@ -36,6 +66,7 @@ export function visibleSidebarPipeNames(latestExecutionId?: number;}>,sessions: SessionRecord[],+ inventoryAuthoritative = false,): string[] {const visible = new Map<string,@@ -51,18 +82,23 @@ export function visibleSidebarPipeNames(});}- // Preserve locally-known history if the activity endpoint is unavailable- // or has not paged/refreshed far enough to include the pipe yet. Only- // terminal pipe-run sessions count here; live pipe-watch sessions should not- // move a group to "now" until that execution actually becomes history.+ // Preserve locally-known history only while the activity endpoint is+ // unavailable. Once its page is authoritative, disk history may update a+ // visible row but must not add rows outside that page. Only terminal+ // pipe-run sessions count here; live pipe-watch sessions should not move a+ // group to "now" until that execution actually becomes history.for (const session of sessions) {const name = session.pipeContext?.pipeName;if (session.kind !== "pipe-run" || !name) continue;const current = visible.get(name);+ if (inventoryAuthoritative && !current) continue;if (!current || session.updatedAt > current.latestRun) {visible.set(name, {latestRun: session.updatedAt,- latestExecutionId: current?.latestExecutionId ?? 0,+ latestExecutionId: Math.max(+ session.pipeContext?.executionId ?? 0,+ current?.latestExecutionId ?? 0,+ ),});}}