Skip to content

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: Process done marker not found in read with timeout

Kilian Lieret5f42dc840617
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.py
index 0b1b41cd..7a26692c 100644
--- a/sweagent/environment/swe_env.py
+++ b/sweagent/environment/swe_env.py
@@ -641,7 +641,9 @@ class SWEEnv(gym.Env):
) -> str:
"""Experimental version of `_communicate`"""
assert self.container is not None
- command_suffix = f"echo {PROCESS_DONE_MARKER_START}$?{PROCESS_DONE_MARKER_END}\n"
+ # Sleep to ensure that the exit code is in the last line
+ # See https://github.com/princeton-nlp/SWE-agent/issues/595
+ command_suffix = f"sleep 0.01; echo {PROCESS_DONE_MARKER_START}$?{PROCESS_DONE_MARKER_END}\n"
try:
self.returncode = None
cmd = input if input.endswith("\n") else input + "\n"
diff --git a/sweagent/environment/utils.py b/sweagent/environment/utils.py
index 6a9ad4f6..b6870757 100644
--- a/sweagent/environment/utils.py
+++ b/sweagent/environment/utils.py
@@ -238,10 +238,9 @@ def read_with_timeout_experimental(container: subprocess.Popen, timeout_duration
raise TimeoutError(msg)
decoded = buffer.decode()
body = "\n".join(line for line in decoded.splitlines() if not line.startswith(PROCESS_DONE_MARKER_START))
- last_line = decoded.splitlines()[-1]
- _results = PROCESS_DONE_REGEX.search(last_line)
+ _results = PROCESS_DONE_REGEX.search(decoded)
if _results is None:
- msg = f"Could not find process done marker in last line: {last_line=}, {body=}"
+ msg = f"Could not find process done marker in last line: {decoded=}, {body=}"
raise ValueError(msg)
exit_code = _results.group(1)
return body, exit_code