From 32a97a20af025a05621c4961c4bd7dbbe5af5299 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Sat, 20 Jun 2026 16:27:28 +0530 Subject: [PATCH] fix(signal): strip self-mention in all groups, not just require_mention Review follow-up on the salvaged self-mention strip (#31217): the original only stripped the bot's rendered @/@ self-mention inside the `require_mention=true` branch, so groups with require_mention=false still leaked it into the agent text. Hoist the strip to run for every group message (fixing the whole bug class), and collapse the doubled space a mid-sentence removal leaves while preserving intentional newlines. --- gateway/platforms/signal.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/gateway/platforms/signal.py b/gateway/platforms/signal.py index 790c4ef8934..1b41bc47444 100644 --- a/gateway/platforms/signal.py +++ b/gateway/platforms/signal.py @@ -620,17 +620,27 @@ class SignalAdapter(BasePlatformAdapter): "Signal: ignoring group message (require_mention=true, bot not mentioned)" ) return - # Strip the bot's own @mention from the message text so the agent - # doesn't misinterpret "@+155****4567 say hello" as a directive to - # contact that phone number. _render_mentions replaces the Signal - #  placeholder with @, which looks like an - # addressee to the LLM rather than a self-reference. + + # Strip the bot's own @mention from any group message so the agent + # doesn't misinterpret "@+155****4567 say hello" as a directive to + # contact that phone number. _render_mentions replaces the Signal + #  placeholder with @, which looks like an + # addressee to the LLM rather than a self-reference. Applies to every + # group (not just require_mention groups) so the self-mention is + # cleaned wherever it appears. + if is_group and text: + account_norm = self._account_normalized if account_norm: - text = text.replace(f"@{account_norm}", "").strip() + text = text.replace(f"@{account_norm}", "") # Also strip if the mention was rendered using the bot's UUID bot_uuid = self._recipient_uuid_by_number.get(account_norm) if bot_uuid: - text = text.replace(f"@{bot_uuid}", "").strip() + text = text.replace(f"@{bot_uuid}", "") + # Tidy the spacing the removed mention left behind: collapse the + # double-space at a mid-sentence removal and trim the ends. + # Only touches the doubled space the removal introduced, so + # intentional newlines in a multi-line message are preserved. + text = text.replace(" ", " ").strip() # Extract quote (reply-to) context from Signal dataMessage. Signal's # quote.id is the timestamp of the quoted message; quote.author points