The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(relay): dedupe key reads chat identity from event.source, keyed per platform
Ben Barclay22dfdc1c56a4
diff --git a/gateway/relay/adapter.py b/gateway/relay/adapter.pyindex 96218277814..2101a8faff7 100644--- a/gateway/relay/adapter.py+++ b/gateway/relay/adapter.py@@ -396,18 +396,26 @@ class RelayAdapter(BasePlatformAdapter):_SEEN_INBOUND_MAX = 512def _inbound_dedupe_key(self, event) -> Optional[str]:- """Stable replay identity: (chat, platform message id).+ """Stable replay identity: (platform, chat, platform message id).++ Chat identity lives on ``event.source`` (MessageEvent has no top-level+ ``chat_id``), and this adapter can front SEVERAL platforms over one+ relay socket (Phase 1.5 multiplex), so the underlying platform joins+ the key — two platforms' numeric chat/message ids must never collide+ into one identity.Returns None when the event carries no platform message id (syntheticevents, some prompt responses) — those never dedupe, fail-open bydesign: dropping a real user message is strictly worse than rerunningone, so only dedupe when identity is certain."""+ source = getattr(event, "source", None)message_id = getattr(event, "message_id", None)- chat_id = getattr(event, "chat_id", None)+ chat_id = getattr(source, "chat_id", None)if not message_id or not chat_id:return None- return f"{chat_id}:{message_id}"+ platform = getattr(getattr(source, "platform", None), "value", "")+ return f"{platform}:{chat_id}:{message_id}"def _relay_slack_extra(self) -> Dict[str, Any]:"""The Slack-behavior subset of the RELAY platform config.diff --git a/tests/gateway/relay/test_relay_inbound_dedupe.py b/tests/gateway/relay/test_relay_inbound_dedupe.pyindex ac7b8c7f92e..561537094e8 100644--- a/tests/gateway/relay/test_relay_inbound_dedupe.py+++ b/tests/gateway/relay/test_relay_inbound_dedupe.py@@ -14,11 +14,11 @@ seen-set drops them. Fail-open: events without a message_id never dedupefrom __future__ import annotationsimport asyncio-from types import SimpleNamespaceimport pytest-from gateway.config import PlatformConfig+from gateway.config import Platform, PlatformConfig+from gateway.platforms.base import MessageEvent, SessionSourcefrom gateway.relay.adapter import RelayAdapterfrom gateway.relay.descriptor import CONTRACT_VERSION, CapabilityDescriptorfrom tests.gateway.relay.stub_connector import StubConnector@@ -78,9 +78,19 @@ class TestInboundReplayDedupe:after a WS re-handshake must not re-run the turn."""def _event(self, message_id="1700.100", chat_id="C1", text="hi"):- return SimpleNamespace(- message_id=message_id, chat_id=chat_id, text=text, media=None+ # A REAL MessageEvent, shaped exactly as _event_from_wire produces it:+ # chat identity lives on event.source, NOT as a top-level attribute.+ # (The first version of these tests used a SimpleNamespace with a+ # top-level chat_id — a shape no production code path produces — and+ # green-lit a dedupe key that read the wrong field.)+ source = SessionSource(+ platform=Platform.SLACK,+ chat_id=chat_id,+ chat_type="channel",+ user_id="U1",+ message_id=message_id,)+ return MessageEvent(text=text, source=source, message_id=message_id)def _tap(self, adapter, handled):adapter.handle_message = lambda e: _record(handled, e)