fix: tolerate duplicate dev environment creation during concurrent invite acceptance#4257
Draft
claude[bot] wants to merge 1 commit into
Draft
fix: tolerate duplicate dev environment creation during concurrent invite acceptance#4257claude[bot] wants to merge 1 commit into
claude[bot] wants to merge 1 commit into
Conversation
…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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-projectcreateEnvironmentcall now catches a PrismaP2002unique-constraint violation on(projectId, slug, orgMemberId)and treats that project as already provisioned, continuing the loop instead of throwing. This mirrors the existingP2002handling already used for the org-membership row in the same accept flow. Non-P2002errors still surface the incomplete-setup error as before.✅ Checklist
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