RitaHan almost describe all CfSetInSyncState behavior. And
I would expect that the first block (setting non sync file to sync) would not fail, since the USN did not changed before the cfSetInSyncState call. (This is what currently blocks me)
As CfSetInSyncState showed, the USN* parameter is InSync-Usn. So This parameter needs to be a NULL pointer for NOT_IN_SYNC.
We can not just call CfSetInSyncState() with USN=0, because the file content may be modified on the client, between steps 2 and 3. This may result in changes being lost.
Why does this result in changes being lost? The previous read USN is not the same as USN generated by the modified file content. Isn‘t It developer’s duty to Hydrate based on some criteria(USN)? May you need CfUpdatePlaceholder(UpdateUsn)?