twentyhq/twenty · error · Error

Failed to add coreWorkflowVersionId field for workspace ${wo

Error message

Failed to add coreWorkflowVersionId field for workspace ${workspaceId}

What it means

Thrown by the 2.22 command that adds the coreWorkflowVersionId field, after the standard field was successfully resolved. The command calls validateBuildAndRunLegacyWorkspaceMigration with a fieldMetadata creation operation. If the legacy pipeline returns status 'fail', the result is logged to logger.error and the generic error is thrown. The legacy path replays a state the engine convention already defines without side-effect expansion.

Source

Thrown at packages/twenty-server/src/database/commands/upgrade-version-command/2-22/2-22-workspace-command-1784193206000-add-workflow-version-core-soft-ref-field.command.ts:134

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

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

      throw new Error(
        `Failed to add coreWorkflowVersionId field for workspace ${workspaceId}`,
      );
    }

    this.logger.log(
      `Added coreWorkflowVersionId field for workspace ${workspaceId}`,
    );
  }
}

View on GitHub (pinned to 1f5dd2bbd2)

Solutions

  1. Read the logger.error JSON output for the specific failure report
  2. Flush flatFieldMetadataMaps from workspace cache and retry — the command is idempotent (skips if the field already exists)
  3. Verify the workflowVersion object exists in flatObjectMetadataMaps before the command runs
  4. Run with --dryRun to confirm the operation shape
Defensive patterns

Strategy: retry

Validate before calling

// Before running, flush field metadata cache to ensure the builder sees fresh state
await workspaceCacheService.invalidateAndRecompute(workspaceId, [
  'flatFieldMetadataMaps',
  'flatObjectMetadataMaps',
]);

// Confirm the workflowVersion object exists
const { flatObjectMetadataMaps } = await workspaceCacheService.getOrRecompute(workspaceId, [
  'flatObjectMetadataMaps',
]);

const hasWorkflowVersion = isDefined(
  flatObjectMetadataMaps.byUniversalIdentifier[STANDARD_OBJECTS.workflowVersion.universalIdentifier]
);

if (!hasWorkflowVersion) {
  console.log('workflowVersion object does not exist — command will skip');
}

Try / catch

// Retry once after flushing cache — the command is idempotent
try {
  await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });
} catch (error) {
  if (error.message.includes('Failed to add coreWorkflowVersionId field')) {
    await workspaceCacheService.flush(workspaceId, ['flatFieldMetadataMaps']);
    await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });
  } else {
    throw error;
  }
}

Prevention

When it happens

Trigger: validateBuildAndRunLegacyWorkspaceMigration returns status 'fail' when creating the coreWorkflowVersionId FlatFieldMetadata. Caused by: the workflowVersion object not existing in workspace metadata at build time, a universal identifier collision (field already exists under a different identifier), stale flatFieldMetadataMaps cache, or a DB error during column creation.

Common situations: Workspace cache is stale and reports the field as missing when it actually exists; a prior partial run created the DB column but not the metadata row; concurrent workspace operations modified fieldMetadata during the upgrade.

Related errors


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