Syncgateway rejecting document with missing role

I have given permission to insert first revision of document for level-3 role user if documents having channels attribute and for update level-2 role users

i am getting sync function rejection(403 missing role) when user of level-2 who is updating a document with channels attribute.
below is sync function
if ((oldDoc == null) || ((oldDoc != null) && (oldDoc._deleted)))
{
if (doc.channels) {
requireRole(“level-3”);
}
else{
requireRole([“level-2”]);
}
}
else if ((!doc._deleted) && (oldDoc != null) && (!oldDoc._deleted)) {
if ((oldDoc.channels) && (doc.channels.toString() == oldDoc.channels.toString())) {
requireRole(“level-2”);
}
else{
requireRole(“level-3”);
}
}

log details

2017-08-28T15:24:44.769+05:30 Bucket: Update("_sync:user:917567894338", 0, …) --> CAS quit [665.995µs]
2017-08-28T15:24:44.769+05:30 HTTP: #1012: POST /ptxdata/_revs_diff?_nonce=1503914037120 (as 917567894338)
2017-08-28T15:24:44.770+05:30 Bucket: Get(“dc1503728802417_CCallLog”) [890.975µs]
2017-08-28T15:24:44.771+05:30 HTTP+: #1012: --> 200 (2.0 ms)
2017-08-28T15:24:44.780+05:30 HTTP: #1013: OPTIONS /ptxdata/_bulk_docs?_nonce=1503914037161
2017-08-28T15:24:44.780+05:30 HTTP+: #1013: --> 204 (0.1 ms)
2017-08-28T15:24:44.786+05:30 Bucket: Update("_sync:user:917567894338", 0, …) --> CAS quit [389.078µs]
2017-08-28T15:24:44.786+05:30 HTTP: #1014: POST /ptxdata/_bulk_docs?_nonce=1503914037161 (as 917567894338)
2017-08-28T15:24:44.787+05:30 CRUD+: Invoking sync on doc “dc1503728802417_CCallLog” rev 22-ebd88f43b91fdd10dbd686fb2f5b3ed5
2017-08-28T15:24:44.787+05:30 Bucket: GetRaw("_sync:rev:dc1503728802417_CCallLog:35:21-4b3dc7904e113f001841c0bc7a392c4d") [202.612µs]
2017-08-28T15:24:44.788+05:30 CRUD+: No old revision “dc1503728802417_CCallLog” / “21-4b3dc7904e113f001841c0bc7a392c4d"
2017-08-28T15:24:44.788+05:30 Sync fn rejected: new=map[_revisions:map[start:22 ids:[ebd88f43b91fdd10dbd686fb2f5b3ed5 4b3dc7904e113f001841c0bc7a392c4d 09745a20cad52306bbc5ca68cdf103c0 aea0c23a4e013ca98226771cd8f45b80 92a8263bf9a18537d161ba3dd1cf68d5 0df00a1ce6f970d162794250a5084d67 b3aefc8eed52c3a35f6b60df112b13bd 281413a74e289308397c5a9be56640c6 6f01a2da957d8069c2420b724116887c 418b321d5eb98d5ec49634c78cba845e 55b12b8c37e0d961bdce82257737656b 3662b44179dc4dc3571502ee6fa910f4 d4d797d2faca55df9c1927b6edba7b9d e64ecc75c7cd9a74726db059b1a0df53 f31d9504754b2bf8162de25ec88b5455 aa5cd2d8c29aede526fa4c315c3941bb 9dee724317b27e45f9edc1460bc0f384 42aab19460c2666510cfac277361ed3e df13250f8e6410e456dc9a63ea8e81a9 9887d12ee5976be28959c5dcfc3718ac 84ff5adc3ae06b30924b57813b8ad4b6 c577b0ea8bdde099b90a7d5146b3c5f0]] status:0 type:currentcalllog channels:[dc1503728802417-calllog-private-CH ccalllog-public-CH dc1503728802417-CH] callLog:[map[duration:00:00:18 direction:0 groupName: deliveryReport: callType:1 peerName:!Yod groupId: sessionId:762031_0_10_1503914435@s3poc1.kodiakstgpoc.com timeStamp:1.503914018531e+12 recordingFiles:[map[fileName:917567894338_28_8_2017__15_23_38_0.mp3 fileIndex:0 startTimeStamp:1.503914018531e+12 duration:00:18]] callID:FAD811CA-3C14-DC63-A301-3C06CC0F6633 mdn:919586923545]] state:processed ver:1.0 _id:dc1503728802417_CCallLog _rev:22-ebd88f43b91fdd10dbd686fb2f5b3ed5] old={“callLog”:[],“channels”:[“dc1503728802417-calllog-private-CH”,“ccalllog-public-CH”,“dc1503728802417-CH”],“state”:“processed”,“status”:0,“type”:“currentcalllog”,“ver”:“1.0”} --> 403 missing role
2017-08-28T15:24:44.788+05:30 Bucket: WriteUpdate(“dc1503728802417_CCallLog”, 0, …) --> 403 missing role [1.687667ms]
2017-08-28T15:24:44.788+05:30 BulkDocs: Doc “dc1503728802417_CCallLog” --> 403 missing role (403 missing role)
2017-08-28T15:24:44.788+05:30 HTTP+: #1014: --> 201 (2.4 ms)
2017-08-28T15:24:44.795+05:30 HTTP: #1015: OPTIONS /ptxdata/_local/jzdAcBfhqtgWRjVNc4CP8w%3D%3D?_nonce=1503914037176
2017-08-28T15:24:44.795+05:30 HTTP+: #1015: --> 204 (0.2 ms)
2017-08-28T15:24:44.803+05:30 Bucket: Update(”_sync:user:917567894338", 0, …) --> CAS quit [391.684µs]
2017-08-28T15:24:44.803+05:30 HTTP: #1016: GET /ptxdata/_local/jzdAcBfhqtgWRjVNc4CP8w%3D%3D?_nonce=1503914037176 (as 917567894338)
2017-08-28T15:24:44.803+05:30 Bucket: Get("_sync:local:jzdAcBfhqtgWRjVNc4CP8w==") [239.315µs]
2017-08-28T15:24:44.803+05:30 HTTP+: #1016: --> 200 (0.8 ms)
2017-08-28T15:24:44.810+05:30 Bucket: Update("_sync:user:917567894338", 0, …) --> CAS quit [286.927µs]
2017-08-28T15:24:44.810+05:30 HTTP: #1017: PUT /ptxdata/_local/jzdAcBfhqtgWRjVNc4CP8w%3D%3D (as 917567894338)
2017-08-28T15:24:44.810+05:30 Bucket: Update("_sync:local:jzdAcBfhqtgWRjVNc4CP8w==", 0, …) --> [743.319µs]
2017-08-28T15:24:44.810+05:30 HTTP+: #1017: --> 201 (1.2 ms)

We have set revs_limit=60. how many old revision will be stored in couchbase or syncgateway.
Ans also when documents are in conflct state.

From the logs we are observing revision “21-4b3dc7904e113f001841c0bc7a392c4d" which is not exists.

The revs_limit determines the max depth of the tree before revisions are removed.So in your case 60 is the max limit before revisions get pruned out. You can read about revs_limit here and this [blog] (Managing Database Sizes in Couchbase Mobile and Conflict Resolution) will give you more details on affects of conflict resolution.

Thanks @priya.rajagopal… just missed doc is updated.
can you clarify the below

From log below, CRUD+: No old revision “dc1503728802417_CAuditLog” / “17-0f1332cdac8fad329eca5eb945e0964a” i could see old revision 17 is not present.
but while comparing with old documents in sync function , old document is below
old={“auditLog”:[{“auditID”:“CCE7B6BF-FA62-D36E-AF67-542B8D6BF413”,“auditType”:“Operations”,“message”:“Added to favorite list: Assigned”,“status”:“Success”,“timestamp”:1.503898607486e+12},{“auditID”:“0B3CA4DC-C059-1E71-8410-07C34F70F2A7”,“auditType”:“Operations”,“message”:“Removed from favorite list: @Qw412563987+++))?”}\u003e\u003c,./|}{",“status”:“Success”,“timestamp”:1.503898630321e+12}],“channels”:[“dc1503728802417-auditlog-private-CH”,“cauditlog-public-CH”,“dc1503728802417-CH”],“state”:“processed”,“status”:0,“type”:“currentauditlog”,“ver”:“1.0”}

Syncgateway logs
2017-08-28T11:22:05.431+05:30 HTTP: #348: POST /ptxdata/_bulk_docs?_nonce=1503899478103 (as 917567894338)
2017-08-28T11:22:05.433+05:30 CRUD+: Invoking sync on doc “dc1503728802417_CAuditLog” rev 18-f49f4b0d8657dcc1400d1623579d7dbf
2017-08-28T11:22:05.435+05:30 Bucket: GetRaw(“sync:rev:dc1503728802417_CAuditLog:35:17-0f1332cdac8fad329eca5eb945e0964a") [1.245493ms]
2017-08-28T11:22:05.435+05:30 CRUD+: No old revision “dc1503728802417_CAuditLog” / "17-0f1332cdac8fad329eca5eb945e0964a"
2017-08-28T11:22:05.435+05:30 Sync fn rejected: new=map[state:processed type:currentauditlog id:dc1503728802417_CAuditLog channels:[dc1503728802417-auditlog-private-CH cauditlog-public-CH dc1503728802417-CH] auditLog:[map[auditID:CCE7B6BF-FA62-D36E-AF67-542B8D6BF413 auditType:Operations message:Added to favorite list: Assigned status:Success timestamp:1.503898607486e+12] map[auditID:0B3CA4DC-C059-1E71-8410-07C34F70F2A7 auditType:Operations message:Removed from favorite list: @Qw412563987++
+))?”}><,./|}{ status:Success timestamp:1.503898630321e+12] map[auditID:7D7430FA-366D-B4C2-ABF7-4D7A8D117ADF status:Success timestamp:1.503899462521e+12 message:Sign in Success auditType:Operations] map[status:Success timestamp:1.503899477349e+12 message:Signed out auditType:Operations auditID:0132458B-C902-49DB-A223-AEDA0B258C88]] revisions:map[start:18 ids:[f49f4b0d8657dcc1400d1623579d7dbf 0f1332cdac8fad329eca5eb945e0964a ce92af9ab2ad9273ab787e22943a2819 81367782b5b9119d0f602eed7de4c605 b795f852618521cf07b84f65fa2214be 7071423d0c82e2bb309fc259732d47f1 67a012cbedb29b6ff701bc8027cb672f ad95673e923181bc4e25597f67a50f0c 9193a1aa13bbb49032e95b64c300cc6d 4b7a6e9da08b7820c3e9e4e53811f383 8f1bcc16ab8016eb5664e728f43e9e95 23384fe4825a914e078b772d575fb03b f502a2a099c10f880df34dc44f89b4f1 83bd877bca7d3a99a5d3f4eec070dd0d 55565dad438d5520caa9b7e9db23892f fd6b928a81a51c3c002b63693b05d9d8 b5aa0433486b5cc81768fd958df4bb9d 188fd45f700e220954dae29ca12b8768]] status:0 ver:1.0 rev:18-f49f4b0d8657dcc1400d1623579d7dbf] old={“auditLog”:[{“auditID”:“CCE7B6BF-FA62-D36E-AF67-542B8D6BF413”,“auditType”:“Operations”,“message”:“Added to favorite list: Assigned”,“status”:“Success”,“timestamp”:1.503898607486e+12},{“auditID”:“0B3CA4DC-C059-1E71-8410-07C34F70F2A7”,“auditType”:“Operations”,“message”:"Removed from favorite list: @Qw412563987+++))?"}\u003e\u003c,./|}{",“status”:“Success”,“timestamp”:1.503898630321e+12}],“channels”:[“dc1503728802417-auditlog-private-CH”,“cauditlog-public-CH”,“dc1503728802417-CH”],“state”:“processed”,“status”:0,“type”:“currentauditlog”,“ver”:“1.0”} --> 403 missing role