The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(relay): dedupe key platform component is spelling-invariant
Ben Barclayc60a525380d2
diff --git a/gateway/relay/adapter.py b/gateway/relay/adapter.pyindex 2101a8faff7..8139882373d 100644--- a/gateway/relay/adapter.py+++ b/gateway/relay/adapter.py@@ -414,7 +414,14 @@ class RelayAdapter(BasePlatformAdapter):chat_id = getattr(source, "chat_id", None)if not message_id or not chat_id:return None- platform = getattr(getattr(source, "platform", None), "value", "")+ # Normalize the platform component: production wire decoding always+ # yields a Platform enum (unknowns canonicalize to Platform.RELAY),+ # but alternate constructors may carry the plain string. Use the+ # enum's value when present, the string itself otherwise — both+ # spellings of one platform must produce ONE key, and two different+ # string platforms must not collapse into the same empty component.+ raw_platform = getattr(source, "platform", None)+ platform = getattr(raw_platform, "value", raw_platform) or ""return f"{platform}:{chat_id}:{message_id}"def _relay_slack_extra(self) -> Dict[str, Any]:diff --git a/tests/gateway/relay/test_relay_inbound_dedupe.py b/tests/gateway/relay/test_relay_inbound_dedupe.pyindex 0fd717fae1a..008540a0338 100644--- a/tests/gateway/relay/test_relay_inbound_dedupe.py+++ b/tests/gateway/relay/test_relay_inbound_dedupe.py@@ -200,3 +200,32 @@ class TestWireLevelReplayDedupe:adapter._on_inbound(self._decode(source={"platform": "discord"})))assert len(handled) == 2+++class TestDedupeKeyPlatformNormalization:+ """The platform component of the key must be spelling-invariant: a+ Platform enum and its plain-string form are ONE platform (one key), and+ two different string platforms must never collapse into a shared empty+ component. Production wire decoding always yields the enum; alternate+ event constructors may carry the string."""++ def _key(self, platform):+ adapter, _ = _connected_adapter()+ source = SessionSource(+ platform=platform, chat_id="C1", chat_type="channel", message_id="m1"+ )+ event = MessageEvent(text="hi", source=source, message_id="m1")+ return adapter._inbound_dedupe_key(event)++ def test_enum_and_string_spellings_produce_one_key(self):+ assert self._key(Platform.SLACK) == self._key("slack")++ def test_distinct_string_platforms_stay_distinct(self):+ assert self._key("slack") != self._key("discord")++ def test_missing_platform_still_yields_a_key(self):+ # Fail-open on identity is reserved for missing message/chat ids;+ # a missing platform alone must not disable dedupe.+ key = self._key(None)+ assert key is not None+ assert key.startswith(":")