Repository navigation
feat(identities): Cache Identity reads and linked handle lookups - #4196
Conversation
Read the User behind an Identity id through the state-adapter user cache, so webhook login checks, work owners, and Inbox items skip Postgres on a repeat read. Cache found results of findLinkedHandle for an hour, with stale-if-error, so a repeat reviewer or assignee lookup makes no Slack call and still resolves while Slack fails. A per-provider version, bumped on each Identity write that changes a lookup column and on unlink, clears them. Co-Authored-By: BYK <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort 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 fa87550. Configure here.
A lookup for one provider matches the Identities of every provider, such as the Slack Identities that link a person, so one version now covers every cached linked handle. Co-Authored-By: BYK <[email protected]>
| return await readCachedLinkedHandle( | ||
| input, | ||
| async () => await loadLinkedHandle(provider, lookup), | ||
| ); | ||
| } |
There was a problem hiding this comment.
Successful non-found linked-handle reload leaves stale found entry for later Slack errors
After a cached found handle goes stale, a successful reload that returns not_found, unlinked, or ambiguous does not replace the staleIfError entry, so a later Slack failure resurrects the outdated found handle.
Evidence
findLinkedHandlenow serves results throughreadCachedLinkedHandle, which stores only{ status: "found" }withstaleIfError: trueand returns bare{ value }for every other status.createCache().getOrLoadwrites only whenentry.ttlMs !== undefined, so a successful non-found reload leaves the previous stale entry in place for up toLAST_GOOD_MS(24h).- On the next load failure,
getOrLoadcatches the error and returns that leftoverhit.value, replaying the old{ status: "found", handle }. - Identity writes bump the linked-handle version, but Slack directory changes (rename, departure, new same-name match) only rely on TTL and do not clear the key.
Identified by Warden · code-review · SM6-WHW

Closes #4123
No caller of the GitHub account ↔ Identity mapping calls GitHub. The mapping already lives in
junior_identities, which OAuth account linking writes (GET /user, once). So caching it would save no GitHub call, and lookups already work while GitHub is down. The real costs are Postgres (Identity → User reads) and Slack (resolving a named person infindLinkedHandle). This PR caches both in the state adapter. A miss still reads Postgres and Slack as before.Identity → User.
readIdentityByIdFromSqlreads through the existing user cache inchat/identities/user-cache.ts. That coversloadGitHubLoginin the GitHub webhooks, work owners, Inbox items, andreadActorIdentity. A newidentity:{id}entry maps an Identity to its User id. A linked Identity never moves to another User, so this entry stays valid. The User entry is versioned and cleared on every Identity write, as before. Unlink deletes the Identity, so the cached User no longer has it, and the read falls back to SQL.findLinkedHandle. Afoundresult is cached by provider, team, providers, and query, with stale-if-error. Other answers (unlinked,not_found,ambiguous) are never cached, because they can change when a person joins or links an account. One version clears every cached handle, because a lookup for one provider also matches the Identities of the other providers, such as the Slack Identities that link a person. A new Identity of any provider, or a write that changes its User, handle, or verified email, bumps the version, and so does unlink. Writes that change none of these, such as the actor of each message, do not bump it. So a person's first Slack message or a profile change clears every cached handle.TTLs and stale window:
review_byresolution in #4100 (tool-support/issue-reviewers.ts) should go throughctx.users.findLinkedHandlewhen it rebuilds, so it gets this cache.via @BYK.
--
View Session [Sentry]