Repository navigation
perf(api): Read the detail record and unread with the state - #2991
Merged
Merged
Conversation
Fold the Conversation record and the unread-reply check into the detail state statement, so the report's record comes from the same snapshot as the ETag version token. The mailbox checks existence through the shared access read instead of reading the Conversation again. Co-Authored-By: BYK <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The generic selectConversationRecords return type was too large for the declaration emit in the package build (TS7056). Share the record columns and join conditions as constants instead.
Contributor
|
9 screenshot changes — 9 changed · 0 added · 0 removed Review screenshots in Frameshift |
BYK
approved these changes
Nov 9, 2026
23 tasks done
BYK
added a commit
that referenced
this pull request
Nov 17, 2026
Turns the perf patterns from #3184, #2820, #2991, #3271, #2921 and #3449 into checks that fail CI, and fixes the code that breaks them. `policies/performance.md` lists each rule and the check behind it. The DB and request budgets come in a follow-up PR. | Rule | Where | Fixed | Left | | --- | --- | --- | --- | | `unicorn/no-array-for-each` | root + dashboard | 43 | 0 | | `query-invalidation/no-broad-query-invalidation` (new, dashboard JS plugin) | dashboard `src` | 20 calls | 5 disable comments with reasons | | `junior/bounded-fan-out` (new) | `packages/*/src` | 24 (19 behind `pLimit`, 5 batched reads) | 13 disable comments naming the cap | | `no-await-in-loop` | `packages/*/src` | 3 moved to bounded `Promise.all`, 2 dashboard disables | 467 sites in 137 files, baselined | **`query-invalidation/no-broad-query-invalidation`** fails on `invalidateQueries`, `refetchQueries`, `resetQueries` or `removeQueries` when the key is missing, a literal of 2 or fewer parts, or a bare prefix const, unless the call passes `exact: true`. The fixes: - `invalidateConversationFeeds` replaces each `["dashboard", "conversations"]` refresh. - Rename writes the response title into the feeds and does not refetch. - `reviewItemQueryKey` and `invalidateReviewItemCollections` let Review item actions write item details from the response and refresh only count, list and waiting conversations. **`junior/bounded-fan-out`** flags `Promise.all`/`allSettled(<list>.map(async …))` unless the callback calls a `p-limit` limiter. A literal array is not flagged. Fixes use limits of 5 for provider APIs and 8 for internal storage. Batched fixes are `readSubscriptions` (one `mGet`) in `chat/events/store.ts` and `getStateValues` in cache warming. `junior-github` gets a `p-limit` dependency. **`no-await-in-loop` uses a baseline** because 467 sites is too many to triage safely in one PR. Many are intentionally sequential: cursor pages, ordered writes, rate limits, stop-on-first-failure. `tools/oxlint/await-in-loop.json` turns the rule off only for the listed files, and `scripts/await-in-loop-baseline.json` holds their per-file counts. `pnpm await-in-loop:check` (part of `pnpm lint`) fails when: - a count goes up, - a count goes down and the entry is not lowered or removed, - the two file lists drift. New files get the rule with no exemption. **Automations exclusion:** Otto is rewriting this code in #3570, so it is left alone. In the dashboard, `pages/automations/**`, `inbox/pages/automations/**` and `review-desk/inboxQueries.ts` have `no-broad-query-invalidation` and `no-await-in-loop` turned off. The server-side Automations files sit in the `no-await-in-loop` baseline like any other file. None of them had fan-out sites. Remove the dashboard override when that rewrite lands. <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A7e1432c2f4a2110ee7bb48718f8b6fad --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A7e1432c2f4a2110ee7bb48718f8b6fad) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A7e1432c2f4a2110ee7bb48718f8b6fad/?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
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.
Shortens the detail read chain. A detail read reads the
junior_conversationsrecord twice, and the unread-reply check waits for the state row.selectConversationRecords, whichrecord.tsnow exports as the shared constantsconversationRecordColumnsandconversationRecordJoins.readConversationDetailuses that record instead of callingreadConversationRecordFromSqlafter the ETag phase (spanf1308061).getConversationStore().get(the other fulljunior_conversationsselect,07956ffe).8c0a949c) is a column of the state statement (829eaa0b), built with the existingunreadReplySql. It no longer runs as a second round after the state row.Why one statement and not parallel reads: the report must never be older than its ETag. If the record were read before or beside the version token, a write in between could pair an old record with a new ETag. Later polls would then answer 304 and keep the stale record, for example an execution status that never finishes. One statement reads one snapshot, so the record, unread and the version token always agree. Folding the unread check in also saves a query and a pool connection, where a parallel read would still use both.
The ETag value and its basis are unchanged.
Measurements
Local Postgres 17, pool
maxraised to 10 for the run. Seeded data: a private root with 20 visible messages, a child Conversation and a participant viewer with a read position. Requests go throughcreateJuniorApi()with?mailbox=true, matching the dashboard. Each run makes 100 requests after a warm-up; I ran three before/after pairs, interleaved on the same machine.The state statement costs about 0.8ms more locally. It replaces two reads, the record (~0.7ms) and the unread check (~1.1ms), that ran in their own rounds. In prod each removed query can also mean one fewer new Neon WebSocket (115–190ms when cold), so the saving there should be larger than local wall time shows (inference).
Checks
pnpm typecheckandpnpm lintpass.vitest run tests/integration/api: 209 passed. This covers the detail, ETag, unread, read-position, pending-message and MCP tests.tool-repliesandagent-run-provider-retrycomponent tests, which callreadConversationDetaildirectly: 17 passed.Server-only change, so no screenshots.
via @BYK.
--
View Session in Sentry