Repository navigation
perf(objects): Cache identities and extract objects once per message - #3310
Merged
Merged
Conversation
Cache each User and their user Identities in the state cache, by User id and by primary email. Identity and User writers clear the entry. The viewer read and person cards use the cache. Resolve the links of one message in one request. Co-Authored-By: BYK <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
BYK
approved these changes
Nov 12, 2026
BYK
enabled auto-merge (squash)
November 12, 2026 22:21
Contributor
|
Found 1 test failure on Blacksmith runners: Failure
|
…cache # Conflicts: # packages/junior-dashboard/e2e/conversation-object-links.spec.ts # packages/junior/tests/integration/api/objects.test.ts
- A link that registers after the first card request of its message now joins a new request, so its card shows. - The email to User id cache keeps only found Users. A first sign-in can create a User at any time, so a cached miss could hide it. This also removes clearCachedEmail and the hash in the key. - The Nitro output test uses memory state, because its job runs no Redis server.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1b84eea. Configure here.
Contributor
|
15 screenshot changes — 15 changed · 0 added · 0 removed Review screenshots in Frameshift Show 9 more changed screenshots |
BYK
pushed a commit
that referenced
this pull request
Nov 13, 2026
…3317) ## Problem #3310 moved the person resolver onto the identity cache. When a User has no name and no Slack Identity, the fallback now reads the name of the User a second time, so the person card has no name. Before #3310, the fallback read the name of an Identity, for example a Google Identity. Bugbot found this on #3310 after it merged ([comment](#3310 (comment))). ## Fix The name comes from the User first, then from the Slack Identity, then from any other Identity. ## Tests - `tests/integration/api/objects.test.ts` adds a User whose only name is on a Google Identity. The test fails without the fix, because the card label is the email. - `pnpm typecheck`, `pnpm lint` and the full dashboard e2e (162 passed) pass. <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A3327eedcd48b4d0139d324d264a639d1 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A3327eedcd48b4d0139d324d264a639d1) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A3327eedcd48b4d0139d324d264a639d1/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
23 tasks done
thomasjiangcy
added a commit
that referenced
this pull request
Nov 13, 2026
#3310 added a Redis cache of Users (`email:<addr>` → User id, then the User). Evals reset Postgres before each test but keep Redis, so a later test resolves its viewer email to a User id from an earlier test, which no longer exists. The viewer is then not a participant: the auth prompt is hidden, DM titles fall back to "Direct Message", and DM tool payloads are redacted. The eval clock restarts at the same instant for every test, so the 10-second settle window does not protect the `user:` entries either. Before each live eval, `src/setup.ts` now deletes every key under the user cache namespace. The prefix comes from the cache itself (`cacheKeyPrefix(USER_CACHE_NAMESPACE)`, then `redisStateKey`), so a new key in that namespace is covered without fixture changes. Redis is not flushed, because the tests share the cached Sandbox snapshots in it. The OAuth eval `identityChecks` helper now fails with an assertion when a bash call has no output, instead of crashing on `JSON.stringify(undefined).includes`. Local results, whole files, `ROACH_MODE=off`, Docker sandbox provider, suite default model: | File | `main` | This branch | | --- | --- | --- | | `auth/dashboard.eval.ts` | 2/3, case 3 fails (`expected undefined to deeply equal Any<String>`) | 3/3, 2 of 2 runs | | `conversation/assistant-thread.eval.ts` | 3/3 | 3/3 | | `conversation/steering.eval.ts` | 7/7 | 7/7 | | `src/fixture/history.eval.ts` | 5/5 | 5/5 | | `auth/oauth.eval.ts` | 1/6 | 1/6, same 5 cases | The `oauth.eval.ts` failures are the same on `main` and are local only: with the Docker provider, the credentialed `curl https://example.com/junior-eval-oauth/whoami` gets a 404 instead of the eval OAuth fixture. CI on this PR is the check for that file. Run alone, the other files did not show the leak on `main` locally. It needs an earlier long test in the same Redis. **Product cache, not changed here:** The cache does not recover when a cached User id points at a row that no longer exists. No product path deletes or merges a User, and a primary email never changes, so this happens only if someone removes a row by hand. If it does: - `readCachedUserByEmail` keeps `email:` → old id for 24 hours (`user-cache.ts:181`) and does not look up the email again when that id has no User (`user-cache.ts:184`). - If the `user:` entry is cached (24 hours, `user-cache.ts:157`), the viewer resolves to the removed User, which is the same failure as in the evals. - If not, `resolveViewerUser` recovers on each request with an insert and a read (`viewer.ts:97`), but nothing is cached. `findUserByEmail` and person cards (`api/objects/person.ts:32`) return nothing until the email entry expires. A product fix would be a separate PR. <!-- junior-request-attribution:start --> via @thomasjiangcy. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A7fde6121914317e769e85db571998d01 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A7fde6121914317e769e85db571998d01) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A7fde6121914317e769e85db571998d01/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Thomas Jiang <[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.
![Fix with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/fix-with-codesmith-light-3x.png)

Problem
Review of #3296 asked for a fix.
Fix
chat/identities/user-cache.tskeeps each User and their user Identities (Slack, GitHub handle, photo) in the state cache. The entries are by User id and by primary email → User id. The TTL is 24 h, as a safety net. No migration and no new table.upsertIdentityRecord: link, profile sync, photo sync, and Google sign-in.junior_userscolumns are not in the cache, so their writers do not clear it.Numbers
These are on 5,000 Users with Slack and GitHub Identities: the mean of 50 warm calls. The state adapter in tests keeps data in memory. With Redis, each state read is 1 round trip.
Tests
objects.test.ts: a person card comes from the cache for a second viewer, after a database write that skips the writers.objects.test.ts: a GitHub link, then an unlink, shows on the same viewer's next read.conversation-object-links.spec.ts: a reply with 2 links far apart asks for both in one request.viewer-display-name.test.tsdoes the same, because each of its tests has its own database.pnpm typecheck,pnpm lint, the junior, plugin, and dashboard unit tests, and the full dashboard e2e (160 passed) pass.attachment-s3-storage.test.tsfails locally because no S3 server runs. It fails onmaintoo.No UI change, so no screenshots.
via @BYK.
--
View Session [Sentry]