Skip to content

perf(api): Open conversation detail at the last 3 Turns in one pass - #2722

Merged
BYK merged 4 commits into
mainfrom
perf/detail-sync-path
Nov 5, 2026
Merged

BYK merged 4 commits into
mainfrom
perf/detail-sync-path

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Cut the server time of the conversation detail read that the dashboard waits on when a conversation opens.

What changed

The first page holds the latest three Turns, up to 500 events. It applies only when the request has no limit. The page starts after the Turn before those three, so it includes their input messages, which are written before turn_started. With fewer than three Turns, it starts at the beginning. When the three Turns hold more than 500 events, it returns the latest 500, as before. previousCursor still points before the first event, so scrolling up loads earlier pages.

  • The start is one lookup on (conversation_id, type, seq). It is a subquery of the row read, so it adds no round trip.
  • An explicit limit (MCP, evals) and /events behave as before.

One pass per page. Each scan chunk is decoded and counted once, and the page is projected once. Its context reads (Turn boundary, model call, subagent starts, tool starts, attachments) run together.

Per-viewer reads happen once per request. The version-token read returns the state that it hashes: access, marks, read position, forks, agent tree and auto-archive. The report reuses it, so the report always matches its token.

More reads run in parallel. The event page runs beside the metadata batch, and sidebar annotations run beside mentions. On a first open, the version token is read beside the mailbox. The mailbox is still read before history.

Numbers

Local Postgres behind a ~4ms round-trip proxy, pool of 10. The conversation has 1,995 rows in 105 Turns; the last three Turns are 57 events. Default detail, warm p50 over 12 reads, 3 runs:

main this PR
p50 ~168ms ~72ms
events 500 57
response 322 KB 38 KB
queries 38 29

With an explicit limit=500, the single pass and the parallel reads alone take it from ~168ms to ~121ms.

Not changed

  • The page around the read position (unreadPage) still has 500 events. It now applies to readers more than three Turns behind.
  • When the first page is shorter than the screen plus 600px, the dashboard loads one earlier page right after the transcript shows.
  • One zod parse instead of two: a parse measured 0.5–2.2ms, so it stays.
  • Polls that return only new events: not needed for this, and out of scope.

Tests

The event-list paging scenario covers a default page that starts at the third-latest Turn, with a previousCursor walk over all events. It also covers fewer than three Turns, three Turns over 500 events, and a subagent start more than one scan chunk older.

via @thomasjiangcy.

--

View Session [Sentry]

Default the Conversation detail page to 50 events and project scanned
rows once instead of once per chunk. Reuse the detail state that the
ETag reads, so the report does not read it again, start the event page
beside the metadata reads, and read the ETag beside the mailbox.
@vercel

vercel Bot commented Nov 5, 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 5, 2026 10:48am UTC

Request Review

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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

Review screenshots in Frameshift

Conversation Share Details · Desktop
Conversation Share Details · Desktop
Changed
Settings Mcp · Desktop
Settings Mcp · Desktop
Changed

A 50-event page can end in the middle of a Turn. Keep the old default;
the single-pass page read, the reused version-token state and the
parallel reads stay.

Co-Authored-By: Thomas Jiang <[email protected]>
Without a limit, the detail page holds the latest three Turns, capped
at 500 events. The page starts after the Turn before them, so it keeps
their input messages. The start lookup is a subquery of the row read,
so it adds no round trip. An explicit limit and the events endpoint
keep their behavior.

Co-Authored-By: Thomas Jiang <[email protected]>
@BYK
BYK marked this pull request as ready for review November 5, 2026 10:36
@BYK
BYK enabled auto-merge (squash) November 5, 2026 10:36
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 5, 2026
# Conflicts:
#	packages/junior/tests/integration/api/conversations/event-list.test.ts
@sentry-junior sentry-junior Bot changed the title perf(api): Read a 50-event detail page in one pass perf(api): Open conversation detail at the last 3 Turns in one pass Nov 5, 2026
@BYK
BYK merged commit 2358e6c into main Nov 5, 2026
44 checks passed
@BYK
BYK deleted the perf/detail-sync-path branch November 5, 2026 10:56
BYK added a commit that referenced this pull request Nov 5, 2026
Part of #2568. Follows #2722, which moved the default first page to the
latest 3 Turns.

Three dashboard pages still held up to 500 events:
- earlier and newer pages: `/events` with `before` or `after`
- the page around the read position: `unreadPage`, and `around`
- the `event=` and `turn=` link pages

The default first page also fell back to 500 events when the latest 3
Turns held more. All of these now hold at most 150 events
(`CONVERSATION_EVENT_PAGE_LIMIT`). Callers that pass a `limit` see no
change (CLI briefs pass `limit=1000`, MCP and evals pass `limit`). The
client code is unchanged.

## Numbers

These use the same setup as #2722: local Postgres behind a ~4 ms
round-trip proxy, a pool of 10, and in-process API requests. The viewer
can see private content. The Conversation has 1,920 events in 105 Turns,
and every 20th Turn is a 184-event tool loop. Each figure is the warm
p50 of 12 reads, and the range covers 3 runs.

| Read | main | this PR |
|---|---|---|
| earlier page (`before`) | 69–77 ms · 500 events · 311 KB | 31–42 ms ·
150 events · 99 KB |
| around page (`around`, `event=`, `unreadPage`) | 70–72 ms · 500 events
· 305 KB | 33–39 ms · 150 events · 91 KB |
| default detail, latest 3 Turns hold 552 events | 83–85 ms · 500 events
· 343 KB | 47–49 ms · 150 events · 105 KB |
| default detail, latest 3 Turns hold 30 events | 30–37 ms · 30 events |
32–40 ms · 30 events (unchanged) |

Why 150: page cost by `limit`, measured on the same Conversation:

| limit | 50 | 100 | 150 | 250 | 500 |
|---|---|---|---|---|---|
| `before` p50 | 19 ms | 25 ms | 31 ms | 45 ms | 68 ms |
| size | 30 KB | 64 KB | 99 KB | 160 KB | 311 KB |

A page costs a fixed ~15 ms plus ~0.1 ms and ~620 bytes per event. At
150 events, the per-event cost is about the same as the fixed cost.
Going lower saves a few ms per page but needs more requests, and each
one adds a browser round trip in production.

## Considered and not done

**Turn-aligned earlier and around pages.** On short Turns, these pages
would hold fewer events (about 30 instead of 150) and save ~10 ms server
time per page. Scrolling the same distance would then take about 5× more
requests. On long Turns the 150 cap applies anyway. So the only extra
step is the cap: earlier and around pages stay fixed-count, and only the
first page keeps #2722's 3-Turn start.

## Behavior changes

- Scrolling far back needs about 3× more requests for the same distance:
10 × ~33 ms instead of 3 × ~70 ms for 1,500 events. Pages load as the
reader nears the top or bottom edge. Short pages chain through the same
observer, so no client change was needed.
- Readers more than 3 Turns behind open with 75 events on each side of
the read position, down from 250. Newer pages load as they scroll down.
Jump to latest still skips them.
- The event log searches loaded events only, so a far-behind open starts
with fewer events in scope. More events come into scope as pages load.
- The mock reporting `/events` route uses the shared schema default, so
mock `before` pages are now 150 too. Mock conversations fit one page.

## Tests

- `event-list` scenario: the long-Turns case now covers a 150-event
default detail, plus a default `before` page and a default `event=`
page.
- `tests/integration/api/conversations/` (72 tests),
`dashboard-reporting` and `conversation-sql` pass on local Postgres.
- Dashboard e2e passes, 36/36: `conversations-read-position`,
`conversations-event-log`, `conversations-mobile`, `conversations.spec`,
`conversation-details`.
- tsc (junior and dashboard), lint, prettier and file-length pass.

No UI change, so no screenshots.

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

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

--

[View Session in
Sentry](https://sentry.sentry.io/explore/conversations/agent%3Acf99e96c9651a1a9b5d0dc762cd5a99d/?project=4510944073809921)

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

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <[email protected]>
thomasjiangcy added a commit that referenced this pull request Nov 5, 2026
)

Adds the telemetry that is missing for the slowest unexplained part of
opening a Conversation in prod (0.279.0).

## What prod traces show

Warm pageloads of `/conversations/:conversationId` after the 0.279.0
deploy:

| trace | detail `http.client` ends | `Conversation transcript shown` |
unexplained |
|---|---|---|---|
|
[3cbaa159](https://sentry.sentry.io/explore/traces/trace/3cbaa159341f43209a469484bc6d32f9/)
| 2.41s | 3.51s | 1.10s |
|
[232562e7](https://sentry.sentry.io/explore/traces/trace/232562e77fd8480e8a77c3136942bef3/)
| 2.24s | 3.41s | 1.17s |
|
[4a3de783](https://sentry.sentry.io/explore/traces/trace/4a3de7839e624ef8814d83ca59220684/)
| 3.81s | 4.30s | 0.49s |

In each, the only long animation frame in the gap is the last ~175–230ms
(`TimerHandler:setTimeout`, the query result render). The rest is not
covered by any span:

- The browser `http.client` span ends when the response headers arrive.
Body download, `JSON.parse`, and the zod check are outside it.
- The first detail fetch of each pageload also has no resource-timing
attributes (`http.request.response_end` and the others). Other fetches
on the same page have them. So there is no record of when its body
finished.

## Change

`readResponseJson` in `client/sentry.ts` reads, parses, and validates a
dashboard API response. While a `pageload` or `navigation` span is open,
it records a `deserialize` span named `Read API response`, from the
response headers to the validated value:

- `url.path`
- `app.dashboard.response.chars`
- `app.dashboard.response.json_parse_ms`
- `app.dashboard.response.schema_parse_ms`

Body download time = span duration − the two parse times.

All JSON reads in `client/http.ts` and the Conversation detail read go
through it. Polls after the route span ends add no spans. `TELEMETRY.md`
documents the span and adds a query recipe.

With this span, the gap above splits into three measured parts: body
download, parse, and validation (this span). The render is already
measured by the long animation frame. What is left is the time from the
end of this span to the transcript render.

## Checked

- Local `JUNIOR_DASHBOARD_MOCK_CONVERSATIONS=true pnpm dev` with
`SENTRY_DSN` pointed at a local envelope capture. A Conversation open
sent `Read API response` spans under the `pageload` for
`/api/conversations`, `/api/user-pages`,
`/api/review-items/waiting-conversations`, and the detail. The detail
span started at the end of its `http.client` span (+6887ms vs +6757ms +
130ms) and ended right before the render frame. Polls after the pageload
sent no `deserialize` spans.
- `tsc`, oxlint, dashboard vitest (52 files pass).
`tests/dashboard-output.test.ts` fails the same way on `main` in my
sandbox (`nitro build` error), so it is not related to this change.

## Not in scope

- **Server CPU gaps in `GET /api/conversations/:id`.** On 0.279.0, about
400ms of 1.2–1.6s is not covered by a span. #2722 restructures this
exact path and is not released yet. Re-measure after the next release
before adding server spans.
- **Slow `pre_fetch_ms` pageloads (1.5–3.9s).** Each one in the last 3h
follows a `GET /auth/login` → `GET /api/auth/*` sign-in round trip. The
existing attribute already marks them.

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

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:local%3Aweb%3A5af549fdd530218cd1a45226 -->

--

[View Session in
Sentry](https://sentry.sentry.io/explore/conversations/local%3Aweb%3A5af549fdd530218cd1a45226/?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]>

This branch was successfully deployed

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

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant