Skip to content

test(api): Budget the size of conversation feed rows - #3809

Merged
BYK merged 4 commits into
mainfrom
test/response-size-budget
Nov 19, 2026
Merged

BYK merged 4 commits into
mainfrom
test/response-size-budget

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

expectSqlBudget holds the SQL work of hot routes, but nothing holds the size of what they send. GET /api/conversations rows carry content with no cap, so the body grows with the data.

expectResponseBudget (packages/junior/tests/fixtures/response-budget.ts) takes a request and a budget per list path, such as conversations or conversations.threads, and holds the largest item of each list. A nested list with its own entry is left out of its parent item, so each entry holds only the item's own fields. A failure names the size and the three biggest fields of the item.

The feed scenario seeds a heavy viewer: heavy pins, plain rows, and heavy waiting rows older than the page. A heavy row has a full title, Threads, a 32,000-char latest message, a Brief, an open Review item, and annotations with every field at its max length. Each budget is the size on main:

Path Chars Gap
conversations 1_959 + 32_069 The activity preview holds the whole latest message.
conversations.annotations 16,654 No cap on the count.
conversations.sidebarAnnotations 674 No cap on the count.
conversations.participants 52 No cap on the count.
conversations.threads 637 No cap on the count.

The body has no total budget: pins and waiting rows are not paged, so the row count has no cap.

policies/performance.md gets a bullet next to the SQL budget.

via @BYK.

--

View Session [Sentry]

Add expectResponseBudget, which fails when the largest item of a list in a
JSON body grows past a budget, and names its biggest fields. A nested list
with its own budget is left out of its parent item.

Seed a heavy viewer feed with pins, waiting rows outside the page, Threads,
a Brief, a long latest message, and annotations at their max lengths. Set
each budget to the size measured on main.

Co-Authored-By: BYK <[email protected]>
@sentry-junior
sentry-junior Bot requested a review from BYK November 19, 2026 17:48
@vercel

vercel Bot commented Nov 19, 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 19, 2026 6:50pm UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 19, 2026
@BYK
BYK enabled auto-merge (squash) November 19, 2026 17:54

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c3edabf. Configure here.

…r max

The heavy row now stores 4 KiB of object facts and a 400-char Brief
intent, so the row and annotation budgets hold for a legal max payload.
@BYK
BYK merged commit 6c69e7b into main Nov 19, 2026
52 checks passed
@BYK
BYK deleted the test/response-size-budget branch November 19, 2026 19:04
BYK added a commit that referenced this pull request Nov 19, 2026
`GET /api/conversations` waited on reads that did not depend on each
other. On the heavy feed seed from #3809 (`include=links,media`), it ran
23 statements in 7 serial rounds. It now runs 21 statements in 3 rounds.
The response stays the same.

- **Waiting rows:** the first page read the waiting ids, then the rows
for the ids outside the page. Now a third row read in the first round
filters by `waitingConversationIdsQuery` as a subquery, and the feed
dedupes it in JS against the pins and the page.
`listWaitingConversations` and the subquery share one root expression.
- **Threads:** `readFeedThreads` waited on access before it read
anything. `readFeedThreadRecords` now reads the Thread rows, trees and
the first messages of untitled Threads in the main batch, and
`nestFeedThreads` applies access afterwards.
- **Slack tenants:** `attachActivityPreviewMentions` read each
conversation's tenant again. The feed now takes it from the rows it
already has, through `conversationSlackTenantId`, which
`loadConversationSlackTenantIds` also uses. The detail route keeps its
lookup.

Mention resolution and sidebar annotations now run together after the
batch.

| Heavy seed | Statements | Rounds |
| --- | --- | --- |
| Before | 23 | 7 |
| After | 21 | 3 |

On the same seed with preview mentions and an untitled Thread, the
request goes from 25 statements in 9 rounds to 23 in 5.

The `serialRounds` budgets on the feed scenarios go down to match:
`list-brief` 3 → 2, `list-answer` 5 → 3, `tree-state` feed 5 → 3. The
statement budgets do not change.

The heavy viewer's feed in `list-budget.test.ts` now also has an
`expectSqlBudget` of 21 statements and 3 serial rounds.

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

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

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A2c3e432e56cd1bf6d0fbfabed08dc476)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A2c3e432e56cd1bf6d0fbfabed08dc476/?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]>
BYK added a commit that referenced this pull request Nov 19, 2026
`GET /api/conversations` read some rows twice. On the heavy feed seed
from #3809 (`include=links,media`), it ran 23 statements. It now runs
20. The response stays the same.

- **Participants:** access read the viewer's participant rows, and the
pin marks read the same rows again with `pinned_at is not null`. The
feed now reads them once with `readMemberParticipants` and passes the
roots to `conversationAccessFromRows`. `readConversationAccessFromSql`
is now `readConversationAccessRows` plus that projection, so its other
callers do not change. Feed rows are roots, so these roots cover the
access check. An actor email feed with no viewer still reads only its
pin marks.
- **Avatars:** `readConversationParticipants` and
`readConversationAuthors` read user photos in a second statement. Both
participant reads now join the photo Identities with `hasUserPhoto`.
`userAvatarUrlsFromJoinedPhotos` picks the photo, and
`readMentionedPeople` uses it too.
- **Children:** `listConversationWork` and `readFeedThreads` each read
the children of the same roots. The feed reads `readConversationTrees`
once and passes it to both. `ConversationTreeNode` now carries
`rootConversationId` for the work owners. Other `listConversationWork`
callers read the tree themselves.

| Heavy seed | Statements | Rounds |
| --- | --- | --- |
| Before | 23 | 7 |
| After | 20 | 7 |

The rounds do not change here. #3820 removes them. On
the same seed with preview mentions and an untitled Thread, the request
goes from 25 statements to 22.

The SQL budgets go down to match: `list-brief` 15 → 14 statements,
`list-answer` 19/5 → 17/4, `tree-state` feed 20/5 → 17/4 and detail 20 →
19 statements.

This PR and #3820 both change
`readConversationFeedFromSql`. The one that merges second merges `main`
in and keeps both changes.

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

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

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A2c3e432e56cd1bf6d0fbfabed08dc476)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A2c3e432e56cd1bf6d0fbfabed08dc476/?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]>
BYK added a commit that referenced this pull request Nov 22, 2026
`GET /api/conversations` had no cap on the Threads that a row nests or
on the waiting rows that the first page adds from outside the page
(#3809). Both caps sit well above what real feeds carry,
so no row loses data today; they only bound the response.

**Threads** (`CONVERSATION_FEED_THREAD_LIMIT = 100` per root, at any
depth)
- `nestFeedThreads` keeps Threads depth first in activity order, so a
kept Thread always has its parent.
- A root past the cap carries `omittedThreadCount`. The root's own page
still lists every Thread.
- The dashboard (sidebar and the new UI's rows) shows a muted "+N more"
under the root's Threads once every loaded Thread shows.

**Waiting rows** (`CONVERSATION_FEED_WAITING_LIMIT = 50`)
- The waiting read skips pins (they already show) and reads `limit + 50
+ 1` rows, so it knows whether the cap cut some without another
statement.
- The newest waiting rows join the first page. When some are cut, the
feed sets `waitingRowsTruncated: true`. The rest come on later pages by
activity like any other row, so the dashboard does not lose them.

Pins are still not paged; this leaves them as they are.

### Screenshots

Mock data with `omittedThreadCount: 12` on a root with two Threads.

Current dashboard sidebar:

![Sidebar shows +12 more under the root's
Threads](https://junior-prod.sentry.dev/public/artifacts/b362ee4c-90fb-49f4-b652-eb14e64e2e0e.png)

New dashboard Conversations view:

![Conversation row shows +12 more under its
Threads](https://junior-prod.sentry.dev/public/artifacts/2f431ca1-776f-4d6f-8272-3996b9bdfdc1.png)

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

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

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A89f267e0ff71aeabd08513df3cdf5741)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A89f267e0ff71aeabd08513df3cdf5741/?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 — 93f7f0e2 Deployed Nov 19, 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