Skip to content

feat: trust whatsapp_from_owner flag for /takeback recognition - #4

Merged
keiravoss94 merged 1 commit into
mainfrom
feat/whatsapp-from-owner-takeback
Apr 27, 2026
Merged

keiravoss94 merged 1 commit into
mainfrom
feat/whatsapp-from-owner-takeback

Conversation

@keiravoss94

Copy link
Copy Markdown
Collaborator

Motivation

In profiles where the owner notification destination is Telegram but the human owner actually types replies from the same WhatsApp Business account as the bot (e.g. basketball-jersey-demo), /takeback from the owner's phone is not recognized as owner-issued — _is_owner_message only matched on (handover.owner.platform, handover.owner.chat_id). Result: the bot only resumes when the sliding TTL expires.

Design

Extend rules/handover.py::_is_owner_message with a metadata short-circuit before the legacy platform/sender check:

metadata = getattr(event, "metadata", None) or {}
if metadata.get("whatsapp_from_owner"):
    return True

The bridge LRU classifier in hermes-agent (WhatsAppAdapter._build_message_event, gated by WHATSAPP_FORWARD_OWNER_MESSAGES) only sets that flag for inbounds that came from the bot's own WhatsApp account — by definition the owner. Same trust model as the implicit-owner-activate branch shipped in #3.

The legacy (platform, sender_id) path is unchanged for profiles that don't enable owner forwarding.

No config change

No new keys, no schema bump. Profiles opt in via the existing WHATSAPP_FORWARD_OWNER_MESSAGES env in hermes-agent.

Dependencies

Tests

Two new tests in tests/test_rules.py::TestHandover:

  1. test_takeback_via_whatsapp_from_owner_flag_alone_deactivates — owner configured for Telegram, /takeback arrives via WhatsApp with metadata['whatsapp_from_owner']=True → handover ends.
  2. test_takeback_without_owner_flag_from_stranger_does_not_deactivate — no flag, non-owner sender, /takeback text → falls through to the active-handover silent-ingest path; handover stays active.

Existing 42 tests remain green; suite is now 44.

Profiles where the owner notification platform is Telegram but the
human owner actually types from the same WhatsApp Business account
as the bot (e.g. basketball-jersey-demo) couldn't deactivate
handover via /takeback because the rule only matched on
(platform, sender_id) against the configured owner. With the
WHATSAPP_FORWARD_OWNER_MESSAGES flag now propagating
metadata["whatsapp_from_owner"] from the bridge LRU classifier,
any inbound with that flag set is by definition owner-equivalent
- same trust model as the implicit-owner-activate branch shipped
in PR #3.

No new config. Pre-existing platform/sender_id matching path is
unchanged for profiles that don't enable owner forwarding.
@keiravoss94
keiravoss94 merged commit 6922514 into main Apr 27, 2026
@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@keiravoss94 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minutes and 44 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b68896b1-ba9a-4a2e-8ad3-fd9aaf64f44a

📥 Commits

Reviewing files that changed from the base of the PR and between ad41982 and 7e49730.

📒 Files selected for processing (2)
  • rules/handover.py
  • tests/test_rules.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/whatsapp-from-owner-takeback

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@keiravoss94
keiravoss94 deleted the feat/whatsapp-from-owner-takeback branch April 27, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant