CM12 Sync failed: Failed to sync some of the updates

In CM12, you may face errors like the following, in the WSYNCMGR.log:

Failed to sync update cc21164f-2c8a-493f-90f0-6783f24a90cd. Error: Failed to save update 679fddc4-b4aa-40fa-8ceb-46ace5b0deec. CCISource error: -1. Source:
Microsoft.SystemsManagementServer.SoftwareUpdatesManagement.UpdatesManager.UpdatesManagerClass.DefineUpdate SMS_WSUS_SYNC_MANAGER        

Failed to sync update cc21164f-2c8a-493f-90f0-6783f24a90cd. Error: Failed to save update 679fddc4-b4aa-40fa-8ceb-46ace5b0deec. CCISource error: -1. Source:
Microsoft.SystemsManagementServer.SoftwareUpdatesManagement.UpdatesManager.UpdatesManagerClass.DefineUpdate SMS_WSUS_SYNC_MANAGER

Sync failed: Failed to sync some of the updates. Source: Microsoft.SystemsManagementServer.SoftwareUpdatesManagement.WsusSyncAction.WSyncAction.SyncUpdates SMS_WSUS_SYNC_MANAGER

This is a known issue with Configmgr 2012 and the resolution method for this, is the following:

Normally the below query should not return any values:
Select * from CI_DocumentStore where Document_ID not in (select Document_ID from CI_CIDocuments)

In case you face this issue, this query may return some lines... Those data have been orphaned in the CI_DocumentStore table.

By running the query below, we are able to clean things up:
Select * from CI_DocumentStore where Document_ID not in (select Document_ID from CI_CIDocuments)
delete from CI_DocumentStore where Document_ID not in (select Document_ID from CI_CIDocuments)

At that point, the synchronization should finish successfully .

If that is not enough and you see that the sync errors appear again, then you should review the installation requirements [below] and especially the accounts used and their permissions
(for example, the domain user that installed the SUP is Local Admin on SQL server? etc..)
https://technet.microsoft.com/en-us/library/gg712696.aspx