Skip to content

Give people a handle they can be mentioned by - #267

Closed
imshashank wants to merge 1 commit into
mainfrom
fix/clean-signup-handles
Closed

imshashank wants to merge 1 commit into
mainfrom
fix/clean-signup-handles

Conversation

@imshashank

@imshashank imshashank commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Every account created through sign-up gets a handle like ada-lovelace-3402a5fa15, because handleFor appended 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 as hey-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.ts so 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.ts covering the name and email bases, the member fallback, 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.

  • Adds batched availability lookup for the base and numbered handle candidates.
  • Updates the sign-up hook to generate handles asynchronously.
  • Adds unit coverage for base derivation, collisions, numbering, fallback behavior, and batched lookup.

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

Filename Overview
apps/web/src/lib/auth/handle.ts Introduces testable base and candidate selection logic, but selection does not reserve the chosen handle.
apps/web/src/lib/auth/server.ts Adds the batched database lookup and asynchronous sign-up integration, leaving a race between availability lookup and insertion.
apps/web/tests/lib/auth/handle.test.ts Thoroughly covers sequential generation behavior, although concurrent collision handling is not represented.

Sequence Diagram

sequenceDiagram
  participant A as Sign-up A
  participant B as Sign-up B
  participant H as Handle generator
  participant DB as Database
  A->>H: Generate handle for shared base
  B->>H: Generate handle for shared base
  H->>DB: Query candidate handles
  H->>DB: Query candidate handles
  DB-->>H: Base is available
  DB-->>H: Base is available
  H-->>A: Return base
  H-->>B: Return base
  A->>DB: Insert user with base
  DB-->>A: Success
  B->>DB: Insert user with base
  DB-->>B: Unique constraint failure
Loading

Fix All in Claude Code

Prompt To Fix All With AI
### Issue 1
apps/web/src/lib/auth/server.ts:89
**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.

Reviews (1): Last reviewed commit: "fix(auth): give people a handle they can..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

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.
@imshashank
imshashank requested a review from pulkitxm as a code owner August 9, 2026 09:33
@vercel

vercel Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
orbit Ready Ready Preview Aug 9, 2026 9:34am

Request Review

@github-actions github-actions Bot added tests Test coverage and test infrastructure area: web The Next.js app and its UI area: auth Sign-in, sessions, passkeys, OAuth labels Aug 9, 2026
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@imshashank, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 440ff776-49b2-4a69-aae2-5757ee8062ee

📥 Commits

Reviewing files that changed from the base of the PR and between 808d714 and 8142bb0.

📒 Files selected for processing (3)
  • apps/web/src/lib/auth/handle.ts
  • apps/web/src/lib/auth/server.ts
  • apps/web/tests/lib/auth/handle.test.ts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

const rows = await db
.select({ handle: schema.user.handle })
.from(schema.user)
.where(inArray(schema.user.handle, [...candidates]));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

Fix in Claude Code

@imshashank imshashank closed this Aug 9, 2026
@imshashank
imshashank deleted the fix/clean-signup-handles branch August 9, 2026 09:59

This branch was successfully deployed

1 active deployment
Preview — 8142bb0f Deployed Aug 9, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: auth Sign-in, sessions, passkeys, OAuth area: web The Next.js app and its UI tests Test coverage and test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant