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

Fix room state being updated with old (now overwritten) state and emitting for those updates. #4242

Merged
merged 9 commits into from
Jul 5, 2024

Conversation

toger5
Copy link
Contributor

@toger5 toger5 commented Jun 13, 2024

This is a workaround at best and mostly serves the purpose to show that this issue exist and to have a starting point to look into the underlying problem.

Checklist

  • Tests written for new code (and old code if feasible).
  • New or updated public/exported symbols have accurate TSDoc documentation.
  • Linter and other CI checks pass.
  • Sign-off given on the changes (see CONTRIBUTING.md).

src/models/room-state.ts Outdated Show resolved Hide resolved
Add configuration for toStartOfTimeline
@toger5
Copy link
Contributor Author

toger5 commented Jun 18, 2024

I added tests to see what this actually does.

@@ -419,13 +428,26 @@ export class RoomState extends TypedEventEmitter<EmittedEvents, EventHandlerMap>
this.setBeacon(event);
}

const lastStateEvent = this.getStateEventMatching(event);
const lastStateEv = this.getStateEventMatching(event);
Copy link
Member

Choose a reason for hiding this comment

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

Why did this get renamed to something less clear?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Otherwise, we had a lot more linewraps that made I judged as harder to read overall.

Copy link
Member

Choose a reason for hiding this comment

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

That's only because on L435 and L436 you're using the array syntax to set variables which is really redundant. It'd be clearer as 4 separate instantiations.

src/models/room-state.ts Outdated Show resolved Hide resolved
src/models/room-state.ts Outdated Show resolved Hide resolved
Comment on lines 47 to 53
/** Whether the event is inserted at the start of the timeline
* or at the end. This is relevant for doing a sanity check:
* "Is the event id of the added event the same as the replaces_state id of the current event"
* We need to do this because sync sometimes feeds previous state events.
* If set to true the sanity check is inverted
* "Is the event id of the current event the same as the replaces_state id of the added event"
*/
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this makes sense, as a RoomState is only ever in one direction. This sounds like if toStartOfTimeline=false then you should always drop the state event as they're never live. It should be a property on a RoomState if required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a good observation. The state itself might be the right location to store if it's a start state or an end state.
It should never change and also not be relevant outside the state object it seems logical to belong to the state.

I have trouble understanding the exact definition of start state anyway however:

If we have a state that is only set at the beginning of the room, events from a time-line in a specific interval cannot be enough to compute the start state because the start state needs all state events BEFORE the start of the time-line but the time-line only includes events after the "start".

This is slightly off topic but i still wanted to being it up. Feel free to DM me about this or point me to where i can lookup how start state is defined.

Copy link
Member

Choose a reason for hiding this comment

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

as I understand it, it is the state at the start of the timeline, and it walks backwards as you backpaginate and load older events which undo the more recent state events.

Copy link
Contributor Author

@toger5 toger5 Jun 18, 2024

Choose a reason for hiding this comment

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

That would also be how i understand start state. But this is not what we are doing.
We use the content to set the state keys. What we would need to do is set the state with the previous_content field.

| = start of timeline
|| = end of timeline
--- = time steps
XV> = state event changing the state (the content of the state event is the current state from that time on (X is an arbitrary label for the state event (f.ex. a member event) X is the type and V is the value

X0>-----|X1>----X2>----||
Here we have an example where the state is changed with the first event in the timeline. But the start imo is before that event. So the state at the start is X0.

This becomes more clear when adding another type:
X0>--A0>--|A1>-A2>-X1>--||
At the start of the timeline we have X0 A0 but definitly not X1 which would be the first X type state event.

If we use the previous_content we have <XV as the previous content.

<X0>--<A0>--|<A1>-<A2>-<X1>--||

Then <A1 & <X1 is the same as X0> & A0> and the correct start state.

Copy link
Member

Choose a reason for hiding this comment

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

I suggest raising this to the wider team as the code & intent predates me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure. Sorry for escalating this but I always found the startState to be arguably the correct name for that variable the way its implemented and this seemed to be relevant for this discussion. Somewhat relevant, you comment is just about where to store start/end.
What I do like about making it part of the setStateEvents property is that is makes it testable in a more isolated env.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To get back to the topic what do you think about the more encapsulated testability with the current approach?

@toger5 toger5 requested a review from t3chguy June 19, 2024 11:31
Copy link
Member

@t3chguy t3chguy left a comment

Choose a reason for hiding this comment

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

I think your suggestions are sane

@fkwp
Copy link

fkwp commented Jun 20, 2024

I think your suggestions are sane

who else do we need to unlock this? Could you pls invite?

@t3chguy
Copy link
Member

t3chguy commented Jun 20, 2024

My outstanding comments need dealing with, e.g. property of room state and random variable name change

@toger5
Copy link
Contributor Author

toger5 commented Jun 21, 2024

@t3chguy
Just to make sure this comment:

My outstanding comments need dealing with, e.g. property of room state and random variable name change

did not get missed,
this

To get back to the topic what do you think about the more encapsulated testability with the current approach?

implies you still prefer making it part of the state object although it allows the encapsulated testing?

@toger5
Copy link
Contributor Author

toger5 commented Jun 21, 2024

@t3chguy I updated the variable names back to what they were. And noticed the test can be done equally simple.

src/models/room-state.ts Outdated Show resolved Hide resolved
src/models/room-state.ts Show resolved Hide resolved
src/models/room-state.ts Outdated Show resolved Hide resolved
@toger5 toger5 added this pull request to the merge queue Jul 5, 2024
Merged via the queue into develop with commit 957329b Jul 5, 2024
27 checks passed
@toger5 toger5 deleted the toger5/wrong-room-state branch July 5, 2024 09:36
toger5 added a commit that referenced this pull request Nov 15, 2024
… and emitting for those updates. (#4242)"

This reverts commit 957329b.
t3chguy pushed a commit that referenced this pull request Nov 19, 2024
… and emitting for those updates. (#4242)"

This reverts commit 957329b.
t3chguy pushed a commit that referenced this pull request Nov 19, 2024
… and emitting for those updates. (#4242)"

This reverts commit 957329b.
github-merge-queue bot pushed a commit that referenced this pull request Nov 27, 2024
… and emitting for those updates. (#4242)" (#4532)

This reverts commit 957329b.
github-merge-queue bot pushed a commit that referenced this pull request Nov 27, 2024
* WIP support for state_after

* Fix sliding sync sdk / embedded tests

* Allow both state & state_after to be undefined

Since it must have allowed state to be undefined previously: the test
had it as such.

* Fix limited sync handling

* Need to use state_after being undefined

if state can be undefined anyway

* Make sliding sync sdk tests pass

* Remove deprecated interfaces & backwards-compat code

* Remove useless assignment

* Use updates unstable prefix

* Clarify docs

* Remove additional semi-backwards compatible overload

* Update unstable prefixes

* Iterate

Signed-off-by: Michael Telatynski <[email protected]>

* Iterate

Signed-off-by: Michael Telatynski <[email protected]>

* Fix test

Signed-off-by: Michael Telatynski <[email protected]>

* Iterate

Signed-off-by: Michael Telatynski <[email protected]>

* Iterate

Signed-off-by: Michael Telatynski <[email protected]>

* Add test for MSC4222 behaviour

Signed-off-by: Michael Telatynski <[email protected]>

* Improve coverage

Signed-off-by: Michael Telatynski <[email protected]>

* Iterate

Signed-off-by: Michael Telatynski <[email protected]>

* Fix tests

Signed-off-by: Michael Telatynski <[email protected]>

* Iterate

Signed-off-by: Michael Telatynski <[email protected]>

* Tidy

Signed-off-by: Michael Telatynski <[email protected]>

* Add comments to explain why things work as they are.

* Fix sync accumulator for state_after sync handling

Signed-off-by: Michael Telatynski <[email protected]>

* Add tests

Signed-off-by: Michael Telatynski <[email protected]>

* Revert "Fix room state being updated with old (now overwritten) state and emitting for those updates. (#4242)"

This reverts commit 957329b.

* Fix Sync Accumulator toJSON putting start timeline state in state_after field

Signed-off-by: Michael Telatynski <[email protected]>

* Update tests

Signed-off-by: Michael Telatynski <[email protected]>

* Add test case

Signed-off-by: Michael Telatynski <[email protected]>

* Iterate

Signed-off-by: Michael Telatynski <[email protected]>

---------

Signed-off-by: Michael Telatynski <[email protected]>
Co-authored-by: Hugh Nimmo-Smith <[email protected]>
Co-authored-by: Michael Telatynski <[email protected]>
Co-authored-by: Timo <[email protected]>
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.

3 participants