From 1ffaae17ff1c51c0ff3fd63955d37fcc7dfe8c3d Mon Sep 17 00:00:00 2001 From: "sp.wack" <83104063+amanape@users.noreply.github.com> Date: Thu, 1 May 2025 20:06:20 +0400 Subject: [PATCH] hotfix(backend): Handle errors when executing run actions (#8160) --- openhands/runtime/action_execution_server.py | 28 +++++++++++--------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/openhands/runtime/action_execution_server.py b/openhands/runtime/action_execution_server.py index b0a17a671d..d91126202c 100644 --- a/openhands/runtime/action_execution_server.py +++ b/openhands/runtime/action_execution_server.py @@ -309,19 +309,23 @@ class ActionExecutor: async def run( self, action: CmdRunAction ) -> CmdOutputObservation | ErrorObservation: - if action.is_static: - path = action.cwd or self._initial_cwd - result = await AsyncBashSession.execute(action.command, path) - obs = CmdOutputObservation( - content=result.content, - exit_code=result.exit_code, - command=action.command, - ) - return obs + try: + if action.is_static: + path = action.cwd or self._initial_cwd + result = await AsyncBashSession.execute(action.command, path) + obs = CmdOutputObservation( + content=result.content, + exit_code=result.exit_code, + command=action.command, + ) + return obs - assert self.bash_session is not None - obs = await call_sync_from_async(self.bash_session.execute, action) - return obs + assert self.bash_session is not None + obs = await call_sync_from_async(self.bash_session.execute, action) + return obs + except Exception as e: + logger.error(f'Error running command: {e}') + return ErrorObservation(str(e)) async def run_ipython(self, action: IPythonRunCellAction) -> Observation: assert self.bash_session is not None