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(chat): keep viewed conversations in place

Louis Beaumont9c14630fb0c8
diff --git a/apps/screenpipe-app-tauri/components/__tests__/chat-sidebar-focus.test.tsx b/apps/screenpipe-app-tauri/components/__tests__/chat-sidebar-focus.test.tsx
index fe64979d2..802bc9c72 100644
--- a/apps/screenpipe-app-tauri/components/__tests__/chat-sidebar-focus.test.tsx
+++ b/apps/screenpipe-app-tauri/components/__tests__/chat-sidebar-focus.test.tsx
@@ -189,6 +189,32 @@ describe("Recents provider filtering", () => {
]);
expect(sessions[0].id).toBe("priority-first");
});
+
+ it("does not promote a viewed chat above a chat with newer content", () => {
+ const sessions: SessionRecord[] = [
+ {
+ ...baseSession,
+ id: "viewed-older-chat",
+ updatedAt: 500,
+ lastViewedAt: 500,
+ lastContentAt: 100,
+ lastUserMessageAt: 90,
+ },
+ {
+ ...baseSession,
+ id: "newer-content-chat",
+ updatedAt: 300,
+ lastViewedAt: 300,
+ lastContentAt: 300,
+ lastUserMessageAt: 290,
+ },
+ ];
+
+ expect(sortRecents(sessions, "updated").map(({ id }) => id)).toEqual([
+ "newer-content-chat",
+ "viewed-older-chat",
+ ]);
+ });
});
describe("menu letter shortcuts", () => {
diff --git a/apps/screenpipe-app-tauri/components/chat-sidebar.tsx b/apps/screenpipe-app-tauri/components/chat-sidebar.tsx
index 1a48d399d..f49454bcd 100644
--- a/apps/screenpipe-app-tauri/components/chat-sidebar.tsx
+++ b/apps/screenpipe-app-tauri/components/chat-sidebar.tsx
@@ -216,9 +216,19 @@ export function sortRecents(
sort: RecentSort,
): SessionRecord[] {
if (sort === "priority") return sessions;
+
+ // Loading a chat can update persistence metadata such as `updatedAt` and
+ // `lastViewedAt`. Sort by message activity so selecting a row never promotes
+ // it above chats that actually received newer content.
+ const contentActivityAt = (session: SessionRecord) =>
+ session.lastContentAt
+ ?? session.lastUserMessageAt
+ ?? session.updatedAt
+ ?? session.createdAt;
+
return [...sessions].sort(
(left, right) =>
- right.updatedAt - left.updatedAt ||
+ contentActivityAt(right) - contentActivityAt(left) ||
right.createdAt - left.createdAt ||
left.id.localeCompare(right.id),
);