The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: exempt the Matrix quote block from the mention strip only on real replies
teknium1060e2a428643
diff --git a/plugins/platforms/matrix/adapter.py b/plugins/platforms/matrix/adapter.pyindex 64e1126d7c5..418882f9089 100644--- a/plugins/platforms/matrix/adapter.py+++ b/plugins/platforms/matrix/adapter.py@@ -2025,9 +2025,13 @@ class MatrixAdapter(BasePlatformAdapter):# Strip the mention from the reply text only: the quote block carries the# ``> <@bot:srv> ...`` reply pill, which _extract_reply_context parses later# for reply_to_author_id. A whole-body replace rewrote the pill to ``> <>``- # and silently dropped the replied-to author (#111233).- quote_block, reply_text = _split_reply_fallback(body)- body = quote_block + self._strip_mention(reply_text)+ # and silently dropped the replied-to author (#111233). Only a real reply carries a+ # pill; a hand-typed blockquote in a plain message is stripped whole as before.+ if relates_to.get("m.in_reply_to"):+ quote_block, reply_text = _split_reply_fallback(body)+ body = quote_block + self._strip_mention(reply_text)+ else:+ body = self._strip_mention(body)# Real thread roots are preserved above; synthetic roots (this event) follow policy: DM# @mention threads / DM auto-thread, or room auto-thread unless session_scope pins the room.if not thread_id:diff --git a/tests/gateway/test_matrix_message_event_metadata.py b/tests/gateway/test_matrix_message_event_metadata.pyindex ee61090916d..89cb5ea66af 100644--- a/tests/gateway/test_matrix_message_event_metadata.py+++ b/tests/gateway/test_matrix_message_event_metadata.py@@ -290,3 +290,19 @@ async def test_reply_with_explicit_mention_still_strips_it_from_reply_text(monkeassert msg.reply_to_author_id == "@carol:example.org"assert msg.reply_to_text == "original question"assert msg.text == "because reasons"+++async def test_plain_blockquote_without_reply_is_stripped_whole(monkeypatch):+ """The quote exemption keys on m.in_reply_to, not on a leading ``> ``: a hand-typed+ blockquote mentioning the bot in a non-reply message must not reach the agent raw."""+ adapter = _make_adapter(require_mention=True, monkeypatch=monkeypatch)+ adapter._startup_ts = time.time() - 10++ event = _make_event("> @hermes:example.org please summarise\n\nthanks", event_id="$evt_quote")+ await adapter._on_room_message(event)++ msg = adapter.handle_message.await_args.args[0]+ assert msg.reply_to_message_id is None+ assert "@hermes:example.org" not in msg.text+ assert "thanks" in msg.text