Repository navigation
Give people a handle they can be mentioned by - #267
imshashank wants to merge 1 commit into
Conversation
Every account created since sign-up existed got a handle of the form name-3402a5fa15, because handleFor appended ten random characters unconditionally. Handles are how mentions work, so nobody could realistically be @-mentioned unless their handle predated sign-up, which in practice meant only imported accounts had a usable one. The base now stands on its own. A collision takes ada-lovelace-2, then -3, and the random suffix survives only as the last resort after twenty numbered candidates are gone. One query covers every candidate.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Next review available in: 24 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| const rows = await db | ||
| .select({ handle: schema.user.handle }) | ||
| .from(schema.user) | ||
| .where(inArray(schema.user.handle, [...candidates])); |
There was a problem hiding this comment.
Handle allocation races insertion
If two sign-ups with the same slugified name overlap, both availability queries can select the same free handle before either insertion completes, causing one sign-up to fail on the unique handle constraint instead of receiving the next numbered handle.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/web/src/lib/auth/server.ts
Line: 89
Comment:
**Handle allocation races insertion**
If two sign-ups with the same slugified name overlap, both availability queries can select the same free handle before either insertion completes, causing one sign-up to fail on the unique handle constraint instead of receiving the next numbered handle.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Every account created through sign-up gets a handle like
ada-lovelace-3402a5fa15, becausehandleForappended ten random characters unconditionally. Handles are how mentions resolve, so in practice nobody could be @-mentioned unless their handle predated sign-up, which meant only imported accounts had a usable one.Found while setting up an integration account: it was invited as
[email protected]and came out ashey-3402a5fa15, which no colleague is going to type.What changes
The base handle now stands on its own. A real collision takes
ada-lovelace-2, then-3, and the random suffix survives only as a last resort once twenty numbered candidates are gone. All candidates are checked in one query.Generation moves to
apps/web/src/lib/auth/handle.tsso it can be tested without standing up auth: the caller passes in the "which of these are taken" lookup, and the sign-up hook supplies the database one.Existing accounts
Not touched. Anyone already carrying a random suffix can change it in profile settings, which already validates uniqueness.
Testing
Nine cases in
apps/web/tests/lib/auth/handle.test.tscovering the name and email bases, thememberfallback, first-come clean handles, numbering on collision, and the random-suffix last resort. Verified by mutation: restoring the unconditional suffix fails four of them.Greptile Summary
The PR extracts handle generation into a testable module and assigns clean handles first, followed by numbered candidates and a random fallback.
Confidence Score: 4/5
The concurrent handle-allocation race should be fixed before merging because it can reject an otherwise valid sign-up.
The availability query and uniquely constrained insertion are separate operations, so simultaneous sign-ups sharing a handle base can select the same candidate and cause one insertion to fail.
Files Needing Attention: apps/web/src/lib/auth/server.ts and apps/web/src/lib/auth/handle.ts
Important Files Changed
Sequence Diagram
Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix(auth): give people a handle they can..." | Re-trigger Greptile