Skip to content

fix(onboarding): fix org creation timeout and improve error handling#2503

Merged
tofikwest merged 13 commits intomainfrom
fix/onboarding-org-creation-timeout
Apr 10, 2026
Merged

fix(onboarding): fix org creation timeout and improve error handling#2503
tofikwest merged 13 commits intomainfrom
fix/onboarding-org-creation-timeout

Conversation

@tofikwest
Copy link
Copy Markdown
Contributor

Summary

  • Root cause: initializeOrganization runs 20+ DB operations inside a single Prisma $transaction (create controls, policies, policy versions, tasks, requirement maps, relation updates). Users selecting multiple frameworks hit the default 5s timeout, causing "Failed to create organization" errors.
  • Set global transactionOptions.timeout to 30s across all 5 Prisma client instances (apps/api, apps/app, apps/framework-editor, apps/portal, packages/db)
  • Clean up partially created org on failure to prevent orphan orgs on retry
  • Surface actual server error messages in the toast instead of generic "Failed to create organization"

Test plan

  • Create a new org in onboarding with multiple frameworks selected — should succeed without timeout
  • Verify existing transactions across the app still work (no regressions from 30s default)
  • Simulate a failure (e.g., invalid framework ID) and verify the error message is shown and no orphan org is left behind

🤖 Generated with Claude Code

The initializeOrganization transaction runs 20+ DB operations (controls,
policies, tasks, versions, requirement maps) and was hitting Prisma's
default 5s timeout for users selecting multiple frameworks.

- Set global transaction timeout to 30s across all 5 Prisma client instances
- Clean up partially created org on failure to prevent orphans on retry
- Surface actual error messages instead of generic "Failed to create organization"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
comp-framework-editor Ready Ready Preview, Comment Apr 10, 2026 8:11pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
app Skipped Skipped Apr 10, 2026 8:11pm
portal Skipped Skipped Apr 10, 2026 8:11pm

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 10, 2026

PR Summary

Medium Risk
Changes global Prisma transaction timeouts and adds flows that switch active orgs and delete organizations; mistakes could impact data integrity or user sessions, though logic includes guardrails and rollback attempts.

Overview
Improves onboarding reliability under heavy DB work. Sets Prisma transactionOptions.timeout to 30s across all Prisma clients to avoid timeouts during multi-step org initialization.

Hardens org creation and cancellation flows. createOrganizationMinimal now cleans up partially created orgs on failure and treats cache revalidation as non-critical; client-side onboarding shows more informative failure logging and prevents finishing while onboarding is in progress.

Adds cancel onboarding UX for users with existing orgs. Introduces a cancelOnboarding server action + CancelOnboardingButton that (owner-only) switches the session to a fallback completed org before deleting the incomplete org, and wires this into /setup, /onboarding, and /upgrade pages (only shown when another completed org exists).

Reviewed by Cursor Bugbot for commit 438d371. Bugbot is set up for automated code reviews on this repo. Configure here.

Address Bugbot review: if setActiveOrganization succeeded but a later
step (revalidatePath) threw, the cleanup would delete a fully initialized
org while the session still referenced it. Now cleanup is disabled after
activation, and revalidatePath errors are caught separately since they
are non-critical.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
isOnboarding is true during the server action but wasn't used in the
disabled prop — only isSubmitting (react-hook-form) was, which resets
after the synchronous onSubmit handler. This allowed double-clicks to
create duplicate orgs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…to previous org

When users create an additional org via create-additional flow, they get
trapped in the onboarding funnel with no way to go back. This adds a
Cancel button (visible only when user has other completed orgs) to:

- Pre-payment setup form: navigates back to root (no org to delete yet)
- Upgrade page: deletes incomplete org, switches to previous org
- Post-payment onboarding: deletes incomplete org, switches to previous org

Includes confirmation step before deletion to prevent accidental cancels.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…before delete

- Reject cancel on orgs with onboardingCompleted=true
- Switch activeOrganization BEFORE deleting so session never references
  a deleted org (prevents dangling session on slow client redirect)
- Fail cancel if org switch fails rather than leaving orphaned state

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Don't expose raw Prisma/DB error messages (like constraint violations or
connection details) in user-facing toasts. Log the raw error to console
for debugging, show a generic user-friendly message in the toast.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Refuse to delete org if no fallback org exists server-side. Prevents
race condition where other orgs are removed between page render (which
checks hasOtherOrgs) and action execution, which would leave the
session pointing at a deleted org.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
If setActiveOrganization succeeds but organization.delete fails, roll
back the active org to the original one so the session stays consistent
with what the user sees on screen.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9b884f0. Configure here.

…-flight

Prevents race between org deletion and completeOnboarding by hiding the
cancel button when isOnboarding or isFinalizing is true.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel vercel bot temporarily deployed to Preview – portal April 10, 2026 20:11 Inactive
@vercel vercel bot temporarily deployed to Preview – app April 10, 2026 20:11 Inactive
@tofikwest tofikwest merged commit 0ec7eed into main Apr 10, 2026
8 of 9 checks passed
@tofikwest tofikwest deleted the fix/onboarding-org-creation-timeout branch April 10, 2026 20:11
@claudfuen
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.21.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants