Monitoring Plugin (MAM) — doubled/quadrupled messages after relogin

Hello.

I’m getting duplicate messages in 1:1 chats (but not in MUC rooms) after restarting a client or logging out and back in. It happens with both Gajim and Conversatons, so it is probably not client-specific. Sometimes it’s two of the same message, sometimes four.

The issue seems to be related with the monitoring plugin, as it stops if I remove the plugin. I don’t remember changing any settings for the monitoring plugin from default, apart from making sure that all the checkboxes are enabled.

I tried to look into the protocol log on the client, and the same message was indeed received four time from the server.

(user2@example.org sends two messages to user1@example.com: “320test” and “321test”. The former doubled, the latter quadrupled.)

Спойлер
<!-- Incoming Thu 20 Jun 2024 01:19:45 PM +07 (user1@example.com) -->
<message xmlns="jabber:client" from="user2@example.org/gajim.XXXXXXXX" to="user1@example.com" xml:lang="en" type="chat" id="340df5e9-3ecf-48cd-8069-2c65202d60d9">
  <body>320test</body>
  <origin-id xmlns="urn:xmpp:sid:0" id="340df5e9-3ecf-48cd-8069-2c65202d60d9" />
  <request xmlns="urn:xmpp:receipts" />
  <active xmlns="http://jabber.org/protocol/chatstates" />
  <markable xmlns="urn:xmpp:chat-markers:0" />
</message>


<!-- Incoming Thu 20 Jun 2024 01:19:49 PM +07 (user1@example.com) -->
<message xmlns="jabber:client" from="user2@example.org/gajim.XXXXXXXX" to="user1@example.com" xml:lang="en" type="chat" id="bc6b3162-2971-422a-a50d-998fc42994de">
  <body>321test</body>
  <origin-id xmlns="urn:xmpp:sid:0" id="bc6b3162-2971-422a-a50d-998fc42994de" />
  <request xmlns="urn:xmpp:receipts" />
  <active xmlns="http://jabber.org/protocol/chatstates" />
  <markable xmlns="urn:xmpp:chat-markers:0" />
</message>


<!-- I relogined here -->


<!-- Outgoing Thu 20 Jun 2024 01:20:25 PM +07 (user1@example.com) -->
<iq xmlns="jabber:client" to="user1@example.com" type="set" id="0396c955-c892-4e34-af61-e096dda9054e">
  <query xmlns="urn:xmpp:mam:2" queryid="410d78b8-5190-4ad3-bd58-f1d85131c771">
    <x xmlns="jabber:x:data" type="submit">
      <field type="hidden" var="FORM_TYPE">
        <value>urn:xmpp:mam:2</value>
      </field>
    </x>
    <set xmlns="http://jabber.org/protocol/rsm">
      <max>70</max>
      <after>2040</after>
    </set>
  </query>
</iq>


<!-- Incoming Thu 20 Jun 2024 01:20:25 PM +07 (user1@example.com) -->
<message xmlns="jabber:client" from="user2@example.org/gajim.AJWQJWI3" to="user1@example.com" xml:lang="en" type="chat" id="bc6b3162-2971-422a-a50d-998fc42994de">
  <body>321test</body>
  <origin-id xmlns="urn:xmpp:sid:0" id="bc6b3162-2971-422a-a50d-998fc42994de" />
  <request xmlns="urn:xmpp:receipts" />
  <active xmlns="http://jabber.org/protocol/chatstates" />
  <markable xmlns="urn:xmpp:chat-markers:0" />
  <delay xmlns="urn:xmpp:delay" stamp="2024-06-20T06:19:49.306Z" from="example.com" />
</message>


<!-- Incoming Thu 20 Jun 2024 01:20:26 PM +07 (user1@example.com) -->
<message xmlns="jabber:client" to="user1@example.com/gajim.YYYYYYYY">
  <result xmlns="urn:xmpp:mam:2" queryid="410d78b8-5190-4ad3-bd58-f1d85131c771" id="2041">
    <forwarded xmlns="urn:xmpp:forward:0">
      <delay xmlns="urn:xmpp:delay" stamp="2024-06-20T06:19:46.016Z" />
      <message xmlns="jabber:client" from="user2@example.org/gajim.XXXXXXXX" to="user1@example.com" xml:lang="en" type="chat" id="340df5e9-3ecf-48cd-8069-2c65202d60d9">
        <body>320test</body>
        <origin-id xmlns="urn:xmpp:sid:0" id="340df5e9-3ecf-48cd-8069-2c65202d60d9" />
        <request xmlns="urn:xmpp:receipts" />
        <active xmlns="http://jabber.org/protocol/chatstates" />
        <markable xmlns="urn:xmpp:chat-markers:0" />
</message>
</forwarded>
</result>
</message>


<!-- Incoming Thu 20 Jun 2024 01:20:26 PM +07 (user1@example.com) -->
<message xmlns="jabber:client" to="user1@example.com/gajim.YYYYYYYY">
  <result xmlns="urn:xmpp:mam:2" queryid="410d78b8-5190-4ad3-bd58-f1d85131c771" id="2042">
    <forwarded xmlns="urn:xmpp:forward:0">
      <delay xmlns="urn:xmpp:delay" stamp="2024-06-20T06:19:49.306Z" />
      <message xmlns="jabber:client" from="user2@example.org/gajim.XXXXXXXX" to="user1@example.com" xml:lang="en" type="chat" id="bc6b3162-2971-422a-a50d-998fc42994de">
        <body>321test</body>
        <origin-id xmlns="urn:xmpp:sid:0" id="bc6b3162-2971-422a-a50d-998fc42994de" />
        <request xmlns="urn:xmpp:receipts" />
        <active xmlns="http://jabber.org/protocol/chatstates" />
        <markable xmlns="urn:xmpp:chat-markers:0" />
</message>
</forwarded>
</result>
</message>


<!-- Incoming Thu 20 Jun 2024 01:20:26 PM +07 (user1@example.com) -->
<message xmlns="jabber:client" to="user1@example.com/gajim.YYYYYYYY">
  <result xmlns="urn:xmpp:mam:2" queryid="410d78b8-5190-4ad3-bd58-f1d85131c771" id="2043">
    <forwarded xmlns="urn:xmpp:forward:0">
      <delay xmlns="urn:xmpp:delay" stamp="2024-06-20T06:20:02.950Z" />
      <message xmlns="jabber:client" from="user2@example.org/gajim.XXXXXXXX" to="user1@example.com" xml:lang="en" type="chat" id="bc6b3162-2971-422a-a50d-998fc42994de">
        <body>321test</body>
        <origin-id xmlns="urn:xmpp:sid:0" id="bc6b3162-2971-422a-a50d-998fc42994de" />
        <request xmlns="urn:xmpp:receipts" />
        <active xmlns="http://jabber.org/protocol/chatstates" />
        <markable xmlns="urn:xmpp:chat-markers:0" />
        <delay xmlns="urn:xmpp:delay" stamp="2024-06-20T06:19:49.306Z" from="example.com" />
</message>
</forwarded>
</result>
</message>


<!-- Incoming Thu 20 Jun 2024 01:20:26 PM +07 (user1@example.com) -->
<iq xmlns="jabber:client" type="result" id="0396c955-c892-4e34-af61-e096dda9054e" from="user1@example.com" to="user1@example.com/gajim.YYYYYYYY">
  <fin xmlns="urn:xmpp:mam:2" queryid="410d78b8-5190-4ad3-bd58-f1d85131c771" complete="true">
    <set xmlns="http://jabber.org/protocol/rsm">
      <first>2041</first>
      <last>2043</last>
      <count>220</count>
</set>
</fin>
</iq>

I have cut everything that didn’t seem related for reading convenience. I’m not fluent with XMPP, so I could miss something important. I can upload the full protocol log if required.

Is it maybe a normal server behavior and it’s client’s responsibility to check for duplicates? Or maybe client request was somehow incorrect? Or is it something that can be fixed on the server side?