SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]
Fix: 'NoneType' object has no attribute 'session_process' (#776)
Kilian Lieret71a0fe3c43a9
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.pyindex 5440d933..5f7f9686 100644--- a/sweagent/environment/swe_env.py+++ b/sweagent/environment/swe_env.py@@ -489,11 +489,18 @@ class SWEEnv(gym.Env):return f"Interactive session already open. Please close the current interactive session: {self.interactive_session.name} with the command: `{exit_command}`"def _terminate_interactive_session(self, session_name: str):+ if not self.interactive_session:+ # Maybe fixing #772+ returntry:self.interactive_session.session_process.terminate()self.communicate(self.args.interactive_sessions_config[session_name].exit_command)except Exception as e:- self.logger.warning(f"Failed to terminate interactive session {session_name}: {e}")+ msg = (+ f"Failed to terminate interactive session {session_name}: {e}."+ "\nHere's the full traceback\n" + traceback.format_exc()+ )+ self.logger.warning(msg)self.interactive_session = Nonedef _handle_interactive_commands(self, observation: str) -> str:@@ -532,11 +539,14 @@ class SWEEnv(gym.Env):self.args.interactive_sessions_config[session_name].cmdline,)elif command == "STOP":- if self.interactive_session.session_process.poll() is None:- self.logger.warning("Session did not quit successfully, terminating.")- self.interactive_session.session_process.terminate()- observation = f"Interactive session {session_name} stopped successfully"- self.interactive_session = None+ if self.interactive_session is None:+ observation = f"Interactive session {session_name} is not running, so it cannot be stopped!"+ else:+ if self.interactive_session.session_process.poll() is None:+ self.logger.warning("Session did not quit successfully, terminating.")+ self.interactive_session.session_process.terminate()+ observation = f"Interactive session {session_name} stopped successfully"+ self.interactive_session = Noneelse:if self.interactive_session is None:self.logger.warning("Tried to run interactive commands without starting session")diff --git a/tests/test_replay_ctf.py b/tests/test_replay_ctf.pyindex 02a1ad5c..75b1b8a4 100644--- a/tests/test_replay_ctf.py+++ b/tests/test_replay_ctf.py@@ -1,7 +1,6 @@from __future__ import annotationsimport copy-import sysfrom typing import Anyimport pytest@@ -75,8 +74,8 @@ _REPLAY_TESTS = {["pwn/warmup.traj", "forensics/flash.traj", "web/i_got_id_demo.traj", "rev/rock.traj", "misc/networking_1.traj"],)def test_ctf_traj_replay(test_ctf_trajectories_path, traj_rel_path, ctf_data_path, capsys):- if sys.platform == "darwin" and traj_rel_path in ["pwn/warmup.traj", "rev/rock.traj"]:- pytest.skip("Skipping test on macOS")+ # if sys.platform == "darwin" and traj_rel_path in ["pwn/warmup.traj", "rev/rock.traj"]:+ # pytest.skip("Skipping test on macOS")traj_path = test_ctf_trajectories_path / traj_rel_pathchallenge_dir = ctf_data_path / traj_rel_path.removesuffix(".traj")assert challenge_dir.is_dir()