π OpenHands: AI-Driven Development
Fix passing environment (#8483)
tofarr8d2ac5990932
diff --git a/openhands/runtime/base.py b/openhands/runtime/base.pyindex b494e380e3..e517399df3 100644--- a/openhands/runtime/base.py+++ b/openhands/runtime/base.py@@ -135,6 +135,10 @@ class Runtime(FileEditRuntimeMixin):atexit.register(self.close)self.initial_env_vars = _default_env_vars(config.sandbox)++ # also update with runtime_startup_env_vars+ self.initial_env_vars.update(self.config.sandbox.runtime_startup_env_vars)+if env_vars is not None:self.initial_env_vars.update(env_vars)diff --git a/openhands/runtime/impl/docker/docker_runtime.py b/openhands/runtime/impl/docker/docker_runtime.pyindex 883877cafe..c42890e0c7 100644--- a/openhands/runtime/impl/docker/docker_runtime.py+++ b/openhands/runtime/impl/docker/docker_runtime.py@@ -23,7 +23,7 @@ from openhands.runtime.impl.action_execution.action_execution_client import (from openhands.runtime.impl.docker.containers import stop_all_containersfrom openhands.runtime.plugins import PluginRequirementfrom openhands.runtime.utils import find_available_tcp_port-from openhands.runtime.utils.command import get_action_execution_server_startup_command+from openhands.runtime.utils.command import DEFAULT_MAIN_MODULE, get_action_execution_server_startup_commandfrom openhands.runtime.utils.log_streamer import LogStreamerfrom openhands.runtime.utils.runtime_build import build_runtime_imagefrom openhands.utils.async_utils import call_sync_from_async@@ -80,6 +80,7 @@ class DockerRuntime(ActionExecutionClient):status_callback: Callable | None = None,attach_to_existing: bool = False,headless_mode: bool = True,+ main_module: str = DEFAULT_MAIN_MODULE,):if not DockerRuntime._shutdown_listener_id:DockerRuntime._shutdown_listener_id = add_shutdown_listener(@@ -109,6 +110,7 @@ class DockerRuntime(ActionExecutionClient):self.runtime_container_image = self.config.sandbox.runtime_container_imageself.container_name = CONTAINER_NAME_PREFIX + sidself.container: Container | None = None+ self.main_module = main_moduleself.runtime_builder = DockerRuntimeBuilder(self.docker_client)@@ -309,16 +311,15 @@ class DockerRuntime(ActionExecutionClient):)# Combine environment variables- environment = {+ environment = dict(**self.initial_env_vars)+ environment.update({'port': str(self._container_port),'PYTHONUNBUFFERED': '1','VSCODE_PORT': str(self._vscode_port),'PIP_BREAK_SYSTEM_PACKAGES': '1',- }+ })if self.config.debug or DEBUG:environment['DEBUG'] = 'true'- # also update with runtime_startup_env_vars- environment.update(self.config.sandbox.runtime_startup_env_vars)self.log('debug', f'Workspace Base: {self.config.workspace_base}')@@ -336,11 +337,7 @@ class DockerRuntime(ActionExecutionClient):f'Sandbox workspace: {self.config.workspace_mount_path_in_sandbox}',)- command = get_action_execution_server_startup_command(- server_port=self._container_port,- plugins=self.plugins,- app_config=self.config,- )+ command = self.get_action_execution_server_startup_command()try:self.container = self.docker_client.containers.run(@@ -534,3 +531,11 @@ class DockerRuntime(ActionExecutionClient):passfinally:docker_client.close()++ def get_action_execution_server_startup_command(self):+ return get_action_execution_server_startup_command(+ server_port=self._container_port,+ plugins=self.plugins,+ app_config=self.config,+ main_module=self.main_module,+ )diff --git a/openhands/runtime/impl/remote/remote_runtime.py b/openhands/runtime/impl/remote/remote_runtime.pyindex 746a53f3ab..5d5324f1b7 100644--- a/openhands/runtime/impl/remote/remote_runtime.py+++ b/openhands/runtime/impl/remote/remote_runtime.py@@ -24,7 +24,7 @@ from openhands.runtime.impl.action_execution.action_execution_client import (ActionExecutionClient,)from openhands.runtime.plugins import PluginRequirement-from openhands.runtime.utils.command import get_action_execution_server_startup_command+from openhands.runtime.utils.command import DEFAULT_MAIN_MODULE, get_action_execution_server_startup_commandfrom openhands.runtime.utils.request import send_requestfrom openhands.runtime.utils.runtime_build import build_runtime_imagefrom openhands.utils.async_utils import call_sync_from_async@@ -54,6 +54,7 @@ class RemoteRuntime(ActionExecutionClient):headless_mode: bool = True,user_id: str | None = None,git_provider_tokens: PROVIDER_TOKEN_TYPE | None = None,+ main_module: str = DEFAULT_MAIN_MODULE,) -> None:super().__init__(config,@@ -85,6 +86,7 @@ class RemoteRuntime(ActionExecutionClient):)assert self.config.sandbox.remote_runtime_class in (None, 'sysbox', 'gvisor')+ self.main_module = main_moduleself.runtime_builder = RemoteRuntimeBuilder(self.config.sandbox.remote_runtime_api_url,@@ -231,11 +233,7 @@ class RemoteRuntime(ActionExecutionClient):def _start_runtime(self) -> None:# Prepare the request body for the /start endpoint- command = get_action_execution_server_startup_command(- server_port=self.port,- plugins=self.plugins,- app_config=self.config,- )+ command = self.get_action_execution_server_startup_command()environment: dict[str, str] = {}if self.config.debug or os.environ.get('DEBUG', 'false').lower() == 'true':environment['DEBUG'] = 'true'@@ -492,3 +490,11 @@ class RemoteRuntime(ActionExecutionClient):def _stop_if_closed(self, retry_state: RetryCallState) -> bool:return self._runtime_closed++ def get_action_execution_server_startup_command(self):+ return get_action_execution_server_startup_command(+ server_port=self.port,+ plugins=self.plugins,+ app_config=self.config,+ main_module=self.main_module,+ )diff --git a/openhands/runtime/utils/command.py b/openhands/runtime/utils/command.pyindex b2485d09fb..66787b2e28 100644--- a/openhands/runtime/utils/command.py+++ b/openhands/runtime/utils/command.py@@ -9,6 +9,7 @@ DEFAULT_PYTHON_PREFIX = ['poetry','run',]+DEFAULT_MAIN_MODULE = 'openhands.runtime.action_execution_server'def get_action_execution_server_startup_command(@@ -18,6 +19,7 @@ def get_action_execution_server_startup_command(python_prefix: list[str] = DEFAULT_PYTHON_PREFIX,override_user_id: int | None = None,override_username: str | None = None,+ main_module: str = DEFAULT_MAIN_MODULE,) -> list[str]:sandbox_config = app_config.sandbox@@ -45,7 +47,7 @@ def get_action_execution_server_startup_command('python','-u','-m',- 'openhands.runtime.action_execution_server',+ main_module,str(server_port),'--working-dir',app_config.workspace_mount_path_in_sandbox,