The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(whatsapp): contentless Cloud API envelopes no longer start blank agent turns
Tekniumf90721e95a45
diff --git a/gateway/platforms/whatsapp_cloud.py b/gateway/platforms/whatsapp_cloud.pyindex 92c5f8767f7..1830607317c 100644--- a/gateway/platforms/whatsapp_cloud.py+++ b/gateway/platforms/whatsapp_cloud.py@@ -86,6 +86,10 @@ _WHATSAPP_MIME_EXTENSION_OVERRIDES: Dict[str, str] = {}_INBOUND_MEDIA_KINDS = {"image", "video", "audio", "voice", "document", "sticker"}+# ``system`` = user_changed_number / user_changed_user_id (BSUID rotation, Aug 2026);+# ``reaction`` = emoji tap (extension point if emoji-approval flows ever land);+# ``unsupported``/``unknown`` = payloads the Cloud API cannot render.+_CONTENTLESS_KINDS = {"system", "reaction", "unsupported", "unknown"}_TEXT_INJECT_EXTS = {".txt", ".md", ".csv", ".json", ".xml", ".yaml", ".yml", ".log", ".py", ".js", ".ts", ".html", ".css"}_MAX_TEXT_INJECT_BYTES = 100 * 1024 # matches Telegram/Discord/Slack_MESSAGE_TYPE_BY_KIND = {@@ -949,6 +953,11 @@ class WhatsAppCloudAdapter(WhatsAppBehaviorMixin, BasePlatformAdapter):) -> Optional[MessageEvent]:"""Convert a Cloud-API message object into a MessageEvent, or None if gated out."""msg_type_str = str(raw_message.get("type") or "text").lower()+ # Contentless envelopes arrive on the same ``messages`` webhook field and carry no+ # user utterance; falling through would start a blank agent turn (#90157).+ if msg_type_str in _CONTENTLESS_KINDS:+ logger.debug("[whatsapp_cloud] skipping contentless %s envelope (wamid=%s)", msg_type_str, raw_message.get("id"))+ return None# Button taps route to the gateway resolver BEFORE text dispatch — the# resolver unblocks the waiting agent, so don't also start a fresh turn.if msg_type_str == "interactive" and await self._dispatch_interactive_reply(raw_message, contacts_by_waid):diff --git a/tests/gateway/test_whatsapp_cloud.py b/tests/gateway/test_whatsapp_cloud.pyindex 1b43f333b26..cd9056fd228 100644--- a/tests/gateway/test_whatsapp_cloud.py+++ b/tests/gateway/test_whatsapp_cloud.py@@ -913,6 +913,65 @@ class TestGroupMessageGuard:adapter.handle_message.assert_not_called()+class TestContentlessEnvelopeGuard:+ """Meta delivers non-conversational payloads on the same ``messages``+ webhook field: ``system`` (user_changed_number, and since Aug 11 2026+ user_changed_user_id BSUID-rotation events), ``reaction`` (emoji taps),+ and ``unsupported``/``unknown``. None carry a user utterance — without+ the guard they'd become MessageEvents with empty text and trigger a+ blank agent turn."""++ @pytest.mark.asyncio+ @pytest.mark.parametrize("msg_type,extra", [+ (+ "system",+ {"system": {+ "type": "user_changed_user_id",+ "previous_user_id": "bsuid-old",+ "user_id": "bsuid-new",+ }},+ ),+ (+ "system",+ {"system": {"type": "user_changed_number", "body": "changed number"}},+ ),+ ("reaction", {"reaction": {"message_id": "wamid.orig", "emoji": "👍"}}),+ ("unsupported", {"errors": [{"code": 131051, "title": "Unsupported message type"}]}),+ ("unknown", {}),+ ])+ async def test_contentless_envelope_dropped(self, msg_type, extra):+ adapter = _make_adapter()+ adapter.handle_message = AsyncMock()+ raw = {+ "from": "15551234567",+ "id": f"wamid.{msg_type}1",+ "timestamp": "0",+ "type": msg_type,+ **extra,+ }+ event = await adapter._build_message_event_from_cloud(+ raw, {"15551234567": "Alice"}, {}+ )+ assert event is None+ adapter.handle_message.assert_not_called()++ @pytest.mark.asyncio+ async def test_plain_text_still_processed(self):+ adapter = _make_adapter()+ raw = {+ "from": "15551234567",+ "id": "wamid.text1",+ "timestamp": "0",+ "type": "text",+ "text": {"body": "hello"},+ }+ event = await adapter._build_message_event_from_cloud(+ raw, {"15551234567": "Alice"}, {}+ )+ assert event is not None+ assert event.text == "hello"++# =========================================================================# Phase 9 — Interactive button messages (clarify / approval / slash-confirm)# =========================================================================