Skip to content

perf(api): Return only newer events to detail polls - #2749

Merged
thomasjiangcy merged 1 commit into
mainfrom
perf/detail-poll-append
Nov 5, 2026
Merged

thomasjiangcy merged 1 commit into
mainfrom
perf/detail-poll-append

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

Stacked on #2748.

When the detail version changes, a poll rebuilds the whole latest page: it scans up to two batches of rows, then projects and hydrates all of them again. In slow prod traces that page build was the largest part of the server time, 300 ms to 1.2 s. For a live Conversation, most polls only need the few events written since the last poll.

The detail now returns an appendCursor. The dashboard sends it as after on the next poll. The server then reads only the events after it (readConversationEventPageAfter) and marks the report appended: true. The client puts them after its cached events and keeps its own previousCursor and unreadCursor. The report metadata is still built in full.

Stored events only grow, so older events stay valid while they would project the same way. The cursor holds a transcript version, which is a hash of three things:

  • the viewer's access to private content,
  • the Junior version, so a deploy that changes the projection resets readers,
  • a fingerprint of the live Slack attachments, because hydrateMessageAttachments can attach a file that is stored later to a message that the reader already has.

When the version does not match, the transcript was purged, the read asks for unreadPage, or more than a page of events is new, the poll gets the latest page as before. The transcript version is read with the other detail state, before the page, so a file stored between the two reads makes the next poll read the full page. It is not read after the page, where it could hide that change.

Not covered: mentions and names in events that the reader already has. They refresh with a reload, like names and avatars already do for 304 polls.

Part of #2568.

via @thomasjiangcy.

--

View Session in Sentry

@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 2:51pm UTC

Request Review

Co-Authored-By: Thomas Jiang <[email protected]>
Co-Authored-By: Thomas Jiang <[email protected]>
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

1 screenshot change — 1 changed · 0 added · 0 removed

Review screenshots in Frameshift

Settings Mcp · Desktop
Settings Mcp · Desktop
Changed

@thomasjiangcy
thomasjiangcy merged commit 1b84b3a into main Nov 5, 2026
44 checks passed
@thomasjiangcy
thomasjiangcy deleted the perf/detail-poll-append branch November 5, 2026 14:59
BYK added a commit that referenced this pull request Nov 7, 2026
)

Follow-up to #2419, #2422, and #2423 after a review of the merged code.

## Inline send can stay in the transcript tail

#2423 shows an idle send in the transcript and keeps the outbox row
until history has a `message` event with the same id. Some sends never
get their own Message:

- **Joined Turn input.** A Turn joins contiguous sends from one author
into the Message of the first one (`userMessageId =
first.message.inboundMessageId`). The second id is only in
`turn_lifecycle` `started.inputMessageIds`. Two quick idle sends can
both be inline.
- **Removed from the queue elsewhere.** Another participant can delete
the send from their queue, or another tab can stop the Turn.

In both cases the row stayed as a pending transcript row until reload.
`awaitingMessage` kept the 2s poll on, and `sendsInline` stayed false,
so every later send went to the queue.

Fix: a new `settleConversationOutboxMessages` in `conversationOutbox.ts`
holds the cleanup rule that was inline in the `useConversationData`
effect:

- A history `message` event settles a row. A `turn_lifecycle`
`started.inputMessageIds` entry settles a row only after the mailbox no
longer lists it. The Turn starts before the mailbox ack, so a joined
send stays inline until then and never shows in the queue.
- Each outbox row records when its accept arrived (`acceptedAtMs`). Each
snapshot records when its mailbox read started (`mailboxReadAtMs`). The
server writes the mailbox before it accepts a send, and the snapshot
reads the mailbox before history. So a mailbox read that started after
the accept and has neither copy means the send was removed. This also
works for a background tab, a removal between polls, and an older
snapshot that a failed archive restores.

## Edit and steer feedback when no id comes back

Steer did nothing when `steeredInboundMessageIds` was empty. It now
shows "That message was already read, steered, or removed." The steer
API also returns no ids for a message that another tab already steered.
Edit now shows "That message was already read or removed.", because
cancel also returns no ids when someone else removed it.

## Checked and left as is

- Server steering (`attempt-selection.ts`, `web-steering.ts`,
`state.ts`, worker drain scoping): a web steer joins only a web Turn of
the same Actor. A Slack Turn filters to Slack records. A paused Turn
drains same-author steers. `attemptStartInterruptIds` is computed from
the leased state before resume, so steers made while paused are still
eligible.
- Draft images are lost when the composer unmounts during an edit
cancel. This is by design: drafts never store image bytes.
- The participant check in `steer-pending-messages.ts` repeats the one
in cancel, stop, archive, and create. This is the existing pattern, so
this PR does not change it.

## Tests

- `tests/conversation-outbox.test.ts`: queued rows, joined input while
queued (including the split into queue and transcript) and after the
ack, removal by accept time, a send older than the loaded events, and
unchanged identity.
- After the rebase: dashboard typecheck and vitest (394) pass locally.
CI passes, including `test / dashboard e2e` and `visual / dashboard`.

## Revival (2026-11-07)

Rebased onto main as one commit. Main now reads the mailbox and detail
in one request (#2748, #2749), so `mailboxReadAtMs` is stamped in
`readConversationData`. The reply footer moved to
`ConversationReplyFooter.tsx`, so the steer and edit copy changes moved
with it.

The accept-time rule now also settles queued rows, and it covers one
more case: the loaded events hold only the latest window. When that
window moves past a send before the client sees its Message (for
example, while the app is in the background), the row never settled. An
inline row then rendered after the newest history with its old
timestamp. Reported by BYK in Junior web: a message from 11:44:05 showed
after a 12:32:43 reply.

<!-- junior-request-attribution:start -->
via **Aditya Mathur**, @BYK.
<!-- junior-request-attribution:end -->

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

--

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

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 017bf209 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: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant