twentyhq/twenty · error · Error

Failed to align the message campaign record page for workspa

Error message

Failed to align the message campaign record page for workspace ${workspaceId}: ${JSON.stringify(validateAndBuildResult, null, 2)}

What it means

Thrown by the 2.25 command that aligns the message campaign record page to a home Fields tab plus an Email composer tab. After computing all create/update/delete operations across pageLayoutTab, pageLayoutWidget, view, viewField, and viewFieldGroup, the command calls validateBuildAndRunLegacyWorkspaceMigration. If the pipeline fails, the error is thrown WITH the full validateAndBuildResult JSON inlined in the message (unlike other commands that only log it separately).

Source

Thrown at packages/twenty-server/src/database/commands/upgrade-version-command/2-25/2-25-workspace-command-1785229940000-add-message-campaign-composer-tab.command.ts:327

              flatEntityToDelete: [],
              flatEntityToUpdate: [],
            },
            viewField: {
              flatEntityToCreate: viewFieldsToCreate,
              flatEntityToDelete: [],
              flatEntityToUpdate: [],
            },
            viewFieldGroup: {
              flatEntityToCreate: viewFieldGroupsToCreate,
              flatEntityToDelete: [],
              flatEntityToUpdate: [],
            },
          },
        },
      );

    if (validateAndBuildResult.status === 'fail') {
      throw new Error(
        `Failed to align the message campaign record page for workspace ${workspaceId}: ${JSON.stringify(
          validateAndBuildResult,
          null,
          2,
        )}`,
      );
    }

    this.logger.log(
      `Aligned the message campaign record page for workspace ${workspaceId}`,
    );
  }
}

View on GitHub (pinned to 1f5dd2bbd2)

Solutions

  1. The thrown error message itself contains JSON.stringify(validateAndBuildResult, null, 2) — parse it for the exact failure report
  2. Flush flatPageLayoutMaps, flatPageLayoutTabMaps, flatPageLayoutWidgetMaps, flatViewMaps, flatViewFieldMaps, flatViewFieldGroupMaps from workspace cache and retry
  3. Verify all referenced standard universal identifiers resolve via getStandardFlatEntitiesToCreateOrThrow (which throws earlier if a standard entity is missing)
  4. Run with --dryRun to inspect the operations
Defensive patterns

Strategy: retry

Validate before calling

// Before running, flush all relevant cache keys
await workspaceCacheService.invalidateAndRecompute(workspaceId, [
  'flatPageLayoutMaps',
  'flatPageLayoutTabMaps',
  'flatPageLayoutWidgetMaps',
  'flatViewMaps',
  'flatViewFieldMaps',
  'flatViewFieldGroupMaps',
]);

// Confirm the message campaign page layout exists (the command guards on this)
const { flatPageLayoutMaps } = await workspaceCacheService.getOrRecompute(workspaceId, [
  'flatPageLayoutMaps',
]);

const hasLayout = isDefined(
  flatPageLayoutMaps.byUniversalIdentifier[MESSAGE_CAMPAIGN_PAGE_LAYOUT_UID]
);

if (!hasLayout) {
  console.log('Message campaign page layout does not exist — command will skip');
}

Try / catch

// The thrown error includes the full JSON — parse it to distinguish retryable failures
try {
  await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });
} catch (error) {
  // The error message embeds the validateAndBuildResult JSON
  const isValidationFailure = error.message.includes('"status": "fail"');
  if (isValidationFailure) {
    await workspaceCacheService.flush(workspaceId, [
      'flatPageLayoutMaps', 'flatPageLayoutTabMaps', 'flatPageLayoutWidgetMaps',
    ]);
    await command.runOnWorkspace({ workspaceId, options: { dryRun: false } });
  } else {
    throw error;
  }
}

Prevention

When it happens

Trigger: validateBuildAndBuildLegacyWorkspaceMigration returns status 'fail' when applying the multi-entity record-page alignment operations. Caused by: a referenced standard page-layout tab/widget/view/viewField/viewFieldGroup not existing in the workspace, a universal identifier collision, position/constraint validation rejection, stale cache, or a DB error.

Common situations: Workspace predates the message campaign record page entirely (page layout doesn't exist — but this is guarded by an early return); the composer tab was partially created by a prior failed run; cache doesn't reflect actual DB state.

Related errors


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