From 6c9746ec76fff6a4b51320a0ff988c7bdf873cd8 Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Tue, 24 Jun 2025 13:02:22 +0200 Subject: [PATCH] Log task scheduling and execution explicitly, adding task identifiers Lock task scheduling (just in case we call it from multiple threads in the future) --- src/serena/agent.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/serena/agent.py b/src/serena/agent.py index 407b18ce..43538ba1 100644 --- a/src/serena/agent.py +++ b/src/serena/agent.py @@ -9,6 +9,7 @@ import platform import re import shutil import sys +import threading import traceback import webbrowser from abc import ABC, abstractmethod @@ -788,6 +789,8 @@ class SerenaAgent: # create executor for starting the language server and running tools in another thread # This executor is used to achieve linear task execution, so it is important to use a single-threaded executor. self._task_executor = ThreadPoolExecutor(max_workers=1, thread_name_prefix="SerenaAgentExecutor") + self._task_executor_lock = threading.Lock() + self._task_executor_task_index = 1 # Initialize the prompt factory self.prompt_factory = SerenaPromptFactory() @@ -957,7 +960,16 @@ class SerenaAgent: :param task: the task to execute :return: a Future object representing the execution of the task """ - return self._task_executor.submit(task) + with self._task_executor_lock: + task_name = f"Task-{self._task_executor_task_index}" + self._task_executor_task_index += 1 + + def task_execution_wrapper() -> Any: + with LogTime(task_name, logger=log): + return task() + + log.info(f"Scheduling {task_name} ({task.__name__})") + return self._task_executor.submit(task_execution_wrapper) def _activate_project(self, project: Project) -> None: log.info(f"Activating {project.project_name} at {project.project_root}")