From 70d780107d3ed07a7c27e00f08cc97b714dab924 Mon Sep 17 00:00:00 2001 From: Dotta <34892728+cryppadotta@users.noreply.github.com> Date: Fri, 4 Dec 2026 10:10:42 -0600 Subject: [PATCH] fix(ui): stop re-sorting Recents sidebar items to the top on click (#23404) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - The sidebar includes a Recents list that mixes recent tasks, agent chats, and projects. > - Opening an existing task or project from Recents currently writes `Date.now()` as its timestamp and jumps that item to the top. > - That breaks spatial stability when a person clicks through items in Recents, because every click re-sorts the list. > - This pull request stops passive opens and clicks from changing an existing item's recency timestamp, seeds unseen items from their latest activity timestamp, and records explicit user activity when a person takes action on a task. > - The benefit is a predictable Recents list that orders items by recent activity without shifting on click. ## Linked Issues or Issue Description **What happened?** When a person clicked an existing task or project in the sidebar Recents list, opening that item stamped it with `Date.now()` and moved it to the top of Recents. Clicking through several recent items constantly re-sorted the sidebar. **Expected behavior** Recents sorts items with the most recent activity at the top, and clicking or passively opening an existing item keeps the list order unchanged. Only real activity (such as creating, editing, commenting, approving/rejecting, or responding to an interaction on a task, or server-side updates on chats and projects) moves an item to the top. **Steps to reproduce** 1. Open the Coordinator workspace with at least two tasks or projects in the sidebar Recents list. 2. Click an older item lower in Recents. 3. Observe that the clicked item jumps to the top of Recents even though no activity occurred. **Paperclip version or commit** Reproduced on `master` (`b63445c8f1`). **Deployment mode** Local dev (source checkout). Related PRs: #22219, #22024. ## What Changed - Updated `recordRecentTask` in `ui/src/lib/recent-tasks.ts` so passive opens never change an existing entry's `recordedAt`, and unseen passive opens seed chronologically from `lastActivityAt` or `updatedAt` (falling back below existing history when no valid timestamp exists). - Removed visit-time `Date.now()` bumping in `ui/src/pages/IssueDetail.tsx` and centralized explicit local activity updates (`recordLocalTaskActivity`) across task edits, comments, approvals (captured at mutation start), interaction responses, and isolated re-issues for both Streamlined and Coordinator modes. - Enabled immediate recent-task recording on task creation in `ui/src/components/NewIssueDialog.tsx` when Coordinator mode is enabled (previously gated only on Streamlined mode). - Extracted `recordProjectRecentVisit` and `buildCoordinatorRecents` in `ui/src/components/CoordinatorSidebar.tsx` so revisiting a project keeps its existing entry unchanged, unseen projects seed from `project.updatedAt`, real project updates advance its sort time via `Math.max`, and memo inputs remain referentially stable. - Updated `DESIGN.md` and `doc/PRODUCT.md` to document activity-based Recents ordering without click-driven re-sorting. - Added and updated unit and component tests in `ui/src/lib/recent-tasks.test.ts`, `ui/src/components/CoordinatorSidebar.recents.test.ts` (including a linear-scan read-budget check across 450 items), and `ui/src/pages/IssueDetail.mobile.test.tsx`. ## Verification Tested on rebased commit `79f028344b56ec41092ad458b956c3fd02be0fe0`: - `pnpm --filter @paperclipai/ui typecheck` — passed (0 errors). - `pnpm --filter @paperclipai/ui exec vitest run src/lib/recent-tasks.test.ts src/hooks/useRecentTasks.test.tsx src/hooks/useRecentTaskOpenWarmup.test.tsx src/components/CoordinatorSidebar.recents.test.ts src/pages/IssueDetail.mobile.test.tsx` — passed (5 files, 68 tests). - `pnpm check:token-gates` — passed (all 4 token gates clean). - Broad typecheck, build, and full test coverage will be verified by GitHub CI on this PR. ## Risks - Low risk. Changes are scoped to client-side Recents ordering, state recording, and documentation. No database migrations, API schema changes, or permission changes. - Users who relied on clicking an old task solely to pin it at the top of Recents can use the existing sidebar pin control or take action on the task. ## Model Used - Antigravity (Google DeepMind agentic assistant) with code inspection, file editing, shell execution, Vitest, TypeScript, and GitHub CLI tools. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip --- DESIGN.md | 8 +- doc/PRODUCT.md | 15 +- ui/src/components/CoordinatorSidebar.tsx | 46 +++-- ui/src/components/NewIssueDialog.tsx | 2 +- ui/src/lib/coordinator-recents.test.ts | 225 +++++++++++++++++++++++ ui/src/lib/coordinator-recents.ts | 79 ++++++++ ui/src/lib/recent-tasks.test.ts | 88 ++++++++- ui/src/lib/recent-tasks.ts | 45 ++++- ui/src/pages/IssueDetail.mobile.test.tsx | 194 ++++++++++++++++++- ui/src/pages/IssueDetail.tsx | 94 +++++++--- 10 files changed, 723 insertions(+), 73 deletions(-) create mode 100644 ui/src/lib/coordinator-recents.test.ts create mode 100644 ui/src/lib/coordinator-recents.ts diff --git a/DESIGN.md b/DESIGN.md index 66afaae09a0..265e8f2d96b 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -776,9 +776,11 @@ Recents appears only when it contains entries, without an empty state. Task entries require the viewer's own participation under the Mine inbox rule, regardless of inbox archive state. Automated provenance, account ownership and read-only visits do not establish participation. A qualifying task's title and -status stay current, but passive visits and background updates do not promote it -above newer user activity. A first passive visit places a qualifying candidate -below existing history. Readable subtasks remain contextual navigation under a +status stay current, but clicking or passively visiting an existing entry and +background updates do not promote it above newer user activity. A first passive +visit seeds an unseen qualifying entry from its latest activity timestamp (or +below existing history when unavailable) so newer items sort near the top +without re-sorting on click. Readable subtasks remain contextual navigation under a qualifying parent. ### Reuse collection behavior as well as appearance diff --git a/doc/PRODUCT.md b/doc/PRODUCT.md index 4b95c53eeb3..48e19b2cd95 100644 --- a/doc/PRODUCT.md +++ b/doc/PRODUCT.md @@ -120,13 +120,14 @@ The Tasks tab keeps the full relationship list and shows each task once. Project groups omit tasks already shown in the other sections and disappear when empty. Sidebar Recents and Classic Recent Tasks show tasks from the viewer’s own -recent activity as a flat list. A subtask has its own row and its own unread -marker. Tasks archived from the viewer’s inbox leave Recents. Canceled and -completed tasks remain eligible. Opening a recent task moves its row to the top -of Recents. Any task a person opens is eligible for their Recents, including -routine, channel, and agent-created tasks. When a person runs a routine manually, -the task that run creates goes to the top of their Recents at once, before they -open it. Neither of these adds the task to Mine. +recent activity as a flat list ordered by most recent activity. A subtask has +its own row and its own unread marker. Tasks archived from the viewer’s inbox +leave Recents. Canceled and completed tasks remain eligible. Clicking or opening +an existing item in Recents does not move it to the top; items re-sort only +when new activity occurs. Any task a person opens is eligible for their Recents, +including routine, channel, and agent-created tasks. When a person runs a +routine manually, the task that run creates goes to the top of their Recents at +once, before they open it. Neither of these adds the task to Mine. Standard Recents also shows recent chats and projects. The Coordinator sidebar pins **Plugins** above **More** by default. Users can diff --git a/ui/src/components/CoordinatorSidebar.tsx b/ui/src/components/CoordinatorSidebar.tsx index 0b7952b2532..249f2b0458c 100644 --- a/ui/src/components/CoordinatorSidebar.tsx +++ b/ui/src/components/CoordinatorSidebar.tsx @@ -1,7 +1,7 @@ import { useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from "react"; import { useQuery } from "@tanstack/react-query"; import { Inbox, Boxes, CircleCheck, Compass, Folder, History, LayoutDashboard, MessageCircle, MoreHorizontal, Network, Plus, Repeat, Search, Settings, SquarePen, Unplug, type LucideIcon } from "lucide-react"; -import type { Agent, IssueSummary, Project } from "@paperclipai/shared"; +import type { Agent, Issue, IssueSummary, Project } from "@paperclipai/shared"; import { useCoordinatorAttentionCount } from "@/hooks/useCoordinatorAttentionCount"; import { instanceSettingsApi } from "@/api/instanceSettings"; import { useAgentChatNavigation } from "@/hooks/useAgentChatNavigation"; @@ -12,6 +12,11 @@ import { projectPinKey, usePinnedNavigation } from "@/hooks/usePinnedNavigation" import { useDialogActions } from "@/context/DialogContext"; import { useSidebar } from "@/context/SidebarContext"; import { queryKeys } from "@/lib/queryKeys"; +import { + buildCoordinatorRecents, + recordProjectRecentVisit, + type CoordinatorProjectVisits, +} from "@/lib/coordinator-recents"; import type { RecentTaskEntry } from "@/lib/recent-tasks"; import { Link, useLocation } from "@/lib/router"; import { agentRouteRef, projectRouteRef } from "@/lib/utils"; @@ -33,6 +38,9 @@ import { companyProjectsQuery } from "@/lib/company-projects-query"; import { NavigationPinButton, type PinControls } from "./NavigationPinButton"; import { SidebarProjectTasks } from "./SidebarProjectTasks"; +const NO_AGENTS: readonly Agent[] = []; +const NO_CHATS: readonly Issue[] = []; +const NO_PROJECTS: readonly Project[] = []; const NO_RECENT_TASKS: never[] = []; const TASK_PIN_ID_PATTERN = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i; const taskPinKey = (companyId: string, id: string) => `task:${companyId}:${id}`; @@ -156,29 +164,29 @@ export function CoordinatorSidebar({ children }: { children?: ReactNode }) { const { openNewIssue } = useDialogActions(); const attentionCount = useCoordinatorAttentionCount(companyId); const { data: projects } = useQuery({ ...companyProjectsQuery(companyId!), enabled: !!companyId }); - const orderedPins = useMemo(() => buildPinnedNavigationItems(pinnedNavigation.pins, agents.data ?? [], destinations, - pinnedTasks, session.isSuccess ? projects : undefined), [pinnedNavigation.pins, agents.data, destinations, pinnedTasks, projects, session.isSuccess]); - // Only project IDs and visit times are kept in memory. Labels and task lists + const agentList = agents.data ?? NO_AGENTS; + const chatList = chats.data ?? NO_CHATS; + const projectList = projects ?? NO_PROJECTS; + const orderedPins = useMemo(() => buildPinnedNavigationItems(pinnedNavigation.pins, agentList, destinations, + pinnedTasks, session.isSuccess ? projectList : undefined), [pinnedNavigation.pins, agentList, destinations, pinnedTasks, projectList, session.isSuccess]); + // Only project IDs and activity timestamps are kept in memory. Labels and task lists // always come from the authorized API, scoped to the current person/company. const scope = `${companyId}:${userId}`; - const [projectVisits, setProjectVisits] = useState<{ scope: string; entries: Record }>({ scope, entries: {} }); + const [projectVisits, setProjectVisits] = useState({ scope, entries: {} }); useEffect(() => { const ref = location.pathname.match(/\/projects\/([^/]+)/)?.[1]; - const project = projects?.find(item => item.id === ref || projectRouteRef(item) === ref); + const project = projectList.find(item => item.id === ref || projectRouteRef(item) === ref); if (!project) return; - setProjectVisits(previous => ({ scope, entries: { ...(previous.scope === scope ? previous.entries : {}), [project.id]: Date.now() } })); - }, [location.pathname, projects, scope]); - const recents = useMemo(() => { - const roster = new Map((agents.data ?? []).map(agent => [agent.id, agent])); - const taskRows = recentTasks.map(task => ({ kind: "task" as const, id: task.id, time: task.recordedAt, task })); - const chatRows = (chats.data ?? []).flatMap(chat => { - const agent = chat.conversationAgentId ? roster.get(chat.conversationAgentId) : null; - return agent ? [{ kind: "chat" as const, id: chat.id, time: new Date(chat.updatedAt).getTime(), agent }] : []; - }); - const projectRows = (projects ?? []).flatMap(project => projectVisits.scope === scope && projectVisits.entries[project.id] - ? [{ kind: "project" as const, id: project.id, time: projectVisits.entries[project.id]!, project }] : []); - return [...taskRows, ...chatRows, ...projectRows].sort((a, b) => b.time - a.time); - }, [agents.data, chats.data, recentTasks, projects, projectVisits, scope]); + setProjectVisits(previous => recordProjectRecentVisit(previous, scope, project)); + }, [location.pathname, projectList, scope]); + const recents = useMemo(() => buildCoordinatorRecents({ + agents: agentList, + chats: chatList, + recentTasks, + projects: projectList, + projectVisits, + scope, + }), [agentList, chatList, recentTasks, projectList, projectVisits, scope]); const newTaskButton =