Skip to content

Commit

Permalink
fix empty cmd handling
Browse files Browse the repository at this point in the history
  • Loading branch information
xingyaoww committed Nov 19, 2024
1 parent cf7897b commit b430cb4
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions openhands/runtime/utils/bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}:
Expand All @@ -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()
Expand Down

0 comments on commit b430cb4

Please sign in to comment.