Skip to content

fix(webapp): prevent duplicate envs from provision race#4261

Open
carderne wants to merge 1 commit into
mainfrom
fix/duplicate-root-environments-tri-12078
Open

fix(webapp): prevent duplicate envs from provision race#4261
carderne wants to merge 1 commit into
mainfrom
fix/duplicate-root-environments-tri-12078

Conversation

@carderne

Copy link
Copy Markdown
Collaborator

Fixes TRI-12078

Summary

Prevents concurrent environment setup requests from creating duplicate Staging and Preview environments.

Fix

Adds database-enforced uniqueness for root Staging and Preview environments.

If two requests race, the losing request loads the environment created by the winner and continues successfully instead of creating a duplicate or returning an error.

@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: db6bd6a

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

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a partial unique index enforcing one root Staging or Preview environment per project and runtime type. Updates environment upsert logic to identify root environments, handle Prisma unique-constraint conflicts from overlapping creation requests, re-query the existing environment, and update its concurrency limits. Adds schema documentation and a server-changes entry.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the fix but misses most required template sections, including checklist, testing, changelog, and screenshots. Add the missing template sections: Closes #, checklist, testing steps, changelog, and screenshots placeholder.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately reflects the main fix: preventing duplicate environments during a provisioning race.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/duplicate-root-environments-tri-12078

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.

@carderne carderne marked this pull request as ready for review July 14, 2026 14:31
@@ -0,0 +1,4 @@
CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS "RuntimeEnvironment_projectId_type_staging_preview_root_key"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Do not merge until this has been backfilled.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 0 potential issues.

Open in Devin Review

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