Summary
When multiple Hermes Agent bots share a Matrix room, MATRIX_AUTO_THREAD=true (the default) causes severe infinite reply loops. The root cause is that in_bot_thread bypass logic skips @mention gating for threaded messages, and thread_require_mention is not implemented for the Matrix adapter.
Impact
- Multi-agent rooms flood with hundreds of messages in minutes
- API tokens wasted on loop traffic
- Gateway instability amplifies the loop during restarts
Root Cause
Issue 1: in_bot_thread bypass eliminates @mention gating in shared threads
In _resolve_message_context() (~line 1692 of gateway/platforms/matrix.py):
in_bot_thread = bool(thread_id and thread_id in self._threads)
if self._require_mention and not is_free_room and not in_bot_thread:
if not is_mentioned:
return None # only this path checks @mention
When multiple bots auto-thread the same message into a shared thread, in_bot_thread is true for all of them, bypassing @mention entirely. This design assumes one bot per room. Additionally, self._threads.mark(thread_id) at line 1727 executes unconditionally after any successful message processing, so even bots with MATRIX_AUTO_THREAD=false get registered once @mentioned into the thread.
Issue 2: thread_require_mention is Discord-only
matrix:
thread_require_mention: true # Set in config, but Matrix adapter ignores it
MatrixPlatform.__init__() never parses this field. It only exists for Discord, creating a false sense of security on Matrix.
Loop Mechanism
- Bot A (auto_thread=true) receives message M1, creates thread from event_id
- Bot A replies in thread (no @mention per convention)
- Bot B sees A's reply, in_bot_thread=True, @mention bypassed, B replies
- N-way positive feedback loop, hundreds of messages in minutes
Reproduction
- Set up 3+ Hermes bots with default
MATRIX_AUTO_THREAD=true in one room
- Send a message @mentioning one bot
- Bots reply endlessly within the shared thread
Proposed Fix
Implement thread_require_mention for Matrix, mirroring Discord adapter behavior (default false for backward compatibility):
A. Parse config in __init__():
self._thread_require_mention: bool = (
config.extra.get("thread_require_mention")
if config.extra.get("thread_require_mention") is not None
else os.getenv("MATRIX_THREAD_REQUIRE_MENTION", "false").lower()
in {"true", "1", "yes"}
)
B. Add thread-level @mention check in _resolve_message_context():
elif self._thread_require_mention and in_bot_thread:
if not is_mentioned:
logger.debug(
"Matrix: ignoring message %s in thread %s — no @mention "
"(thread_require_mention=true)",
event_id, thread_id,
)
return None
Immediate Workaround
Set MATRIX_AUTO_THREAD=false on all bots sharing a room.
Environment
- Hermes Agent latest (2026-05-18)
- Matrix gateway adapter
- 9-bot shared room reproducing the issue
Summary
When multiple Hermes Agent bots share a Matrix room,
MATRIX_AUTO_THREAD=true(the default) causes severe infinite reply loops. The root cause is thatin_bot_threadbypass logic skips@mentiongating for threaded messages, andthread_require_mentionis not implemented for the Matrix adapter.Impact
Root Cause
Issue 1:
in_bot_threadbypass eliminates @mention gating in shared threadsIn
_resolve_message_context()(~line 1692 ofgateway/platforms/matrix.py):When multiple bots auto-thread the same message into a shared thread,
in_bot_threadis true for all of them, bypassing@mentionentirely. This design assumes one bot per room. Additionally,self._threads.mark(thread_id)at line 1727 executes unconditionally after any successful message processing, so even bots withMATRIX_AUTO_THREAD=falseget registered once @mentioned into the thread.Issue 2:
thread_require_mentionis Discord-onlyMatrixPlatform.__init__()never parses this field. It only exists for Discord, creating a false sense of security on Matrix.Loop Mechanism
Reproduction
MATRIX_AUTO_THREAD=truein one roomProposed Fix
Implement
thread_require_mentionfor Matrix, mirroring Discord adapter behavior (defaultfalsefor backward compatibility):A. Parse config in
__init__():B. Add thread-level @mention check in
_resolve_message_context():Immediate Workaround
Set
MATRIX_AUTO_THREAD=falseon all bots sharing a room.Environment