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(sidebar): sort pipe runs by execution recency

Louis Beaumonta48d79a31345
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.ts
index d1881d5fd..039abc989 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,7 @@ import {
buildGroupedRecents,
buildSidebarRecentsSections,
latestSidebarPipeRunTimes,
+ sortSidebarPipeRuns,
visibleSidebarPipeNames,
listMoveTargetGroups,
recurringPipeGroupKeys,
@@ -227,6 +228,46 @@ describe("visibleSidebarPipeNames", () => {
});
});
+describe("sortSidebarPipeRuns", () => {
+ it("keeps the newest execution first regardless of global chat priority", () => {
+ const olderUserPromptRun = {
+ ...s("old", "imessage-sync #23034", "imessage-sync"),
+ createdAt: Date.parse("2026-08-24T12:00:00.000Z"),
+ updatedAt: Date.parse("2026-08-24T12:01:00.000Z"),
+ lastUserMessageAt: Date.parse("2026-08-24T12:00:30.000Z"),
+ pipeContext: { pipeName: "imessage-sync", executionId: 23034 },
+ };
+ const newestRun = {
+ ...s("new", "imessage-sync #23055", "imessage-sync"),
+ createdAt: Date.parse("2026-08-24T13:00:00.000Z"),
+ updatedAt: Date.parse("2026-08-24T13:01:00.000Z"),
+ pipeContext: { pipeName: "imessage-sync", executionId: 23055 },
+ };
+
+ expect(
+ sortSidebarPipeRuns([olderUserPromptRun, newestRun]).map((run) => run.id),
+ ).toEqual(["new", "old"]);
+ });
+
+ it("falls back to run timestamps when execution ids are unavailable", () => {
+ const older = {
+ ...s("older", "legacy run", "legacy"),
+ updatedAt: 100,
+ pipeContext: { pipeName: "legacy" },
+ };
+ const newer = {
+ ...s("newer", "legacy run", "legacy"),
+ updatedAt: 200,
+ pipeContext: { pipeName: "legacy" },
+ };
+
+ expect(sortSidebarPipeRuns([older, newer]).map((run) => run.id)).toEqual([
+ "newer",
+ "older",
+ ]);
+ });
+});
+
function s(
id: string,
title: string,
diff --git a/apps/screenpipe-app-tauri/components/chat-sidebar.tsx b/apps/screenpipe-app-tauri/components/chat-sidebar.tsx
index 9d208e864..44f572b18 100644
--- a/apps/screenpipe-app-tauri/components/chat-sidebar.tsx
+++ b/apps/screenpipe-app-tauri/components/chat-sidebar.tsx
@@ -134,6 +134,7 @@ import {
latestSidebarPipeRunTimes,
listMoveTargetGroups,
recurringPipeGroupKeys,
+ sortSidebarPipeRuns,
visibleSidebarPipeNames,
sessionGroupKey,
type SidebarItem,
@@ -762,11 +763,13 @@ export function ChatSidebar({ className, onViewAll }: ChatSidebarProps) {
});
const merged = [...(sessionsByPipe.get(name) ?? []), ...cached];
const seen = new Set<string>();
- const sessions = merged.filter((session) => {
- if (seen.has(session.id)) return false;
- seen.add(session.id);
- return true;
- });
+ const sessions = sortSidebarPipeRuns(
+ merged.filter((session) => {
+ if (seen.has(session.id)) return false;
+ seen.add(session.id);
+ return true;
+ }),
+ );
return {
kind: "group" as const,
key: `pipe:${name}`,
diff --git a/apps/screenpipe-app-tauri/lib/utils/chat-sidebar-grouping.ts b/apps/screenpipe-app-tauri/lib/utils/chat-sidebar-grouping.ts
index 1b4fea59a..7e14213c4 100644
--- a/apps/screenpipe-app-tauri/lib/utils/chat-sidebar-grouping.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/chat-sidebar-grouping.ts
@@ -80,6 +80,33 @@ export function visibleSidebarPipeNames(
.map(([name]) => name);
}
+/**
+ * Pipe history is ordered by execution recency, independently from the global
+ * chat sidebar order. The chat order intentionally prioritizes user-authored
+ * conversations, which can otherwise leave a newly completed pipe run below
+ * older runs that contain a persisted user prompt.
+ */
+export function sortSidebarPipeRuns(
+ sessions: SessionRecord[],
+): SessionRecord[] {
+ return [...sessions].sort((a, b) => {
+ const aExecutionId = a.pipeContext?.executionId;
+ const bExecutionId = b.pipeContext?.executionId;
+ if (
+ aExecutionId != null &&
+ bExecutionId != null &&
+ aExecutionId !== bExecutionId
+ ) {
+ return bExecutionId - aExecutionId;
+ }
+ return (
+ b.updatedAt - a.updatedAt ||
+ b.createdAt - a.createdAt ||
+ a.id.localeCompare(b.id)
+ );
+ });
+}
+
// ── Types ────────────────────────────────────────────────────────────
export type SidebarItem =