diff --git a/src/coding_agent_telegram/router/base.py b/src/coding_agent_telegram/router/base.py index 22702b6..adecb95 100644 --- a/src/coding_agent_telegram/router/base.py +++ b/src/coding_agent_telegram/router/base.py @@ -188,6 +188,15 @@ async def typing_loop() -> None: # Give thread-safe Telegram notifications one event-loop turn to run # before we close the progress channel and finalize the response. await asyncio.sleep(0) + pending_progress = tuple(progress_state["futures"]) + if pending_progress: + try: + await asyncio.wait_for( + asyncio.gather(*(asyncio.wrap_future(future) for future in pending_progress), return_exceptions=True), + timeout=0.1, + ) + except asyncio.TimeoutError: + pass progress_state["closed"] = True for future in tuple(progress_state["futures"]): future.cancel()