Skip to content

perf(api): Share Slack names for mentions across instances - #2921

Merged
BYK merged 2 commits into
mainfrom
perf/shared-slack-mention-names
Nov 8, 2026
Merged

BYK merged 2 commits into
mainfrom
perf/shared-slack-mention-names

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

In prod, 19% of GET /api/conversations requests wait on Slack users.info after the main queries finish. That wait happens when an activity preview mentions a Slack user who has no name in Junior (readMentionedPeople in api/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

lookupSlackUser caches answers only in process memory, for 5 minutes. Prod data for the last 24h:

  • 1,586 list requests ran on 237 instances, about 7 requests per instance per day.
  • 305 of them called 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 (in chat/slack/user.ts): reads all shared entries slack-user-names:{team}:{user} with one MGET (getStateValues from perf(api): Batch cost cache reads and share Slack team domains #2821). It calls users.info only for the users that are missing, then writes the names it found in one pipeline.
  • Failed lookups stay local: only answers from Slack are shared, so a transient Slack failure affects one request, the same as before.
  • Callers: the mention lookup now uses lookupSlackUserNames. That covers the list previews, detail events, the Brief, pending messages and Automations. Other lookupSlackUser callers (Turns, avatars, timezones) are unchanged.
  • No background work: I didn't use the background-resolve approach. With a shared cache, only the first read of a new mention in a workspace each day waits on Slack. The list never shows a placeholder, so nothing visible changes and there are no screenshots.

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.info is delayed to match Slack.

users.info delay p50 p95 Reads that waited on Slack users.info calls
57 ms (prod p50) before 103 ms 112 ms 40/40 120
after 37 ms 60 ms 1/40 3
300 ms (slow) before 345 ms 362 ms 40/40 120
after 42 ms 59 ms 1/40 3

Checks

  • pnpm typecheck and pnpm lint pass.
  • Postgres-backed tests: tests/integration/api/conversations/, user-lookup, slack/actor-avatar, api/automations, state-batch-redis and unit/slack/user (28 files, 133 tests).
  • Owning scenario extended: "resolves mentioned Slack users with current names" in detail.test.ts now checks two things. A name already in shared state resolves without users.info, and a name from Slack is written to shared state. The test fails without the fix.
  • file-length:check, test-architecture:check and diff-quality: no findings to fix.

via @BYK.

--

View Session in Sentry

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]>
@vercel

vercel Bot commented Nov 8, 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 8, 2026 1:39pm UTC

Request Review

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

6 screenshot changes — 6 changed · 0 added · 0 removed

Review screenshots in Frameshift

Conversation Captured Memories Popover · Mobile
Conversation Captured Memories Popover · Mobile
Changed
Conversation Details Watched Linked Work · Desktop
Conversation Details Watched Linked Work · Desktop
Changed
Conversation Details Watched Linked Work · Mobile
Conversation Details Watched Linked Work · Mobile
Changed
Conversation Long Transcript Touch · Mobile
Conversation Long Transcript Touch · Mobile
Changed
Memories · Mobile
Memories · Mobile
Changed
Settings Mcp · Desktop
Settings Mcp · Desktop
Changed

Comment thread packages/junior/src/chat/slack/user.ts Resolved
Comment thread packages/junior/src/chat/slack/user.ts Resolved
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
BYK merged commit 130e741 into main Nov 8, 2026
47 of 49 checks passed
@BYK
BYK deleted the perf/shared-slack-mention-names branch November 8, 2026 13:53
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

1 active deployment
Preview – junior-docs — 2ca7268c Deployed Nov 8, 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