CBL clients using delta sync are incorrectly not incrementing an attachment's revpos when the attachment contents change when using delta sync.
This results in the attachment not being updated when the revision is pushed to Sync Gateway - delta sync merges the incoming _attachment property with the previous one, resulting in the older revpos value. Since the revpos is old, Sync Gateway assumes it already knows about this attachment and doesn't update the _attachment metadata.
Here's an example. This is the initial payload sent by CBL for the first version of the attachment:
The attachment is updated on the client, and CBL sends this delta:
Since revpos isn't included in the delta, the _attachments content doesn't get updated on the SG side, resulting in this:
Prior to Sync Gateway 3.0 this worked. I believe this is due to revpos being computed conservatively prior to 3.0, as a side effect of shared attachment storage. That's been fixed in 3.0, but has exposed this existing CBL issue.
There will be a CBL fix to correct the revpos value, but we'd like to explore whether Sync Gateway can also be more defensive in this case, to provide backward compatibility with non-patched CBL clients. In addition to the revpos check, evaluate whether we can check for differences in attachment digest, and override the client's revpos value when that differs (to set the revpos to the current rev generation).