Skip to content

fix(tools): route encrypted matrix send_message through adapter - #23382

Closed
32r4 wants to merge 1 commit into
NousResearch:mainfrom
32r4:fix/23055-matrix-send-message-e2ee
Closed

fix(tools): route encrypted matrix send_message through adapter#23382
32r4 wants to merge 1 commit into
NousResearch:mainfrom
32r4:fix/23055-matrix-send-message-e2ee

Conversation

@32r4

@32r4 32r4 commented May 10, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes Matrix send_message delivery for encrypted rooms. Before this change, text-only Matrix sends used the lightweight direct /_matrix/client/v3/rooms/.../send/m.room.message/... path, which bypassed the gateway's mautrix E2EE client and caused plaintext sends to fail in encrypted rooms. This PR routes encrypted Matrix sends through the adapter path that already handles E2EE correctly, while preserving the lightweight direct send path for non-E2EE text-only sends.

Related Issue

Fixes #23055

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • Updated tools/send_message_tool.py so Matrix sends use _send_matrix_via_adapter() whenever media is attached or Matrix encryption is enabled.
  • Preserved the existing lightweight direct REST send path for text-only Matrix sends when E2EE is disabled.
  • Updated _send_matrix_via_adapter() to reuse the live gateway Matrix adapter when available before creating a temporary adapter instance.
  • Added regression tests for:
    • text-only Matrix sends staying on the lightweight path when encryption is disabled
    • text-only Matrix sends using the adapter path when encryption is enabled
    • reusing the live Matrix gateway adapter
  • Fixed an existing cross-platform test issue by switching a Matrix media test from a hardcoded /tmp/... path to tmp_path, so it passes on Windows.

How to Test

  1. Configure Matrix with MATRIX_ENCRYPTION=true and a reachable encrypted room.
  2. Use send_message to send a text-only message to that Matrix target.
  3. Confirm the message is delivered successfully via the adapter/E2EE path instead of the bare client-server m.room.message REST send.
  4. Run automated coverage:
    • uv run pytest -q tests/tools/test_send_message_tool.py -q
    • uv run pytest -q tests/tools/test_send_message_missing_platforms.py -q

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Windows 11

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

  • Verified with targeted uv run pytest coverage for the affected Matrix send_message paths.
  • Note: pytest emits a Windows temp-directory cleanup PermissionError at interpreter exit in this environment; the test runs themselves complete successfully.

@alt-glitch alt-glitch added type/bug Something isn't working comp/tools Tool registry, model_tools, toolsets platform/matrix Matrix adapter (E2EE) P2 Medium — degraded but workaround exists labels May 10, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #20259 — same fix (route text-only Matrix send_message through adapter when E2EE is enabled). Same files changed, same approach.

@teknium1

teknium1 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Closing as a duplicate of #20259, which fixed the same text-only Matrix E2EE routing bug and was submitted first (May 5 vs your May 10). Merged via PR #56106 (commit a537baa on main).

Both approaches route text-only Matrix sends through the adapter; #20259 routes unconditionally, which is simpler and correct since the adapter sends plaintext to unencrypted rooms fine. Thanks for the contribution and the extra live-adapter-reuse test coverage — appreciated.

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

Labels

comp/tools Tool registry, model_tools, toolsets P2 Medium — degraded but workaround exists 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]: send_message Matrix path posts plaintext events into encrypted rooms

3 participants