From 3d4892394a75fb01f14745ed401f7e753defde7c Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Mon, 16 Jun 2025 02:40:04 +0200 Subject: [PATCH] Fixed project activation in process-isolated agent --- src/serena/agent.py | 3 --- src/serena/mcp.py | 6 ++++-- src/serena/process_isolated_agent.py | 3 +++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/serena/agent.py b/src/serena/agent.py index a169e2fc..1933d8e1 100644 --- a/src/serena/agent.py +++ b/src/serena/agent.py @@ -569,7 +569,6 @@ class MemoriesManagerMDFilesInProject(MemoriesManager): def create_serena_config( - project: str | None = None, serena_config: SerenaConfigBase | None = None, context: SerenaAgentContext | None = None, modes: list[SerenaAgentMode] | None = None, @@ -585,7 +584,6 @@ def create_serena_config( This function extracts the configuration creation logic from SerenaAgent.__init__ to allow creating configurations independently for process isolation and other use cases. - :param project: the project to register/activate or None :param serena_config: the base Serena configuration or None to read from default location :param context: the context in which the agent will operate :param modes: list of modes in which the agent will operate @@ -670,7 +668,6 @@ class SerenaAgent: """ # obtain serena configuration using the decoupled factory function self.serena_config = create_serena_config( - project=None, # Don't pass project here, handle activation separately serena_config=serena_config, context=context, modes=modes, diff --git a/src/serena/mcp.py b/src/serena/mcp.py index 3551ec11..3eab295f 100644 --- a/src/serena/mcp.py +++ b/src/serena/mcp.py @@ -137,9 +137,11 @@ def create_mcp_server_and_agent( context_instance = SerenaAgentContext.load(context) modes_instances = [SerenaAgentMode.load(mode) for mode in modes] + if project is not None: + log.info(f"Will use project at mcp server startup: {project}") + try: serena_config = create_serena_config( - project=project, context=context_instance, modes=modes_instances, enable_web_dashboard=enable_web_dashboard, @@ -148,7 +150,7 @@ def create_mcp_server_and_agent( trace_lsp_communication=trace_lsp_communication, tool_timeout=tool_timeout, ) - serena_agent_process = ProcessIsolatedSerenaAgent(serena_config=serena_config) + serena_agent_process = ProcessIsolatedSerenaAgent(project=project, serena_config=serena_config) # Start process-isolated dashboard if enabled serena_dashboard_process = None diff --git a/src/serena/process_isolated_agent.py b/src/serena/process_isolated_agent.py index 768e45f6..f87856b6 100644 --- a/src/serena/process_isolated_agent.py +++ b/src/serena/process_isolated_agent.py @@ -436,6 +436,7 @@ class ProcessIsolatedSerenaAgent: # Use the default config loader self.serena_config = SerenaConfig.from_config_file() self.process: multiprocessing.Process | None = None + self.project = project self.conn: Connection | None = None def start(self) -> None: @@ -456,12 +457,14 @@ class ProcessIsolatedSerenaAgent: # Initialize the agent in the worker process try: + # TODO: instead pass config and project to worker, use at startup of agent there # Prepare initialization parameters, converting complex objects to dict if present init_params = self._init_params.copy() if init_params["serena_config"] is not None and hasattr(init_params["serena_config"], "to_dict"): # Convert SerenaConfigBase to dict for serialization serena_config_obj = init_params["serena_config"] init_params["serena_config"] = serena_config_obj.to_dict() # type: ignore + # init_params["project"] = self.project # Note: context and modes are not serializable across processes, # so they will be None and SerenaAgent will use defaults init_params["context"] = None