twentyhq/twenty · error · Error

Failed to add Send Email record-selection commands for…

Error message

Failed to add Send Email record-selection commands for workspace ${workspaceId}

What it means

Thrown by the 1.22 workspace upgrade command when validateBuildAndRunLegacyWorkspaceMigration returns status 'fail' during creation of the new 'Send Email' record-selection command menu items. The detailed failure payload is logged before the throw so the operator can see why the build rejected the create operations.

Solutions

  1. Inspect the logged validateAndBuildResult JSON for the specific create rejection (duplicate identifier, missing parent, etc.).
  2. Recompute the workspace cache and re-run so the existing-items diff is accurate.
  3. Run --dryRun first to see the planned itemsToCreate.
  4. Scope the upgrade to the failing workspace and resolve the flagged metadata before continuing the fleet.
Defensive patterns

Strategy: validation

Validate before calling

// Dry-run to preview itemsToCreate, and confirm the parent Send Email command exists:
await workspaceCacheService.invalidate(workspaceId);
const { flatCommandMenuItemMaps } = await workspaceCacheService.getOrRecompute(workspaceId, ['flatCommandMenuItemMaps']);
const parentExists = isDefined(flatCommandMenuItemMaps.byUniversalIdentifier[SEND_EMAIL_COMMAND_ID]);
if (!parentExists) throw new Error('Parent Send Email command missing; cannot attach record-selection items');

Try / catch

try {
  await command.runOnWorkspace({ workspaceId, options });
} catch (err) {
  logger.error(`Send Email item creation failed for workspace ${workspaceId}`, err);
  failedWorkspaces.push(workspaceId);
}

Prevention

When it happens

Trigger: Running the 1.22 Send Email record-selection command-menu-item creation on a workspace where the referenced parent command or object metadata is absent, or where the new items duplicate existing universal identifiers / keys the validator forbids.

Common situations: Workspace cache lacks the Send Email command the items attach to; a previous run partially created the items leaving duplicates; standard application flat-entity maps out of sync with the workspace's stored application.

Related errors


AI-assisted analysis of twentyhq/twenty@1f5dd2bbd2 (2026-08-12). Data as JSON: /api/errors/321097cdfc763590. Report an issue: GitHub.

Appendix: source

Thrown at packages/twenty-server/src/database/commands/upgrade-version-command/1-22/1-22-workspace-command-1775500016000-add-send-email-record-selection-command-menu-items.command.ts:126

          allFlatEntityOperationByMetadataName: {
            commandMenuItem: {
              flatEntityToCreate: itemsToCreate,
              flatEntityToDelete: [],
              flatEntityToUpdate: [],
            },
          },
          workspaceId,
          applicationUniversalIdentifier:
            twentyStandardFlatApplication.universalIdentifier,
        },
      );

    if (validateAndBuildResult.status === 'fail') {
      this.logger.error(
        `Failed to add Send Email record-selection commands:\n${JSON.stringify(validateAndBuildResult, null, 2)}`,
      );

      throw new Error(
        `Failed to add Send Email record-selection commands for workspace ${workspaceId}`,
      );
    }

    this.logger.log(
      `Successfully added ${itemsToCreate.length} Send Email record-selection commands for workspace ${workspaceId}`,
    );
  }
}

View on GitHub (pinned to 1f5dd2bbd2)