mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-11 03:13:51 +00:00
Merge pull request #1195 from Asher-/fix/agent-shutdown-lifecycle
Fix agent shutdown lifecycle: no-op shutdown, orphaned LS processes, missing MCP cleanup
This commit is contained in:
2 files changed
+13
-3
No files matched your search
+7
-1
@@ -699,6 +699,11 @@ class SerenaAgent:
|
||||
f"(2) Configure one MCP server per backend in your client."
|
||||
)
|
||||
|
||||
# shut down the previously active project to release its language server processes
|
||||
if self._active_project is not None:
|
||||
log.info(f"Shutting down previously active project '{self._active_project.project_name}' before switching")
|
||||
self._active_project.shutdown()
|
||||
|
||||
self._active_project = project
|
||||
project.set_agent(self)
|
||||
|
||||
@@ -845,7 +850,8 @@ class SerenaAgent:
|
||||
"""
|
||||
Shuts down the agent, freeing resources and stopping background tasks.
|
||||
"""
|
||||
if not hasattr(self, "_is_initialized"):
|
||||
# guard against __del__ being called on a partially constructed instance
|
||||
if not hasattr(self, "_active_project"):
|
||||
return
|
||||
log.info("SerenaAgent is shutting down ...")
|
||||
if self._active_project is not None:
|
||||
|
||||
+6
-2
@@ -341,8 +341,12 @@ class SerenaMCPFactory:
|
||||
openai_tool_compatible = self.context.name in ["chatgpt", "codex", "oaicompat-agent"]
|
||||
self._set_mcp_tools(mcp_server, openai_tool_compatible=openai_tool_compatible)
|
||||
log.info("MCP server lifetime setup complete")
|
||||
yield
|
||||
log.info("MCP server shutting down")
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
log.info("MCP server shutting down")
|
||||
if self.agent is not None:
|
||||
self.agent.shutdown()
|
||||
|
||||
def _get_initial_instructions(self) -> str:
|
||||
assert self.agent is not None
|
||||
|
||||
Reference in new issue
Block a user