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]

Improve handling of unicode decode failures (#683)

Kilian Lieretc9b56aa5e18d
diff --git a/sweagent/environment/utils.py b/sweagent/environment/utils.py
index a4a7cc91..6e1eff64 100644
--- a/sweagent/environment/utils.py
+++ b/sweagent/environment/utils.py
@@ -217,6 +217,7 @@ def read_with_timeout_experimental(container: subprocess.Popen, timeout_duration
return True
return bool(select.select([fd], [], [], 0.01)[0])
+ n_decode_failures = 0
while time.time() < end_time:
if ready_to_read(fd):
try:
@@ -226,7 +227,14 @@ def read_with_timeout_experimental(container: subprocess.Popen, timeout_duration
break
if data:
buffer += data
- if PROCESS_DONE_MARKER_START in buffer.decode():
+ try:
+ decoded = buffer.decode()
+ except UnicodeDecodeError:
+ n_decode_failures += 1
+ if n_decode_failures > 30:
+ msg = "Too many decode failures while reading from subprocess."
+ raise RuntimeError(msg)
+ if PROCESS_DONE_MARKER_START in decoded:
break
time.sleep(0.01) # Prevents CPU hogging