Skip to content

🙌 OpenHands: AI-Driven Development

Fix: Parse exit code correctly for background commands (#3161)

மனோஜ்குமார் பழனிச்சாமி570fd6e48325
diff --git a/opendevin/runtime/client/client.py b/opendevin/runtime/client/client.py
index 41187d2b98..aa3c12d9fb 100644
--- a/opendevin/runtime/client/client.py
+++ b/opendevin/runtime/client/client.py
@@ -128,7 +128,7 @@ class RuntimeClient:
self.shell.expect(self.__bash_expect_regex)
_exit_code_output = self.shell.before
logger.debug(f'Exit code Output: {_exit_code_output}')
- exit_code = int(_exit_code_output.strip())
+ exit_code = int(_exit_code_output.strip().split()[0])
return output, exit_code
async def run_action(self, action) -> Observation:
diff --git a/opendevin/runtime/docker/ssh_box.py b/opendevin/runtime/docker/ssh_box.py
index d7650cc76f..b691749d22 100644
--- a/opendevin/runtime/docker/ssh_box.py
+++ b/opendevin/runtime/docker/ssh_box.py
@@ -444,7 +444,7 @@ class DockerSSHBox(Sandbox):
return self._send_interrupt(
cmd, command_output, ignore_last_output=True
)
- cleaned_exit_code_str = exit_code_str.replace('echo $?', '').strip()
+ cleaned_exit_code_str = exit_code_str.replace('echo $?', '').strip().split()[0]
try:
exit_code = int(cleaned_exit_code_str)