From b430cb46e2305be55fc2448e5ee19ffb22d0a843 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Tue, 19 Nov 2024 20:59:30 +0000 Subject: [PATCH] fix empty cmd handling --- openhands/runtime/utils/bash.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/openhands/runtime/utils/bash.py b/openhands/runtime/utils/bash.py index 8c15ef5a060e..e8a72e3ea76c 100644 --- a/openhands/runtime/utils/bash.py +++ b/openhands/runtime/utils/bash.py @@ -276,20 +276,8 @@ def _handle_hard_timeout_command( def execute(self, action: CmdRunAction) -> CmdOutputObservation | ErrorObservation: """Execute a command in the bash session.""" - logger.debug(f'Executing command: {action.command}') - splited_commands = split_bash_commands(action.command) - if len(splited_commands) > 1: - return ErrorObservation( - content=( - f'ERROR: Cannot execute multiple commands at once.\n' - f'Please run each command separately OR chain them into a single command via && or ;\n' - f'Provided commands:\n{"\n".join(f"({i+1}) {cmd}" for i, cmd in enumerate(splited_commands))}' - ) - ) - if action.command.strip() == '' and self.prev_status not in { BashCommandStatus.CONTINUE, - BashCommandStatus.COMPLETED, BashCommandStatus.NO_CHANGE_TIMEOUT, BashCommandStatus.HARD_TIMEOUT, }: @@ -300,6 +288,16 @@ def execute(self, action: CmdRunAction) -> CmdOutputObservation | ErrorObservati metadata=CmdOutputMetadata(), ) + splited_commands = split_bash_commands(action.command) + if len(splited_commands) > 1: + return ErrorObservation( + content=( + f'ERROR: Cannot execute multiple commands at once.\n' + f'Please run each command separately OR chain them into a single command via && or ;\n' + f'Provided commands:\n{"\n".join(f"({i+1}) {cmd}" for i, cmd in enumerate(splited_commands))}' + ) + ) + start_time = time.time() last_change_time = start_time last_pane_output = self._get_pane_content()