Skip to content

Allocate device list stream IDs per batch - #20151

Draft
sandhose wants to merge 1 commit into
developfrom
quenting/device-list-stream-ids-per-batch
Draft

Allocate device list stream IDs per batch#20151
sandhose wants to merge 1 commit into
developfrom
quenting/device-list-stream-ids-per-batch

Conversation

@sandhose

@sandhose sandhose commented Aug 26, 2026

Copy link
Copy Markdown
Member

add_device_change_to_streams chunks device_ids into batches of 1000, but allocated len(device_ids) stream IDs for every batch instead of len(batch_device_ids). Both _add_device_change_to_stream_txn and _add_device_outbound_room_poke_txn zip the IDs against the batch they were handed, so the surplus was silently discarded.

This was particularly a problem when deleting devices on m.org on accounts with >1M devices, as every batch would allocate millions of stream IDs, making it impossible for consumers to ever catch up. This fix is currently deployed on m.org

@sandhose sandhose added the Z-Deployed-On-Morg This PR has been deployed on matrix.org, so we must either merge it soon or roll it back label Aug 26, 2026
`add_device_change_to_streams` chunks `device_ids` into batches of 1000, but
the transaction allocated `len(device_ids)` stream IDs on every batch instead
of `len(batch_device_ids)`. Both `_add_device_change_to_stream_txn` and
`_add_device_outbound_room_poke_txn` zip the IDs against the batch they were
handed, so the surplus was silently discarded.

For a user with N devices this allocated N * ceil(N / 1000) IDs to write N
rows, so the `device_lists` stream ID space advanced quadratically in the
number of devices a user has. Accounts holding ~1.1M devices burned over a
billion IDs per change, pushing the stream head far enough ahead that readers
could not catch up -- the catch-up path in
`get_all_device_list_changes_for_remotes` fetches 100 rows at a time and
advances only as far as the last row's stream ID.
@sandhose
sandhose force-pushed the quenting/device-list-stream-ids-per-batch branch from cf87187 to ddc00d7 Compare August 26, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Device-List-Tracking Z-Deployed-On-Morg This PR has been deployed on matrix.org, so we must either merge it soon or roll it back

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants