Skip to content

MSC4140: schedule delayed events through the dedicated endpoint, and test finalised delayed events - #927

Closed
barodeur wants to merge 3 commits into
matrix-org:mainfrom
barodeur:msc4140-endpoint-and-finalised
Closed

barodeur wants to merge 3 commits into
matrix-org:mainfrom
barodeur:msc4140-endpoint-and-finalised

Conversation

@barodeur

@barodeur barodeur commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

This is a sister PR to element-hq/synapse#19354 and element-hq/synapse#19038

Supersedes #818

Dedicated endpoint

MSC4140 schedules delayed events with PUT /rooms/{roomId}/delayed_event/{eventType}/{txnId}, taking delay_ms, content and, for state events, state_key in the body. The tests in tests/msc4140 schedule delayed events with the org.matrix.msc4140.delay query parameter on /send and /state, which the MSC now lists as a rejected alternative.

This PR:

  • moves the existing tests to PUT /_matrix/client/unstable/org.matrix.msc4140/rooms/{roomId}/delayed_event/{eventType}/{txnId}, and drops the query parameter form
  • adds tests to ensure
    • the endpoint is transactional: the same txnId gives back the same delay_id
    • a missing, zero or negative delay_ms is rejected with a 400

Finalised delayed events

The MSC keeps delayed events once they are finalised: sent, cancelled by the user, or cancelled due to an error. GET /delayed_events/{delay_id} describes the outcome in a finalised object, and a management action on a finalised delayed event succeeds if it matches the outcome, or answers 409 if it conflicts with it.

This PR adds tests to ensure

  • the lookup of a finalised delayed event has
    • finalised.event_id set to the event seen in the room, and no error, once sent on timeout
    • neither event_id nor error once cancelled, and no finalised object while still scheduled
    • finalised.error with an errcode, and no event_id, once it failed to be sent because its sender left the room
  • a repeated send on a sent delayed event, or cancel on a cancelled one, returns 200, as does cancel on one that failed to be sent
  • cancel on a sent delayed event, and send or restart on a cancelled one, return 409
  • restart on a sent delayed event returns 409; MSC4140 leaves this case open, and MSC4542 proposes a 409
  • another user looking up a finalised delayed event gets a 404
  • GET /delayed_events still lists scheduled delayed events only

These tests need the updates in element-hq/synapse#20229, which builds on element-hq/synapse#19038

Signed-off-by: Paul Chobert paul@chobert.fr

MSC4140 schedules delayed events with
`PUT /rooms/{roomId}/delayed_event/{eventType}/{txnId}`, taking `delay_ms`,
`content` and, for state events, `state_key` in the body. Scheduling
through the `org.matrix.msc4140.delay` query parameter on `/send` and
`/state` is now one of the MSC's rejected alternatives.

Schedule every delayed event through the unstable form of the endpoint,
giving state events a transaction ID of their own. The existing
"same txnID" subtest now checks that the endpoint is transactional, and
the state event tests check that a state event scheduled through it
lands as room state. A new test checks that a missing, zero or negative
`delay_ms` is rejected with a 400.

One test still schedules a message event and a state event through the
query parameter, so that form stays covered until homeservers drop it.

Signed-off-by: Paul Chobert <paul@chobert.fr>
MSC4140 keeps delayed events once they are finalised: sent, cancelled
by the user, or cancelled due to an error. `GET /delayed_events/{delay_id}`
describes the outcome in a `finalised` object, with `finalised_ts`, plus
`event_id` if the event was sent or `error` if sending it failed. A
management action on a finalised delayed event succeeds if it matches
the outcome, and answers 409 if it conflicts with it.

Add tests for:
- the lookup of a delayed event sent on timeout, cancelled, or that
  failed to be sent because its sender left the room
- a 200 for a repeated `send` or `cancel`, including `cancel` on a
  delayed event that failed to be sent
- a 409 for `cancel` on a sent delayed event, and for `send` or
  `restart` on a cancelled one
- a 409 for `restart` on a sent delayed event, which MSC4140 leaves
  open and MSC4542 proposes
- a 404 when another user looks up a finalised delayed event
- the bulk `GET /delayed_events` still listing scheduled delayed events
  only

Signed-off-by: Paul Chobert <paul@chobert.fr>
@barodeur barodeur changed the title MSC4140: schedule delayed events through the dedicated endpoint MSC4140: schedule delayed events through the dedicated endpoint, and test finalised delayed events Sep 25, 2026
@barodeur

Copy link
Copy Markdown
Contributor Author

I'm likely going to split this PR in two

@barodeur barodeur closed this Sep 25, 2026
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.

1 participant