MSC4140: update error responses - #19539
Conversation
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
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.
| raise ConfigError( | ||
| "Expected a positive value", ("max_event_delay_duration",) | ||
| ) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
267a7e5 rewords the error message to be a bit more descriptive, and to follow the same format used by similar errors in this module.
There was a problem hiding this comment.
Per the original intentions, I was more looking for something like this:
| 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: 100If we're going with 0 as a valid value to disable delayed events, I guess the updated error message works ⏩
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
This reverts commit f69ddc1. See element-hq#19539 (comment)
Do this as it is intuitive to want to configure a limit of 0 in order to disable delayed events. Update errors & config parsing as appropriate. Also raise the same error for whether the max allowed delay duration or the max number of delayed events is 0.
Ensure that, after reducing the limit of scheduled delayed events, that the number of existing delayed events will be greater than, not equal to, the new limit.
Co-authored-by: Eric Eastwood <madlittlemods@gmail.com>
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.
|
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) |
Co-authored-by: Eric Eastwood <madlittlemods@gmail.com>
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))
Pull Request Checklist
EventStoretoEventWorkerStore.".code blocks.