twentyhq/twenty · error · Error

Failed to add REPLY_TO option to messageParticipant role fie

Error message

Failed to add REPLY_TO option to messageParticipant role field for workspace ${workspaceId}

What it means

Thrown by the 2.17 command that adds the REPLY_TO option to the messageParticipant.role SELECT field when validateBuildAndRunLegacyWorkspaceMigration returns status 'fail'. The logger.error above prints the full result; the thrown error is workspace-scoped. The payload updates the role field's options array to include REPLY_TO.

Source

Thrown at packages/twenty-server/src/database/commands/upgrade-version-command/2-17/2-17-workspace-command-1801000001000-add-reply-to-message-participant-role-option.command.ts:84

    const validateAndBuildResult =
      await this.workspaceMigrationValidateBuildAndRunService.validateBuildAndRunLegacyWorkspaceMigration(
        {
          isSystemBuild: true,
          workspaceId,
          applicationUniversalIdentifier:
            twentyStandardFlatApplication.universalIdentifier,
          allFlatEntityOperationByMetadataName: {
            fieldMetadata: fieldMetadataOperations,
          },
        },
      );

    if (validateAndBuildResult.status === 'fail') {
      this.logger.error(
        `Failed to add REPLY_TO option to messageParticipant role field:\n${JSON.stringify(validateAndBuildResult, null, 2)}`,
      );

      throw new Error(
        `Failed to add REPLY_TO option to messageParticipant role field for workspace ${workspaceId}`,
      );
    }

    this.logger.log(
      `Successfully added REPLY_TO option to messageParticipant role field for workspace ${workspaceId}`,
    );
  }
}

View on GitHub (pinned to 1f5dd2bbd2)

Solutions

  1. Read the logger.error JSON to find the failing option and error code.
  2. Inspect core.fieldMetadata for the messageParticipant role field; dedupe or repair its options array.
  3. Ensure the role field type is SELECT and that no other migration is editing it concurrently.
  4. Re-run the workspace upgrade.
Defensive patterns

Strategy: validation

Validate before calling

// Confirm the messageParticipant role field is SELECT and does not already
// contain a conflicting REPLY_TO option.
const role = await dataSource.query(`
  SELECT "type", "options" FROM core."fieldMetadata"
  WHERE "nameSingular" = 'role'
    AND "objectMetadataId" = (SELECT id FROM core."objectMetadata" WHERE "nameSingular" = 'messageParticipant')
`);
if (role[0]?.type !== 'SELECT') throw new Error('role field is not SELECT');
const hasReplyTo = role[0]?.options?.some((o: any) => o.value === 'REPLY_TO');
if (hasReplyTo) throw new Error('REPLY_TO already present; reconcile before upgrade');

Type guard

function isFailResult(r: unknown): r is { status: 'fail' } {
  return typeof r === 'object' && r !== null && (r as any).status === 'fail';
}

Try / catch

try {
  const res = await service.validateBuildAndRunLegacyWorkspaceMigration(payload);
  if (res.status === 'fail') throw new Error(`... for workspace ${workspaceId}`);
} catch (err) { upgradeAudit.record(workspaceId, command.id, err); throw err; }

Prevention

When it happens

Trigger: Running the 2.17 upgrade where the messageParticipant role field is not a SELECT, already contains REPLY_TO in a form that conflicts with the new option (duplicate value/color/label), or has options missing required keys the validator expects.

Common situations: Custom edit of the role field options; prior partial run that added REPLY_TO without required keys; standard seed drift; concurrent migration runs.

Related errors


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