Skip to content

MSC4140: update error responses - #19539

Merged
AndrewFerr merged 68 commits into
element-hq:developfrom
AndrewFerr:msc4140-error-updates
Jul 11, 2026
Merged

MSC4140: update error responses#19539
AndrewFerr merged 68 commits into
element-hq:developfrom
AndrewFerr:msc4140-error-updates

Conversation

@AndrewFerr

@AndrewFerr AndrewFerr commented Mar 9, 2026

Copy link
Copy Markdown
Member
  • Impose limit of scheduled delayed events
  • Update error codes to match latest draft of MSC4140

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)

Prevent users from having more than a configured number of delayed
events scheduled at once.
Also don't return a custom error (that was never in the MSC) when adding
a delayed event if not enabled in the config
@AndrewFerr
AndrewFerr requested a review from a team as a code owner March 9, 2026 20:45
Comment thread tests/rest/client/test_rooms.py Outdated
Comment thread synapse/config/experimental.py Outdated
Comment thread synapse/rest/client/room.py Outdated
Set the new "max_delayed_events_per_user" config in the same module
as where the other MSC4140 config ("max_event_delay_duration") is set.

Also give it aliases for experimental & stable usage.
in an attempt to better explain what it is and why it is being examined
Don't want a stable alias for it yet, as it may change
Set its value to the remaining time until the requesting user's next
delayed event will be sent.

Also drop test against the error message of the thrown
LimitExceededError, as now the Retry-After is there to clearly
distinguish the thrown error as being related to a specific delayed
event request.
If delayed events are to be disabled, it should be done by leaving the
max_event_delay_duration config unspecified, not by setting the delayed
event limit to 0.

Also add test coverage, and tweak the error thrown for
max_delay_event_ms to be consistent with the newly-added error.
Comment thread synapse/config/server.py Outdated
Comment thread synapse/storage/databases/main/delayed_events.py Outdated
Comment thread synapse/config/server.py
Comment on lines +918 to +920
raise ConfigError(
"Expected a positive value", ("max_event_delay_duration",)
)

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.

Explain more why and what do do.

Enforce max delayed event config to be positive

If delayed events are to be disabled, it should be done by leaving the
max_event_delay_duration config unspecified, not by setting the delayed
event limit to 0.

-- 43e14e9

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.

267a7e5 rewords the error message to be a bit more descriptive, and to follow the same format used by similar errors in this module.

@MadLittleMods MadLittleMods Jun 8, 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.

Per the original intentions, I was more looking for something like this:

Suggested change
raise ConfigError(
"Expected a positive value", ("max_event_delay_duration",)
)
raise ConfigError(
"Expected a non-zero, positive value for the delay duration. To disable delayed events, leave `max_event_delay_duration` unspecified.", ("max_event_delay_duration",)
)

It seems like ideally, we would have had this kind of structure for delayed event config:

delayed_events:
  enabled: true
  max_event_delay_duration: 24h
  max_delayed_events_per_user: 100

If we're going with 0 as a valid value to disable delayed events, I guess the updated error message works ⏩

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.

That new config does look better, though I'd prefer using a dedicated PR to change it, given that max_event_delay_duration has been around for a while now & moving it would be a breaking change.

I'd also prefer to keep config suggestions in the documentation instead of error messages, to reduce churn on code changes while the MSC is still unstable.

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.

It looks like msc4140_enabled was added. Are we interested in getting the config shape correct from the beginning?

Generally, we try not to break peoples homeserver config. And changing this later means even more complication for the backwards compatibility.

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.

msc4140_enabled isn't a real config key. It's just a computed value to make it easier to have /versions report whether delayed events are enabled via the other config keys, done since 0859de0. (It is also used in c33d443.)

Which is to say, the config shape has not changed, nor do I intend to change it.

Comment thread synapse/storage/databases/main/delayed_events.py Outdated
Comment thread tests/rest/client/test_rooms.py Outdated
Comment thread tests/rest/client/test_rooms.py Outdated
Comment thread tests/rest/client/test_rooms.py Outdated
Comment thread tests/rest/client/test_rooms.py Outdated
Comment thread tests/config/test_server.py
Comment thread tests/config/test_server.py Outdated
@AndrewFerr
AndrewFerr requested a review from MadLittleMods June 8, 2026 13:05
Comment thread tests/rest/client/test_rooms.py Outdated
Comment thread tests/rest/client/test_rooms.py Outdated
Comment thread synapse/storage/databases/main/delayed_events.py
Comment thread synapse/storage/databases/main/delayed_events.py
Comment thread synapse/storage/databases/main/delayed_events.py Outdated
Comment thread synapse/storage/databases/main/delayed_events.py Outdated
Comment thread synapse/storage/databases/main/delayed_events.py Outdated
AndrewFerr and others added 7 commits July 8, 2026 13:10
@AndrewFerr
AndrewFerr requested a review from MadLittleMods July 8, 2026 20:50

@MadLittleMods MadLittleMods 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.

(review pass)

AndrewFerr and others added 5 commits July 9, 2026 13:21
Co-authored-by: Eric Eastwood <madlittlemods@gmail.com>
Also convey an unset/default max delay config with a zero value instead
of None, and have downstream code assume it is never negative (which is
enforced at config time) to allow for some code simplifications
In regards to the merge conflict:
With the /versions response body now being generated in Rust, properties
of the HomeServerConfig get mirrored into Rust.  One of those values was
the maximum allowed delay, which used to be in milliseconds, but is now
a Duration, which is not as straightforward to mirror into Rust.  So as
a simplification, have the config store a boolean flag that reflects
whether MSC4140 is functionally enabled, and mirror that into Rust for
it to use to populate /versions instead of inspecting the max delay.
@AndrewFerr

Copy link
Copy Markdown
Member Author

To view just the merge conflict resolution made by 0859de0, you can use this:

diff <(git diff $(git merge-base develop fair/msc4140-error-updates^1) fair/msc4140-error-updates^1) <(git diff develop fair/msc4140-error-updates)

@AndrewFerr
AndrewFerr requested a review from MadLittleMods July 10, 2026 17:55
Comment thread tests/rest/client/test_rooms.py Outdated
Comment thread synapse/handlers/delayed_events.py Outdated
Comment thread synapse/storage/databases/main/delayed_events.py
Comment thread synapse/storage/databases/main/delayed_events.py
Comment thread tests/rest/client/test_rooms.py Outdated
Comment thread tests/rest/client/test_rooms.py Outdated
Comment thread tests/rest/client/test_rooms.py Outdated
Comment thread synapse/storage/databases/main/delayed_events.py
@AndrewFerr
AndrewFerr requested a review from MadLittleMods July 10, 2026 20:28
@MadLittleMods
MadLittleMods removed their request for review July 10, 2026 20:57
@AndrewFerr
AndrewFerr enabled auto-merge (squash) July 10, 2026 21:29
@AndrewFerr
AndrewFerr merged commit c0c2b37 into element-hq:develop Jul 11, 2026
76 of 78 checks passed
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Jul 26, 2026
Tested on NetBSD 10 amd64 with 2026Q2 environment.

# Synapse 1.157.1 (2026-07-22)

# Synapse 1.157.0 (2026-07-21)

Please check [the relevant section in the upgrade notes](https://github.com/element-hq/synapse/blob/develop/docs/upgrade.md#upgrading-to-v11570) as this release removes support for the deprecated MSC3861 Auth Delegation (`experimental_features.msc3861`).

## Features

- [MSC4140: Cancellable delayed events](matrix-org/matrix-spec-proposals#4140): Limit how many delayed events a user may have scheduled at once. ([\#19539](element-hq/synapse#19539))
- Support [MSC4446](matrix-org/matrix-spec-proposals#4446) for moving fully read markers backwards. Contributed by @SpiritCroc @ Beeper. ([\#19663](element-hq/synapse#19663))
- Add before and after time filters to the ['Redact events of a user'](https://element-hq.github.io/synapse/v1.157/admin_api/user_admin_api.html#redact-events-of-a-user) Admin API. ([\#19802](element-hq/synapse#19802))
- Updated experimental support for [MSC4388: Secure out-of-band channel for sign in with QR](matrix-org/matrix-spec-proposals#4388). ([\#19808](element-hq/synapse#19808))
- Add an `exclude_rooms_from_presence` configuration option to stop presence being routed between users solely because they share one of the listed rooms. ([\#19935](element-hq/synapse#19935))

## Deprecations and Removals

- Remove support for experimental [MSC3861](matrix-org/matrix-spec-proposals#3861) auth delegation, in favour of the stable Matrix Authentication Service integration support. See [the upgrade notes](https://element-hq.github.io/synapse/v1.157/upgrade.html#upgrading-to-v11570). ([\#19895](element-hq/synapse#19895))
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.

2 participants