From c82e18306699395b8d5a5894437869cee04b450e Mon Sep 17 00:00:00 2001 From: Tim O'Farrell Date: Thu, 20 Nov 2025 11:59:58 +0000 Subject: [PATCH] Fix Docker hostname issues in HTTP requests (#11787) Co-authored-by: openhands --- .../event_callback/set_title_callback_processor.py | 10 +++++++++- .../app_server/sandbox/process_sandbox_service.py | 14 +++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/openhands/app_server/event_callback/set_title_callback_processor.py b/openhands/app_server/event_callback/set_title_callback_processor.py index 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 InjectorState from 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.py index 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 SandboxSpecInfo from openhands.app_server.sandbox.sandbox_spec_service import SandboxSpecService from 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 responding try: - 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(