Skip to content

feat(api): Page the conversation feed and return dashboard links - #2232

Closed
sentry-junior[bot] wants to merge 1 commit into
mainfrom
feat/conversation-list-cursor
Closed

sentry-junior[bot] wants to merge 1 commit into
mainfrom
feat/conversation-list-cursor

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2231. Rebased on main (2026-11-07).

Cursor. GET /api/conversations takes an optional cursor and returns nextCursor while more rows remain. The cursor is signed and holds the position of the last row: lastActivityAt, conversationId, and whether the row is pinned. Pins sort first for the viewer's active feed, so the keyset must cross the pin boundary. The cursor holds no filters. Callers send the same q / status on each page. An invalid cursor returns 400 Invalid conversation cursor.

The first page still adds roots that wait on the viewer (waitingRowsOutsidePage). Those roots can also show on their own later page, so a client that reads every page can see one twice. The CLI in #2234 drops repeated ids. A root with new activity during paging moves above the cursor and later pages skip it.

Links. Conversation and Automation summaries return an optional dashboardUrl from getDashboardConversationLink() / getDashboardTaskLink(). It includes the dashboard base path and is missing when the dashboard is off. The MCP mappers now read this field instead of building the link again.

No other change to the REST shape. Automations keep page + total.

Tests: tests/integration/api/conversations/list-paging.test.ts covers paging one row at a time with a tie on lastActivityAt, paging across a pin, the /dashboard base path in dashboardUrl, and the invalid-cursor 400. search-automations.test.ts asserts the MCP url. The paging test is a new file because list.test.ts is at the 1,000-line limit.

via @dingsdax.

--

View Session [Sentry]

@vercel

vercel Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 7, 2026 3:14pm UTC

Request Review

@github-actions github-actions Bot added the risk: high PR risk score: high label Oct 26, 2026
@dingsdax
dingsdax marked this pull request as draft October 26, 2026 18:51
@sentry-junior
sentry-junior Bot force-pushed the feat/conversation-list-cursor branch from 6317dde to 114bc9d Compare October 29, 2026 09:54
thomasjiangcy added a commit that referenced this pull request Nov 5, 2026
`GET /api/conversations` (the dashboard sidebar) runs p50 688ms / p95
2.3s on the server, and the dashboard polls it every 10s while a listed
Conversation is active. In the 40 slowest prod requests over 3 days (all
over 2s, up to 17.7s), the slowest DB span was one of two event queries
in 34 of them:

| Query | Slowest in | Median | Max |
| --- | --- | --- | --- |
| participants `select distinct on (conversation_id, actor_identity_id)
…` | 21 / 40 | 2.5s | 17.4s |
| `readLastUserMessageAtByConversation` `max(created_at) … type in
(user_message, message)` | 13 / 40 | 1.9s | 6.1s |

Example trace: `19019d5f769341a2916e865e93267baa` (5.5s and 3.3s).

**Participants.** The old query joined every authored event to
identities, conversations, and participants before `DISTINCT ON`.
Postgres does not carry an `IN` list across a join, and no index starts
with `conversation_id` and covers authored rows. Locally it scanned the
non-null part of `junior_conversation_events_actor_identity_idx`, so its
cost grows with all human messages in the database, not with the 50
listed Conversations. Now:
- A `GROUP BY` subquery finds each author's first `seq`, then joins.
- It is served by a new partial index
`junior_conversation_events_author_idx (conversation_id,
actor_identity_id, seq) WHERE actor_identity_id IS NOT NULL`. Only
`message` / `message_updated` rows with an author set this column, so
the index is small (13 MB, against 221 MB for the existing actor index,
on the fixture below).
- The `IN` list is repeated on `junior_conversations`.
- The result is the same: the join filters depend only on (Conversation,
author), so the first `seq` per pair does not change.
`readConversationAuthors` (detail) uses the same rows and gets the same
speedup.

**Last user message time.** `isConversationPriority` reads
`lastUserMessageAt` only for assigned work with a finish time. The list
now reads it only for those ids, after `listConversationWork` (about
40ms in prod traces) and still inside the same `Promise.all`. Before, it
read and detoasted every `user_message` and `message` payload of all 50
Conversations.

**Evidence.** On a local Postgres 17 fixture (40k Conversations, 4.4M
events), the exact generated SQL dropped from 80ms / 16.3k buffers to
9ms / 2.6k buffers on a warm cache. That's a relative change only. Prod
runs on Neon with cold reads, so I expect a bigger absolute drop there,
but that's not measured.

**Migration.** `0078` follows the `0062` pattern. For a busy database,
first build the index `CONCURRENTLY` outside a transaction. The
migration then skips the DDL and checks that the index is valid and
ready.

**Overlap**
- #2713 also adds core migration `0078`, a different partial index on
`structured_event` rows, so the indexes don't duplicate. The PR that
merges second must renumber its migration to `0079` and regenerate the
journal and snapshot.
- #2232 / #2234 (cursor paging for this endpoint) change
`conversationRows` and the response. This PR changes only the auxiliary
reads after the page is chosen, so it composes with paging. Expect a
small textual conflict in `list.ts`.

**Not in this PR**
- The `conversation_subtree` auxiliary-cost aggregate
(`readConversationAuxiliaryCostsFromSql`) is the next slowest: median
0.9s, max 4.4s, slowest in 4 / 40.
- The 10s list poll (`useConversationsData`) runs on every dashboard
page, including open Conversations.

Checks:
- `vitest run tests/integration/api/conversations/
tests/integration/dashboard-reporting.test.ts` passed (74 tests)
- `tsc --noEmit` (junior), oxlint, prettier, `migration-metadata:check`,
`file-length:check`
- `db:generate` reports no further changes

<!-- junior-request-attribution:start -->
via @thomasjiangcy.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3Aa40c0c19633f683c13aa6acb1ea1ee47 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3Aa40c0c19633f683c13aa6acb1ea1ee47)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3Aa40c0c19633f683c13aa6acb1ea1ee47/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Thomas Jiang <[email protected]>
GET /api/conversations accepts a signed cursor and returns nextCursor
while more rows remain. The cursor holds the position of the last row and
whether it is pinned, so paging stays stable across the pin boundary.
Callers send the same filters on each page.

Conversation and automation summaries now carry an optional dashboardUrl
built by the server, so clients do not rebuild dashboard paths. The MCP
mappers read the same field.

Refs #2231

Co-Authored-By: johdax <[email protected]>
Co-Authored-By: Johannes Daxboeck <[email protected]>
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

16 screenshot changes — 16 changed · 0 added · 0 removed

Review screenshots in Frameshift

Code · Desktop
Code · Desktop
Changed
Conversation Attachment · Desktop
Conversation Attachment · Desktop
Changed
Conversation Attachment Zoom · Desktop
Conversation Attachment Zoom · Desktop
Changed
Conversation Captured Memories Popover · Desktop
Conversation Captured Memories Popover · Desktop
Changed
Conversation Captured Memories Popover · Mobile
Conversation Captured Memories Popover · Mobile
Changed
Conversation Catch Up · Mobile
Conversation Catch Up · Mobile
Changed
Show 10 more changed screenshots
Conversation Details Watched Linked Work · Desktop
Conversation Details Watched Linked Work · Desktop
Changed
Conversation Details Watched Linked Work · Mobile
Conversation Details Watched Linked Work · Mobile
Changed
Conversation Event Log Virtual · Desktop
Conversation Event Log Virtual · Desktop
Changed
Conversation Event Log Virtual · Mobile
Conversation Event Log Virtual · Mobile
Changed
Conversation Fork Dialog · Desktop
Conversation Fork Dialog · Desktop
Changed
Conversation Fork Dialog · Mobile
Conversation Fork Dialog · Mobile
Changed
Conversation Long Transcript Touch · Mobile
Conversation Long Transcript Touch · Mobile
Changed
Conversation Stop Active · Mobile
Conversation Stop Active · Mobile
Changed
Conversation Unsent Answers · Desktop
Conversation Unsent Answers · Desktop
Changed
Conversation Unsent Answers · Mobile
Conversation Unsent Answers · Mobile
Changed

@sentry-junior
sentry-junior Bot added this pull request to stack #2881 November 7, 2026 15:26
@sentry-junior sentry-junior Bot changed the title feat(api): Page the conversation list with a signed cursor feat(api): Page the conversation feed and return dashboard links Nov 7, 2026
@dingsdax dingsdax closed this Nov 9, 2026
@sentry-junior
sentry-junior Bot deleted the feat/conversation-list-cursor branch November 14, 2026 20:28

This branch was successfully deployed

1 active deployment
Preview – junior-docs — d604489e Deployed Nov 7, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant