Repository: matrix-org/synapse

Issue:
Assertion error on startup in 1.76
### Description

I've updated from 1.74 to 1.76 and now on startup get
```
2023-02-07 09:40:49,117 - root - 344 - WARNING - main - ***** STARTING SERVER *****
2023-02-07 09:40:49,118 - root - 348 - WARNING - main - Server /home/matrix/synapse/env37/lib/python3.7/site-packages/synapse/app/homeserver.py version 1.76.0
2023-02-07 09:40:51,594 - synapse.metrics.background_process_metrics - 246 - ERROR - _handle_new_device_update_async-0 - Background process '_handle_new_device_update_async' threw an exception
Traceback (most recent call last):
  File "/home/matrix/synapse/env37/lib/python3.7/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
    result = g.send(result)
StopIteration: []

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/matrix/synapse/env37/lib/python3.7/site-packages/synapse/metrics/background_process_metrics.py", line 242, in run
    return await func(*args, **kwargs)
  File "/home/matrix/synapse/env37/lib/python3.7/site-packages/synapse/handlers/device.py", line 726, in _handle_new_device_update_async
    assert max_stream_id == stream_id
AssertionError
```

Restarting yields the same error.

Otherwise, the server seems to work fine.

### Steps to reproduce

- Upgrade synapse
- and just start it


### Homeserver

self-hosted

### Synapse Version

1.76

### Installation Method

pip (from PyPI)

### Database

Postgresql

### Workers

Single process

### Platform

Raspberry Pi, Rasbian 10

### Configuration

_No response_

### Relevant log output

```shell
2023-02-07 09:40:49,117 - root - 344 - WARNING - main - ***** STARTING SERVER *****
2023-02-07 09:40:49,118 - root - 348 - WARNING - main - Server /home/matrix/synapse/env37/lib/python3.7/site-packages/synapse/app/homeserver.py version 1.76.0
2023-02-07 09:40:51,594 - synapse.metrics.background_process_metrics - 246 - ERROR - _handle_new_device_update_async-0 - Background process '_handle_new_device_update_async' threw an exception
Traceback (most recent call last):
  File "/home/matrix/synapse/env37/lib/python3.7/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
    result = g.send(result)
StopIteration: []

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/matrix/synapse/env37/lib/python3.7/site-packages/synapse/metrics/background_process_metrics.py", line 242, in run
    return await func(*args, **kwargs)
  File "/home/matrix/synapse/env37/lib/python3.7/site-packages/synapse/handlers/device.py", line 726, in _handle_new_device_update_async
    assert max_stream_id == stream_id
AssertionError
```


### Anything else that would be useful to know?

_No response_


Discussion:

Resolving patch:
diff --git a/synapse/storage/databases/main/devices.py b/synapse/storage/databases/main/devices.py
--- a/synapse/storage/databases/main/devices.py
+++ b/synapse/storage/databases/main/devices.py
@@ -100,6 +100,7 @@ def __init__(
                 ("device_lists_outbound_pokes", "stream_id"),
                 ("device_lists_changes_in_room", "stream_id"),
                 ("device_lists_remote_pending", "stream_id"),
+                ("device_lists_changes_converted_stream_position", "stream_id"),
             ],
             is_writer=hs.config.worker.worker_app is None,
         )


Test patch: