Skip to content

Commit c3af443

Browse files
MadLittleModsanoadragon453AndrewFerr
authored
Fix /sync missing membership in state_after (re-introduce) (#19460)
*This PR was originally only to enable [MSC4222](matrix-org/matrix-spec-proposals#4222) Complement tests (`/sync` `state_after`) but after merging the [fix PR](#19463), we discovered that while the tests pass locally, [fail in CI](#19460 (comment)). To unblock the RC, we decided to revert the fix PR (see #19474 (comment) for more info). To better ensure tests actually pass in CI, we're re-introducing the fix here in the same PR that we enable the tests in.* --- Fix `/sync` missing membership in `state_after`. This applies to any scenario where the first membership has a different `sender` compared to the `state_key` and then the second membership has the same `sender`/`state_key`. Like someone inviting another person and then them joining. Or someone being kicked and then they leave. This bug has been present since the MSC4222 implementation was introduced into the codebase (#17888). --- Fix #19455 Fix element-hq/customer-success#656 I have a feeling, this might also fix these issues (will close and see how people report back): Fix #18182 Fix #19478 ### Testing strategy Complement tests: matrix-org/complement#842 We will need #19460 to merge in order to enable the Complement tests in Synapse but this PR should be merged first so they pass in the first place. I've tested locally that the Complement tests pass with this fix. ### Dev notes [MSC4222](matrix-org/matrix-spec-proposals#4222) has already been merged into the spec and is already part of Matrix v1.16 but we haven't [stabilized support in Synapse yet](#19414). --- In the same ballpark: - #19455 - #17050 - #17430 - #16940 - #18182 - #18793 - #19478 --- Docker builds preferring remote image over the local image we just built, #19460 (comment) `containerd` image store (storage driver, driver type) -> #19475 ### Todo - [x] Wait for #19463 to merge so the Complement tests all pass - [x] Wait for #19475 to merge ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [x] Pull request is based on the develop branch * [x] Pull request includes a [changelog file](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#changelog). The entry should: - Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from `EventStore` to `EventWorkerStore`.". - Use markdown where necessary, mostly for `code blocks`. - End with either a period (.) or an exclamation mark (!). - Start with a capital letter. - Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry. * [x] [Code style](https://element-hq.github.io/synapse/latest/code_style.html) is correct (run the [linters](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#run-the-linters)) --------- Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Co-authored-by: Andrew Ferrazzutti <andrewf@element.io>
1 parent 094a48e commit c3af443

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

changelog.d/19460.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix `/sync` missing membership event in `state_after` (experimental [MSC4222](https://github.com/matrix-org/matrix-spec-proposals/pull/4222) implementation) in some scenarios.

docker/complement/conf/workers-shared-extra.yaml.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ experimental_features:
141141
msc4306_enabled: true
142142
# Sticky Events
143143
msc4354_enabled: true
144+
# `/sync` `state_after`
145+
msc4222_enabled: true
144146

145147
server_notices:
146148
system_mxid_localpart: _server

scripts-dev/complement.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ main() {
264264
./tests/msc4140
265265
./tests/msc4155
266266
./tests/msc4306
267+
./tests/msc4222
267268
)
268269

269270
# Export the list of test packages as a space-separated environment variable, so other

synapse/handlers/sync.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,9 +1046,18 @@ async def compute_state_delta(
10461046
if event.sender not in first_event_by_sender_map:
10471047
first_event_by_sender_map[event.sender] = event
10481048

1049-
# We need the event's sender, unless their membership was in a
1050-
# previous timeline event.
1051-
if (EventTypes.Member, event.sender) not in timeline_state:
1049+
# When using `state_after`, there is no special treatment with
1050+
# regards to state also being in the `timeline`. Always fetch
1051+
# relevant membership regardless of whether the state event is in
1052+
# the `timeline`.
1053+
if sync_config.use_state_after:
1054+
members_to_fetch.add(event.sender)
1055+
# For `state`, the client is supposed to do a flawed re-construction
1056+
# of state over time by starting with the given `state` and layering
1057+
# on state from the `timeline` as you go (flawed because state
1058+
# resolution). In this case, we only need their membership in
1059+
# `state` when their membership isn't already in the `timeline`.
1060+
elif (EventTypes.Member, event.sender) not in timeline_state:
10521061
members_to_fetch.add(event.sender)
10531062
# FIXME: we also care about invite targets etc.
10541063

0 commit comments

Comments
 (0)