element-hq / element-hq/synapse

Room notification count not always decreasing when redacting messages

Open
#15,698 0 comments 0 reactions 0 assignees View on GitHub
O-Occasional S-Minor T-Defect
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

This issue has been migrated from [#15698](https://github.com/matrix-org/synapse/issues/15698).

---

### Description

When unread messages get redacted, the room notification count sometimes does not decrease accordingly and instead gets stuck. Said differently: if a user has some unread messages in a room, and isn't looking at this room, and if these unread messages are redacted/removed by someone else, the unread count for this room usually decreases accordingly, but sometimes doesn't and gets stuck. One way to unblock/reset it is to open that room. The behaviour isn't very consistent, but very easy to repro with the steps below by repeating them once or twice if the issue doesn't surface the first time.

Repro steps:
- As user A create channel 1
- As user B join channel 1
- As user A open another channel than channel1
- As user B send 5 messages in channel1
- As user A see that the notification count for channel1 is 5
- As user B redact the 5 messages sent in channel1 one by one
- As user A check the notification count for channel1. Sometimes the result will be 0 as expected, but sometimes it will be a number between 1 and 5 which isn't expected. If the notification count is 0, try again the same steps until hitting the issue (may need to repeat once or twice).

![image](https://github.com/matrix-org/synapse/assets/9506771/467b3831-50e2-40dd-8598-8abf94d6d09d)

This is reproducible on https://app.element.io/

By "room notification count", I mean `rooms.join[“roomId”]. unread_notifications.notification_count` from the `/sync` response.

On a stack where I have DB access, this is what appears in `event_push_actions` and `event_push_summary` in an example where 4 messages were sent, 2 redacted, and the notification count was stuck at 4 instead of 2:

```
select * FROM event_push_actions where user_id = 'userId' and room_id = 'roomId';
room_id | event_id | user_id | profile_tag | actions | topological_ordering | stream_ordering | notif | highlight | unread | thread_id
----------------------------------------------+----------------------------------------------+-----------------------------------------
roomId | $event1 | userId | | | 71 | 2226732 | 1 | 0 | 0 | main
roomId | $event2 | userId | | | 72 | 2226733 | 1 | 0 | 0 | main
```

```
select * from event_push_summary where user_id = 'userId' and room_id = 'roomId';
user_id | room_id | notif_count | stream_ordering | unread_count | last_receipt_stream_ordering | thread_id
----------------------------------------------------------------+-------------------------------------------
userId | roomId | 4 | 2226735 | 0 | 2226260 | main
```

So `event_push_actions` correctly indicates the 2 unread, but `event_push_summary` incorrectly indicates a `notif_count` of 4 instead of 2.

### Steps to reproduce

Repro steps:
- As user A create channel 1
- As user B join channel 1
- As user A open another channel than channel1
- As user B send 5 messages in channel1
- As user A see that the notification count for channel1 is 5
- As user B redact the 5 messages sent in channel1 one by one
- As user A check the notification count for channel1. Sometimes the result will be 0 as expected, but sometimes it will be a number between 1 and 5 which isn't expected. If the notification count is 0, try again the same steps until hitting the issue (may need to repeat once or twice).

![image](https://github.com/matrix-org/synapse/assets/9506771/467b3831-50e2-40dd-8598-8abf94d6d09d)

This is reproducible on https://app.element.io/

### Homeserver

matrix.org

### Synapse Version

1.85.0rc1 (b=matrix-org-hotfixes,4427151a21)

### Installation Method

Docker (matrixdotorg/synapse)

### Database

Not sure what https://app.element.io/ is using

### Workers

I don't know

### Platform

Not sure what https://app.element.io/ is using

### Configuration

_No response_

### Relevant log output

```shell
NA
```

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

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.