Resolve reaction/reply targets across all XMPP message ID forms #3

Merged
skunky merged 2 commits from reaction-id-aliases into main 2026-11-08 20:00:51 +00:00
Owner

Problem

Reactions (XEP-0444), replies (XEP-0461), edits (XEP-0308), retractions (XEP-0424) and read markers (XEP-0333) from XMPP clients were still dropped with Target message for reaction not found even after #1.

Root cause: the bridge stores each message under exactly one ID form (oid:<origin-id> / id:<id attribute> / sid:<stanza-id>), while remote clients reference whichever form they saw — usually the room-distributed id attribute, sometimes a stanza-id. When those differ, the lookup finds nothing and the event is queued with a prefixedFallback ID that can never match.

Fix

  • Forward aliases: every identifier form observed on the wire (id attribute, origin-id, all stanza-ids) is recorded as an alias of the stored message ID — volatile roomIDCache + durable kv_store (xmpp/roomid/<room>/<raw>). resolveMessageID consults the volatile cache, then the durable aliases, then the DB forms.
  • Reverse mapping: MessageMetadata.RoomID is now set at convert time for MUC messages (the distributed id attribute) and backfilled into the DB row when our own MUC reflections arrive; rawIDForOutgoingReference (replies, reactions, edits, retractions, read receipts from Matrix) prefers it, then the reverse alias (xmpp/roomraw/<room>/<stored>), then the stored value — so references bridged from Matrix use the form other XMPP clients actually see.
  • Own outgoing messages record the reverse mapping at send time, so they are referenceable even if the room reflection is missed.
  • MAM: aliases are recorded after the archive-ID override, so history/backfilled messages resolve as well.

Also updates AGENTS.md with the alias architecture and adds tests for alias recording/resolution, outgoing reference selection and MUC metadata.

Testing

  • go build ./..., go vet ./..., go test ./... pass (new tests in reactions_test.go).
  • After deploying: reacting to and replying to messages whose origin-id differs from the id attribute (or reacting via stanza-id) must produce Matrix reactions/replies instead of Target message for reaction not found warnings; the same must work for messages fetched by MAM backfill.
## Problem Reactions (XEP-0444), replies (XEP-0461), edits (XEP-0308), retractions (XEP-0424) and read markers (XEP-0333) from XMPP clients were still dropped with `Target message for reaction not found` even after #1. Root cause: the bridge stores each message under exactly **one** ID form (`oid:<origin-id>` / `id:<id attribute>` / `sid:<stanza-id>`), while remote clients reference whichever form they saw — usually the room-distributed `id` attribute, sometimes a stanza-id. When those differ, the lookup finds nothing and the event is queued with a `prefixedFallback` ID that can never match. ## Fix - **Forward aliases**: every identifier form observed on the wire (id attribute, origin-id, all stanza-ids) is recorded as an alias of the stored message ID — volatile `roomIDCache` + durable `kv_store` (`xmpp/roomid/<room>/<raw>`). `resolveMessageID` consults the volatile cache, then the durable aliases, then the DB forms. - **Reverse mapping**: `MessageMetadata.RoomID` is now set at convert time for MUC messages (the distributed id attribute) and backfilled into the DB row when our own MUC reflections arrive; `rawIDForOutgoingReference` (replies, reactions, edits, retractions, read receipts from Matrix) prefers it, then the reverse alias (`xmpp/roomraw/<room>/<stored>`), then the stored value — so references bridged from Matrix use the form other XMPP clients actually see. - **Own outgoing messages** record the reverse mapping at send time, so they are referenceable even if the room reflection is missed. - **MAM**: aliases are recorded after the archive-ID override, so history/backfilled messages resolve as well. Also updates AGENTS.md with the alias architecture and adds tests for alias recording/resolution, outgoing reference selection and MUC metadata. ## Testing - `go build ./...`, `go vet ./...`, `go test ./...` pass (new tests in `reactions_test.go`). - After deploying: reacting to and replying to messages whose origin-id differs from the id attribute (or reacting via stanza-id) must produce Matrix reactions/replies instead of `Target message for reaction not found` warnings; the same must work for messages fetched by MAM backfill.
Resolve reaction/reply targets across all XMPP message ID forms
Some checks failed
CI / test (pull_request) Has been cancelled
2f5bcb0da0
XMPP clients are free to reference a message by its id attribute, its
origin-id or a server-assigned stanza-id, while the bridge stored the
message under exactly one of those forms. Reactions (XEP-0444), replies
(XEP-0461), edits (XEP-0308), retractions (XEP-0424) and read markers
(XEP-0333) targeting such messages were dropped with "Target message
for reaction not found" whenever the referenced form differed from the
stored one.

Every identifier form observed on the wire is now recorded as an alias
of the stored message ID, both in a volatile cache and durably in the
kv_store (xmpp/roomid/<room>/<raw>), and resolveMessageID consults the
aliases before falling back to the database. The reverse mapping
(xmpp/roomraw/<room>/<stored>, plus MessageMetadata.RoomID set at
convert time and backfilled from own MUC reflections) makes replies,
reactions, edits and read receipts bridged from Matrix use the form
other XMPP clients actually see. Own outgoing MUC messages record the
reverse mapping at send time as well.

MAM-fetched messages record their aliases after the archive ID
override, so history messages resolve too.
Clarify resolveMessageID resolution order in docs
Some checks failed
CI / test (pull_request) Has been cancelled
b73557acaa
skunky merged commit a6689fa306 into main 2026-11-08 20:00:51 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
xmpp-bridge/mautrix-xmpp!3
No description provided.