From 3f0d8e7f471475cf328666435bbfbf36cf7de36c Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Thu, 29 May 2025 15:52:13 -0400 Subject: [PATCH] add more logging to debug runtime restarts (#8799) --- openhands/runtime/impl/remote/remote_runtime.py | 17 +++++++++++++---- openhands/server/listen_socket.py | 6 ++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/openhands/runtime/impl/remote/remote_runtime.py b/openhands/runtime/impl/remote/remote_runtime.py index dc269124c2..c3c20d58cc 100644 --- a/openhands/runtime/impl/remote/remote_runtime.py +++ b/openhands/runtime/impl/remote/remote_runtime.py @@ -101,7 +101,15 @@ class RemoteRuntime(ActionExecutionClient): def log(self, level: str, message: str, exc_info: bool | None = None) -> None: message = f'[runtime session_id={self.sid} runtime_id={self.runtime_id or "unknown"}] {message}' - getattr(logger, level)(message, stacklevel=2, exc_info=exc_info) + getattr(logger, level)( + message, + stacklevel=2, + exc_info=exc_info, + extra={ + 'session_id': self.sid, + 'runtime_id': self.runtime_id, + }, + ) @property def action_execution_server_url(self) -> str: @@ -285,9 +293,10 @@ class RemoteRuntime(ActionExecutionClient): f'{self.config.sandbox.remote_runtime_api_url}/resume', json={'runtime_id': self.runtime_id}, ) + self.log('info', 'Runtime resumed, waiting for it to be alive...') self._wait_until_alive() self.setup_initial_env() - self.log('debug', 'Runtime resumed.') + self.log('info', 'Runtime resumed and alive.') def _parse_runtime_response(self, response: httpx.Response) -> None: start_response = response.json() @@ -407,7 +416,7 @@ class RemoteRuntime(ActionExecutionClient): f'{self.config.sandbox.remote_runtime_api_url}/pause', json={'runtime_id': self.runtime_id}, ) - self.log('debug', 'Runtime paused.') + self.log('info', 'Runtime paused.') except Exception as e: self.log('error', f'Unable to pause runtime: {str(e)}') raise e @@ -420,7 +429,7 @@ class RemoteRuntime(ActionExecutionClient): f'{self.config.sandbox.remote_runtime_api_url}/stop', json={'runtime_id': self.runtime_id}, ) - self.log('debug', 'Runtime stopped.') + self.log('info', 'Runtime stopped.') except Exception as e: self.log('error', f'Unable to stop runtime: {str(e)}') raise e diff --git a/openhands/server/listen_socket.py b/openhands/server/listen_socket.py index 20a96c9f81..365c63d1d0 100644 --- a/openhands/server/listen_socket.py +++ b/openhands/server/listen_socket.py @@ -90,6 +90,9 @@ async def connect(connection_id: str, environ: dict) -> None: ) latest_event_id = -1 conversation_id = query_params.get('conversation_id', [None])[0] + logger.info( + f'Socket request for conversation {conversation_id} with connection_id {connection_id}' + ) raw_list = query_params.get('providers_set', []) providers_list = [] for item in raw_list: @@ -112,6 +115,9 @@ async def connect(connection_id: str, environ: dict) -> None: user_id = await conversation_validator.validate( conversation_id, cookies_str, authorization_header ) + logger.info( + f'User {user_id} is allowed to connect to conversation {conversation_id}' + ) conversation_init_data = await setup_init_convo_settings(user_id, providers_set) agent_loop_info = await conversation_manager.join_conversation(