Skip to content

Evict oldest OTKs if clients upload more than 500 keys - #20159

Closed
kaylendog wants to merge 4 commits into
element-hq:developfrom
kaylendog:kaylendog/feat/limit-otks
Closed

Evict oldest OTKs if clients upload more than 500 keys#20159
kaylendog wants to merge 4 commits into
element-hq:developfrom
kaylendog:kaylendog/feat/limit-otks

Conversation

@kaylendog

@kaylendog kaylendog commented Aug 27, 2026

Copy link
Copy Markdown

Motivation

In matrix-org/matrix-js-sdk#5501, clients can upload arbitrary numbers of one-time keys (up to several thousand) while forgetting about their private halves (Vodozemac keeps 100 locally), leading peers to claim OTKs and use them to send pre-key sessions the client cannot decrypt, preventing new Olm sessions from being established.

No server-side limit exists in Synapse, and the specification does not prevent us from forgetting about older keys as long as we guarantee only one peer can ever claim a particular key. This limit would mitigate some of the effects of OTK starvation, although it is best paired with the relevant JS SDK fix, matrix-org/matrix-js-sdk#5503.

Notes

Two important things worth considering before merging:

  • This PR makes changes to the database schema;
  • The OTK eviction task could start performing a lot of work when deployed to old/large homeservers, e.g. matrix.org - worth checking how many devices already exceed the 500 limit.

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. 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.
  • Code style is correct (run the linters)

Signed-off-by: Skye Elliot <actuallyori@gmail.com>
Signed-off-by: Skye Elliot <actuallyori@gmail.com>
Signed-off-by: Skye Elliot <actuallyori@gmail.com>
Signed-off-by: Skye Elliot <actuallyori@gmail.com>
@kaylendog
kaylendog force-pushed the kaylendog/feat/limit-otks branch from 79dff2c to 448b1bf Compare August 27, 2026 16:51
@kaylendog

Copy link
Copy Markdown
Author

Closed in favour of #20162 which is both simpler and safer for pre-existing large homeservers.

@kaylendog kaylendog closed this Aug 28, 2026
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.

1 participant