Repository navigation
perf(api): Share Slack names for mentions across instances - #2921
Merged
Merged
Conversation
Mention lookups cached Slack users.info answers only in process memory for 5 minutes. Dashboard list reads spread across many instances, so most reads with an unnamed mention waited on Slack. Share the names in state for a day and read them with one MGET. Co-Authored-By: BYK <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
6 screenshot changes — 6 changed · 0 added · 0 removed Review screenshots in Frameshift |
BYK
requested changes
Nov 8, 2026
Use p-limit so a cold read with many mentioned users does not burst users.info calls, and use for...of loops instead of forEach.
BYK
approved these changes
Nov 8, 2026
23 tasks done
This was referenced Nov 16, 2026
sentry-junior Bot
added a commit
that referenced
this pull request
Nov 16, 2026
Reviewers asked for `for...of` over `forEach` in #2921 ("for .. of would be better here") and #3271 ("always prefer for-of over forEach"). Nothing failed, so agents kept copying the `forEach` sites that were already in the repo. This turns on `unicorn/no-array-for-each` and converts the 31 existing calls, including `Headers` and `FormData` iteration. A callback `return` is now `continue`. Co-Authored-By: David Cramer <[email protected]>
sentry-junior Bot
added a commit
that referenced
this pull request
Nov 16, 2026
Reviewers asked for bounded concurrency on `Promise.all(items.map(fn))` in #2921 ("May wanna pLimit this?"), #2989 ("No pLimit?"), and twice in #3271. The list size sets how many Slack, GitHub, Postgres, or Redis calls run at once. `pnpm unbounded-concurrency:check` counts `Promise.all` and `Promise.allSettled` over `items.map(...)` or `Array.from(...)` per file in production source. It fails when a file gains one, and names `pLimit(LIMIT).map(items, fn)` as the fix. The 70 sites that exist today are in scripts/unbounded-concurrency-baseline.json, which can only shrink. The six p-limit call sites now use `limit.map`, so the nearest example is the supported one. The type assertion ratchet and this one share scripts/source-ratchet.mjs. Co-Authored-By: David Cramer <[email protected]>
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.
In prod, 19% of
GET /api/conversationsrequests wait on Slackusers.infoafter the main queries finish. That wait happens when an activity preview mentions a Slack user who has no name in Junior (readMentionedPeopleinapi/mentions.ts). This PR stores those names in shared state for 24 hours, so a list read on a new instance doesn't call Slack.Why the cache missed
lookupSlackUsercaches answers only in process memory, for 5 minutes. Prod data for the last 24h:users.info, on 164 instances.So the per-instance cache was nearly always cold. A longer TTL alone wouldn't help, but a shared cache does.
Also, 36 lookups repeated on the same instance within the 5-minute TTL. Those were either different users or lookups that Slack didn't answer. A failed lookup isn't cached anywhere, before or after this change. I can't tell the two cases apart from telemetry (inference).
Change
lookupSlackUserNames(inchat/slack/user.ts): reads all shared entriesslack-user-names:{team}:{user}with one MGET (getStateValuesfrom perf(api): Batch cost cache reads and share Slack team domains #2821). It callsusers.infoonly for the users that are missing, then writes the names it found in one pipeline.lookupSlackUserNames. That covers the list previews, detail events, the Brief, pending messages and Automations. OtherlookupSlackUsercallers (Turns, avatars, timezones) are unchanged.Numbers
Local benchmark: 30 conversations whose previews mention 3 unnamed users. Each run is 40 list reads, and each read is on a cold instance (fresh modules, so the process cache is empty), with Redis state.
users.infois delayed to match Slack.users.infodelayusers.infocallsChecks
pnpm typecheckandpnpm lintpass.tests/integration/api/conversations/,user-lookup,slack/actor-avatar,api/automations,state-batch-redisandunit/slack/user(28 files, 133 tests).detail.test.tsnow checks two things. A name already in shared state resolves withoutusers.info, and a name from Slack is written to shared state. The test fails without the fix.file-length:check,test-architecture:checkand diff-quality: no findings to fix.via @BYK.
--
View Session in Sentry