From e7317ce99f95e2a743cc5867318ab67ee9ecf8d9 Mon Sep 17 00:00:00 2001 From: dst03106 Date: Tue, 13 May 2025 14:46:50 +0900 Subject: [PATCH 1/3] Add timeout to asyncio.wait --- pr_agent/cli.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pr_agent/cli.py b/pr_agent/cli.py index ef161437..13058971 100644 --- a/pr_agent/cli.py +++ b/pr_agent/cli.py @@ -86,7 +86,9 @@ def run(inargs=None, args=None): if get_settings().litellm.get("enable_callbacks", False): # There may be additional events on the event queue from the run above. If there are give them time to complete. get_logger().debug("Waiting for event queue to complete") - await asyncio.wait([task for task in asyncio.all_tasks() if task is not asyncio.current_task()]) + tasks = [task for task in asyncio.all_tasks() if task is not asyncio.current_task()] + if tasks: + await asyncio.wait(tasks, timeout=30) return result From d86d1ef3dc072523dbac29ef62e5e8c26db1d14e Mon Sep 17 00:00:00 2001 From: Yunhui Chae <53514545+dst03106@users.noreply.github.com> Date: Tue, 13 May 2025 17:34:30 +0900 Subject: [PATCH 2/3] Log a warning when there are pending asyncio tasks Co-authored-by: qodo-merge-pro-for-open-source[bot] <189517486+qodo-merge-pro-for-open-source[bot]@users.noreply.github.com> --- pr_agent/cli.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pr_agent/cli.py b/pr_agent/cli.py index 13058971..64ea5199 100644 --- a/pr_agent/cli.py +++ b/pr_agent/cli.py @@ -88,7 +88,9 @@ def run(inargs=None, args=None): get_logger().debug("Waiting for event queue to complete") tasks = [task for task in asyncio.all_tasks() if task is not asyncio.current_task()] if tasks: - await asyncio.wait(tasks, timeout=30) + done, pending = await asyncio.wait(tasks, timeout=30) + if pending: + get_logger().warning(f"{len(pending)} callback tasks did not complete within timeout") return result From e2af22d2a00504d2f67de2cf3fe45276c336114d Mon Sep 17 00:00:00 2001 From: dst03106 Date: Tue, 13 May 2025 17:37:09 +0900 Subject: [PATCH 3/3] Log a warning for pending asyncio tasks with coroutine details --- pr_agent/cli.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pr_agent/cli.py b/pr_agent/cli.py index 64ea5199..a741a0b8 100644 --- a/pr_agent/cli.py +++ b/pr_agent/cli.py @@ -88,9 +88,11 @@ def run(inargs=None, args=None): get_logger().debug("Waiting for event queue to complete") tasks = [task for task in asyncio.all_tasks() if task is not asyncio.current_task()] if tasks: - done, pending = await asyncio.wait(tasks, timeout=30) + _, pending = await asyncio.wait(tasks, timeout=30) if pending: - get_logger().warning(f"{len(pending)} callback tasks did not complete within timeout") + get_logger().warning( + f"{len(pending)} callback tasks({[task.get_coro() for task in pending]}) did not complete within timeout" + ) return result