From 8257ae70cc703a1e3a6d57b0a444303a21f1dfca Mon Sep 17 00:00:00 2001 From: Tim O'Farrell Date: Thu, 11 Sep 2025 09:06:19 -0600 Subject: [PATCH] Additional logs to debug container working directories (#10902) Co-authored-by: Chuck Butkus --- openhands/runtime/action_execution_server.py | 5 +++++ openhands/runtime/utils/bash.py | 15 ++++++++++++--- .../docker_nested_conversation_manager.py | 3 ++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/openhands/runtime/action_execution_server.py b/openhands/runtime/action_execution_server.py index 2275f17cdb..757c97e524 100644 --- a/openhands/runtime/action_execution_server.py +++ b/openhands/runtime/action_execution_server.py @@ -358,6 +358,11 @@ class ActionExecutor: INIT_COMMANDS.append(no_pager_cmd) + # Hack: for some reason when you set the openhands user to anything but root, tmux changes out + # of the mount directory on the first invocation. + if self.user_id != 0: + INIT_COMMANDS.append(f'cd {self._initial_cwd}') + logger.info(f'Initializing by running {len(INIT_COMMANDS)} bash commands...') for command in INIT_COMMANDS: action = CmdRunAction(command=command) diff --git a/openhands/runtime/utils/bash.py b/openhands/runtime/utils/bash.py index 8afd5a1add..7371a829d6 100644 --- a/openhands/runtime/utils/bash.py +++ b/openhands/runtime/utils/bash.py @@ -206,7 +206,9 @@ class BashSession: # else: window_command = _shell_command - logger.debug(f'Initializing bash session with command: {window_command}') + logger.debug( + f'Initializing bash session in {self.work_dir} with command: {window_command}' + ) session_name = f'openhands-{self.username}-{uuid.uuid4()}' self.session = self.server.new_session( session_name=session_name, @@ -331,6 +333,9 @@ class BashSession: # Update the current working directory if it has changed if metadata.working_dir != self._cwd and metadata.working_dir: + logger.debug( + f'directory_changed: {self._cwd}; {metadata.working_dir}; {command}' + ) self._cwd = metadata.working_dir logger.debug(f'COMMAND OUTPUT: {pane_content}') @@ -598,8 +603,12 @@ class BashSession: logger.debug( f'PANE CONTENT GOT after {time.time() - _start_time:.2f} seconds' ) - logger.debug(f'BEGIN OF PANE CONTENT: {cur_pane_output.split("\n")[:10]}') - logger.debug(f'END OF PANE CONTENT: {cur_pane_output.split("\n")[-10:]}') + cur_pane_lines = cur_pane_output.split('\n') + if len(cur_pane_lines) <= 20: + logger.debug('PANE_CONTENT: {cur_pane_output}') + else: + logger.debug(f'BEGIN OF PANE CONTENT: {cur_pane_lines[:10]}') + logger.debug(f'END OF PANE CONTENT: {cur_pane_lines[-10:]}') ps1_matches = CmdOutputMetadata.matches_ps1_metadata(cur_pane_output) current_ps1_count = len(ps1_matches) diff --git a/openhands/server/conversation_manager/docker_nested_conversation_manager.py b/openhands/server/conversation_manager/docker_nested_conversation_manager.py index 3bf889565a..13f23e01ab 100644 --- a/openhands/server/conversation_manager/docker_nested_conversation_manager.py +++ b/openhands/server/conversation_manager/docker_nested_conversation_manager.py @@ -567,7 +567,8 @@ class DockerNestedConversationManager(ConversationManager): env_vars['SERVE_FRONTEND'] = '0' env_vars['RUNTIME'] = 'local' # TODO: In the long term we may come up with a more secure strategy for user management within the nested runtime. - env_vars['USER'] = 'root' + env_vars['USER'] = 'openhands' if config.run_as_openhands else 'root' + env_vars['SANDBOX_USER_ID'] = str(config.sandbox.user_id) env_vars['SESSION_API_KEY'] = self._get_session_api_key_for_conversation(sid) # We need to be able to specify the nested conversation id within the nested runtime env_vars['ALLOW_SET_CONVERSATION_ID'] = '1'