element-hq / element-hq/synapse

Room deletion (and purging) does not always send a leave down sync to clients

Open
#18,599 3 comments 1 reaction 0 assignees View on GitHub
A-Admin-API A-purge-room A-Retention A-Sync T-Defect
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

Related to https://github.com/element-hq/synapse/issues/18464

### Problem

Room deletion (v2, and possibly v1) will purge the room upon deletion. It will first send a bunch of kick events, which are intended to go to clients to let them know to remove the room from their room list. The problem is however immediately after sending these the room is purged from the database so unless you are federated or happened to be syncing exactly as the leave was sent, you will miss the leave event. The leave events are purged along with the room itself.

Subsequent syncs made after the room is purged never include the leave event, so any clients that did not sync will be stuck with broken state.

### Proposed solution

Synapse should generate synthetic leave events for users with devices that existed at the point in time the room was alive. Rather than relying on events in the room which may be purged, the homeserver should keep a mapping of user, device and room_id of deleted rooms that can be popped as the device syncs to ensure they see a leave down the sync in all cases. This minimises the retention of data onto the server with the bare minimum required to execute the leaves, without leaving any metadata.

To keep in mind that quite like device messages, these rows could hang around forever if devices do not sync so a sensible cleanup period should be incorporated (perhaps a month, or so) where these rows are purged anyway.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the room deletion and purge flow for v1 and v2, then inspect how device sync handles events after a room is removed. The fix should ensure devices that existed when the room was alive receive a leave during a later sync, while retained mappings are eventually cleaned up. Check the related issue 18464 for context.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, databases
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.