Skip to content

MSC4140: drop delayed state interference - #19495

Merged
reivilibre merged 10 commits into
element-hq:developfrom
AndrewFerr:msc4140-drop-state-cancel-rule
Oct 12, 2026
Merged

reivilibre merged 10 commits into
element-hq:developfrom
AndrewFerr:msc4140-drop-state-cancel-rule

Conversation

@AndrewFerr

Copy link
Copy Markdown
Member

No longer cancel a user's delayed state events by a more recent state event sent from a different user. This behaviour has been delegated to an "alternative" in the delayed event MSC for some time now, and is not known to be used by any module other than experimental iterations of MatrixRTC.

See also: matrix-org/complement#845

Pull Request Checklist

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

No longer cancel a user's delayed state events by a more recent state
event sent from a different user.  This behaviour has been delegated to
an "alternative" in the delayed event MSC for some time now, and is not
known to be used by any module other than experimental iterations of
MatrixRTC.
@AndrewFerr
AndrewFerr requested a review from a team as a code owner February 24, 2026 03:41
@reivilibre
reivilibre self-requested a review March 3, 2026 13:32

@reivilibre reivilibre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This makes sense, just need to go through the slightly tedious motions for the schema version, I think

Comment thread changelog.d/19495.removal Outdated
CREATE INDEX delayed_events_is_processed ON delayed_events (is_processed);
CREATE INDEX delayed_events_room_state_event_idx ON delayed_events (room_id, event_type, state_key) WHERE state_key IS NOT NULL;

-- TODO: delete this table in the next Synapse release that can handle a breaking DB change

@reivilibre reivilibre Mar 3, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is possibly better tracked as a GitHub issue instead of a comment here.

More concretely, we need to study https://element-hq.github.io/synapse/latest/development/database_schema.html#synapse-schema-versions

There's a worked example with a table removal. Since I think it's fine to have degraded rollback support for this experimental feature (as in, I think it's probably OK to stop reading and writing to this table at the same time), I think for us this is something along the lines of:

  • SCHEMA_VERSION needs to be increased now, with a comment on the version saying that in the new SCHEMA_VERSION we no longer use this table.

  • In a later version, we can make SCHEMA_COMPAT_VERSION match that as we drop the table, preventing rollback to the older SCHEMA_VERSION.


Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  • SCHEMA_VERSION needs to be increased now, with a comment on the version saying that in the new SCHEMA_VERSION we no longer use this table.

Since the schema isn't actually changed by this PR, would it be acceptable to put that comment on the latest SCHEMA_VERSION (which is a newer version than when the table was created) instead of creating an "empty" bump?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This question still stands.

@AndrewFerr AndrewFerr Oct 5, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In the timeless interval that has passed, I've come to better understand the point of the schema versioning & agree with your approach.

4f9d70a makes the version bump, and #20311 tracks the task to drop the table alongside a compat version bump.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry I didn't see this earlier. Please do make use of the re-request button :-)

@MadLittleMods MadLittleMods Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Anything to learn here and better document in docs/development/database_schema.md ? (a new worked example?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Maybe what's worth mentioning is that the DB schema version isn't the version of the physical DB schema itself, but a version of the intended usage / guarantees of the schema. Realizing that is what made the docs "click" for me.

Co-authored-by: Olivier 'reivilibre' <olivier@librepush.net>
MadLittleMods pushed a commit to matrix-org/complement that referenced this pull request Mar 4, 2026
Don't test that a user's delayed state events are cancelled by a more recent
state event from a different user.  That behaviour [has been delegated to
an "alternative"]
(matrix-org/matrix-spec-proposals@3efecea)
in the delayed event MSC4140 for some time now, and may be removed from
Synapse ([Synapse PR](element-hq/synapse#19495))
AndrewFerr and others added 2 commits May 14, 2026 08:47
Resolve the conflict in the delayed events handler:

- Keep the removal of `notify_new_event`, `_unsafe_process_new_event`
  and `_handle_state_deltas`. Develop only touched them to swap
  `Sentinel.UNSET_SENTINEL` for `Absent`.
- Imports: take develop's `Codes` and `SynapseError`, which `add` now
  needs for its 403 `M_FORBIDDEN` and `DELAY_TOO_LARGE` errors, and
  drop `Measure` and `Absent`, which only the removed code used.
Include new methods & tests from element-hq#20247
Use a DB schema version update to document the change in behaviour,
rather than a TODO comment on the table itself.
Remove test that was modified by element-hq#19354 but had been removed by this PR

@reivilibre reivilibre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@reivilibre
reivilibre merged commit 40acb97 into element-hq:develop Oct 12, 2026
42 checks passed
AndrewFerr added a commit to AndrewFerr/synapse that referenced this pull request Oct 16, 2026
AndrewFerr added a commit to AndrewFerr/synapse that referenced this pull request Oct 16, 2026
When a batch of timed out delayed events includes state events, simply
send those state events in order with all other events to be sent,
rather than sending only the first state event per matching state key &
doing so after sending message events.

This is safe now that delayed state event intererence has been dropped
(see element-hq#19495).
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.

4 participants