Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: always prefer unthreaded receipt when >1 exist (MSC4102) #16927

Merged

Conversation

kegsay
Copy link
Contributor

@kegsay kegsay commented Feb 16, 2024

Pull Request Checklist

MSC: matrix-org/matrix-spec-proposals#4102
Tests: matrix-org/complement#709

  • 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)

@kegsay kegsay requested a review from a team as a code owner February 16, 2024 11:19
@anoadragon453
Copy link
Member

As this PR references server behaviour specified by an MSC, my initial reaction was that "this needs an experimental_features flag"! However, I think we can make an exception here, as:

  1. This does not communicate any unstable prefixes for clients to start relying on.
  2. The MSC selects a specific action for cases where the spec previously had undefined and implementation-dependent behaviour.

In essence this change already fits within the current spec version, which was ambiguous. Today, this change in Synapse wouldn't require an MSC. However, I commend @kegsay for going and clarifying the spec as well by writing an MSC.

@kegsay
Copy link
Contributor Author

kegsay commented Feb 16, 2024

Yeah @turt2live said much the same in that it doesn't really need to be an MSC, it's a clarification of previously undefined behaviour.

Copy link
Member

@anoadragon453 anoadragon453 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on! A couple small suggestions.

changelog.d/16927.bugfix Outdated Show resolved Hide resolved
# This means we will drop some receipts, but MSC4102 is designed to drop semantically
# meaningless receipts, so this is okay. Previously, we would drop meaningful data!
receipt_data = db_to_json(data)
if user_id in receipt_type_dict: # existing receipt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the first arm of this if statement does not handle the following cases:

  • there is an existing receipt, and it is unthreaded
  • there is an existing receipt and it is threaded, but there is an incoming threaded receipt

In both of those cases, receipt_type_dict is not modified. Is this on purpose? If not, perhaps it'd be best to pull line 490 up and out of this if statement, so that it is run regardless (and then potentially overridden later).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is an existing receipt, and it is unthreaded then it should not be replaced so I would expect the conditional to fail.

It is impossible for there to be a threaded receipt and then another threaded receipt for the same (user, event, type) tuple. If that did happen, it's undefined behaviour.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. I was perplexed that the old code would always update receipt_type_dict, whereas this new code does not in some cases. But I suppose that was the "last receipt always wins" behaviour you described that you seek to replace.

N.B. I find the (prior) code in this method a bit too magical. But your changes look sound.

Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
# This means we will drop some receipts, but MSC4102 is designed to drop semantically
# meaningless receipts, so this is okay. Previously, we would drop meaningful data!
receipt_data = db_to_json(data)
if user_id in receipt_type_dict: # existing receipt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. I was perplexed that the old code would always update receipt_type_dict, whereas this new code does not in some cases. But I suppose that was the "last receipt always wins" behaviour you described that you seek to replace.

N.B. I find the (prior) code in this method a bit too magical. But your changes look sound.

@anoadragon453 anoadragon453 enabled auto-merge (squash) February 20, 2024 14:00
@anoadragon453 anoadragon453 merged commit c51a224 into develop Feb 20, 2024
38 checks passed
@anoadragon453 anoadragon453 deleted the kegan/to-thread-or-not-to-thread-that-is-the-question branch February 20, 2024 14:12
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Mar 9, 2024
# Synapse 1.102.0 (2024-03-05)

### Bugfixes

- Revert element-hq/synapse#16756, which caused incorrect notification counts on mobile clients since v1.100.0. ([\#16979](element-hq/synapse#16979))


# Synapse 1.102.0rc1 (2024-02-20)

### Features

- A metric was added for emails sent by Synapse, broken down by type: `synapse_emails_sent_total`. Contributed by Remi Rampin. ([\#16881](element-hq/synapse#16881))

### Bugfixes

- Do not send multiple concurrent requests for keys for the same server. ([\#16894](element-hq/synapse#16894))
- Fix performance issue when joining very large rooms that can cause the server to lock up. Introduced in v1.100.0. ([\#16903](element-hq/synapse#16903))
- Always prefer unthreaded receipt when >1 exist ([MSC4102](matrix-org/matrix-spec-proposals#4102)). ([\#16927](element-hq/synapse#16927))

### Improved Documentation

- Fix a small typo in the Rooms section of the Admin API documentation. Contributed by @RainerZufall187. ([\#16857](element-hq/synapse#16857))

### Internal Changes

- Don't invalidate the entire event cache when we purge history. ([\#16905](element-hq/synapse#16905))
- Add experimental config option to not send device list updates for specific users. ([\#16909](element-hq/synapse#16909))
- Fix incorrect docker hub link in release script. ([\#16910](element-hq/synapse#16910))



### Updates to locked dependencies

* Bump attrs from 23.1.0 to 23.2.0. ([\#16899](element-hq/synapse#16899))
* Bump bcrypt from 4.0.1 to 4.1.2. ([\#16900](element-hq/synapse#16900))
* Bump pygithub from 2.1.1 to 2.2.0. ([\#16902](element-hq/synapse#16902))
* Bump sentry-sdk from 1.40.0 to 1.40.3. ([\#16898](element-hq/synapse#16898))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants