Skip to content

The agent that grows with you

fix(pairing): purge revoked users from live allowlist sets in place

kshitijk4pooreafbe60bf958
diff --git a/gateway/pairing.py b/gateway/pairing.py
index 95d357e7438..cd01cd35179 100644
--- a/gateway/pairing.py
+++ b/gateway/pairing.py
@@ -216,11 +216,13 @@ def _sync_live_adapter_allowlist_remove(platform: str, user_id: str) -> None:
for attr in ("_allow_from", "_allowed_user_ids"):
if hasattr(adapter, attr):
with contextlib.suppress(Exception):
- setattr(
- adapter,
- attr,
- _purge_allowlist_entries(getattr(adapter, attr), platform_name, user_id),
- )
+ current = getattr(adapter, attr)
+ purged = _purge_allowlist_entries(current, platform_name, user_id)
+ if isinstance(current, set):
+ # In place: Discord approval views / VoiceReceiver hold this same set.
+ current.intersection_update(purged)
+ else:
+ setattr(adapter, attr, purged)
extra = getattr(getattr(adapter, "config", None), "extra", None)
if isinstance(extra, dict):
for key in ("allow_from", "allowed_users"):
diff --git a/tests/gateway/test_pairing_allowlist_bypass.py b/tests/gateway/test_pairing_allowlist_bypass.py
index c30c09ed32d..12aeb351700 100644
--- a/tests/gateway/test_pairing_allowlist_bypass.py
+++ b/tests/gateway/test_pairing_allowlist_bypass.py
@@ -397,9 +397,7 @@ def test_whatsapp_live_allowlist_denies_when_env_key_removed(monkeypatch):
@pytest.mark.asyncio
-async def test_matrix_pairing_revoke_denies_live_message_and_approval_without_restart(
- store, monkeypatch,
-):
+async def test_matrix_pairing_revoke_denies_live_message_and_approval_without_restart(store):
"""The runner's live pairing verdict must gate both Matrix messages and approvals."""
from unittest.mock import AsyncMock, patch
@@ -460,9 +458,7 @@ async def test_matrix_pairing_revoke_denies_live_message_and_approval_without_re
assert before_prompt.resolved is True
before_resolve.assert_called_once_with("session-$before", "once")
- adapter_identity = id(adapter)
assert store.revoke("matrix", user_id) is True
- assert id(adapter) == adapter_identity
assert store.is_approved("matrix", user_id) is False
assert runner._is_user_authorized(source) is False
@@ -504,6 +500,7 @@ def test_matrix_pairing_revoke_purges_live_allowlist_snapshot(store, monkeypatch
)
)
assert adapter._is_authorized_user(paired_id) is True
+ held = adapter._allowed_user_ids # e.g. a Discord approval view's reference
runner = SimpleNamespace(
adapters={Platform.MATRIX: adapter},
@@ -514,4 +511,5 @@ def test_matrix_pairing_revoke_purges_live_allowlist_snapshot(store, monkeypatch
assert store.revoke("matrix", paired_id) is True
assert os.environ["MATRIX_ALLOWED_USERS"] == owner_id
assert paired_id not in adapter._allowed_user_ids
+ assert paired_id not in held
assert adapter._is_authorized_user(paired_id) is False