From eb4bb4a470035cea473f23903cac2c179c8a5024 Mon Sep 17 00:00:00 2001 From: Nikita Nosov <20nik.nosov21@gmail.com> Date: Fri, 8 May 2026 11:52:24 +0000 Subject: [PATCH 1/2] feat(gateway): stream Telegram edits safely --- cli-config.yaml.example | 1 + gateway/platforms/telegram.py | 8 ++++++ tests/gateway/test_telegram_format.py | 41 +++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/cli-config.yaml.example b/cli-config.yaml.example index d7b7dcf931eb..07d00add21ab 100644 --- a/cli-config.yaml.example +++ b/cli-config.yaml.example @@ -500,6 +500,7 @@ group_sessions_per_user: true # Stream tokens to messaging platforms in real-time. The bot sends a message # on first token, then progressively edits it as more tokens arrive. # Disabled by default — enable to try the streaming UX on Telegram/Discord/Slack. +# For Telegram, partial edits are sent as plain text and only the final edit uses MarkdownV2. streaming: enabled: false # transport: edit # "edit" = progressive editMessageText diff --git a/gateway/platforms/telegram.py b/gateway/platforms/telegram.py index 2949680b50f4..0ae2787debf8 100644 --- a/gateway/platforms/telegram.py +++ b/gateway/platforms/telegram.py @@ -1515,6 +1515,14 @@ async def edit_message( if not self._bot: return SendResult(success=False, error="Not connected") try: + if not finalize: + await self._bot.edit_message_text( + chat_id=int(chat_id), + message_id=int(message_id), + text=content, + ) + return SendResult(success=True, message_id=message_id) + formatted = self.format_message(content) try: await self._bot.edit_message_text( diff --git a/tests/gateway/test_telegram_format.py b/tests/gateway/test_telegram_format.py index 594e0bd01ded..5ca3e21e1af5 100644 --- a/tests/gateway/test_telegram_format.py +++ b/tests/gateway/test_telegram_format.py @@ -716,3 +716,44 @@ async def _fake_send_message(**kwargs): assert len(sent_texts) > 1 assert re.search(r" \\\([0-9]+/[0-9]+\\\)$", sent_texts[0]) assert re.search(r" \\\([0-9]+/[0-9]+\\\)$", sent_texts[-1]) + + +# ========================================================================= +# edit_message — streaming Markdown safety +# ========================================================================= + + +class TestEditMessageStreamingSafety: + @pytest.mark.asyncio + async def test_non_final_edit_uses_plain_text_without_markdown(self): + adapter = TelegramAdapter(PlatformConfig(enabled=True, token="fake-token")) + adapter._bot = MagicMock() + adapter._bot.edit_message_text = AsyncMock() + + result = await adapter.edit_message("123", "456", "partial **bold", finalize=False) + + assert result.success is True + adapter._bot.edit_message_text.assert_awaited_once_with( + chat_id=123, + message_id=456, + text="partial **bold", + ) + + @pytest.mark.asyncio + async def test_final_edit_uses_markdownv2_with_plain_fallback(self): + adapter = TelegramAdapter(PlatformConfig(enabled=True, token="fake-token")) + adapter._bot = MagicMock() + adapter._bot.edit_message_text = AsyncMock(side_effect=[Exception("bad markdown"), None]) + + result = await adapter.edit_message("123", "456", "final **bold**", finalize=True) + + assert result.success is True + first_call = adapter._bot.edit_message_text.await_args_list[0].kwargs + second_call = adapter._bot.edit_message_text.await_args_list[1].kwargs + assert "parse_mode" in first_call + assert first_call["text"] == "final *bold*" + assert second_call == { + "chat_id": 123, + "message_id": 456, + "text": "final **bold**", + } From c4cd7d1cb26d8c3875eb364f3fbfeed52403535a Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Sat, 9 May 2026 17:02:37 +0530 Subject: [PATCH 2/2] chore: add nik1t7n to AUTHOR_MAP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nikita Nosov (nik1t7n, PR #22264) — first-time contributor email and noreply alias. --- scripts/release.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/release.py b/scripts/release.py index d809259a9978..a9c5af442137 100755 --- a/scripts/release.py +++ b/scripts/release.py @@ -170,6 +170,8 @@ "momowind@gmail.com": "momowind", "clockwork-codex@users.noreply.github.com": "misery-hl", "207811921+misery-hl@users.noreply.github.com": "misery-hl", + "20nik.nosov21@gmail.com": "nik1t7n", + "90299797+nik1t7n@users.noreply.github.com": "nik1t7n", "suncokret@protonmail.com": "suncokret12", "mio.imoto.ai@gmail.com": "mioimotoai-lgtm", "aamirjawaid@microsoft.com": "heyitsaamir",