Skip to content

Mark the /context response fields as required - #2473

Open
sandhose wants to merge 1 commit into
matrix-org:mainfrom
sandhose:quenting/context-required-fields
Open

sandhose wants to merge 1 commit into
matrix-org:mainfrom
sandhose:quenting/context-required-fields

Conversation

@sandhose

@sandhose sandhose commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

This clarifies which fields are required on GET /_matrix/client/v3/rooms/{roomId}/context/{eventId}. There's a sibling PR to document the "404" response: #2474

Currently, none of them are required: the response has had no required list since the original definition (matrix-org/matrix-spec-proposals#139).
I made them all required here. This is the reasoning for each field, and I'm open to relaxing some of them:

  • event: sure, else it definitely should be 404
  • events_before/events_after: if there are no events before or after, an empty array feels more appropriate. Problem is that Ruma-based homeservers and Dendrite omit the field if it's empty, so they would need fixing
  • state: this can legitimately be empty, for example when the filter excludes everything, so an empty array feels more appropriate here too. Same problem: Ruma-based HSes omit the field if it's empty, and Dendrite omits it when limit is 0. (If the server cannot know the state around the event at all, it should return a 404 as per Document the 404 response of /context #2474.)
  • start/end: arguably, we could omit them if it's the start or end of the timeline, but this is a cursor position, not a guarantee that there is something before or after. Clients should IMO instead try those cursors in /messages if they really want to check and get more events around.
    • This differs from /messages, which omits end when there are no more events (Clarifications to pagination parameters for various APIs matrix-spec-proposals#3353). There, the server has just paginated and knows it reached the end; here, the tokens are only positions around the event.
    • On the create event, Synapse returns a real start token, and /messages?dir=b from it returns an empty chunk with no end.
    • Dendrite doesn't omit them, but sends an empty string at the edges of the room, which isn't a usable token, so it would need fixing as well.

On why to make them all required: Synapse always sent all 6 for 200 responses, and omitting broke clients in the past element-hq/element-web#31349 because they make assumptions about those fields being there.

There's a Complement test for this in matrix-org/complement#964. It passes on Synapse; the cases where Dendrite omits state or sends empty start/end tokens are skipped there.

Signed-off-by: Quentin Gliech quenting@element.io

Pull Request Checklist

Preview: https://pr2473--matrix-spec-previews.netlify.app

@sandhose
sandhose force-pushed the quenting/context-required-fields branch from b200738 to eed9f7e Compare November 13, 2026 10:03
@sandhose
sandhose marked this pull request as ready for review November 13, 2026 13:59
@sandhose
sandhose requested review from a team and zecakeh as code owners November 13, 2026 13:59
@sandhose sandhose mentioned this pull request Nov 13, 2026
3 tasks done

@richvdh richvdh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For me, the fact that Dendrite, Conduit and Synapse do different things is enough to say there should be an MSC before we change this. event would be fine; the rest not so much.

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

Successfully merging this pull request may close these issues.

2 participants