Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

m.room.create events are not sent in response timelines to clients in an initial sliding sync #343

Open
DMRobertson opened this issue Oct 18, 2023 · 0 comments

Comments

@DMRobertson
Copy link
Contributor

I was surprised by this, but it may not be a bug given that clients can explicitly request the m.room.create state.

Integration test to reproduce:
func TestRoomCreationTimelineSeenInSync(t *testing.T) {
	pqString := testutils.PrepareDBConnectionString()
	v2 := runTestV2Server(t)
	defer v2.close()
	v3 := runTestServer(t, v2, pqString)
	defer v3.close()

	v2.addAccount(t, alice, aliceToken)
	timeline := createRoomState(t, alice, time.Now())
	v2.queueResponse(aliceToken, sync2.SyncResponse{
		NextBatch: "dummy",
		Rooms: sync2.SyncRoomsResponse{
			Join: map[string]sync2.SyncV2JoinResponse{
				"!unimportant": {
					Timeline: sync2.TimelineResponse{
						Events:    timeline,
						PrevBatch: "prevBatch",
					},
				},
			}},
	})

	res := v3.mustDoV3Request(t, aliceToken, sync3.Request{
		RoomSubscriptions: map[string]sync3.RoomSubscription{
			"!unimportant": {
				TimelineLimit: 20,
			},
		},
	})
	m.MatchResponse(t, res, m.MatchRoomSubscription("!unimportant", m.MatchRoomTimeline(timeline)))
}

which fails with

  poller_test.go:1014: MatchResponse: MatchRoomSubscription[!unimportant]: timeline length mismatch: got 3 want 4
        {
            "lists": {},
            "rooms": {
                "!unimportant": {
                    "name": "Empty Room",
                    "avatar": null,
                    "timeline": [
                        {
                            "type": "m.room.member",
                            "state_key": "@alice:localhost",
                            "sender": "@alice:localhost",
                            "content": {
                                "membership": "join"
                            },
                            "event_id": "$event_2_TestRoomCreationTimelineSeenInSync",
                            "origin_server_ts": 1697631424107
                        },
                        {
                            "type": "m.room.power_levels",
                            "state_key": "",
                            "sender": "@alice:localhost",
                            "content": {
                                "ban": 50,
                                "invite": 50,
                                "kick": 50,
                                "redact": 50,
                                "users": {
                                    "@alice:localhost": 100
                                },
                                "users_default": 0,
                                "events": null,
                                "events_default": 0,
                                "state_default": 50,
                                "notifications": {
                                    "room": 50
                                }
                            },
                            "event_id": "$event_3_TestRoomCreationTimelineSeenInSync",
                            "origin_server_ts": 1697631424107
                        },
                        {
                            "type": "m.room.join_rules",
                            "state_key": "",
                            "sender": "@alice:localhost",
                            "content": {
                                "join_rule": "public"
                            },
                            "event_id": "$event_4_TestRoomCreationTimelineSeenInSync",
                            "origin_server_ts": 1697631424107
                        }
                    ],
                    "notification_count": 0,
                    "highlight_count": 0,
                    "initial": true,
                    "joined_count": 1,
                    "invited_count": 0,
                    "timestamp": 1697631424107
                }
            },
            "extensions": {},
            "pos": "1"
        }

I think this is because we load timelines here

timelines := s.userCache.LazyLoadTimelines(ctx, s.anchorLoadPosition, roomIDs, int(roomSub.TimelineLimit))

where anchorloadPos is 0. That calls

roomIDToLatestEvents, err := c.store.LatestEventsInRooms(c.UserID, roomIDs, loadPos, maxTimelineEvents)

with loadPos 0, maxTimelineEvents 10. Next we call

roomIDToRanges, err := s.visibleEventNIDsBetweenForRooms(userID, roomIDs, 0, to)

with to = 10. The next level is

return s.visibleEventNIDsWithData(joinTimingsAtFromByRoomID, membershipEvents, userID, from, to)

with from = 0, to=10. This ultimately returns a range of (2, 10), because our join event has NID 2. But the create event has NID 1, and so is not loaded from the database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant