Skip to content

fix(whatsapp): enforce sendPolicy on auto-reply delivery path#21827

Closed
rsuk-mb wants to merge 2 commits intoopenclaw:mainfrom
rsuk-mb:fix/enforce-sendpolicy-whatsapp-autoreply
Closed

fix(whatsapp): enforce sendPolicy on auto-reply delivery path#21827
rsuk-mb wants to merge 2 commits intoopenclaw:mainfrom
rsuk-mb:fix/enforce-sendpolicy-whatsapp-autoreply

Conversation

@rsuk-mb
Copy link
Copy Markdown

@rsuk-mb rsuk-mb commented Feb 20, 2026

Summary

  • Enforce session.sendPolicy deny rules on the WhatsApp auto-reply delivery path
  • Add resolveSendPolicy check in on-message.ts before dispatching auto-replies, matching enforcement already present in commands-core.ts and gateway/server-methods/agent.ts

Problem

sendPolicy deny rules had no effect on WhatsApp auto-replies. The auto-reply pipeline (on-message.tsprocess-message.tsdeliverWebReply) never called resolveSendPolicy, so deny rules intended to suppress replies to specific DM sessions were silently ignored.

This prevented a "see but don't reply" configuration for non-self DMs — the assistant would auto-reply to contacts even when sendPolicy explicitly denied their session key.

Related: #6301 (sendPolicy bypassed by system notifications — same root cause, different vector)

Test plan

  • Existing send-policy.test.ts unit tests still pass
  • Configure sendPolicy with a deny rule for a WhatsApp DM session and verify auto-reply is suppressed
  • Verify self-chat and group mentions still receive replies when allowed by sendPolicy
  • Verify logVerbose message appears when a reply is blocked

Closes #21824

🤖 Generated with Claude Code

Greptile Summary

Adds sendPolicy enforcement to WhatsApp auto-reply path by checking resolveSendPolicy before dispatching messages, matching the enforcement pattern already present in commands-core.ts:168 and gateway/server-methods/agent.ts:410.

Key changes:

  • Imports resolveSendPolicy from sessions/send-policy.js
  • Checks sendPolicy after group gating but before broadcast/message dispatch
  • Returns early with logVerbose message when policy denies the session
  • Calls loadConfig() fresh to ensure latest policy rules are applied

Potential consideration:

  • Broadcast messages (maybeBroadcastMessage) create separate session keys for each agent, but the check only validates the primary route's sendPolicy. If per-agent sendPolicy rules differ, broadcast agents might need individual checks within broadcast.ts:75

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk
  • The fix correctly adds missing sendPolicy enforcement to the WhatsApp auto-reply path, following the same pattern used in other code paths (commands-core.ts and gateway/server-methods/agent.ts). The implementation is straightforward and well-commented. The only consideration is whether broadcast agents should have individual sendPolicy checks, but this is likely an enhancement rather than a blocker, as the primary route's policy provides baseline protection.
  • No files require special attention

Last reviewed commit: ed1b9a2

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

@openclaw-barnacle openclaw-barnacle bot added channel: whatsapp-web Channel integration: whatsapp-web size: XS labels Feb 20, 2026
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Feb 20, 2026

Additional Comments (1)

src/web/auto-reply/monitor/on-message.ts
broadcast agents create their own session keys (see broadcast.ts:58-68), but sendPolicy is only checked for the primary route. If you have per-agent sendPolicy rules configured, broadcast agents might bypass their individual deny rules.

consider moving the sendPolicy check inside broadcast.ts:75 before calling processMessage, or verify that the primary route's sendPolicy is intended to govern all broadcast agents.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/web/auto-reply/monitor/on-message.ts
Line: 169-183

Comment:
broadcast agents create their own session keys (see `broadcast.ts:58-68`), but sendPolicy is only checked for the primary route. If you have per-agent sendPolicy rules configured, broadcast agents might bypass their individual deny rules.

consider moving the sendPolicy check inside `broadcast.ts:75` before calling `processMessage`, or verify that the primary route's sendPolicy is intended to govern all broadcast agents.

How can I resolve this? If you propose a fix, please make it concise.

@rsuk-mb rsuk-mb force-pushed the fix/enforce-sendpolicy-whatsapp-autoreply branch from ed1b9a2 to c2ab205 Compare February 20, 2026 14:27
sendPolicy deny rules were only checked in the gateway and command
paths, not on the WhatsApp auto-reply pipeline.  This meant deny rules
intended to suppress replies to specific DM sessions were silently
ignored — the assistant would still auto-reply to contacts that should
have been blocked.

Add resolveSendPolicy checks to:
- on-message.ts: before dispatching the non-broadcast auto-reply
- broadcast.ts: per-agent before calling processMessage, so each
  broadcast agent's session key is individually evaluated

This matches the enforcement already present in commands-core.ts
and gateway/server-methods/agent.ts.

Closes openclaw#21824

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@rsuk-mb rsuk-mb force-pushed the fix/enforce-sendpolicy-whatsapp-autoreply branch from c2ab205 to 49b1212 Compare February 20, 2026 14:39
@rsuk-mb
Copy link
Copy Markdown
Author

rsuk-mb commented Feb 21, 2026

Closing in favour of #21893 which addresses the same issue with a cleaner single-insertion-point approach.

@rsuk-mb rsuk-mb closed this Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: whatsapp-web Channel integration: whatsapp-web size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sendPolicy not enforced on WhatsApp auto-reply delivery path

1 participant