Skip to content

fix(matrix,gateway): Matrix E2EE installs full dep set; plugins respect is_connected - #31688

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-3cbc992b
May 24, 2026
Merged

teknium1 merged 1 commit into
mainfrom
hermes/hermes-3cbc992b

Conversation

@teknium1

@teknium1 teknium1 commented May 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fresh-install Matrix gateway now connects with E2EE, and plugin platforms (Discord/Teams/Google Chat) no longer auto-enable themselves uninvited. Closes #31116.

Two distinct bugs surfaced by the reporter:

1. Matrix E2EE missing 4 of 5 deps.
The setup wizard installed only `mautrix[encryption]`, leaving `asyncpg`, `aiosqlite`, `Markdown`, and `aiohttp-socks` uninstalled. `MatrixAdapter.connect()` uses `PgCryptoStore` (needs asyncpg) and `Database.create("sqlite:///...")` (needs aiosqlite), so the first encrypted connect failed with `No module named 'asyncpg'`. The runtime guard `check_matrix_requirements()` short-circuited the lazy installer on `import mautrix` alone, so the missing 4 packages were never pulled in. `_check_e2ee_deps()` only tested `OlmMachine` import, so health-checks reported "all good" while connect kept crashing.

2. Discord auto-enabled uninvited.
`gateway/config.py` plugin-enablement loop gated `enabled=True` on `entry.check_fn()` alone ("is the SDK importable?") and ignored `entry.is_connected` ("did the user configure credentials?"). Same bug class as commit 7849a3d fixed for `_platform_status` in the setup wizard; this is the runtime counterpart. Affects every plugin that registers both hooks — Discord, Teams, Google Chat.

Changes

  • `hermes_cli/setup.py::_setup_matrix` — install via `lazy_deps.ensure("platform.matrix")` so the full feature group lands. Legacy single-package fallback kept for the edge case where `tools.lazy_deps` itself fails to import.
  • `gateway/platforms/matrix.py::_check_e2ee_deps` — verify `asyncpg` + `aiosqlite` + `PgCryptoStore` in addition to `OlmMachine`, so E2EE failures surface at startup instead of at first encrypted-room connect.
  • `gateway/platforms/matrix.py::check_matrix_requirements` — use `feature_missing("platform.matrix")` as the install gate instead of a single `import mautrix` check, so partial installs trigger the lazy installer.
  • `gateway/config.py` plugin-enablement loop — consult `entry.is_connected` before flipping `enabled=True`. Explicit YAML `enabled: true` still wins (user override).

Tests

3 new in `tests/gateway/test_matrix.py`:

  • `test_check_e2ee_deps_requires_asyncpg` — blocks asyncpg import, asserts False
  • `test_check_e2ee_deps_requires_aiosqlite` — blocks aiosqlite import, asserts False
  • `test_check_requirements_runs_lazy_install_when_partial` — partial install must call `ensure_and_bind`

5 new in `tests/gateway/test_platform_registry.py` (new `TestPluginEnablementGate` class):

  • `is_connected=False` blocks enablement
  • `is_connected=True` still enables
  • `is_connected=None` falls back to `check_fn` (legacy plugins keep working)
  • Raising probe doesn't enable (defensive)
  • Explicit YAML `enabled: true` wins over `is_connected=False`

Validation

Result
`tests/gateway/test_matrix.py::TestMatrixRequirements` 9/9 pass
`tests/gateway/test_platform_registry.py` 48/48 pass
`test_matrix + test_config + test_platform_registry + test_discord_connect` 262/262 pass
`tests/hermes_cli/test_setup.py + test_gateway_platform_gating.py` 23/23 pass
E2E hermetic — no `DISCORD_BOT_TOKEN` set discord NOT enabled ✓
E2E hermetic — `DISCORD_BOT_TOKEN` set discord enabled ✓
E2E — `_check_e2ee_deps()` with all 5 deps installed returns True ✓
E2E — `check_matrix_requirements()` with no creds returns False ✓

Infographic

matrix-gateway-fresh-install-fix

…ct is_connected

Fixes #31116 — two distinct bugs in fresh-install Matrix gateway:

1. Matrix E2EE setup installed only mautrix[encryption], leaving asyncpg
   / aiosqlite / Markdown / aiohttp-socks uninstalled. The first encrypted
   connect failed with 'No module named asyncpg' deep inside
   MatrixAdapter.connect(). Root cause: the setup wizard hand-rolled a
   pip install of one package instead of using lazy_deps.ensure(
   'platform.matrix'), and check_matrix_requirements() short-circuited the
   runtime installer on 'import mautrix' alone — so the other 4 packages
   were never pulled in.

2. Discord auto-enabled itself on every gateway start, even when the user
   never selected Discord and had no DISCORD_BOT_TOKEN. Root cause:
   gateway/config.py plugin-enablement loop gated enablement on
   entry.check_fn() (just 'is the SDK importable?') and ignored
   entry.is_connected (the 'did the user configure credentials?' probe).
   Same bug class as commit 7849a3d fixed for _platform_status in the
   setup wizard; this is the runtime counterpart. Affects Discord, Teams,
   and Google Chat.

Changes:
- hermes_cli/setup.py::_setup_matrix — install via
  lazy_deps.ensure('platform.matrix') to pull the full feature group.
- gateway/platforms/matrix.py::_check_e2ee_deps — verify asyncpg +
  aiosqlite + PgCryptoStore in addition to OlmMachine, so E2EE failures
  surface at startup instead of at first encrypted-room connect.
- gateway/platforms/matrix.py::check_matrix_requirements — use
  feature_missing('platform.matrix') as the install gate instead of a
  single 'import mautrix' check, so partial installs trigger the lazy
  installer correctly.
- gateway/config.py plugin-enablement loop — consult entry.is_connected
  before flipping enabled=True. Explicit YAML enabled=true still wins.

Tests: 3 new in tests/gateway/test_matrix.py (asyncpg-required,
aiosqlite-required, partial-install lazy-runs), 5 new in
tests/gateway/test_platform_registry.py (is_connected=False blocks,
is_connected=True enables, is_connected=None falls back to check_fn,
raising probe doesn't enable, explicit YAML wins).

Validation: 310 tests across affected test modules pass.
@github-actions

Copy link
Copy Markdown
Contributor

🚨 CRITICAL Supply Chain Risk Detected

This PR contains a pattern that has been used in real supply chain attacks. A maintainer must review the flagged code carefully before merging.

🚨 CRITICAL: Install-hook file added or modified

These files can execute code during package installation or interpreter startup.

Files:

hermes_cli/setup.py

Scanner only fires on high-signal indicators: .pth files, base64+exec/eval combos, subprocess with encoded commands, or install-hook files. Low-signal warnings were removed intentionally — if you're seeing this comment, the finding is worth inspecting.

@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-3cbc992b vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 9091 on HEAD, 9088 on base (🆕 +3)

🆕 New issues (3):

Rule Count
unresolved-import 2
invalid-assignment 1
First entries
gateway/platforms/matrix.py:272: [invalid-assignment] invalid-assignment: Object of type `None` is not assignable to `def ensure_and_bind(feature: str, importer: () -> dict[str, Any], target_globals: dict[Unknown, Unknown], *, prompt: bool = False) -> bool`
gateway/platforms/matrix.py:232: [unresolved-import] unresolved-import: Cannot resolve imported module `asyncpg`
gateway/platforms/matrix.py:233: [unresolved-import] unresolved-import: Cannot resolve imported module `aiosqlite`

✅ Fixed issues (1):

Rule Count
unresolved-import 1
First entries
gateway/platforms/matrix.py:243: [unresolved-import] unresolved-import: Cannot resolve imported module `mautrix`

Unchanged: 4838 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@teknium1
teknium1 merged commit 54e61f9 into main May 24, 2026
25 of 26 checks passed
@teknium1
teknium1 deleted the hermes/hermes-3cbc992b branch May 24, 2026 22:16
@alt-glitch alt-glitch added P1 High — major feature broken, no workaround type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery comp/cli CLI entry point, hermes_cli/, setup wizard platform/matrix Matrix adapter (E2EE) platform/discord Discord bot adapter labels May 24, 2026
@alt-glitch

Copy link
Copy Markdown
Contributor

Supersedes #31236 — same two-bug fix (Matrix E2EE deps + Discord auto-enable) cherry-picked by maintainer onto current main and merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery P1 High — major feature broken, no workaround platform/discord Discord bot adapter platform/matrix Matrix adapter (E2EE) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Matrix gateway configuration on a fresh install does not install properly

2 participants