From b053a7142d6ab52862c94c14b6cbface5926c4bf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 11 Jan 2026 09:01:57 +0000 Subject: [PATCH 1/5] Initial plan From cbcd1c7ec5783dbd6b4d28e28812cf5edd26fd69 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 11 Jan 2026 09:08:09 +0000 Subject: [PATCH 2/5] fix: await telegram local command replies Co-authored-by: BukeLy <19304666+BukeLy@users.noreply.github.com> --- agent-sdk-client/handler.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/agent-sdk-client/handler.py b/agent-sdk-client/handler.py index ae3cd9f..f472583 100644 --- a/agent-sdk-client/handler.py +++ b/agent-sdk-client/handler.py @@ -2,6 +2,7 @@ Receives Telegram webhook, writes to SQS, returns 200 immediately. """ +import asyncio import json import logging from typing import Any @@ -128,11 +129,13 @@ def _handle_local_command(bot: Bot, message, config: Config, cmd: str) -> bool: text = config.unknown_command_message() try: - bot.send_message( - chat_id=message.chat_id, - text=text, - message_thread_id=message.message_thread_id, - reply_to_message_id=message.message_id, + asyncio.run( + bot.send_message( + chat_id=message.chat_id, + text=text, + message_thread_id=message.message_thread_id, + reply_to_message_id=message.message_id, + ) ) except Exception: logger.warning("Failed to send local command response", exc_info=True) From 63f61388e611fc26c596828656d72beec7cd33fd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 11 Jan 2026 09:09:05 +0000 Subject: [PATCH 3/5] refine: reuse event loop for telegram sends Co-authored-by: BukeLy <19304666+BukeLy@users.noreply.github.com> --- agent-sdk-client/handler.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/agent-sdk-client/handler.py b/agent-sdk-client/handler.py index f472583..26240d7 100644 --- a/agent-sdk-client/handler.py +++ b/agent-sdk-client/handler.py @@ -129,14 +129,22 @@ def _handle_local_command(bot: Bot, message, config: Config, cmd: str) -> bool: text = config.unknown_command_message() try: - asyncio.run( - bot.send_message( - chat_id=message.chat_id, - text=text, - message_thread_id=message.message_thread_id, - reply_to_message_id=message.message_id, - ) + try: + loop = asyncio.get_event_loop() + except RuntimeError: + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + + coro = bot.send_message( + chat_id=message.chat_id, + text=text, + message_thread_id=message.message_thread_id, + reply_to_message_id=message.message_id, ) + if loop.is_running(): + loop.create_task(coro) + else: + loop.run_until_complete(coro) except Exception: logger.warning("Failed to send local command response", exc_info=True) From ab8fadbaa2d21951dd7d122fe7bbc1541ee3e7dd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 11 Jan 2026 09:10:58 +0000 Subject: [PATCH 4/5] chore: run telegram sends to completion Co-authored-by: BukeLy <19304666+BukeLy@users.noreply.github.com> --- agent-sdk-client/handler.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/agent-sdk-client/handler.py b/agent-sdk-client/handler.py index 26240d7..5f8eeda 100644 --- a/agent-sdk-client/handler.py +++ b/agent-sdk-client/handler.py @@ -129,22 +129,18 @@ def _handle_local_command(bot: Bot, message, config: Config, cmd: str) -> bool: text = config.unknown_command_message() try: + loop = asyncio.new_event_loop() try: - loop = asyncio.get_event_loop() - except RuntimeError: - loop = asyncio.new_event_loop() - asyncio.set_event_loop(loop) - - coro = bot.send_message( - chat_id=message.chat_id, - text=text, - message_thread_id=message.message_thread_id, - reply_to_message_id=message.message_id, - ) - if loop.is_running(): - loop.create_task(coro) - else: - loop.run_until_complete(coro) + loop.run_until_complete( + bot.send_message( + chat_id=message.chat_id, + text=text, + message_thread_id=message.message_thread_id, + reply_to_message_id=message.message_id, + ) + ) + finally: + loop.close() except Exception: logger.warning("Failed to send local command response", exc_info=True) From 1ac9b232fdaf43e2b0cfe6fbf83aef250ccb4d78 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 11 Jan 2026 09:21:35 +0000 Subject: [PATCH 5/5] chore: use asyncio.run for telegram send Co-authored-by: BukeLy <19304666+BukeLy@users.noreply.github.com> --- agent-sdk-client/handler.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/agent-sdk-client/handler.py b/agent-sdk-client/handler.py index 5f8eeda..f472583 100644 --- a/agent-sdk-client/handler.py +++ b/agent-sdk-client/handler.py @@ -129,18 +129,14 @@ def _handle_local_command(bot: Bot, message, config: Config, cmd: str) -> bool: text = config.unknown_command_message() try: - loop = asyncio.new_event_loop() - try: - loop.run_until_complete( - bot.send_message( - chat_id=message.chat_id, - text=text, - message_thread_id=message.message_thread_id, - reply_to_message_id=message.message_id, - ) + asyncio.run( + bot.send_message( + chat_id=message.chat_id, + text=text, + message_thread_id=message.message_thread_id, + reply_to_message_id=message.message_id, ) - finally: - loop.close() + ) except Exception: logger.warning("Failed to send local command response", exc_info=True)