Skip to content

fix(whatsapp): pass fromMe group messages through bridge in self-chat mode (#20143) - #20429

Open
Beandon13 wants to merge 1 commit into
NousResearch:mainfrom
Beandon13:fix/hermes-20143-whatsapp-self-chat-groups
Open

Beandon13 wants to merge 1 commit into
NousResearch:mainfrom
Beandon13:fix/hermes-20143-whatsapp-self-chat-groups

Conversation

@Beandon13

Copy link
Copy Markdown
Contributor

Summary

  • scripts/whatsapp-bridge/bridge.js unconditionally dropped every fromMe message in a group chat, so self-chat-mode users could not interact with the agent in any WhatsApp group regardless of group_policy / group_allow_from / require_mention.
  • Filter logic moved into a pure shouldFilterFromMeMessage() helper. Self-chat mode now forwards group fromMe messages to the gateway so the existing Python-side group routing rules apply, while DM echo prevention and bot-mode behaviour are unchanged.
  • Echo-loop protection on forwarded messages still relies on the existing REPLY_PREFIX startsWith() and recentlySentIds checks downstream in bridge.js.

Closes #20143

Testing

  • node --test scripts/whatsapp-bridge/from-me-filter.test.mjs
✔ status broadcast fromMe is always dropped (self-chat mode) (0.860583ms)
✔ status broadcast fromMe is always dropped (bot mode) (1.064667ms)
✔ bot mode drops all fromMe messages including groups (0.114625ms)
✔ self-chat mode forwards fromMe group messages to gateway (#20143) (0.095583ms)
✔ self-chat mode forwards fromMe group messages even without sock.user identity (0.088417ms)
✔ self-chat mode forwards user own self-chat DM (classic format) (0.132625ms)
✔ self-chat mode forwards user own self-chat DM (LID format) (0.134291ms)
✔ self-chat mode drops fromMe DMs to other contacts (echo prevention) (0.069208ms)
✔ self-chat mode drops fromMe DMs when sock.user identity is missing (0.097916ms)
ℹ tests 9
ℹ pass 9
ℹ fail 0
  • node --test scripts/whatsapp-bridge/allowlist.test.mjs (existing tests still green)
ℹ tests 4
ℹ pass 4
ℹ fail 0
  • node --check scripts/whatsapp-bridge/bridge.js (parses)

… mode (NousResearch#20143)

The bridge unconditionally dropped every ``fromMe`` message in a group
chat, so a self-chat-mode user could not interact with the agent in any
WhatsApp group regardless of ``group_policy`` / ``group_allow_from`` /
``require_mention`` configuration.  Their own messages were filtered at
the bridge before the gateway ever got a chance to evaluate routing.

The fix splits the filter rules into a pure ``shouldFilterFromMeMessage``
helper:

- status broadcasts → still dropped
- bot mode → still drops all fromMe (separate-number echo prevention)
- self-chat mode + group → forwarded to gateway (group_policy decides)
- self-chat mode + DM → only the user's own self-chat passes (existing
  echo prevention for DMs to other contacts is preserved)

Echo-loop protection on forwarded fromMe group messages remains intact
through the existing REPLY_PREFIX startsWith() and recentlySentIds
checks downstream in bridge.js.

Closes NousResearch#20143
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists platform/whatsapp WhatsApp Business adapter labels May 5, 2026
@SulthanZahran91

Copy link
Copy Markdown

Following up from the review on #30288: agreed that the bridge-level self-chat fix belongs here rather than in a duplicate PR.

The only non-overlapping bit from #30288 is adapter-side env allowlist parity:

  • WHATSAPP_ALLOWED_USERS should feed the Python adapter DM allowlist when WHATSAPP_DM_POLICY=allowlist.
  • WHATSAPP_GROUP_ALLOWED_USERS should feed the Python adapter group allowlist when WHATSAPP_GROUP_POLICY=allowlist.
  • * should remain a wildcard adapter-side, matching the bridge/env-var convention.

I verified the small adapter/docs/test change locally against this PR head:

python -m pytest tests/gateway/test_whatsapp_group_gating.py -q
25 passed in 2.38s
python -m py_compile gateway/platforms/whatsapp.py tests/gateway/test_whatsapp_group_gating.py

If helpful, I can open a small follow-up PR targeting this branch, but I won't paste a large patch inline here.

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for isolating the original self-chat group-routing problem. It is still present on current main: scripts/whatsapp-bridge/bridge.js:549 continues every fromMe group message before the self-chat branch, while gateway/platforms/whatsapp_common.py:348-380 already contains the downstream group-policy and mention gates.

Problems

  • The submitted helper returns true for all bot-mode fromMe messages (scripts/whatsapp-bridge/from-me-filter.js:38). Current main now has an opt-in bot-mode owner-message route at scripts/whatsapp-bridge/bridge.js:558-591; introducing the helper as an early continue would bypass that route.
  • The surrounding handler has moved since this PR's base, so this needs conflict-aware salvage rather than a mechanical application. Open PR #62889 contains the narrower current-context adjustment to the group/status and self-chat identity guards.

Suggested changes

  • Preserve current bot-mode handling; change only the self-chat group conditions so eligible groups proceed to existing gateway policy checks.
  • Cover that current dispatch path with a regression test.

This is an automated hermes-sweeper review.


// Bot mode: bridge runs as a separate WhatsApp number, so every fromMe
// message is necessarily an echo of our own outgoing reply.
if (mode === 'bot') return true;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On current main, bot-mode fromMe events may reach the opt-in classifyOwnerMessageGate() path in bridge.js:558-591. Returning true here before that branch would bypass it entirely; keep the current bot-mode branch outside this self-chat filter when salvaging.

@teknium1 teknium1 added sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium — degraded but workaround exists platform/whatsapp WhatsApp Business adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: WhatsApp self-chat mode silently drops user's own group messages

4 participants