Skip to content

fix: Matrix cron delivery — add sender and origin fallback - #2641

Closed
kpmfyi wants to merge 1 commit into
NousResearch:mainfrom
kpmfyi:fix/matrix-cron-delivery-clean
Closed

fix: Matrix cron delivery — add sender and origin fallback#2641
kpmfyi wants to merge 1 commit into
NousResearch:mainfrom
kpmfyi:fix/matrix-cron-delivery-clean

Conversation

@kpmfyi

@kpmfyi kpmfyi commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add _send_matrix() sender to send_message_tool.py — sends via Matrix CS API (PUT with access token), matching the pattern of _send_telegram/_send_discord/_send_slack. Without this, Matrix cron delivery silently fails with "Direct sending not yet implemented".
  • Add Matrix to platform_map in both _handle_send() and _deliver_result().
  • Fix deliver="origin" with null origin in _resolve_delivery_target() — instead of silently returning None, falls back to checking each platform's HOME_CHANNEL env var (set by /sethome). Logs the fallback for observability.

Context

Cron jobs created via setup scripts or the Python API (rather than interactively via a chat message) have origin=null. Combined with deliver="origin" (the default), _resolve_delivery_target() returned None, silently dropping all cron output. Even after fixing the delivery target to matrix:!room_id, the missing _send_matrix() function meant delivery still failed at the else branch in _send_to_platform().

Test plan

  • 3 new unit tests for origin fallback behavior (with home channel, without, platform priority order)
  • All 32 existing scheduler tests pass
  • All 19 existing send_message_tool tests pass
  • Manual verification: _send_matrix() delivered a test message to a Matrix room (HTTP 200, event_id returned)

🤖 Generated with Claude Code

Two bugs prevented cron job output from being delivered to Matrix:

1. _send_to_platform() had no Matrix handler — it fell through to
   "Direct sending not yet implemented". Added _send_matrix() which
   sends via the Matrix CS API using PUT with an access token. This
   mirrors how _send_telegram/_send_discord/_send_slack work.

2. When deliver="origin" but origin is null (common for jobs created
   via setup scripts or the API rather than interactively), delivery
   was silently dropped. Now falls back to checking each platform's
   HOME_CHANNEL env var (set by /sethome) before giving up.

Also added "matrix" to the platform_map in both _handle_send() and
_deliver_result().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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

teknium1 commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Your origin fallback logic was salvaged into PR #5271 — when deliver=origin but origin is null, it now falls back to HOME_CHANNEL env vars. The Matrix delivery routing was already on main. Your authorship is credited in the commit. 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)
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)
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 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)
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 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)
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 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)
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 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)
melon-xf added a commit to melon-xf/hermes-agent that referenced this pull request Sep 3, 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