Conversation
…s don't share crypto.db Under gateway.multiplex_profiles the gateway imports plugins/platforms/matrix/adapter.py once; the module-level _STORE_DIR/_CRYPTO_DB_PATH constants resolved against the root HERMES_HOME at import time, so every profile's Matrix adapter opened the SAME crypto.db. All bots' Olm identities landed in one store and inbound E2EE failed with 'Error decrypting megolm event, no session found'. Replace the module-level constants with per-instance _get_store_path() / _get_store_dir() that resolve through get_hermes_dir() at connect time. Each profile's adapter is created and connected inside _profile_runtime_scope, so the context-local HERMES_HOME override makes every profile resolve its own store dir. Mirrors the pairing-store migration (a6397c3). Adds tests asserting two profile homes resolve distinct crypto.db paths.
MrSuddenJoy
left a comment
There was a problem hiding this comment.
This code looks good to me. Well done 👍🏻
|
@MrSuddenJoy — follow-up on this PR from Michael Short. Thanks again for the review; the code hasn't changed since your pass. Current state as of now:
Could you formally approve and/or pass this to a maintainer for merge consideration? No code changes are pending from our side — if a rebase/merge of (Note: posting via automation on Michael Short's account — he will not self-merge.) |
@mjshorty thats because both other options are grayed out (not accessible) for me I have to be a contributor to have these 2 enabled.
@mjshorty I would love to, as I see well-crafted code on your side, but I'm not able to technically speaking. |
…import The multiplex gateway imports plugins/platforms/matrix/adapter.py once, so the module-level _STORE_DIR/_CRYPTO_DB_PATH resolved against the root HERMES_HOME for every profile: all bots' Olm identities landed in one crypto.db and inbound E2EE failed with "no session found" (#89168). connect() runs inside _profile_runtime_scope, so resolve the store dir there via get_hermes_dir (honors the context-local HERMES_HOME) and cache it on the instance -- diagnostics and error-log paths read outside the scope then still report the store actually in use. Mirrors the pairing-store fix (a6397c3). Salvage of #89169 (per-call resolvers collapsed into one cached resolve; dead `_CRYPTO_DB_PATH = None` alias dropped -- no external importers). Also routes the last raw MATRIX_HOMESERVER read in check_matrix_requirements through _startup_env_secret like its token/password neighbours (#69943). Fixes #89168 Co-authored-by: Michael Short <18595461+mjshorty@users.noreply.github.com>
…import The multiplex gateway imports plugins/platforms/matrix/adapter.py once, so the module-level _STORE_DIR/_CRYPTO_DB_PATH resolved against the root HERMES_HOME for every profile: all bots' Olm identities landed in one crypto.db and inbound E2EE failed with "no session found" (#89168). connect() runs inside _profile_runtime_scope, so resolve the store dir there via get_hermes_dir (honors the context-local HERMES_HOME) and cache it on the instance -- diagnostics and error-log paths read outside the scope then still report the store actually in use. Mirrors the pairing-store fix (a6397c3). Salvage of #89169 (per-call resolvers collapsed into one cached resolve; dead `_CRYPTO_DB_PATH = None` alias dropped -- no external importers). Also routes the last raw MATRIX_HOMESERVER read in check_matrix_requirements through _startup_env_secret like its token/password neighbours (#69943). Fixes #89168 Co-authored-by: Michael Short <18595461+mjshorty@users.noreply.github.com>
…import The multiplex gateway imports plugins/platforms/matrix/adapter.py once, so the module-level _STORE_DIR/_CRYPTO_DB_PATH resolved against the root HERMES_HOME for every profile: all bots' Olm identities landed in one crypto.db and inbound E2EE failed with "no session found" (#89168). connect() runs inside _profile_runtime_scope, so resolve the store dir there via get_hermes_dir (honors the context-local HERMES_HOME) and cache it on the instance -- diagnostics and error-log paths read outside the scope then still report the store actually in use. Mirrors the pairing-store fix (a6397c3). Salvage of #89169 (per-call resolvers collapsed into one cached resolve; dead `_CRYPTO_DB_PATH = None` alias dropped -- no external importers). Also routes the last raw MATRIX_HOMESERVER read in check_matrix_requirements through _startup_env_secret like its token/password neighbours (#69943). Fixes #89168 Co-authored-by: Michael Short <18595461+mjshorty@users.noreply.github.com>
…import The multiplex gateway imports plugins/platforms/matrix/adapter.py once, so the module-level _STORE_DIR/_CRYPTO_DB_PATH resolved against the root HERMES_HOME for every profile: all bots' Olm identities landed in one crypto.db and inbound E2EE failed with "no session found" (#89168). connect() runs inside _profile_runtime_scope, so resolve the store dir there via get_hermes_dir (honors the context-local HERMES_HOME) and cache it on the instance -- diagnostics and error-log paths read outside the scope then still report the store actually in use. Mirrors the pairing-store fix (a6397c3). Salvage of #89169 (per-call resolvers collapsed into one cached resolve; dead `_CRYPTO_DB_PATH = None` alias dropped -- no external importers). Also routes the last raw MATRIX_HOMESERVER read in check_matrix_requirements through _startup_env_secret like its token/password neighbours (#69943). Fixes #89168 Co-authored-by: Michael Short <18595461+mjshorty@users.noreply.github.com>
…import The multiplex gateway imports plugins/platforms/matrix/adapter.py once, so the module-level _STORE_DIR/_CRYPTO_DB_PATH resolved against the root HERMES_HOME for every profile: all bots' Olm identities landed in one crypto.db and inbound E2EE failed with "no session found" (#89168). connect() runs inside _profile_runtime_scope, so resolve the store dir there via get_hermes_dir (honors the context-local HERMES_HOME) and cache it on the instance -- diagnostics and error-log paths read outside the scope then still report the store actually in use. Mirrors the pairing-store fix (a6397c3). Salvage of #89169 (per-call resolvers collapsed into one cached resolve; dead `_CRYPTO_DB_PATH = None` alias dropped -- no external importers). Also routes the last raw MATRIX_HOMESERVER read in check_matrix_requirements through _startup_env_secret like its token/password neighbours (#69943). Fixes #89168 Co-authored-by: Michael Short <18595461+mjshorty@users.noreply.github.com>
…import The multiplex gateway imports plugins/platforms/matrix/adapter.py once, so the module-level _STORE_DIR/_CRYPTO_DB_PATH resolved against the root HERMES_HOME for every profile: all bots' Olm identities landed in one crypto.db and inbound E2EE failed with "no session found" (#89168). connect() runs inside _profile_runtime_scope, so resolve the store dir there via get_hermes_dir (honors the context-local HERMES_HOME) and cache it on the instance -- diagnostics and error-log paths read outside the scope then still report the store actually in use. Mirrors the pairing-store fix (a6397c3). Salvage of #89169 (per-call resolvers collapsed into one cached resolve; dead `_CRYPTO_DB_PATH = None` alias dropped -- no external importers). Also routes the last raw MATRIX_HOMESERVER read in check_matrix_requirements through _startup_env_secret like its token/password neighbours (#69943). Fixes #89168 Co-authored-by: Michael Short <18595461+mjshorty@users.noreply.github.com>
…import The multiplex gateway imports plugins/platforms/matrix/adapter.py once, so the module-level _STORE_DIR/_CRYPTO_DB_PATH resolved against the root HERMES_HOME for every profile: all bots' Olm identities landed in one crypto.db and inbound E2EE failed with "no session found" (#89168). connect() runs inside _profile_runtime_scope, so resolve the store dir there via get_hermes_dir (honors the context-local HERMES_HOME) and cache it on the instance -- diagnostics and error-log paths read outside the scope then still report the store actually in use. Mirrors the pairing-store fix (a6397c3). Salvage of #89169 (per-call resolvers collapsed into one cached resolve; dead `_CRYPTO_DB_PATH = None` alias dropped -- no external importers). Also routes the last raw MATRIX_HOMESERVER read in check_matrix_requirements through _startup_env_secret like its token/password neighbours (#69943). Fixes #89168 Co-authored-by: Michael Short <18595461+mjshorty@users.noreply.github.com>
|
Thanks @mjshorty — Merged via #101252 (2e25b47) on current main. Your commits from this PR were cherry-picked onto the salvage branch with your git authorship preserved, so the credit is yours in Closing this PR since the work is now on main. |
…import The multiplex gateway imports plugins/platforms/matrix/adapter.py once, so the module-level _STORE_DIR/_CRYPTO_DB_PATH resolved against the root HERMES_HOME for every profile: all bots' Olm identities landed in one crypto.db and inbound E2EE failed with "no session found" (NousResearch#89168). connect() runs inside _profile_runtime_scope, so resolve the store dir there via get_hermes_dir (honors the context-local HERMES_HOME) and cache it on the instance -- diagnostics and error-log paths read outside the scope then still report the store actually in use. Mirrors the pairing-store fix (a6397c3). Salvage of NousResearch#89169 (per-call resolvers collapsed into one cached resolve; dead `_CRYPTO_DB_PATH = None` alias dropped -- no external importers). Also routes the last raw MATRIX_HOMESERVER read in check_matrix_requirements through _startup_env_secret like its token/password neighbours (NousResearch#69943). Fixes NousResearch#89168 Co-authored-by: Michael Short <18595461+mjshorty@users.noreply.github.com>
Summary
Fixes #89168 — the Matrix crypto-store collision under the multiplex gateway.
Root cause:
plugins/platforms/matrix/adapter.pyresolves the crypto store at module scope:With
gateway.multiplex_profiles=true, the multiplexer is a single process that imports this module once;get_hermes_home()at import time resolves to the root~/.hermes. Every profile's Matrix adapter therefore opens the samecrypto.db— all bots' Olm identities collide in one store and inbound E2EE fails withError decrypting megolm event, no session found.Fix: replace the module-level constants with per-instance
_get_store_path()/_get_store_dir()that resolve throughget_hermes_dir()at connect time. Under multiplex, each profile's adapter is created and connected inside_profile_runtime_scope, so the context-local HERMES_HOME override makes every profile resolve its own store dir (<root>/profiles/<name>/platforms/matrix/store/crypto.db).This mirrors the existing pairing-store migration (
a6397c379— "fix(gateway): align multiplex pairing stores"), which fixed the identical module→per-instance bug for the pairing store.Changes
plugins/platforms/matrix/adapter.py_STORE_DIR/_CRYPTO_DB_PATHpath resolution.MatrixAdapter._get_store_path()(crypto.db) andMatrixAdapter._get_store_dir()(store dir for mkdir/legacy pickle cleanup), both resolving per-call throughget_hermes_dir.sqlite:///DB URL, E2EE-enabled log,crypto_store_pathstatus) to go through the instance methods._CRYPTO_DB_PATH = Noneas a back-compat import alias (no external callers read it, but the name was previously importable).tests/gateway/test_matrix_crypto_store_per_profile.py(new)crypto.dbpaths.Test Plan
Result: 121 passed. Also ran
test_multiplex_adapter_registry.py+test_multiplex_phase0.py(31 passed) — no multiplex regressions.(Note: the existing
TestMatrixRequirements::test_check_requirements_encryption_false_no_e2ee_deps_okfails locally when the host env exportsMATRIX_E2EE_MODE=requiredbecauseMATRIX_E2EE_MODEis not credential-shaped and survives the hermetic conftest scrub. It passes with the var unset. That is pre-existing test-env sensitivity, unrelated to this change.)Verification
set_hermes_home_override, the same contextvar the multiplexer uses).grep -n '_get_store_path' plugins/platforms/matrix/adapter.pyshows the new per-instance resolver.