Fix Docker hostname issues in HTTP requests (#11787)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Tim O'Farrell 2025-11-20 11:59:58 +00:00 committed by GitHub
parent 26e7d8060f
commit c82e183066
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 6 deletions

View File

@ -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,
},

View File

@ -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(