Sfoglia il codice sorgente

Initialized plugins only once for persistent sandboxes (#2162)

மனோஜ்குமார் பழனிச்சாமி 1 anno fa
parent
commit
3a4dc5c68c

+ 6 - 1
opendevin/core/main.py

@@ -91,7 +91,12 @@ async def main(
         event_stream=event_stream,
     )
     runtime = ServerRuntime(event_stream=event_stream, sandbox=sandbox)
-    runtime.init_sandbox_plugins(controller.agent.sandbox_plugins)
+
+    if runtime.sandbox.is_initial_session:
+        logger.info('Initializing plugins in the sandbox')
+        runtime.init_sandbox_plugins(controller.agent.sandbox_plugins)
+    else:
+        logger.info('Plugins are already initialized in the sandbox')
     runtime.init_runtime_tools(controller.agent.runtime_tools, is_async=False)
 
     await event_stream.add_event(MessageAction(content=task), EventSource.USER)

+ 3 - 3
opendevin/runtime/docker/ssh_box.py

@@ -238,11 +238,11 @@ class DockerSSHBox(Sandbox):
             self._ssh_port = find_available_tcp_port()
         try:
             docker.DockerClient().containers.get(self.container_name)
-            is_initial_session = False
+            self.is_initial_session = False
         except docker.errors.NotFound:
-            is_initial_session = True
+            self.is_initial_session = True
             logger.info('Creating new Docker container')
-        if not config.persist_sandbox or is_initial_session:
+        if not config.persist_sandbox or self.is_initial_session:
             n_tries = 5
             while n_tries > 0:
                 try:

+ 1 - 0
opendevin/runtime/sandbox.py

@@ -11,6 +11,7 @@ from opendevin.runtime.plugins.mixin import PluginMixin
 class Sandbox(ABC, PluginMixin):
     background_commands: dict[int, Process] = {}
     _env: dict[str, str] = {}
+    is_initial_session: bool = True
 
     def __init__(self, **kwargs):
         for key in os.environ:

+ 6 - 1
opendevin/server/session/agent.py

@@ -101,7 +101,12 @@ class AgentSession:
                 logger.warning(
                     'CodeActAgent requires DockerSSHBox as sandbox! Using other sandbox that are not stateful (LocalBox, DockerExecBox) will not work properly.'
                 )
-        self.runtime.init_sandbox_plugins(agent.sandbox_plugins)
+
+        if self.runtime.sandbox.is_initial_session:
+            logger.info('Initializing plugins in the sandbox')
+            self.runtime.init_sandbox_plugins(agent.sandbox_plugins)
+        else:
+            logger.info('Plugins are already initialized in the sandbox')
         self.runtime.init_runtime_tools(agent.runtime_tools)
 
         self.controller = AgentController(