plandex-ai/plandex · error
error adding org domain users: %v
Error message
error adding org domain users: %v
What it means
Wrapped error from the create-org transaction when db.AddOrgDomainUsers fails while adding existing users with the org's domain to the new org. The transaction rolls back (including org creation) and the handler returns 500.
Source
Thrown at app/server/handlers/orgs.go:115
}
domain = &auth.User.Domain
}
// create a new org
org, err = db.CreateOrg(&req, auth.AuthToken.UserId, domain, tx)
if err != nil {
log.Printf("Error creating org: %v\n", err)
return fmt.Errorf("error creating org: %v", err)
}
if org.AutoAddDomainUsers && org.Domain != nil {
err = db.AddOrgDomainUsers(org.Id, *org.Domain, tx)
if err != nil {
log.Printf("Error adding org domain users: %v\n", err)
return fmt.Errorf("error adding org domain users: %v", err)
}
}
_, apiErr = hooks.ExecHook(hooks.CreateOrg, hooks.HookParams{
Auth: auth,
Tx: tx,
CreateOrgHookRequestParams: &hooks.CreateOrgHookRequestParams{
Org: org,
},
})
return nil
})
if apiErr != nil {
writeApiError(w, *apiErr)
returnView on GitHub (pinned to e2d772072e)
Solutions
- Inspect the wrapped error in logs to pinpoint the DB failure
- Retry org creation; the transaction rollback guarantees no partial org
- If the domain has many users, consider batching AddOrgDomainUsers or adding them asynchronously post-creation
- Check DB connectivity/pool and membership-table schema/constraints
Example fix
// before: one bulk insert inside the tx can time out err = db.AddOrgDomainUsers(org.Id, *org.Domain, tx) // after: add users asynchronously after commit createOrg(); go addDomainUsersInBackground(org.Id, *org.Domain)
Defensive patterns
Strategy: retry
Validate before calling
const domain = userEmail.split('@')[1]
if (!domain || /@(gmail|outlook|hotmail|yahoo)\./i.test(userEmail)) {
req.autoAddDomainUsers = false
} Type guard
function hasCustomDomain(userEmail) {
return /^[^@]+@([a-z0-9-]+\.)+[a-z]{2,}$/i.test(userEmail) &&
!/@(gmail|googlemail|outlook|hotmail|yahoo)\./i.test(userEmail)
} Try / catch
try {
org = await client.CreateOrg(req)
} catch (err) {
if (String(err.message).includes('error adding org domain users')) {
await new Promise(r => setTimeout(r, 1000))
org = await client.CreateOrg(req) // tx rolled back fully; safe to retry
}
} Prevention
- Create the org with autoAddDomainUsers=false and add domain users asynchronously for large domains
- Retry idempotently — the transaction rollback means no partial org exists after failure
- Watch DB connection-pool health during bulk membership operations
When it happens
Trigger: Creating an org with autoAddDomainUsers=true (and a valid non-email-service domain), where the bulk insert of domain users into org membership fails — FK mismatch, connection loss, or a very large user set timing out.
Common situations: Domains with thousands of users causing long-running bulk inserts; DB connectivity issues; schema drift on the org membership table.
Related errors
- error creating org: %v
- error creating invite: %v
- error deleting invite: %v
- error accepting invite: %v
- error creating org user: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/d1fd9a8fefae09bb.
Report an issue: GitHub.