Skip to content

fix: add direct Matrix cron delivery support#3767

Closed
chalkers wants to merge 3 commits intoNousResearch:mainfrom
chalkers:fix/matrix-cron-delivery
Closed

fix: add direct Matrix cron delivery support#3767
chalkers wants to merge 3 commits intoNousResearch:mainfrom
chalkers:fix/matrix-cron-delivery

Conversation

@chalkers
Copy link
Copy Markdown
Contributor

Summary

  • add direct Matrix support to send_message_tool so cron/send_message deliveries no longer fail with Direct sending not yet implemented for matrix
  • cover the one-shot Matrix send path with regression tests for successful delivery and adapter-connect failure

Testing

  • python -m pytest tests/tools/test_send_message_tool.py -q

Notes

  • This fixes cron delivery to Matrix targets/origin chats by wiring Platform.MATRIX through the existing send-message routing layer.

@chalkers
Copy link
Copy Markdown
Contributor Author

Follow-up update pushed to this PR: while testing the original Matrix direct-send fix in a live encrypted Matrix DM, I hit E2EE self-decrypt/session-mismatch issues when cron delivery created a second transient Matrix client. This PR now reuses the running gateway adapter/event loop for cron Matrix delivery when available, and falls back to the one-shot sender only when no live adapter context exists. Added regression coverage in tests/cron/test_scheduler.py.

@chalkers chalkers force-pushed the fix/matrix-cron-delivery branch from 3a5cbd6 to 08f0d4c Compare March 29, 2026 18:43
teknium1 added a commit that referenced this pull request Apr 5, 2026
…origin fallback

Salvaged from PRs #3767 (chalkers), #5236 (ygd58), #2641 (buntingszn).

Three improvements to Matrix cron delivery:

1. Live adapter path: when the gateway is running, cron delivery now uses
   the connected MatrixAdapter via run_coroutine_threadsafe instead of
   the standalone HTTP PUT. This enables delivery to E2EE rooms where
   the raw HTTP path cannot encrypt. Falls back to standalone on failure.
   Threads adapters + event loop from gateway -> cron ticker -> tick() ->
   _deliver_result(). (from #3767)

2. HTML formatted_body: _send_matrix() now converts markdown to HTML
   using the optional markdown library, with h1-h6 to bold conversion
   for Element X compatibility. Falls back to plain text if markdown
   is not installed. Also adds random bytes to txn_id to prevent
   collisions. (from #5236)

3. Origin fallback: when deliver="origin" but origin is null (jobs
   created via API/scripts), falls back to HOME_CHANNEL env vars
   in order: matrix -> telegram -> discord -> slack. (from #2641)
@teknium1
Copy link
Copy Markdown
Contributor

teknium1 commented Apr 5, 2026

The live adapter cron delivery path from your PR was incorporated into PR #5271 — cron delivery now uses the connected gateway adapter for E2EE support, falling back to standalone HTTP. Your cron delivery architecture was the right approach. Thanks!

@teknium1 teknium1 closed this Apr 5, 2026
teknium1 added a commit that referenced this pull request Apr 5, 2026
…origin fallback

Salvaged from PRs #3767 (chalkers), #5236 (ygd58), #2641 (buntingszn).

Three improvements to Matrix cron delivery:

1. Live adapter path: when the gateway is running, cron delivery now uses
   the connected MatrixAdapter via run_coroutine_threadsafe instead of
   the standalone HTTP PUT. This enables delivery to E2EE rooms where
   the raw HTTP path cannot encrypt. Falls back to standalone on failure.
   Threads adapters + event loop from gateway -> cron ticker -> tick() ->
   _deliver_result(). (from #3767)

2. HTML formatted_body: _send_matrix() now converts markdown to HTML
   using the optional markdown library, with h1-h6 to bold conversion
   for Element X compatibility. Falls back to plain text if markdown
   is not installed. Also adds random bytes to txn_id to prevent
   collisions. (from #5236)

3. Origin fallback: when deliver="origin" but origin is null (jobs
   created via API/scripts), falls back to HOME_CHANNEL env vars
   in order: matrix -> telegram -> discord -> slack. (from #2641)
@chalkers chalkers deleted the fix/matrix-cron-delivery branch April 5, 2026 22:38
Tommyeds pushed a commit to Tommyeds/hermes-agent that referenced this pull request Apr 12, 2026
…origin fallback

Salvaged from PRs NousResearch#3767 (chalkers), NousResearch#5236 (ygd58), NousResearch#2641 (buntingszn).

Three improvements to Matrix cron delivery:

1. Live adapter path: when the gateway is running, cron delivery now uses
   the connected MatrixAdapter via run_coroutine_threadsafe instead of
   the standalone HTTP PUT. This enables delivery to E2EE rooms where
   the raw HTTP path cannot encrypt. Falls back to standalone on failure.
   Threads adapters + event loop from gateway -> cron ticker -> tick() ->
   _deliver_result(). (from NousResearch#3767)

2. HTML formatted_body: _send_matrix() now converts markdown to HTML
   using the optional markdown library, with h1-h6 to bold conversion
   for Element X compatibility. Falls back to plain text if markdown
   is not installed. Also adds random bytes to txn_id to prevent
   collisions. (from NousResearch#5236)

3. Origin fallback: when deliver="origin" but origin is null (jobs
   created via API/scripts), falls back to HOME_CHANNEL env vars
   in order: matrix -> telegram -> discord -> slack. (from NousResearch#2641)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants