Skip to content

MSC3871: Gappy timelines - #3871

Open
MadLittleMods wants to merge 19 commits into
mainfrom
madlittlemods/gappy-timelines
Open

MSC3871: Gappy timelines#3871
MadLittleMods wants to merge 19 commits into
mainfrom
madlittlemods/gappy-timelines

Conversation

@MadLittleMods

@MadLittleMods MadLittleMods commented Aug 18, 2022

Copy link
Copy Markdown
Contributor

A proposal for letting homeservers give feedback to clients where there is a gap in the timeline from a /messages response.

Spawned from a discussion with @erikjohnston about making /messages faster

Rendered

Matrix Live demo: https://www.youtube.com/watch?v=Bo7GaLRhtc0&t=409s

Implementations:

@MadLittleMods MadLittleMods changed the title MSCXXX: Gappy timelines MSC3871: Gappy timelines Aug 18, 2022
Comment thread proposals/3871-gappy-timelines.md Outdated
@MadLittleMods
MadLittleMods marked this pull request as ready for review August 18, 2022 02:39
@turt2live turt2live added proposal A matrix spec change proposal. Process state. A-Client Server Client-Server API kind:feature MSC for not-core and not-maintenance stuff needs-implementation This MSC does not have a qualifying implementation for the SCT to review. The MSC cannot enter FCP. labels Aug 18, 2022
Comment thread proposals/3871-gappy-timelines.md Outdated
Comment thread proposals/3871-gappy-timelines.md Outdated
Comment thread proposals/3871-gappy-timelines.md
Comment thread proposals/3871-gappy-timelines.md Outdated
Comment thread proposals/3871-gappy-timelines.md Outdated
Comment thread proposals/3871-gappy-timelines.md
As suggested by @benkuly,
#3871 (comment)

The synthetic event approach is still listed as an alternative
@MadLittleMods
MadLittleMods force-pushed the madlittlemods/gappy-timelines branch from d90bb0b to 5f7bb0e Compare October 7, 2022 21:46
messages anyway but they do probably see our slow `/messages` pagination.


### Expose `prev_events` to the client

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would simplify things dramatically, seems.
Same approach of gap-filling that is used for server-server could be employed for client-server.

Additionally, would make it possible for clients to issue full events, as wondered in MSC4080, since it becomes possible for clients to detect forward extremeties.

Comment on lines +41 to +42
This describes the new `gaps` response field being added to the `200 response`
of `/messages`:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably also add a gaps field to the timeline in /sync. It's important for clients to know wherever they might be missing a message.

Comment on lines +162 to +166
{
"prev_pagination_token": "t9",
"event_id": "$fred",
"next_pagination_token": "t10",
}

@MadLittleMods MadLittleMods Aug 28, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this is in the context of paginating forwards)

I'm not sure whether we should consider the gap in front of the latest events to actually be a gap in the gaps list.

The problem is that the client has no way to know whether it's just a forward extremity (one of the latest events in the room) to know whether it should display the gap in the timeline. I.e. we probably don't want to display a "gap" after the latest events in the room.

We should either omit the gap for forward extremities in the room or add a field to indicate it's a forward extremity.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently thinking that we should just omit the gap after the latest messages in the room. The /messages endpoint already returns start/end pagination tokens for people wanting to continue off either side. And this way clients can simply just display a gap wherever we say there is one without needing complex logic.

MadLittleMods added a commit to element-hq/synapse that referenced this pull request Aug 29, 2025
MadLittleMods added a commit to element-hq/synapse that referenced this pull request Aug 29, 2025
To try out the flow:

 - **Default to fast responses with gaps**: As a default, we can always
     respond quickly and indicate gaps ([MSC3871]
     (matrix-org/matrix-spec-proposals#3871)) for
     clients to paginate at their leisure.
 - **Fast back-pagination**: Clients back-paginate with
     `/messages?dir=b&backfill=false`, and Synapse skips backfilling
     entirely, returning only local history with gaps as necessary.
 - **Explicit gap filling**: To fill in gaps, clients use
     `/messages?dir=b&backfill=true` which works just like today to do a best
     effort backfill.

This allows the client to back-paginate the history we already have without
delay. And can fill in the gaps as they see fit.

This is basically a simplified version of [MSC4282]
(matrix-org/matrix-spec-proposals#4282).

Name | Type | Description | required
--- | --- | --- | ---
`gaps` | `[GapEntry]` | A list of gaps indicating where events are missing in the `chunk` | no

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For ease of processing, we should declare that the order of the gaps is the in the same direction as the chunk of messages.

Comment on lines +113 to +115
"prev_pagination_token": "t6",
"event_id": "$corge",
"next_pagination_token": "t5",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per https://spec.matrix.org/v1.18/appendices/#pagination, we should probably align these fields to be prev_batch and next_batch

MadLittleMods added a commit to element-hq/synapse that referenced this pull request May 1, 2026
The juicy details and explanation are in the diff itself.

Split out from #18873 in order
to fix paginating from
[MSC3871](matrix-org/matrix-spec-proposals#3871)
gap tokens actually backfilling history. To be clear, this is a good
change to make outside of the
[MSC3871](matrix-org/matrix-spec-proposals#3871)
use case. For example (as the new Complement test shows), fixes a
problem where if you try to paginate `/messages` from tokens returned by
`/context`, we could fail to backfill anything new and hide away
history.

Also fixes matrix-org/complement#853
FrenchGithubUser pushed a commit to famedly/synapse-upstreaming that referenced this pull request Jun 12, 2026
The juicy details and explanation are in the diff itself.

Split out from element-hq#18873 in order
to fix paginating from
[MSC3871](matrix-org/matrix-spec-proposals#3871)
gap tokens actually backfilling history. To be clear, this is a good
change to make outside of the
[MSC3871](matrix-org/matrix-spec-proposals#3871)
use case. For example (as the new Complement test shows), fixes a
problem where if you try to paginate `/messages` from tokens returned by
`/context`, we could fail to backfill anything new and hide away
history.

Also fixes matrix-org/complement#853
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Client Server Client-Server API kind:feature MSC for not-core and not-maintenance stuff needs-implementation This MSC does not have a qualifying implementation for the SCT to review. The MSC cannot enter FCP. proposal A matrix spec change proposal. Process state.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants