element-hq / dendrite

Dendrite is a second-generation Matrix homeserver written in Go!
https://element-hq.github.io/dendrite/
GNU Affero General Public License v3.0
6 stars 2 forks source link

Timeline filter impacts `state` in `/sync` response #1886

Open matrixbot opened 2 weeks ago

matrixbot commented 2 weeks ago

This issue was originally created by @PiotrKozimor at https://github.com/matrix-org/dendrite/issues/1886.

Background information

Description

When state events are filtered out from timeline, they are transferred to state object. However, in https://github.com/matrix-org/matrix-doc/issues/627 it is suggested that this behaviour is incorrect.

The incorrect behaviour popped out in https://github.com/matrix-org/synapse/issues/10081.

Please also see https://github.com/matrix-org/synapse/issues/10081#issuecomment-866331619 for link to documentation.

Steps to reproduce

Follow the instructions in https://github.com/matrix-org/synapse/issues/10081#issue-903848773. Please note that test case passes for dendrite and fails for synapse.

Please look below for expected (synapse) and actual (dendrite) /sync response.

Actual

``` { "rooms": { "invite": {}, "join": { "!aZTcnTfR6Alyeps1:dendrite": { "account_data": { "events": [] }, "ephemeral": { "events": [] }, "state": { "events": [ { "content": { "foo": "grfuouzgqzviuj" }, "event_id": "$nnO6JoCEM9e236giMMVqcjG4JTF1xNhotOeOFWLIJfw", "origin_server_ts": 1624387876862, "sender": "@zcncsunwogrlyv:dendrite", "state_key": "one", "type": "my.custom.event", "unsigned": { "prev_content": { "foo": "ckqnycychntthy" }, "prev_sender": "@zcncsunwogrlyv:dendrite", "replaces_state": "$Snb87KMkje-LSv2u1gyn0d-ZuKXZonFn8Wm3NxLGjJE" } }, { "content": { "foo": "mnbhhzjpxkecqh" }, "event_id": "$Y1nfLP7g9QuNsbW6EdF6l7ilrsZMrw6o-9QmcBwyMvw", "origin_server_ts": 1624387876943, "sender": "@zcncsunwogrlyv:dendrite", "state_key": "two", "type": "my.custom.event", "unsigned": { "prev_content": { "foo": "zdcmzyrkpdsqaa" }, "prev_sender": "@zcncsunwogrlyv:dendrite", "replaces_state": "$vAcFSEx0o1I1VdJ007xlL2NtVS4rY6zi0CrIxO6y8jI" } }, { "content": { "foo": "gclqecjbstavcz" }, "event_id": "$BNyGed2A5GUwuWX5rdyRPrdHn732hTa1-Z6oJfsnts0", "origin_server_ts": 1624387877024, "sender": "@zcncsunwogrlyv:dendrite", "state_key": "three", "type": "my.custom.event", "unsigned": { "prev_content": { "foo": "iedxpoqshjioxu" }, "prev_sender": "@zcncsunwogrlyv:dendrite", "replaces_state": "$Lx8pLmR_3NGORxWfXDVkeSLknplDwMR-BpCGrHv4T-s" } } ] }, "timeline": { "events": [ { "content": { "creator": "@zcncsunwogrlyv:dendrite", "room_version": "6" }, "event_id": "$0uatKQUYDRAIxBqBNt8BXS1EDqJtygy-_Vba0Vr9-Z8", "origin_server_ts": 1624387874692, "sender": "@zcncsunwogrlyv:dendrite", "state_key": "", "type": "m.room.create" }, { "content": { "displayname": "zcncsunwogrlyv", "membership": "join" }, "event_id": "$e9m9qUPAs6HBY1viZr2tO0nW00HSC7zlsqpzHfGqAwE", "origin_server_ts": 1624387874692, "sender": "@zcncsunwogrlyv:dendrite", "state_key": "@zcncsunwogrlyv:dendrite", "type": "m.room.member" }, { "content": { "ban": 50, "events": { "m.room.aliases": 0, "m.room.avatar": 50, "m.room.canonical_alias": 50, "m.room.history_visibility": 100, "m.room.name": 50, "m.room.power_levels": 100 }, "events_default": 0, "invite": 0, "kick": 50, "notifications": { "room": 50 }, "redact": 50, "state_default": 50, "users": { "@zcncsunwogrlyv:dendrite": 100 }, "users_default": 0 }, "event_id": "$at7envb_kxr6dlX5jJUCFQQ9t7D6z2XTDMoUQEgT-6c", "origin_server_ts": 1624387874692, "sender": "@zcncsunwogrlyv:dendrite", "state_key": "", "type": "m.room.power_levels" }, { "content": { "join_rule": "invite" }, "event_id": "$DWq6ZgD7DSWsLt7XBiQYvzNSKtQ6jz7RZQizVXTnWyQ", "origin_server_ts": 1624387874692, "sender": "@zcncsunwogrlyv:dendrite", "state_key": "", "type": "m.room.join_rules" }, { "content": { "history_visibility": "shared" }, "event_id": "$R-5vjra24dMUfOfG0SEEbic6MKimoivFENqNBQjJDSc", "origin_server_ts": 1624387874692, "sender": "@zcncsunwogrlyv:dendrite", "state_key": "", "type": "m.room.history_visibility" } ], "limited": false, "prev_batch": "t1_1" } } }, "leave": {}, "peek": {} } } ```

Expected

```json { "rooms": { "invite": {}, "join": { "!syZVgKbGjBXuhlAzmb:dendrite": { "account_data": { "events": [] }, "ephemeral": { "events": [] }, "org.matrix.msc2654.unread_count": 0, "state": { "events": [] }, "summary": {}, "timeline": { "events": [ { "content": { "creator": "@zjangdesopjibi:dendrite", "room_version": "6" }, "event_id": "$fSssSjeYPxOHk27MNBtje8LxeNfoE5jtlg__bb6_3kU", "origin_server_ts": 1624387692833, "sender": "@zjangdesopjibi:dendrite", "state_key": "", "type": "m.room.create", "unsigned": { "age": 1921 } }, { "content": { "displayname": "zjangdesopjibi", "membership": "join" }, "event_id": "$L-KYnoDt4d4mToBZK4rO2zLDNkie-Ktgh_4uM6MrCkY", "origin_server_ts": 1624387692899, "sender": "@zjangdesopjibi:dendrite", "state_key": "@zjangdesopjibi:dendrite", "type": "m.room.member", "unsigned": { "age": 1855 } }, { "content": { "ban": 50, "events": { "m.room.avatar": 50, "m.room.canonical_alias": 50, "m.room.encryption": 100, "m.room.history_visibility": 100, "m.room.name": 50, "m.room.power_levels": 100, "m.room.server_acl": 100, "m.room.tombstone": 100 }, "events_default": 0, "invite": 50, "kick": 50, "redact": 50, "state_default": 50, "users": { "@zjangdesopjibi:dendrite": 100 }, "users_default": 0 }, "event_id": "$WQjk12jM5ElmniWNvkp3MbQiHomrNyl9EsCs565HgZc", "origin_server_ts": 1624387692943, "sender": "@zjangdesopjibi:dendrite", "state_key": "", "type": "m.room.power_levels", "unsigned": { "age": 1811 } }, { "content": { "join_rule": "public" }, "event_id": "$dC0CofzAFpH0KIXoquI_c3FASTVIZnqAN99sppD96us", "origin_server_ts": 1624387692978, "sender": "@zjangdesopjibi:dendrite", "state_key": "", "type": "m.room.join_rules", "unsigned": { "age": 1776 } }, { "content": { "history_visibility": "shared" }, "event_id": "$F9vwOBKEqglsLwCijxk1rCa1ge7tqGMN05n9P79UQNg", "origin_server_ts": 1624387693024, "sender": "@zjangdesopjibi:dendrite", "state_key": "", "type": "m.room.history_visibility", "unsigned": { "age": 1730 } } ], "limited": false, "prev_batch": "s36_2_0_1_1_1_1_2_1" }, "unread_notifications": { "highlight_count": 0, "notification_count": 0 } } }, "leave": {} } } ```

matrixbot commented 2 weeks ago

This comment was originally posted by @kegsay at https://github.com/matrix-org/dendrite/issues/1886#issuecomment-877133458.

Hmm, what is your use case for filtering out my.custom.event in the timeline but then actually caring about it in state?

The overarching issue here is that if you apply a filter for an event type X, it will generally apply to both the timeline and state. I am interested to know why you want to know the state (at the beginning of a chunk) but not the subsequent timeline entries, which are vital to know what the current state for that event is.

matrixbot commented 2 weeks ago

This comment was originally posted by @PiotrKozimor at https://github.com/matrix-org/dendrite/issues/1886#issuecomment-895207395.

The particular use case would be location sharing - some users could sent event with location more frequently than others and we are interested in most recent location only. Filtering out timeline could help save bandwidth for initial sync. However, I would be interested in most recent state, not at the beggining of chunk. That's why I thought initially that the bug is in synapse (https://github.com/matrix-org/synapse/issues/10081). But it was suggested that dendrite behaviuor is incorrect - https://github.com/matrix-org/synapse/issues/10081#issuecomment-866331619. That's why I opened this issue - to be aware of divergence from specification - but it's not serious one.