π OpenHands: AI-Driven Development
Fix Docker hostname issues in HTTP requests (#11787)
Tim O'Farrellc82e18306699
diff --git a/openhands/app_server/event_callback/set_title_callback_processor.py b/openhands/app_server/event_callback/set_title_callback_processor.pyindex 92373dbff0..071d28b5f9 100644--- a/openhands/app_server/event_callback/set_title_callback_processor.py+++ b/openhands/app_server/event_callback/set_title_callback_processor.py@@ -15,6 +15,9 @@ from openhands.app_server.event_callback.event_callback_result_models import ()from openhands.app_server.services.injector import InjectorStatefrom openhands.app_server.user.specifiy_user_context import ADMIN, USER_CONTEXT_ATTR+from openhands.app_server.utils.docker_utils import (+ replace_localhost_hostname_for_docker,+)from openhands.sdk import Event, MessageEvent_logger = logging.getLogger(__name__)@@ -53,8 +56,13 @@ class SetTitleCallbackProcessor(EventCallbackProcessor):conversation_id)assert app_conversation is not None+ app_conversation_url = app_conversation.conversation_url+ assert app_conversation_url is not None+ app_conversation_url = replace_localhost_hostname_for_docker(+ app_conversation_url+ )response = await httpx_client.post(- f'{app_conversation.conversation_url}/generate_title',+ f'{app_conversation_url}/generate_title',headers={'X-Session-API-Key': app_conversation.session_api_key,},diff --git a/openhands/app_server/sandbox/process_sandbox_service.py b/openhands/app_server/sandbox/process_sandbox_service.pyindex b9200f8960..716c2e1b19 100644--- a/openhands/app_server/sandbox/process_sandbox_service.py+++ b/openhands/app_server/sandbox/process_sandbox_service.py@@ -37,6 +37,9 @@ from openhands.app_server.sandbox.sandbox_service import (from openhands.app_server.sandbox.sandbox_spec_models import SandboxSpecInfofrom openhands.app_server.sandbox.sandbox_spec_service import SandboxSpecServicefrom openhands.app_server.services.injector import InjectorState+from openhands.app_server.utils.docker_utils import (+ replace_localhost_hostname_for_docker,+)_logger = logging.getLogger(__name__)@@ -158,9 +161,10 @@ class ProcessSandboxService(SandboxService):start_time = time.time()while time.time() - start_time < timeout:try:- response = await self.httpx_client.get(- f'http://localhost:{port}/alive', timeout=5.0+ url = replace_localhost_hostname_for_docker(+ f'http://localhost:{port}/alive')+ response = await self.httpx_client.get(url, timeout=5.0)if response.status_code == 200:data = response.json()if data.get('status') == 'ok':@@ -199,10 +203,10 @@ class ProcessSandboxService(SandboxService):if status == SandboxStatus.RUNNING:# Check if server is actually respondingtry:- response = await self.httpx_client.get(- f'http://localhost:{process_info.port}{self.health_check_path}',- timeout=5.0,+ url = replace_localhost_hostname_for_docker(+ f'http://localhost:{process_info.port}{self.health_check_path}')+ response = await self.httpx_client.get(url, timeout=5.0)if response.status_code == 200:exposed_urls = [ExposedUrl(