fix(join-callback): consume team invites atomically - #2223
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ef451d626c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!delete_invite_by_pk?.id) { | ||
| throw new Error("Failed to delete invite"); | ||
| } | ||
| acceptedMembership = acceptInviteResult.accept_team_invite[0] ?? null; |
There was a problem hiding this comment.
Avoid committing users before the invite concurrency gate
When two different new users pass the invite lookup concurrently, both InsertUser mutations and both signup_success events complete before this mutation determines the winner. The losing call therefore receives an empty accept_team_invite result and returns invalid_invite, but its user row remains committed with the invited team's team_id; a burst against one invite can consequently create many orphan users and false signup events. The user insertion and invite consumption need to share the atomic operation, or the losing path must safely undo the newly inserted user and defer success tracking until acceptance succeeds.
Useful? React with 👍 / 👎.
PR Type
Description
Fixes a race condition in
/api/join-callbackwhere one invite could create multiple memberships.accept_team_invite()to consume the invite and create the membership atomically.invalid_inviteto concurrent requests that lose the race.Tests, typecheck, and formatting checks pass.
Checklist