π OpenHands: AI-Driven Development
Add debug logging for sandbox startup health checks (#12814)
Tim O'Farrellaffe0af361f2
diff --git a/openhands/app_server/sandbox/docker_sandbox_service.py b/openhands/app_server/sandbox/docker_sandbox_service.pyindex 1114fde577..01829976c6 100644--- a/openhands/app_server/sandbox/docker_sandbox_service.py+++ b/openhands/app_server/sandbox/docker_sandbox_service.py@@ -230,7 +230,7 @@ class DockerSandboxService(SandboxService):except asyncio.CancelledError:raiseexcept Exception as exc:- # If the server is+ # If the server has exceeded the startup grace period, it's an errorif sandbox_info.created_at < utc_now() - timedelta(seconds=self.startup_grace_seconds):@@ -239,6 +239,10 @@ class DockerSandboxService(SandboxService):)sandbox_info.status = SandboxStatus.ERRORelse:+ _logger.debug(+ f'Sandbox server not yet available (still starting): '+ f'{app_server_url} : {exc}'+ )sandbox_info.status = SandboxStatus.STARTINGsandbox_info.exposed_urls = Nonesandbox_info.session_api_key = Nonediff --git a/openhands/app_server/sandbox/sandbox_service.py b/openhands/app_server/sandbox/sandbox_service.pyindex 8fbeb02626..4c8f0f3315 100644--- a/openhands/app_server/sandbox/sandbox_service.py+++ b/openhands/app_server/sandbox/sandbox_service.py@@ -1,4 +1,5 @@import asyncio+import loggingimport timefrom abc import ABC, abstractmethod@@ -18,6 +19,8 @@ from openhands.app_server.utils.docker_utils import (from openhands.sdk.utils.models import DiscriminatedUnionMixinfrom openhands.sdk.utils.paging import page_iterator+_logger = logging.getLogger(__name__)+SESSION_API_KEY_VARIABLE = 'OH_SESSION_API_KEYS_0'WEBHOOK_CALLBACK_VARIABLE = 'OH_WEBHOOKS_0_BASE_URL'ALLOW_CORS_ORIGINS_VARIABLE = 'OH_ALLOW_CORS_ORIGINS_0'@@ -133,12 +136,17 @@ class SandboxService(ABC):Returns:True if agent server is alive, False otherwise"""+ url = Nonetry:agent_server_url = self._get_agent_server_url(sandbox)url = f'{agent_server_url.rstrip("/")}/alive'response = await httpx_client.get(url, timeout=5.0)return response.is_success- except Exception:+ except Exception as exc:+ _logger.debug(+ f'Agent server health check failed for sandbox {sandbox.id}'+ f'{f" at {url}" if url else ""}: {exc}'+ )return Falsedef _get_agent_server_url(self, sandbox: SandboxInfo) -> str: