Skip to content

fix(sdk): correctly import e2ee history in join_room_by_id #5284

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

Merged
merged 6 commits into from
Jun 27, 2025

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Jun 25, 2025

It turns out that downstream clients can and do call Client::join_room_by_id() rather than Room::join, so we need to do the room key history import in the lower-level method.

It turns out that downstream clients can and do call
`Client::join_room_by_id()` rather than `Room::join`, so we need to do the room key history import
in the lower-level method.
@richvdh richvdh requested a review from a team as a code owner June 25, 2025 15:53
@richvdh richvdh requested review from Hywan and removed request for a team June 25, 2025 15:53
Comment on lines 2786 to 2791
/// Information about the state of a room before we joined it.
#[derive(Debug, Clone, Default)]
struct PreJoinRoomInfo {
/// The user that invited us to the room, if any
pub inviter: Option<RoomMember>,
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you include the room state prior to accepting the join, or even better, a mark_as_dm bool that follows the logic that's currently in finish_join_room? Then, we can fix the race you've spotted with respect to sync vs join (and include a test for it 🙃).

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd quite like to make that a separate problem, rather than scope-creeping the current fix into fixing other things.

Comment on lines +1460 to +1463
/// # Arguments
///
/// * `room_id` - The `RoomId` of the room that was joined.
/// * `pre_join_room_info` - Information about the room before we joined.
Copy link
Member

Choose a reason for hiding this comment

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

Do you find that it brings extra usefulness, here? I don't, but would be open to keeping this if you find it useful.

Copy link
Member Author

@richvdh richvdh Jun 26, 2025

Choose a reason for hiding this comment

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

well to be honest no, it's not useful in its own right. You can make the same argument for the docs on join_room_by_id, though.

Generally I favour adding documentation even where it's "obvious", because (a) it saves having to think about the decision about where the line is between "obvious" and not, and (b) it means we have a better starting point for documentation as the api evolves: for example in this case, if we add a third argument which does need documentation, that's easier because the documentation is already there for the other two.

Personally then, I think having the arguments listed is neutral-to-marginally-positive. But not a strong opinion.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'm generally against this list of arguments, unless they bring extra value (and agreed it's not any useful in join_room_by_id either). I've seen so many instances where those argument lists were desynchronized from the actual code, or just repeating the type with more words, that I find that we should avoid them, unless they provide some real value. But it's fine to keep as well, no strong opinions here, once again.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've seen so many instances where those argument lists were desynchronized from the actual code,

Counterpoint: having the argument list in the documentation as a matter of course means that you start to remember that you can't change arguments without changing documentation. If they're only listed occasionally when they bring extra value, then the chances are much higher that people forget to maintain them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since nobody has strong opinions here, I'm just going to leave it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the argument list, if they don't contain useful information to me I can ignore them. If they are missing I can't manifest them back.

I'd like to see them everywhere in the public API as well.

@bnjbvr bnjbvr removed the request for review from Hywan June 25, 2025 16:05
Copy link

codecov bot commented Jun 25, 2025

Codecov Report

Attention: Patch coverage is 77.77778% with 6 lines in your changes missing coverage. Please review.

Project coverage is 88.72%. Comparing base (4046a59) to head (e45773b).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk/src/client/mod.rs 77.77% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5284      +/-   ##
==========================================
- Coverage   90.19%   88.72%   -1.48%     
==========================================
  Files         334      330       -4     
  Lines      105205    88770   -16435     
  Branches   105205    88770   -16435     
==========================================
- Hits        94889    78758   -16131     
+ Misses       6254     6205      -49     
+ Partials     4062     3807     -255     

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

@richvdh richvdh requested a review from bnjbvr June 26, 2025 15:43
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.

lgtm; is it worth adding a new test, or is the test change you've made sufficient? cheers!

@richvdh
Copy link
Member Author

richvdh commented Jun 27, 2025

is it worth adding a new test, or is the test change you've made sufficient?

It's difficult to think of what a new test would look like, other than an exact repeat of the test I've changed.

We talked about this on the crypto team, and concluded that the fundamental problem here was that there is no functional test at the application level to check that the functionality actually works (i.e. that the app is holding matrix-sdk in the way that matrix-sdk expects to be held). But, testing at that level brings its own set of problems.

@richvdh
Copy link
Member Author

richvdh commented Jun 27, 2025

Ignoring the coverage metric because it seems to be bogus

@richvdh richvdh merged commit 4ecd599 into main Jun 27, 2025
43 of 44 checks passed
@richvdh richvdh deleted the rav/history_sharing/fix_join_room branch June 27, 2025 11:29
@poljar
Copy link
Contributor

poljar commented Jun 27, 2025

One thing that comes to mind about the API here is that you can join a room using the join_room_by_id method without ever having synced or having a sync running.

This means that we might not have the bundle available if people just don't sync. I guess that this isn't much different from the bundle arriving late.

Still, I wish that the clients using this over the FFI were more normal and would just use the correct API. 😞

@richvdh richvdh restored the rav/history_sharing/fix_join_room branch June 27, 2025 14:42
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