From 69f3aaa1d696bfe9fe8fd0633b3d265c60601f75 Mon Sep 17 00:00:00 2001 From: Siddharth Balyan <52913345+alt-glitch@users.noreply.github.com> Date: Sat, 11 Apr 2026 10:43:49 -0700 Subject: [PATCH] =?UTF-8?q?fix(matrix):=20pass=20required=20args=20to=20Me?= =?UTF-8?q?moryCryptoStore=20for=20mautrix=20=E2=89=A50.21=20(#7848)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(matrix): pass required args to MemoryCryptoStore for mautrix ≥0.21 MemoryCryptoStore.__init__() now requires account_id and pickle_key positional arguments as of mautrix 0.21. The migration from matrix-nio (commit 1850747) didn't account for this, causing E2EE initialization to fail with: MemoryCryptoStore.__init__() missing 2 required positional arguments: 'account_id' and 'pickle_key' Pass self._user_id as account_id and derive pickle_key from the same user_id:device_id pair already used for the on-disk HMAC signature. Update the test stub to accept the new parameters. Fixes #7803 * fix: use consistent fallback for pickle_key derivation Address review: _pickle_key now uses _acct_id (which has the 'hermes' fallback) instead of raw self._user_id, so both values stay consistent when user_id is empty. --------- Co-authored-by: Hermes Agent --- gateway/platforms/matrix.py | 11 ++++++++++- tests/gateway/test_matrix.py | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/gateway/platforms/matrix.py b/gateway/platforms/matrix.py index 409d2d6e4a..01a5a1b941 100644 --- a/gateway/platforms/matrix.py +++ b/gateway/platforms/matrix.py @@ -352,7 +352,16 @@ class MatrixAdapter(BasePlatformAdapter): from mautrix.crypto import OlmMachine from mautrix.crypto.store import MemoryCryptoStore - crypto_store = MemoryCryptoStore() + # account_id and pickle_key are required by mautrix ≥0.21. + # Use the Matrix user ID as account_id for stable identity. + # pickle_key secures in-memory serialisation; derive from + # the same user_id:device_id pair used for the on-disk HMAC. + _acct_id = self._user_id or "hermes" + _pickle_key = f"{_acct_id}:{self._device_id}" + crypto_store = MemoryCryptoStore( + account_id=_acct_id, + pickle_key=_pickle_key, + ) # Restore persisted crypto state from a previous run. # Uses HMAC to verify integrity before unpickling. diff --git a/tests/gateway/test_matrix.py b/tests/gateway/test_matrix.py index 469bae030e..6bf9862f0a 100644 --- a/tests/gateway/test_matrix.py +++ b/tests/gateway/test_matrix.py @@ -157,7 +157,9 @@ def _make_fake_mautrix(): mautrix_crypto_store = types.ModuleType("mautrix.crypto.store") class MemoryCryptoStore: - pass + def __init__(self, account_id="", pickle_key=""): + self.account_id = account_id + self.pickle_key = pickle_key mautrix_crypto_store.MemoryCryptoStore = MemoryCryptoStore