Skip to content

Self-improving AI Employees for everyone

refactor(D4): drop legacy *_status raw frames; FE consumes typed envelope only

trohitg5ea4e909e10e
diff --git a/client/src/contexts/WebSocketContext.tsx b/client/src/contexts/WebSocketContext.tsx
index baaebb7a..d3ed79fe 100644
--- a/client/src/contexts/WebSocketContext.tsx
+++ b/client/src/contexts/WebSocketContext.tsx
@@ -784,15 +784,6 @@ export const WebSocketProvider: React.FC<{ children: React.ReactNode }> = ({ chi
break;
}
- case 'android_status':
- setAndroidStatus(data || defaultAndroidStatus);
- break;
-
- case 'whatsapp_status':
- setWhatsappStatus(data || defaultWhatsAppStatus);
- invalidateCatalogue(queryClient);
- break;
-
case 'twitter_oauth_complete':
// Handle Twitter OAuth completion broadcast from backend
if (data?.success) {
@@ -832,20 +823,6 @@ export const WebSocketProvider: React.FC<{ children: React.ReactNode }> = ({ chi
}
break;
- case 'telegram_status':
- // Handle Telegram bot status updates
- if (data) {
- setTelegramStatus({
- connected: data.connected || false,
- bot_username: data.bot_username || null,
- bot_name: data.bot_name || null,
- bot_id: data.bot_id || null,
- owner_chat_id: data.owner_chat_id ?? null,
- });
- invalidateCatalogue(queryClient);
- }
- break;
-
case 'whatsapp_message_received':
// Handle incoming WhatsApp message from Go service
if (data) {
diff --git a/server/nodes/android/_events.py b/server/nodes/android/_events.py
index e7f0a496..a0f3c475 100644
--- a/server/nodes/android/_events.py
+++ b/server/nodes/android/_events.py
@@ -11,11 +11,14 @@ factory in ``services/events/envelope.py`` is borderline (parametrized
by plugin but each plugin's payload differs) — Phase B moves the
plugin-specific shape into per-plugin factories.
-Wire format unchanged from X4 (the dual-emit transition pattern):
- - Legacy raw frame: ``{type: "android_status", data: <raw dict>}``
+Wire format (Wave 12 D4 — legacy ``android_status`` raw frame retired):
- Typed CloudEvents sibling: ``{type: "plugin_connection_status",
data: <WorkflowEvent envelope>}``
+The FE handler at ``client/src/contexts/WebSocketContext.tsx::case
+'plugin_connection_status'`` routes by ``envelope.source`` substring to
+the matching Zustand setter.
+
Caller pattern (from ``_refresh.py`` / ``_relay/broadcaster.py``):
from nodes.android import broadcast_android_status
await broadcast_android_status(connected=True, device_id="...", ...)
@@ -28,9 +31,7 @@ from typing import Any, Dict, List, Optional
from services.events.envelope import WorkflowEvent
-# Wire-routing keys are the OUTER ``type`` field on the WS frame, which
-# the FE switches on. Unchanged from X4 so FE listeners keep working.
-_LEGACY_WIRE_KEY = "android_status"
+# Wire-routing key — outer ``type`` field on the WS frame.
_TYPED_WIRE_KEY = "plugin_connection_status"
# Module-level cache mirror — kept in sync with
@@ -106,12 +107,13 @@ async def broadcast_android_status(
qr_data: Optional[str] = None,
session_token: Optional[str] = None,
) -> None:
- """Update the android status cache + emit both the legacy raw
- ``android_status`` frame AND the typed ``plugin_connection_status``
- CloudEvents sibling.
+ """Update the android status cache + emit the typed
+ ``plugin_connection_status`` CloudEvents envelope.
- Replaces ``StatusBroadcaster.update_android_status``. Same wire shape
- on both channels — FE consumers see no change.
+ Replaces ``StatusBroadcaster.update_android_status``. The legacy
+ raw ``android_status`` frame retired in Wave 12 D4 — FE consumes
+ via the envelope-aware ``plugin_connection_status`` case in
+ ``WebSocketContext.tsx`` (routes by ``envelope.source``).
"""
from services.status_broadcaster import get_status_broadcaster
@@ -132,13 +134,6 @@ async def broadcast_android_status(
}
broadcaster._status["android"] = payload
- # Legacy raw frame (FE back-compat).
- await broadcaster.broadcast({
- "type": _LEGACY_WIRE_KEY,
- "data": payload,
- })
-
- # Typed CloudEvents sibling — X4 dual-emit pattern.
event = android_connection_status(
connected=connected,
paired=paired,
diff --git a/server/nodes/telegram/_events.py b/server/nodes/telegram/_events.py
index 50759e23..35b2b81f 100644
--- a/server/nodes/telegram/_events.py
+++ b/server/nodes/telegram/_events.py
@@ -15,12 +15,12 @@ the only callers.
Per RFC plugin_authoring_rfc.md §6.4: plugin-specific factories live in
the plugin folder.
-Wire format preserved:
- - Status: ``{type: "telegram_status", data: <raw>}`` + typed sibling
- on ``plugin_connection_status``
+Wire format (Wave 12 D4 — legacy ``telegram_status`` raw frame retired):
+ - Status: typed CloudEvent on ``plugin_connection_status`` (FE routes
+ by ``envelope.source``).
- Message: typed CloudEvent dispatched to ``event_waiter`` so
``telegramReceive`` trigger nodes match it; legacy wire key
- ``telegram_message_received`` preserved for FE
+ ``telegram_message_received`` preserved for FE.
"""
from __future__ import annotations
@@ -33,7 +33,6 @@ from services.events.envelope import WorkflowEvent
# ---- Wire-routing keys -----------------------------------------------------
-_STATUS_LEGACY_WIRE_KEY = "telegram_status"
_STATUS_TYPED_WIRE_KEY = "plugin_connection_status"
# Legacy event_type the event_waiter dispatches by; trigger nodes
@@ -108,11 +107,12 @@ async def broadcast_telegram_status(
owner_chat_id: Optional[int] = None,
has_stored_token: Optional[bool] = None,
) -> None:
- """Update the telegram status cache + emit both the legacy raw
- ``telegram_status`` frame AND the typed ``plugin_connection_status``
- CloudEvents sibling.
+ """Update the telegram status cache + emit the typed
+ ``plugin_connection_status`` CloudEvents envelope.
- Replaces ``StatusBroadcaster.update_telegram_status``.
+ Replaces ``StatusBroadcaster.update_telegram_status``. Legacy raw
+ ``telegram_status`` frame retired in Wave 12 D4 — FE consumes via
+ the envelope-aware ``plugin_connection_status`` case.
"""
from services.status_broadcaster import get_status_broadcaster
@@ -130,11 +130,6 @@ async def broadcast_telegram_status(
payload["has_stored_token"] = has_stored_token
broadcaster._status["telegram"] = payload
- await broadcaster.broadcast({
- "type": _STATUS_LEGACY_WIRE_KEY,
- "data": payload,
- })
-
event = telegram_connection_status(
connected=connected,
bot_id=bot_id,
diff --git a/server/nodes/whatsapp/_events.py b/server/nodes/whatsapp/_events.py
index b3681a0d..5adc0347 100644
--- a/server/nodes/whatsapp/_events.py
+++ b/server/nodes/whatsapp/_events.py
@@ -17,15 +17,12 @@ Per RFC plugin_authoring_rfc.md §6.4:
- Cross-cutting factories (``credential``, ``oauth_completed``, …)
stay in central envelope.
-Wire format preserved from the pre-migration shape (so FE consumers
-keep working). Each wrapper dual-emits:
- - Legacy raw frame: ``{type: <legacy_key>, data: <raw payload>}``
- - Typed CloudEvents sibling: ``{type: <typed_wire_key>, data:
- <WorkflowEvent envelope>}``
-
-Status events use the existing ``plugin_connection_status`` typed
-channel (matches Wave 11.I X4 + the B1 android migration); message /
-newsletter / history events use new dedicated typed channels.
+Wire format (Wave 12 D4 — legacy ``whatsapp_status`` raw frame retired):
+ - Status: typed CloudEvents envelope on ``plugin_connection_status``
+ (FE routes by ``envelope.source``).
+ - Message / newsletter / history: still dual-emit on their legacy
+ wire keys until the matching FE handlers migrate to envelope-aware
+ readers (follow-up D4 round).
"""
from __future__ import annotations
@@ -42,7 +39,6 @@ from services.events.envelope import WorkflowEvent
# legacy keys). Only the INNER ``data.type`` gains the ``com.machinaos.``
# reverse-DNS prefix via the typed CloudEvents factories below.
-_STATUS_LEGACY_WIRE_KEY = "whatsapp_status"
_STATUS_TYPED_WIRE_KEY = "plugin_connection_status" # shared cross-plugin channel
_MESSAGE_SENT_WIRE_KEY = "whatsapp_message_sent"
@@ -152,11 +148,12 @@ async def broadcast_whatsapp_status(
device_id: Optional[str] = None,
qr: Optional[str] = None,
) -> None:
- """Update the whatsapp status cache + emit both the legacy raw
- ``whatsapp_status`` frame AND the typed
- ``plugin_connection_status`` CloudEvents sibling.
+ """Update the whatsapp status cache + emit the typed
+ ``plugin_connection_status`` CloudEvents envelope.
- Replaces ``StatusBroadcaster.update_whatsapp_status``.
+ Replaces ``StatusBroadcaster.update_whatsapp_status``. Legacy raw
+ ``whatsapp_status`` frame retired in Wave 12 D4 — FE consumes via
+ the envelope-aware ``plugin_connection_status`` case.
"""
from services.status_broadcaster import get_status_broadcaster
@@ -173,13 +170,6 @@ async def broadcast_whatsapp_status(
}
broadcaster._status["whatsapp"] = payload
- # Legacy raw frame (FE back-compat).
- await broadcaster.broadcast({
- "type": _STATUS_LEGACY_WIRE_KEY,
- "data": payload,
- })
-
- # Typed CloudEvents sibling — shared `plugin_connection_status` channel.
event = whatsapp_connection_status(
connected=connected,
has_session=has_session,
diff --git a/server/tests/test_status_broadcasts.py b/server/tests/test_status_broadcasts.py
index 1586e78a..58da30e1 100644
--- a/server/tests/test_status_broadcasts.py
+++ b/server/tests/test_status_broadcasts.py
@@ -328,24 +328,24 @@ class TestStatusBroadcastsUseTypedBuilder:
class TestStatusBroadcastsAlsoEmitTypedEnvelope:
- """Wave 12 B1-B3: per-plugin ``broadcast_<plugin>_status`` wrappers
- in ``nodes/<plugin>/_events.py`` MUST dual-emit (legacy raw frame +
- typed CloudEvents sibling on ``plugin_connection_status``).
-
- Replaces the Wave 11.I X4 invariant which constrained the now-retired
- ``StatusBroadcaster.update_<plugin>_status`` methods + their shared
- ``_emit_connection_typed`` helper. The helper retired in B3 along
- with the last caller (telegram). Plugin-specific typed factories
- (``android_connection_status`` / ``whatsapp_connection_status`` /
- ``telegram_connection_status``) replace the cross-plugin
- parametrised helper per RFC §6.4 plugin-specific classification.
+ """Wave 12 D4: per-plugin ``broadcast_<plugin>_status`` wrappers in
+ ``nodes/<plugin>/_events.py`` MUST emit ONLY the typed CloudEvents
+ envelope on ``plugin_connection_status`` (legacy raw frame retired).
+
+ Phase history:
+ - B1-B3: dual-emit (legacy raw + typed sibling) so the FE could
+ switch between channels without breaking back-compat.
+ - B11: FE adds the ``case 'plugin_connection_status'`` handler
+ that reads the typed envelope.
+ - D4: drops the legacy raw frames now that FE consumes via the
+ typed channel.
Each plugin's wrapper file is parametrized below — every entry must
- contain both wire keys (legacy + ``plugin_connection_status``) and
- construct a CloudEvents envelope.
+ reference ``plugin_connection_status`` AND must NOT reference the
+ retired legacy wire key.
"""
- # (plugin_label, module_path, wrapper_function_name, legacy_wire_key)
+ # (plugin_label, module_path, wrapper_function_name, retired_legacy_key)
_PLUGIN_WRAPPERS = [
("android", "nodes.android._events", "broadcast_android_status", "android_status"),
("whatsapp", "nodes.whatsapp._events", "broadcast_whatsapp_status", "whatsapp_status"),
@@ -353,19 +353,19 @@ class TestStatusBroadcastsAlsoEmitTypedEnvelope:
]
@pytest.mark.parametrize(
- "plugin,module_path,wrapper_name,legacy_key",
+ "plugin,module_path,wrapper_name,retired_legacy_key",
_PLUGIN_WRAPPERS,
ids=[row[0] for row in _PLUGIN_WRAPPERS],
)
- def test_plugin_wrapper_dual_emits(
- self, plugin: str, module_path: str, wrapper_name: str, legacy_key: str,
+ def test_plugin_wrapper_emits_typed_only(
+ self, plugin: str, module_path: str, wrapper_name: str,
+ retired_legacy_key: str,
):
- """Each plugin's broadcaster wrapper emits BOTH the legacy raw
- frame AND the typed ``plugin_connection_status`` sibling.
-
- Introspects the full module source (not just the wrapper body)
- because plugins legitimately hoist the wire keys into
- module-level constants for self-documentation.
+ """Each plugin's broadcaster wrapper emits ONLY the typed
+ ``plugin_connection_status`` envelope. The legacy raw wire key
+ retired in Wave 12 D4 — reintroducing it would resurrect the
+ dual-broadcast bug where the FE handler fired twice per status
+ change.
"""
import importlib
@@ -377,14 +377,24 @@ class TestStatusBroadcastsAlsoEmitTypedEnvelope:
f"wrapper in its plugin folder."
)
mod_src = inspect.getsource(mod)
- assert f'"{legacy_key}"' in mod_src or f"'{legacy_key}'" in mod_src, (
- f"{module_path} must reference legacy wire key {legacy_key!r} "
- f"for FE back-compat (the dual-emit transition contract)."
- )
+ # Positive: typed envelope channel still emitted.
assert "plugin_connection_status" in mod_src, (
- f"{module_path} must emit a typed CloudEvents sibling on "
+ f"{module_path} must emit a typed CloudEvents envelope on "
f"``plugin_connection_status`` (the cross-plugin typed channel)."
)
+ # Negative: legacy raw wire key retired in D4.
+ legacy_double = f'"{retired_legacy_key}"'
+ legacy_single = f"'{retired_legacy_key}'"
+ # Allow mentions inside docstrings / comments — narrow the
+ # negative assertion to lines that look like an actual emit
+ # (``broadcaster.broadcast({"type": "<legacy_key>"`` pattern).
+ emit_double = f'"type": "{retired_legacy_key}"'
+ emit_single = f"'type': '{retired_legacy_key}'"
+ assert emit_double not in mod_src and emit_single not in mod_src, (
+ f"{module_path} must NOT emit on the retired legacy wire key "
+ f"{retired_legacy_key!r}. Wave 12 D4 dropped the dual-emit; "
+ f"FE now consumes via ``plugin_connection_status``."
+ )
def test_emit_connection_typed_helper_retired(self):
"""B3 retired the cross-plugin helper. Locks: nothing on the