Skip to content

Commit 33a29b7

Browse files
committed
MSC4351: Odd Context Limits
Signed-off-by: Jason Volk <[email protected]>
1 parent 130da80 commit 33a29b7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# MSC4351: Odd Context Limits
2+
3+
Client-Server Version 1.15<sup>*</sup> § 10.23.1 [GET /_matrix/client/v3/rooms/{roomId}/context/{eventId}](https://spec.matrix.org/v1.15/client-server-api/#get_matrixclientv3roomsroomidcontexteventid) specifies query parameter `limit`:
4+
5+
> The maximum number of context events to return. The limit applies to the sum of the `events_before` and `events_after` arrays.
6+
7+
The treatment of a remainder from any odd dividend over the specified divisor of two is currently unspecified. The naïve implementation may perform two integer divisions of the `limit` which truncates the remainder to return equal counts of `events_before` and `events_after`; this does not technically violate the specification as it does not exceed the "maximum number" expressed by the `limit`.
8+
9+
Synapse instead biases the remainder to `events_after` which always returns the `limit` as requested (if sufficient events are available) rather than truncation. This is arguably more intuitive to client authors, especially after counting the "specified event" or "requested event" — `?limit=3` plus one for the requested event predictably returns four events, one before, and two after. This can be relied upon rather than ad hoc determinations to make additional requests or assumptions those requests will yield no more results.
10+
11+
We therefore codify the existing de facto behavior for odd context limits. With approximately 73.7% of deployments already running Synapse: the impact is either negligible or actually compelling, with some client and library implementations possibly already making use of this behavior<sup>†</sup>.
12+
13+
## Alternatives
14+
15+
The written specification will remain ambiguous to the de facto behavior of the principal server implementation. There are several negative implications to this alternative:
16+
- Clients may realistically mistake the de facto behavior as canonical and misbehave when used with other implementations.
17+
- The principal implementation has no obligation to maintain the behavior which may put mistaking clients at unnecessary risk.
18+
- Alternative server implementations are under no obligation to _not_ mimic the principal implementation and even have compelling reasons to do so, further diverging the written specification out of relevance.
19+
20+
---
21+
<sup>*. In addition to all earlier stable versions.</sup><br>
22+
<sup>†. Related discussion in issue [2202](https://github.com/matrix-org/matrix-spec/issues/2202).</sup><br>
23+
<sup>א. Potential Issues: None</sup><br>
24+
<sup>ב. Security Implications: None</sup><br>

0 commit comments

Comments
 (0)