Skip to content

Widget driver: Distinguish room state and timeline events #4947

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

robintown
Copy link
Member

@robintown robintown commented Apr 16, 2025

This is an implementation of an update to MSC2762. It changes the widget driver to split state updates out into an update_state action and use the send_event action exclusively for forwarding timeline events. Accordingly, read_events now always reads from /messages, never the state store.

⚠️ Do not merge yet: I do not want to merge this until a new version of Element Call is nearing release which would be compatible with the update_state action. However, I would like this to be reviewed. Once approved I will go back and prepare the Element Call changes.

For https://github.com/element-hq/voip-internal/issues/289

@robintown robintown requested a review from a team as a code owner April 16, 2025 16:08
@robintown robintown requested review from stefanceriu and removed request for a team April 16, 2025 16:08
@robintown robintown force-pushed the widget-update-state branch from 73101ce to 5f3a4c9 Compare April 16, 2025 16:14
Copy link

codecov bot commented Apr 16, 2025

Codecov Report

Attention: Patch coverage is 86.33540% with 22 lines in your changes missing coverage. Please review.

Project coverage is 85.83%. Comparing base (69b8878) to head (1166012).

Files with missing lines Patch % Lines
crates/matrix-sdk/src/widget/machine/mod.rs 85.04% 16 Missing ⚠️
crates/matrix-sdk/src/widget/matrix.rs 85.18% 4 Missing ⚠️
crates/matrix-sdk/src/widget/machine/driver_req.rs 84.61% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4947      +/-   ##
==========================================
+ Coverage   85.81%   85.83%   +0.01%     
==========================================
  Files         325      325              
  Lines       35909    35981      +72     
==========================================
+ Hits        30817    30883      +66     
- Misses       5092     5098       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

I've only looked at the first three commits, a first batch of comments; the change in the second commit is likely wrong.

@stefanceriu stefanceriu removed their request for review April 17, 2025 10:06
@robintown robintown force-pushed the widget-update-state branch 3 times, most recently from 941dabe to 45dbf2d Compare April 17, 2025 10:31
@robintown robintown requested a review from bnjbvr April 18, 2025 09:57
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

A few more remarks. It took me lot of time to read the widget-related code, as it's poorly documented, so let's try to improve the situation here: for each new function/type/trait you're introduced, or that you've touched in this PR, can you add a doc comment, please?

Would you also consider breaking the PR into smaller chunks, or smaller commits? The last one has quite the "draw the rest of the freaking howl" vibe :) and without a commit message or extra guidance where to start reading from, it's a bit overwhelming to review…

[edit] to precise the above request to split: I think it'd be nice also to isolate renamings from other changes, because renaming commits are trivial to review, and the last commit seems to include a few of them, which makes it unnecessarily harder to review. If code has been just moved and not changed, that's also a nice candidate for a separate commit, that doesn't require any review either. Overall, this kind of practices makes it easier for your code to be reviewed, and should give faster review turnaround :)

bnjbvr
bnjbvr previously requested changes Apr 24, 2025
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

(Moar review comments, now that I'm mostly understanding the flow between Machine/Widget/Driver)

Comment on lines 182 to 186
pub(super) struct ReadEventsRequest {
#[serde(rename = "type")]
pub(super) event_type: TimelineEventType,
pub(super) state_key: Option<StateKeySelector>,
pub(super) limit: Option<u32>,
Copy link
Member

Choose a reason for hiding this comment

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

This will badly break the data format, and I suppose that's the reason why you're asking for a coordinated release; is there a chance we could support both the previous and new formats, instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

This struct is internal, right?

The reason I'm asking for a coordinated release is that after these changes, the SDK will no longer be compatible with widgets that don't understand the update_state to-widget action. It's possible to maintain compatibility with older API versions, as this was done in matrix-widget-api for instance (matrix-org/matrix-widget-api#125 matrix-org/matrix-widget-api#126) but the VoIP team doesn't have resources right now to do the same for matrix-rust-sdk. The widget API has no stability guarantees currently, so we would like to simply coordinate this update with Element Call and Element X.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is internal. Your explanation sounds reasonable to me.

One suggestion, you might want to consider adding a snapshot test for this if the serialization format needs to be or become stable.

This will raise an alarm if someone accidentally changes the format.

It's pretty easy to add them:

#[test]
fn snapshot_decryption_settings() {
assert_json_snapshot!(DecryptionSettings {
sender_device_trust_requirement: TrustRequirement::Untrusted,
});
}

Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

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

Alright, I think most of this is good. The one thing that I'm objecting to mostly is the complexity of the capability negotiation.

The biggest issue is the naked unwrap in the mentioned function.

Comment on lines 182 to 186
pub(super) struct ReadEventsRequest {
#[serde(rename = "type")]
pub(super) event_type: TimelineEventType,
pub(super) state_key: Option<StateKeySelector>,
pub(super) limit: Option<u32>,
Copy link
Contributor

Choose a reason for hiding this comment

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

It is internal. Your explanation sounds reasonable to me.

One suggestion, you might want to consider adding a snapshot test for this if the serialization format needs to be or become stable.

This will raise an alarm if someone accidentally changes the format.

It's pretty easy to add them:

#[test]
fn snapshot_decryption_settings() {
assert_json_snapshot!(DecryptionSettings {
sender_device_trust_requirement: TrustRequirement::Untrusted,
});
}

@poljar poljar dismissed bnjbvr’s stale review May 7, 2025 11:34

On holiday.

@poljar poljar removed the request for review from bnjbvr May 7, 2025 11:35
@robintown robintown force-pushed the widget-update-state branch from d64407d to 9f91f9b Compare May 13, 2025 20:00
@robintown robintown requested a review from poljar May 13, 2025 20:09
@robintown robintown force-pushed the widget-update-state branch 3 times, most recently from 7df463f to 2cbc4e2 Compare May 13, 2025 21:28
Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

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

Ok, I think there's still a bit that can be improved as part of this PR.

I think after this we're good. Please don't use force pushes once a review has started. It makes it quite hard to see the changes between the review rounds.

If you'd like to keep the history clean you can use fixup commits and rebase/autosquash once the PR has been approved.

More info about our review process can be found in the contributing guide: https://github.com/matrix-org/matrix-rust-sdk/blob/main/CONTRIBUTING.md#review-process.

@robintown
Copy link
Member Author

robintown commented May 14, 2025

Please don't use force pushes once a review has started. It makes it quite hard to see the changes between the review rounds. If you'd like to keep the history clean you can use fixup commits and rebase/autosquash once the PR has been approved.

Noted. I had to resolve some merge conflicts so I haven't used fixup commits for this most recent round of changes, but if you would prefer I absorb them into the previous commits once this is approved, I could do that. (Just means I have to resolve the conflicts a second time, unless you know of another way.)

@robintown robintown requested a review from poljar May 14, 2025 17:03
@poljar
Copy link
Contributor

poljar commented May 14, 2025

Please don't use force pushes once a review has started. It makes it quite hard to see the changes between the review rounds. If you'd like to keep the history clean you can use fixup commits and rebase/autosquash once the PR has been approved.

Noted. I had to resolve some merge conflicts so I haven't used fixup commits for this most recent round of changes, but if you would prefer I absorb them into the previous commits once this is approved, I could do that. (Just means I have to resolve the conflicts a second time, unless you know of another way.)

It's fine, I'll take a look tomorrow.

Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

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

Alright, I think that this is fine.

You can now get rid of the fixup commits and rebase, or if you don't want to spend time on this we can squash merge as well.

robintown added 11 commits May 15, 2025 08:47
Refactoring the test event implementation to use the From trait rather than ad-hoc methods along the way.
I want to use this JSON in multiple tests.
So that when I need to do this (in later commits) I don't have to cast.
Just making these a bit less verbose and more consistent with surrounding identifiers.
This is an implementation of an update to MSC2762 (matrix-org/matrix-spec-proposals#4237). It changes the widget driver to split state updates out into an `update_state` action and use the `send_event` action exclusively for forwarding timeline events. Accordingly, `read_events` now always reads from /messages, never the state store.
@robintown robintown force-pushed the widget-update-state branch from 6ef21a1 to 1166012 Compare May 15, 2025 12:55
@robintown
Copy link
Member Author

Thanks a bunch for your thorough reviews! As a reminder, this still needs to wait on some Element Call release candidate stuff before it's ready for merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants