π OpenHands: AI-Driven Development
using all available system memory when RUNTIME_MAX_MEMORY_GB is not set (#6691)
Xingyao Wangf7c806c11901
diff --git a/openhands/runtime/action_execution_server.py b/openhands/runtime/action_execution_server.pyindex ccf267bb2c..536a6a6ed8 100644--- a/openhands/runtime/action_execution_server.py+++ b/openhands/runtime/action_execution_server.py@@ -19,7 +19,6 @@ from contextlib import asynccontextmanagerfrom pathlib import Pathfrom zipfile import ZipFile-import psutilfrom fastapi import Depends, FastAPI, HTTPException, Request, UploadFilefrom fastapi.exceptions import RequestValidationErrorfrom fastapi.responses import JSONResponse, StreamingResponse@@ -163,21 +162,14 @@ class ActionExecutor:self.last_execution_time = self.start_timeself._initialized = False+ self.max_memory_gb: int | None = Noneif _override_max_memory_gb := os.environ.get('RUNTIME_MAX_MEMORY_GB', None):self.max_memory_gb = int(_override_max_memory_gb)logger.info(f'Setting max memory to {self.max_memory_gb}GB (according to the RUNTIME_MAX_MEMORY_GB environment variable)')else:- # Get available system memory- total_memory_gb = psutil.virtual_memory().total / (- 1024 * 1024 * 1024- ) # Convert to GB- self.max_memory_gb = int(max(0.5, total_memory_gb - 1.0))- # Reserve 1GB as head room, minimum of 0.5GB- logger.info(- f'Total memory: {total_memory_gb}GB, setting limit to {self.max_memory_gb}GB (reserved 1GB for action execution server, minimum 0.5GB)'- )+ logger.info('No max memory limit set, using all available system memory')@propertydef initial_cwd(self):@@ -191,7 +183,7 @@ class ActionExecutor:no_change_timeout_seconds=int(os.environ.get('NO_CHANGE_TIMEOUT_SECONDS', 30)),- max_memory_mb=self.max_memory_gb * 1024,+ max_memory_mb=self.max_memory_gb * 1024 if self.max_memory_gb else None,)self.bash_session.initialize()