Skip to content

fix(join-callback): consume team invites atomically - #2223

Open
igorosip0v wants to merge 3 commits into
mainfrom
igorosip0v/fix-join-callback-invite-race
Open

fix(join-callback): consume team invites atomically#2223
igorosip0v wants to merge 3 commits into
mainfrom
igorosip0v/fix-join-callback-invite-race

Conversation

@igorosip0v

Copy link
Copy Markdown
Contributor

PR Type

  • Regular Task
  • Bug Fix
  • QA Tests

Description

Fixes a race condition in /api/join-callback where one invite could create multiple memberships.

  • Uses accept_team_invite() to consume the invite and create the membership atomically.
  • Returns invalid_invite to concurrent requests that lose the race.
  • Adds integration coverage for normal and concurrent invite acceptance.

Tests, typecheck, and formatting checks pass.

Checklist

  • I have self-reviewed this PR.
  • I have left comments in the code for clarity.
  • I have added necessary unit tests.
  • I have updated the documentation as needed.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants