Sync gateway with enable_shared_bucket_access and import_docs seems doesn't update changes feed correctly when doc channels change

Server setup (Docker on linux VM)
couchbase:community-5.1.1
couchbase/sync-gateway:2.1.2-community

Sync gateway config:

{
  "log": ["*"],
  "adminInterface": "0.0.0.0:4985",
  "interface": "0.0.0.0:4984",
  "databases": {
    "mybucket": {
      "server": "http://couchbase:8091",
      "use_views": true,
      "bucket": "XXX",
      "username": "myuser",
      "password": "mypassword",
      "enable_shared_bucket_access": true,
      "import_docs": "continuous",
      "users": {
        "GUEST": { "disabled": true  },
        "mybucketuser": { "password": "mybucketpassword" }
      },
      "import_filter": `
        function(doc) {
          if (doc.type != "CONFIG") {
            return false
          }
          return true
        }
      `,
      "sync": `
      function (doc, oldDoc) {
        channel(doc.devices);
      }
      `
    }
  }

Client (Native Android app)
com.couchbase.lite:couchbase-lite-android:2.1.0

I’ve noticed an unexpected behavior while updating documents directly in Couchbase Server (not via Sync Gateway) and the change causes doc channels modification.

Let’s say I have 2 docs, on different channels

{ "type": "CONFIG",
"devices": ["123"],
...}

channel --> 123

and

{ "type": "CONFIG",
"devices": ["abc"],
...}

channel --> abc

Every device pull syncs filtering on its channel and receives its configuration (Device “X” filters on channel “123”, device “Y” filters “abc”).
After modifying from Couchbase web interface (Buckets --> Documents --> Lookup by ID --> change content and save) the documents situation is the following:

{ "type": "CONFIG",
"devices": ["123XXX"],
...}

channel --> 123XXX

and

{ "type": "CONFIG",
"devices": ["abc","123"],
...}

channels -->  123 and abc

Browsing data form Sync Gateway _admin interface shows that the documents channels has been updated as expected, but the device that pulls data filtering on channel “123” receives 2 documents instead of receiving only the second one as expected. I’ve also tried to delete the first doc from db, but it’s still received from the device. Tried to completely remove app from device, reboot, all Android backups are disabled in device & app manifest, last device backup deleted from Google Drive.
Even after deleting the first document it wasn’t reachable any more from the sync gateway rest interface, but still synced via ws protocol.

So, I decided to reboot sync gateway, delete apps data, restart sync and the device received only the second document as expected.

Is there any knows issue while changing data in the document relying on shared bucket access when changes affects docs channels?

I understood that I was misunderstanding channels’ behavior. As per documentation, Couchbase Lite creates a special tombstone revision, adding _removed:true property to the entry when a document is removed form a channel. So

the app code should use views to filter the results rather than just assuming that all documents in its local database are relevant

Moreover, a new client will receive all channel’s history, so also the old docs no more related to a channel will be downloaded by client.

This explains why I receive a document that is no more on the channel.

Yes, a removed revision will be created and synced to clients when the document removed from a SG channel. The removed revision contains empty content with only _removed=true inside. The documents with _removed revision behaves like the documents get removed or gone from the device.

Is "_removed: true’ implemented in CBLite 2.x? I can’t get it working in the environment described above. When document is removed from channel the “_removed” property is not added and document is queriable and readable as every document.

Might the reason be that my user has the “*” channel (I always pull sync filtering on device’s id channel), so even if the document has a new o no channels at all CBL doesn’t add the property because the document is still in user scope?