Repository navigation
perf(api): Open conversation detail at the last 3 Turns in one pass - #2722
Merged
Merged
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
2 screenshot changes — 2 changed · 0 added · 0 removed Review screenshots in Frameshift
|
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
approved these changes
Nov 5, 2026
BYK
marked this pull request as ready for review
November 5, 2026 10:36
BYK
enabled auto-merge (squash)
November 5, 2026 10:36
# Conflicts: # packages/junior/tests/integration/api/conversations/event-list.test.ts
This was referenced Nov 5, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 beforeturn_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.previousCursorstill points before the first event, so scrolling up loads earlier pages.(conversation_id, type, seq). It is a subquery of the row read, so it adds no round trip.limit(MCP, evals) and/eventsbehave 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:
With an explicit
limit=500, the single pass and the parallel reads alone take it from ~168ms to ~121ms.Not changed
unreadPage) still has 500 events. It now applies to readers more than three Turns behind.Tests
The
event-listpaging scenario covers a default page that starts at the third-latest Turn, with apreviousCursorwalk 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]