Skip to content

fix: tolerate duplicate dev environment creation during concurrent invite acceptance#4257

Draft
claude[bot] wants to merge 1 commit into
mainfrom
fix/accept-invite-devenv-provisioning-race
Draft

fix: tolerate duplicate dev environment creation during concurrent invite acceptance#4257
claude[bot] wants to merge 1 commit into
mainfrom
fix/accept-invite-devenv-provisioning-race

Conversation

@claude

@claude claude Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Before / After

Before: If a member accepted an org invite and two requests raced (double-clicked Accept, a retry, or the invite-recovery path overlapping the normal accept), one request would fail with an "environment setup incomplete" error even though the development environment had actually been created — showing the joining user a false failure.

After: The duplicate-creation case is treated as already-provisioned and the accept succeeds.

How

In provisionMemberDevelopmentEnvironments (apps/webapp/app/models/member.server.ts), the per-project createEnvironment call now catches a Prisma P2002 unique-constraint violation on (projectId, slug, orgMemberId) and treats that project as already provisioned, continuing the loop instead of throwing. This mirrors the existing P2002 handling already used for the org-membership row in the same accept flow. Non-P2002 errors still surface the incomplete-setup error as before.

✅ Checklist

  • I have followed every step in the contributing guide
  • The PR title follows the convention.
  • I ran and tested the code works

Testing

Reasoned through the concurrent-accept race (two requests both observe a project as missing its development environment; the loser hits the unique constraint). The fix reuses the same PrismaClientKnownRequestError / code === "P2002" pattern already present and type-checked in this file, so no new types are introduced. A full monorepo typecheck was not run here because dependencies were not installed in this environment.


Changelog

Tolerate a duplicate development-environment creation (P2002) during concurrent invite acceptance so the joining user no longer sees a false "environment setup incomplete" failure.


Generated by Claude Code

…vite acceptance

When two invite-accept requests race for the same member, both can observe a
project as missing its development environment and attempt to create it. The
loser hit the unique constraint on (projectId, slug, orgMemberId) and the
resulting P2002 error propagated, failing the accept with an incomplete-setup
error even though the environment had already been created.

Catch P2002 in the per-project creation loop and treat the project as already
provisioned, matching the existing P2002 handling for the org-membership row.
Non-P2002 errors still surface the incomplete-setup failure.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qe3bkKy2Pzgt3E2EE5CMNY
@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 661249c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@d-cs d-cs self-assigned this Jul 14, 2026
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