Skip to content

Self-improving AI Employees for everyone

feat(Wave 12): email canary opt-in + twitter _events.py infrastructure

trohitg5f36f88566ec
diff --git a/server/nodes/email/__init__.py b/server/nodes/email/__init__.py
index 09451fbb..6808e157 100644
--- a/server/nodes/email/__init__.py
+++ b/server/nodes/email/__init__.py
@@ -1,12 +1,18 @@
"""Plugins for the 'email' palette group.
-Self-registers the trigger filter builder for ``emailReceive`` so the
-central ``services/event_waiter.py`` carries no plugin-specific code.
+Self-registers:
+ - The trigger filter builder for ``emailReceive`` so
+ ``services/event_waiter.py`` carries no plugin-specific code.
+ - ``emailReceive`` into ``services.deployment.canary_registry`` so the
+ Temporal-durable ``TriggerListenerWorkflow`` path activates when
+ ``event_framework_enabled`` is on (default-true post-2026-05-15).
"""
+from services.deployment.canary_registry import register_canary_trigger_type
from services.event_waiter import register_filter_builder
from ._events import dispatch_email_received # noqa: F401 — re-export
from ._filters import build_filter as build_email_filter
register_filter_builder("emailReceive", build_email_filter)
+register_canary_trigger_type("emailReceive")
diff --git a/server/nodes/email/_events.py b/server/nodes/email/_events.py
index 2b2eea21..a2864a47 100644
--- a/server/nodes/email/_events.py
+++ b/server/nodes/email/_events.py
@@ -1,4 +1,4 @@
-"""Wave 12 B4: CloudEvents factories + broadcaster wrappers for email.
+"""Wave 12 B4 + canary opt-in: CloudEvents factories + dispatcher for email.
Plugin-specific event emission — replaces:
- ``event_waiter.dispatch("email_received", email_data)`` in
@@ -9,9 +9,14 @@ the plugin folder.
Legacy ``event_type`` (``"email_received"``) is preserved on the
dispatch path so the ``emailReceive`` trigger node's ``event_type``
-ClassVar still matches without a coordinated registry-side rename
-(Phase B11 / C1 will swap to the typed
-``com.machinaos.email.message.received`` form together).
+ClassVar still matches without a coordinated registry-side rename.
+
+Dual-dispatch (canary opt-in, post-2026-05-15):
+ - Legacy ``event_waiter.dispatch`` for the in-process collector/processor
+ (still production-live for non-canary triggers).
+ - Typed ``services.events.dispatch.emit`` for Temporal-durable
+ ``TriggerListenerWorkflow`` consumers (when canary registry +
+ ``event_framework_enabled`` are both on — both default-true).
"""
from __future__ import annotations
@@ -46,16 +51,38 @@ def email_message_received(email_data: Mapping[str, Any]) -> WorkflowEvent:
# ---- Dispatcher wrapper ----------------------------------------------------
-def dispatch_email_received(email_data: Mapping[str, Any]) -> int:
+async def dispatch_email_received(email_data: Mapping[str, Any]) -> int:
"""Dispatch an incoming email to waiting ``emailReceive`` trigger
- nodes. Returns the count of resolved waiters.
+ nodes.
- Replaces the direct ``event_waiter.dispatch("email_received", ...)``
- call in ``email_receive/__init__.py``.
+ Two delivery paths (mirrors :func:`telegram._events.dispatch_telegram_message_received`):
+
+ 1. **Legacy event_waiter waiters** via :func:`event_waiter.dispatch`
+ (in-process collector/processor; still default for trigger nodes
+ outside the canary registry).
+ 2. **Temporal-durable listeners** via
+ :func:`services.events.dispatch.emit`. ``emit`` is a pass-through
+ no-op when ``event_framework_enabled`` is off; otherwise it
+ Visibility-queries running ``TriggerListenerWorkflow`` instances
+ and signals each.
+
+ Returns the count of legacy waiters resolved.
"""
from services import event_waiter
+ from services.events.dispatch import emit
+
+ payload = dict(email_data)
+ resolved = event_waiter.dispatch(_LEGACY_EVENT_TYPE, payload)
+
+ # Temporal-durable fan-out (canary opt-in via
+ # ``register_canary_trigger_type("emailReceive")`` in
+ # ``nodes/email/__init__.py``).
+ await emit(
+ email_message_received(payload),
+ wire_routing_key=_LEGACY_EVENT_TYPE,
+ )
- return event_waiter.dispatch(_LEGACY_EVENT_TYPE, dict(email_data))
+ return resolved
__all__ = [
diff --git a/server/nodes/email/email_receive/__init__.py b/server/nodes/email/email_receive/__init__.py
index 3e637caa..99454a94 100644
--- a/server/nodes/email/email_receive/__init__.py
+++ b/server/nodes/email/email_receive/__init__.py
@@ -159,10 +159,13 @@ class EmailReceiveNode(PollingTriggerNode):
poll["folder"],
)
- # Wave 12 B4: route through plugin _events.py wrapper.
+ # Wave 12 B4 + canary opt-in: route through plugin
+ # _events.py wrapper. Dual-dispatch via event_waiter
+ # (legacy collector) + dispatch.emit (Temporal-durable
+ # TriggerListenerWorkflow consumers).
from nodes.email import dispatch_email_received
- dispatch_email_received(email_data)
+ await dispatch_email_received(email_data)
return {
"success": True, "node_id": node_id, "node_type": self.type,
"result": email_data,
diff --git a/server/nodes/twitter/__init__.py b/server/nodes/twitter/__init__.py
index e8727331..ef022d29 100644
--- a/server/nodes/twitter/__init__.py
+++ b/server/nodes/twitter/__init__.py
@@ -27,6 +27,7 @@ from services.ws_handler_registry import (
)
from . import _router
+from ._events import dispatch_twitter_event_received # noqa: F401 — re-export
from ._filters import build_filter as build_twitter_filter
from ._handlers import WS_HANDLERS
from ._refresh import refresh_twitter_status
diff --git a/server/nodes/twitter/_events.py b/server/nodes/twitter/_events.py
new file mode 100644
index 00000000..6ffac61f
--- /dev/null
+++ b/server/nodes/twitter/_events.py
@@ -0,0 +1,105 @@
+"""Wave 12: CloudEvents factories + dispatcher for twitter.
+
+Plugin-specific event emission for Twitter/X inbound events (mentions,
+search hits, timeline updates, DMs).
+
+Per RFC plugin_authoring_rfc.md §6.4: plugin-specific factories live in
+the plugin folder.
+
+Legacy ``event_type`` (``"twitter_event_received"``) is preserved on
+the dispatch path so the ``twitterReceive`` trigger node's
+``event_type`` ClassVar still matches without a coordinated
+registry-side rename.
+
+Canary status (2026-05-15):
+ - Typed envelope + dispatcher infrastructure: ready (this file).
+ - Canary registry opt-in: **deferred**. ``twitterReceive`` is a plain
+ ``TriggerNode`` with ``mode="polling"``; the Temporal-durable
+ polling canary path (``PollingTriggerWorkflow`` + ``as_poll_activity``)
+ requires the node class to subclass :class:`PollingTriggerNode` and
+ declare the 4 hooks (``setup_service`` / ``fetch_ids`` /
+ ``fetch_detail`` / ``post_emit``) — same shape as ``GmailReceiveNode``.
+ Once that refactor lands, add
+ ``register_canary_trigger_type("twitterReceive")`` to
+ ``nodes/twitter/__init__.py`` and the deployment manager picks up
+ the polling canary path automatically.
+"""
+
+from __future__ import annotations
+
+from typing import Any, Mapping
+
+from services.events.envelope import WorkflowEvent
+
+
+# Legacy event_type the event_waiter dispatches by; trigger nodes
+# subscribe on this string (matches ``TwitterReceiveNode.event_type``).
+_LEGACY_EVENT_TYPE = "twitter_event_received"
+
+
+# ---- Typed factory ---------------------------------------------------------
+
+
+def twitter_event_received(event_data: Mapping[str, Any]) -> WorkflowEvent:
+ """Inbound Twitter/X event envelope (mention / search hit /
+ timeline update / DM).
+
+ ``subject`` is the tweet/DM id when available so consumers can
+ dedup; the originating Twitter user id is in
+ ``data.author_id`` or ``data.user_id``. The event ``type``
+ distinguishes the kind via the data payload, not the envelope —
+ every twitter inbound shares ``com.machinaos.twitter.event.received``
+ since the producer (polling loop) doesn't always know which kind a
+ given tweet is until the downstream filter runs.
+ """
+ payload = dict(event_data)
+ subject = (
+ payload.get("tweet_id")
+ or payload.get("id")
+ or payload.get("dm_id")
+ )
+ return WorkflowEvent(
+ source="machinaos://nodes/twitter",
+ type="com.machinaos.twitter.event.received",
+ subject=str(subject) if subject else None,
+ data=payload,
+ )
+
+
+# ---- Dispatcher wrapper ----------------------------------------------------
+
+
+async def dispatch_twitter_event_received(event_data: Mapping[str, Any]) -> int:
+ """Dispatch an incoming Twitter/X event to waiting ``twitterReceive``
+ trigger nodes.
+
+ Two delivery paths (mirrors :func:`email._events.dispatch_email_received`):
+
+ 1. **Legacy event_waiter waiters** via :func:`event_waiter.dispatch`
+ (in-process collector/processor; the default while
+ ``twitterReceive`` is not in the canary registry).
+ 2. **Temporal-durable listeners** via
+ :func:`services.events.dispatch.emit`. ``emit`` is a pass-through
+ no-op when ``event_framework_enabled`` is off; otherwise it
+ fan-outs to running consumer workflows via Visibility query.
+
+ Returns the count of legacy waiters resolved.
+ """
+ from services import event_waiter
+ from services.events.dispatch import emit
+
+ payload = dict(event_data)
+ resolved = event_waiter.dispatch(_LEGACY_EVENT_TYPE, payload)
+
+ await emit(
+ twitter_event_received(payload),
+ wire_routing_key=_LEGACY_EVENT_TYPE,
+ )
+
+ return resolved
+
+
+__all__ = [
+ "dispatch_twitter_event_received",
+ "twitter_event_received",
+]