The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(telegram): two edits in one second are two inputs
Teknium84b480d38ea5
diff --git a/gateway/platforms/event.py b/gateway/platforms/event.pyindex 8f2b0dc8888..fe1c16f2da2 100644--- a/gateway/platforms/event.py+++ b/gateway/platforms/event.py@@ -69,7 +69,7 @@ class MessageEvent:# Platform update id (Telegram ``update_id``): ``/restart`` records it so the new gateway# advances past it even if PTB's shutdown ACK times out.platform_update_id: Optional[int] = None- # Revision of an edited message (Telegram ``edit_date``). An edit re-sends its message's own+ # Identity of one edit of a message (Telegram: its ``update_id``). An edit re-sends its message's own# ``message_id`` with new text, so native admission keys it apart from the original send.edit_revision: Optional[str] = None# Media attachments: local file paths (for vision tool access)diff --git a/plugins/platforms/telegram/adapter.py b/plugins/platforms/telegram/adapter.pyindex 6263de61ca0..932c749f55a 100644--- a/plugins/platforms/telegram/adapter.py+++ b/plugins/platforms/telegram/adapter.py@@ -4,6 +4,7 @@import asyncioimport contextlibimport dataclasses+import hashlibimport inspectimport jsonimport logging@@ -7134,13 +7135,20 @@ class TelegramAdapter(TelegramHeldInboundMixin, TelegramTopicRoutingMixin, BasePmessage_id=str(message.message_id), platform_update_id=update_id,reply_to_message_id=reply_to_id, reply_to_text=reply_to_text, auto_skill=topic_skill,channel_prompt=group_identity_prompt(self, message, channel_prompt),- edit_revision=self._edit_revision(message), timestamp=message.date)+ edit_revision=self._edit_revision(message, update_id), timestamp=message.date)@staticmethod- def _edit_revision(message) -> Optional[str]:- """``edit_date`` of an edited message (whole seconds), None for a new send."""+ def _edit_revision(message, update_id: Optional[int]) -> Optional[str]:+ """Identity of one edit of a message, None for a new send. ``edit_date`` has whole-second+ resolution, so two edits in one second would share it: the update id is unique per edit and+ stable on redelivery; without one, the edited text tells same-second edits apart."""edit_date = getattr(message, "edit_date", None)- return str(int(edit_date.timestamp())) if hasattr(edit_date, "timestamp") else None+ if not hasattr(edit_date, "timestamp"):+ return None+ if update_id is not None:+ return f"u{update_id}"+ text = (getattr(message, "text", None) or getattr(message, "caption", None) or "").encode()+ return f"{int(edit_date.timestamp())}.{hashlib.sha256(text).hexdigest()[:16]}"# -- Message reactions (processing lifecycle) --diff --git a/tests/gateway/test_native_admission_edit.py b/tests/gateway/test_native_admission_edit.pyindex 1375e0ee007..ac775d64717 100644--- a/tests/gateway/test_native_admission_edit.py+++ b/tests/gateway/test_native_admission_edit.py@@ -43,22 +43,29 @@ async def test_edit_of_an_admitted_message_is_its_own_admission(tmp_path, monkeyauthority.db.close()-def test_telegram_edit_carries_its_edit_date_as_revision():+def test_telegram_same_second_edits_get_distinct_revisions():+ """``edit_date`` is whole seconds: two edits inside one second must still key apart, while a+ redelivered edit keeps its key (the admission above then replays it once)."""from plugins.platforms.telegram.adapter import TelegramAdapteradapter = object.__new__(TelegramAdapter)adapter.platform = Platform.TELEGRAMadapter.config = PlatformConfig(enabled=True, token='***', extra={})sent = datetime(2026, 10, 18, 2, 5, tzinfo=UTC)- def message(edit_date):- return SimpleNamespace(- message_id=7, text='hello', caption=None, entities=[], caption_entities=[], message_thread_id=None,+ def event(text, edit_date, update_id):+ message = SimpleNamespace(+ message_id=7, text=text, caption=None, entities=[], caption_entities=[], message_thread_id=None,is_topic_message=False, reply_to_message=None, date=sent, edit_date=edit_date, forum_topic_created=None,chat=SimpleNamespace(id=111, type='private', full_name='A', title=None, is_forum=False),from_user=SimpleNamespace(id=111, full_name='A', first_name='A', is_bot=False))+ return adapter._build_message_event(message, MessageType.TEXT, update_id=update_id)- original = adapter._build_message_event(message(None), MessageType.TEXT)- edited = adapter._build_message_event(message(datetime(2026, 10, 18, 2, 6, tzinfo=UTC)), MessageType.TEXT)- assert original.edit_revision is None- assert edited.message_id == original.message_id == '7'- assert edited.edit_revision == str(int(datetime(2026, 10, 18, 2, 6, tzinfo=UTC).timestamp()))+ second = datetime(2026, 10, 18, 2, 6, tzinfo=UTC)+ original = event('helo', None, 100)+ edits = [event('hello', second, 101), event('hello!', second.replace(microsecond=500000), 102)]+ assert original.edit_revision is None and {e.message_id for e in edits} == {'7'}+ assert edits[0].edit_revision != edits[1].edit_revision+ assert event('hello', second, 101).edit_revision == edits[0].edit_revision # redelivery+ # Without an update id (a replayed snapshot), the text still keys same-second edits apart.+ assert event('hello', second, None).edit_revision != event('hello!', second, None).edit_revision+ assert event('hello', second, None).edit_revision == event('hello', second, None).edit_revision