Skip to content

fix(onboarding): add initialize-organization trigger task and recover…#2512

Merged
Marfuen merged 2 commits intomainfrom
mariano/initialize-org-trigger-task
Apr 10, 2026
Merged

fix(onboarding): add initialize-organization trigger task and recover…#2512
Marfuen merged 2 commits intomainfrom
mariano/initialize-org-trigger-task

Conversation

@Marfuen
Copy link
Copy Markdown
Contributor

@Marfuen Marfuen commented Apr 10, 2026

…y guard

If createOrganizationMinimal partially fails (org created but initializeOrganization doesn't run), the org ends up with no framework instances, controls, policies, or tasks. completeOnboarding now detects this and runs initializeOrganization as recovery before triggering the onboard job. A standalone Trigger.dev task allows manual re-runs from the dashboard for orgs already in this broken state.

Also saves raw framework IDs to context for reliable recovery lookups and upserts the onboarding record in case that was also missing.

What does this PR do?

  • Fixes #XXXX (GitHub issue number)
  • Fixes COMP-XXXX (Linear issue number - should be visible at the bottom of the GitHub issue description)

Visual Demo (For contributors especially)

A visual demonstration is strongly recommended, for both the original and new change (video / image - any one).

Video Demo (if applicable):

  • Show screen recordings of the issue or feature.
  • Demonstrate how to reproduce the issue, the behavior before and after the change.

Image Demo (if applicable):

  • Add side-by-side screenshots of the original and updated change.
  • Highlight any significant change(s).

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  • Are there environment variables that should be set?
  • What are the minimal test data to have?
  • What is expected (happy path) to have (input and output)?
  • Any other important info that could help to test that PR

Checklist

  • I haven't read the contributing guide
  • My code doesn't follow the style guidelines of this project
  • I haven't commented my code, particularly in hard-to-understand areas
  • I haven't checked if my changes generate no new warnings

…y guard

If createOrganizationMinimal partially fails (org created but
initializeOrganization doesn't run), the org ends up with no framework
instances, controls, policies, or tasks. completeOnboarding now detects
this and runs initializeOrganization as recovery before triggering the
onboard job. A standalone Trigger.dev task allows manual re-runs from
the dashboard for orgs already in this broken state.

Also saves raw framework IDs to context for reliable recovery lookups
and upserts the onboarding record in case that was also missing.

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)
app Ready Ready Preview, Comment Apr 10, 2026 8:26pm
comp-framework-editor Ready Ready Preview, Comment Apr 10, 2026 8:26pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
portal Skipped Skipped Apr 10, 2026 8:26pm

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 10, 2026

PR Summary

Medium Risk
Touches onboarding completion flow and framework initialization, adding recovery paths that write core framework/control/policy/task data; failures or mis-resolved framework IDs could leave orgs partially initialized or trigger extra work.

Overview
Ensures orgs that reached completeOnboarding in a partially-created state are automatically recovered by initializing missing framework instances before triggering the main onboarding job, and by upserting a missing onboarding record.

Adds a reusable resolveFrameworkIds helper (prefers stored raw frameworkIds, falls back to name-based lookup) and updates minimal org creation to persist both framework display names and raw ID JSON in onboarding context.

Introduces a standalone Trigger.dev initialize-organization task (queue + retries) to manually or programmatically re-run organization framework initialization, skipping work if initialization already happened.

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

Deduplicates the resolveFrameworkIds logic that was copied in both
complete-onboarding.ts and initialize-organization.ts. Now lives in
actions/organization/lib/resolve-framework-ids.ts alongside
initialize-organization.ts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel vercel bot temporarily deployed to Preview – portal April 10, 2026 20:24 Inactive
@Marfuen Marfuen merged commit 082501f into main Apr 10, 2026
11 checks passed
@Marfuen Marfuen deleted the mariano/initialize-org-trigger-task branch April 10, 2026 20:36
claudfuen pushed a commit that referenced this pull request Apr 10, 2026
# [3.21.0](v3.20.2...v3.21.0) (2026-04-10)

### Bug Fixes

* **onboarding:** add initialize-organization trigger task and recover… ([#2512](#2512)) ([082501f](082501f))
* **onboarding:** disable Complete button while server action is running ([8e53a10](8e53a10))
* **onboarding:** don't delete org after session activation succeeds ([a9cb9c5](a9cb9c5))
* **onboarding:** fix org creation timeout and improve error handling ([726760d](726760d))
* **onboarding:** harden cancel action — guard completed orgs, switch before delete ([b1dec0e](b1dec0e))
* **onboarding:** hide cancel button while onboarding submission is in-flight ([887dfa9](887dfa9))
* **onboarding:** require fallback org before allowing cancel ([03452e3](03452e3))
* **onboarding:** rollback active org switch if delete fails ([9b884f0](9b884f0))
* **onboarding:** sanitize error messages shown to users ([14a35df](14a35df))
* use barrel import for email package (Trigger build fix) ([b165a18](b165a18))

### Features

* add List-Unsubscribe headers and throttle email sends ([#2507](#2507)) ([80db5d9](80db5d9))
* **onboarding:** add cancel button to abandon onboarding and return to previous org ([7d990c2](7d990c2))
@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