Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Replying to the same thread root multiple times throws error #14624

Closed
MadLittleMods opened this issue Dec 6, 2022 · 1 comment
Closed

Replying to the same thread root multiple times throws error #14624

MadLittleMods opened this issue Dec 6, 2022 · 1 comment
Labels
A-Threads Threaded messages

Comments

@MadLittleMods
Copy link
Contributor

MadLittleMods commented Dec 6, 2022

Description

Trying to create multiple thread replies against a thread root will throw M_UNKNOWN: Cannot start threads from an event with a relation.

This can happen in a variety of races:

  1. Two people send an event at the same time and the whoever races to finish first will be the one sent
  2. Your message fails to send, someone else sends a message in the mean-time and then when you retry, it fails
  3. One person's server doesn't have the latest event in the thread yet which already replied to the thread
    • I haven't tested this to see how it reconciles itself and looks for clients against the local and remote server after the dust settles. I know it won't be rejected over federation at least according to the MSC.
  4. Personally, I stumbled upon this while implementing threads with the Gitter bridge and didn't want to reference the latest message event in the thread (always reference the thread root).

I don't see this error scenario specifically mentioned in the threads MSC3440.

Steps to reproduce

  1. Create a message that will act as our thread root
  2. Send a threaded reply where ['m.relates_to']['event_id'] = thread_root
  3. Send another threaded reply where ['m.relates_to']['event_id'] = thread_root ❌ -> M_UNKNOWN: Cannot start threads from an event with a relation

Relevant code:

400, "Cannot start threads from an event with a relation"

Homeserver

...

Synapse Version

1.72.0

Installation Method

Docker (matrixdotorg/synapse)

Database

SQLite

Workers

Single process

Platform

N/A

Configuration

No response

Relevant log output

N/A

Anything else that would be useful to know?

No response

@MadLittleMods MadLittleMods added the A-Threads Threaded messages label Dec 6, 2022
@MadLittleMods
Copy link
Contributor Author

Sorry for the noise 🙇 This works as expected ✅

My bridge code was producing Matrix events with unexpected thread content where it actually was referencing the last event in the thread as the ['m.relates_to']['event_id'] reference (not correct).

Just to re-iterate the correct way:

{
  body: 'thread reply1',
  format: 'org.matrix.custom.html',
  formatted_body: 'thread reply1',
  msgtype: 'm.text',
  'm.relates_to': {
    rel_type: 'm.thread',
    // Always reference thread root for the thread
    event_id: '$foo',
    is_falling_back: true,
    'm.in_reply_to': {
      // The reply fallback should reference the last message in the thread
      // which will still be the thread root for the first reply
      event_id: '$foo'
    }
  }
}
{
  body: 'thread reply2',
  format: 'org.matrix.custom.html',
  formatted_body: 'thread reply2',
  msgtype: 'm.text',
  'm.relates_to': {
    rel_type: 'm.thread',
    // Always reference thread root for the thread
    event_id: '$foo',
    is_falling_back: true,
    'm.in_reply_to': {
      // But the reply fallback should reference the last message in the thread
      event_id: '$bar'
    }
  }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Threads Threaded messages
Projects
None yet
Development

No branches or pull requests

1 participant