diff --git a/opendevin/events/observation/commands.py b/opendevin/events/observation/commands.py index 8d87c31e50..a60ba91531 100644 --- a/opendevin/events/observation/commands.py +++ b/opendevin/events/observation/commands.py @@ -27,6 +27,15 @@ class CmdOutputObservation(Observation): def __str__(self) -> str: return f'**CmdOutputObservation (exit code={self.exit_code})**\n{self.content}' + def __eq__(self, other: object) -> bool: + """ + Compare two CmdOutputObservation objects ignoring the command_id/pid. + """ + if isinstance(other, CmdOutputObservation): + # for loop detection purpose, we care about running the same command, not the same pid + return self.command == other.command and self.exit_code == other.exit_code + return False + @dataclass class IPythonRunCellObservation(Observation): diff --git a/tests/unit/test_is_stuck.py b/tests/unit/test_is_stuck.py index 2fb7cf797d..e442b0e7a6 100644 --- a/tests/unit/test_is_stuck.py +++ b/tests/unit/test_is_stuck.py @@ -115,8 +115,9 @@ class TestAgentController: ), ( CmdRunAction(command='ls'), + # command_id is ignored for the eq check, it could be a pid CmdOutputObservation( - command_id=1, command='ls', content='file1.txt\nfile2.txt' + command_id=2, command='ls', content='file1.txt\nfile2.txt' ), ), ( @@ -128,7 +129,7 @@ class TestAgentController: ( CmdRunAction(command='ls'), CmdOutputObservation( - command_id=1, command='ls', content='file1.txt\nfile2.txt' + command_id=3, command='ls', content='file1.txt\nfile2.txt' ), ), ( @@ -160,7 +161,8 @@ class TestAgentController: ), ( CmdRunAction(command='pwd'), - CmdOutputObservation(command_id=1, command='pwd', content='/home/user'), + # command_id is ignored for the eq check, it could be a pid + CmdOutputObservation(command_id=2, command='pwd', content='/home/user'), ), ( FileReadAction(path='file2.txt'), @@ -170,7 +172,7 @@ class TestAgentController: (message_action, NullObservation(content='')), ( CmdRunAction(command='pwd'), - CmdOutputObservation(command_id=1, command='pwd', content='/home/user'), + CmdOutputObservation(command_id=3, command='pwd', content='/home/user'), ), ( FileReadAction(path='file2.txt'), @@ -195,8 +197,9 @@ class TestAgentController: ), ( CmdRunAction(command='ls'), + # command_id is ignored for the eq check, it could be a pid CmdOutputObservation( - command_id=1, command='ls', content='file1.txt\nfile2.txt' + command_id=2, command='ls', content='file1.txt\nfile2.txt' ), ), # message from the user @@ -204,13 +207,13 @@ class TestAgentController: ( CmdRunAction(command='ls'), CmdOutputObservation( - command_id=1, command='ls', content='file1.txt\nfile2.txt' + command_id=3, command='ls', content='file1.txt\nfile2.txt' ), ), ( CmdRunAction(command='ls'), CmdOutputObservation( - command_id=1, command='ls', content='file1.txt\nfile2.txt' + command_id=4, command='ls', content='file1.txt\nfile2.txt' ), ), ]