Skip to content

The agent that grows with you

docs(matrix): reconcile gate comment states the real premise

kshitijk4poorb98dd991424d
diff --git a/plugins/platforms/matrix/adapter.py b/plugins/platforms/matrix/adapter.py
index b3d7744e282..f25edf244df 100644
--- a/plugins/platforms/matrix/adapter.py
+++ b/plugins/platforms/matrix/adapter.py
@@ -2285,18 +2285,20 @@ class MatrixAdapter(BasePlatformAdapter):
for room_id, invited_room in invites.items():
if room_id in self._joined_rooms:
continue
- # A pending invite reconciled here (e.g. after a gateway
- # restart) never fires _on_invite, so the DM signal must be
- # read from the stripped invite state instead. Without it, a
- # direct invite joined via reconciliation is never recorded in
- # m.direct and gets misclassified as a group.
+ # This reconcile pass runs after _dispatch_sync and sees every
+ # rooms.invite entry, whether _on_invite joined it, rejected
+ # it, or (for invites that arrived while the gateway was down)
+ # is only now seeing it. The invite event object is gone by
+ # this point, so the DM signal must be read from the stripped
+ # invite state; without it a direct invite joined here is never
+ # recorded in m.direct and gets misclassified as a group.
is_direct, inviter = self._extract_invite_dm_signal(invited_room)
- # The inviter allowlist gate from _on_invite applies here too.
- # Without it, an invite from an arbitrary federated user that
- # arrives while the gateway is down would be auto-joined on
- # restart, bypassing the gate. An inviter missing from the
- # stripped invite state fails closed, like an empty sender in
- # _on_invite.
+ # The inviter allowlist gate from _on_invite must apply here
+ # too: an unconditional join would re-admit a live invite that
+ # _on_invite just rejected milliseconds earlier, and would
+ # auto-join any invite from an arbitrary federated user on
+ # restart. An inviter missing from the stripped invite state
+ # fails closed, like an empty sender in _on_invite.
if not self._is_authorized_user(inviter):
logger.warning(
"Matrix: rejecting invite to %s from unauthorized user %s",
diff --git a/tests/gateway/test_matrix_pending_invite_auth.py b/tests/gateway/test_matrix_pending_invite_auth.py
index b7feb2a4515..024e84325ac 100644
--- a/tests/gateway/test_matrix_pending_invite_auth.py
+++ b/tests/gateway/test_matrix_pending_invite_auth.py
@@ -1,11 +1,13 @@
"""Tests for the inviter allowlist gate on pending-invite reconciliation.
-``_on_invite`` only auto-joins when the inviter is allow-listed, but a
-pending invite reconciled from sync's ``rooms.invite`` after a gateway
-restart never fires ``_on_invite``. ``_schedule_pending_invite_joins``
+``_on_invite`` only auto-joins when the inviter is allow-listed, but the
+reconcile pass over sync's ``rooms.invite`` runs after event dispatch and
+sees every pending invite — including ones ``_on_invite`` just rejected,
+and ones that arrived while the gateway was down. An unconditional join
+there re-admitted rejected live invites milliseconds later and auto-joined
+arbitrary federated invites on restart. ``_schedule_pending_invite_joins``
must apply the same gate, reading the inviter from the stripped invite
-state, or an invite from an arbitrary federated user that arrives while
-the gateway is down gets auto-joined on restart.
+state.
"""
import time