feat(recents): store sidebar Recents on the server so every client shares one list (#23706)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The sidebar Recents list shows the tasks from a person's own recent
activity
> - Each browser kept Recents in `localStorage`. A laptop, a phone, and
a second browser each showed a different list
> - People expect one list for their account, the same on every client
> - This pull request moves Recents to the server. The server keeps one
list for each person in each company. The UI shows that list and gets
live updates when another client changes it
> - The benefit is that every client shows the same Recents in the same
order, and a change on one client shows on the others at once

## Linked Issues or Issue Description

**Is your feature request related to a problem? Please describe.**
Recents is kept in the browser. When I open a task on my laptop, the
task does not show in Recents on my phone or in another browser.

**Describe the solution you'd like**
Keep Recents on the server, so that every client that I sign in to shows
the same list.

**Additional context**
Eligibility (which rows show) does not change. The navigation summaries
still decide it (see #23675).

## What Changed

- `packages/db`: new `user_recent_tasks` table (company, user, issue,
`recorded_at`), unique on company + user + issue. Migration `0515`
creates only a new table, so it is `online_compatible`.
- `packages/shared`: `RecentTaskRecord`, `RecentTaskList`,
`RECENT_TASKS_MAX_ENTRIES` (200), and the `recordRecentTaskSchema` and
`importRecentTasksSchema` validators.
- `server`: new `recentTaskService` and routes:
- `GET /api/companies/:companyId/recent-tasks/me`: the list, newest
first.
- `POST /api/companies/:companyId/recent-tasks/me` `{ issueId, touch }`:
`touch: true` moves the task to the top (server time). `touch: false`
adds a missing task below the history and does not move an existing
task.
- `POST /api/companies/:companyId/recent-tasks/me/import`: imports the
list that a browser kept. The later time wins.
  - `DELETE /api/companies/:companyId/recent-tasks/me/:issueId`.
- The server keeps the newest 200 rows for each person. Each change is
in the activity log as `recent_tasks.*` with `entityType: "company"` and
`details.userId`. The entry does not name the task. Viewers can change
their own Recents, like workspace preferences.
- Record, import, and list use the normal task read decision. A private
or unreadable task gets the same 404 as a missing task. The import skips
it, and the list does not return it.
- `server/src/realtime/live-events-ws.ts`: sends `recent_tasks.*` events
only to the owner's connections, without details.
  - OpenAPI entries for the four routes.
- `ui/src/lib/recent-tasks.ts`: the module is now a client mirror of the
server list, not `localStorage`. Optimistic records and removals stay
applied until a server list that was requested after the server saved
them arrives. This prevents a stale list from hiding a new visit.
- `ui/src/hooks/useRecentTasks.ts`: fetches the server list
(`queryKeys.recentTasks`). On the first load it imports the old browser
list one time and then deletes the browser copy. It does not delete
ineligible rows anymore. It hides them, and it requests a new summary
batch when new activity occurs on a hidden task. The `awaitingRead` flow
is removed because nothing deletes the row while the read is in flight.
- `LiveUpdatesProvider`: a `recent_tasks.*` event refreshes Recents.
Other company views do not refresh.
- A failed save is tried again one time. If it fails again, the client
loads the server list again, so an unsaved change does not look saved.
- The import reads only the newest browser storage version.
- `SidebarRecentTasks`: the "Archive" action removes the task from the
server list.
- `doc/PRODUCT.md`: describes the shared list.

## Verification

- `cd server && npx vitest run
src/__tests__/recent-tasks-routes.test.ts` (embedded Postgres): 5
passed. The tests cover: two clients of the same person see the same
order; touch and passive seed; personal and company scope (teammate,
other company, agent, viewer, suspended member); removal plus activity
log plus live events; import, and the 200-row limit.
- `cd server && npx vitest run src/__tests__/openapi-routes.test.ts`: 59
passed.
- `cd server && npx vitest run src/__tests__/recent-tasks-routes.test.ts
src/__tests__/live-events-toast.test.ts`: 21 passed. This includes
private-task checks and owner-only socket delivery.
- `cd ui && npx vitest run src/lib/recent-tasks.test.ts
src/hooks/useRecentTasks.test.tsx
src/context/LiveUpdatesProvider.test.ts`: all passed. New tests cover:
the same list on a second client, legacy import (success and failure),
the record-and-list race, server-time adoption, and live-event scoping.
- `packages/db`: `migration-compatibility.ts` classifies `0515` as
`online_compatible`.
- `packages/shared` typecheck: no errors. `ui` typecheck: no errors in
changed files (errors exist only in the ungenerated Storybook
feature-map indexes).
- `server`: a typecheck of the route, service, and test graph passes.
The full `server` typecheck was killed by the local memory limit (exit
137). CI covers it.
- `pnpm verify` returned exit 2 (the migration needs broad CI coverage).
Required CI supplies that coverage.

## Risks

- Medium. This adds a table and changes where Recents is kept.
- Each task open now sends one more request and writes one activity row
(the same as `issue.read_marked`). The live socket sends the event only
to the owner's connections.
- Rows that are not eligible stay in the server list (hidden) until they
fall out of the newest 200. Before, the client deleted them.
- The import reads `paperclip.recentTasks.v3`, `v2`, and the oldest key
one time for each browser. If the import fails, the browser copy stays
and the next load tries again.
- An old tab from the previous release still writes to `localStorage`.
The next load of a new tab imports those entries. The later time wins,
so this does not reorder newer server entries.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), via Claude Code with tool use
(shell, file edit, test runs).

## 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
- [ ] 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)
- [ ] 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
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: devinfoley <139239+devinfoley@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-12-05 01:44:29 +00:00
1 parent dfe392dada
commit 6a5dfc0288
34 files changed
+3004 -527

No files matched your search

+1
View File
@@ -18,6 +18,7 @@ export { heartbeatsApi } from "./heartbeats";
export { instanceSettingsApi } from "./instanceSettings";
export { sidebarBadgesApi } from "./sidebarBadges";
export { sidebarPreferencesApi } from "./sidebarPreferences";
export { recentTasksApi } from "./recentTasks";
export { resourceMembershipsApi } from "./resourceMemberships";
export { inboxDismissalsApi } from "./inboxDismissals";
export { companySkillsApi } from "./companySkills";
+15
View File
@@ -0,0 +1,15 @@
import type { ImportRecentTasks, RecentTaskList, RecentTaskRecord, RecordRecentTask } from "@paperclipai/shared";
import { api } from "./client";
const base = (companyId: string) => `/companies/${encodeURIComponent(companyId)}/recent-tasks/me`;
export const recentTasksApi = {
list: (companyId: string, options?: { signal?: AbortSignal }) =>
api.get<RecentTaskList>(base(companyId), options),
record: (companyId: string, data: RecordRecentTask) =>
api.post<{ entry: RecentTaskRecord | null }>(base(companyId), data),
importEntries: (companyId: string, data: ImportRecentTasks) =>
api.post<RecentTaskList>(`${base(companyId)}/import`, data),
remove: (companyId: string, issueId: string) =>
api.delete<void>(`${base(companyId)}/${encodeURIComponent(issueId)}`),
};