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(agent): Handle unicode issues in submission

Kilian Lieretded93cadae45
diff --git a/sweagent/__init__.py b/sweagent/__init__.py
index e6059f6b..ab7d5e7f 100644
--- a/sweagent/__init__.py
+++ b/sweagent/__init__.py
@@ -73,7 +73,7 @@ def get_agent_version_info() -> str:
def impose_rex_lower_bound() -> None:
rex_version = get_rex_version()
- minimal_rex_version = "1.0.3"
+ minimal_rex_version = "1.1.0"
if version.parse(rex_version) < version.parse(minimal_rex_version):
msg = (
f"SWE-ReX version {rex_version} is too old. Please update to at least {minimal_rex_version}. "
diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.py
index b404fb56..148c383b 100644
--- a/sweagent/agent/agents.py
+++ b/sweagent/agent/agents.py
@@ -661,10 +661,13 @@ class Agent:
if is_submission or force_submission:
assert self._env is not None
try:
- submission = self._env.read_file("/root/model.patch")
+ submission = self._env.read_file("/root/model.patch", encoding="utf-8", errors="backslashreplace")
except FileNotFoundError:
self.logger.warning("Submission file not found, no submission was made")
return step
+ except Exception as e:
+ self.logger.exception("Failed to read submission file, got %s", e)
+ return step
if submission.strip() != "":
step.submission = submission
else:
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.py
index 076355a9..94aa5869 100644
--- a/sweagent/environment/swe_env.py
+++ b/sweagent/environment/swe_env.py
@@ -217,16 +217,22 @@ class SWEEnv:
raise RuntimeError(msg)
return output
- def read_file(self, path: str | PurePath) -> str:
+ def read_file(self, path: str | PurePath, encoding: str | None = None, errors: str | None = None) -> str:
"""Read file contents from container
Args:
path: Absolute path to file
+ encoding: Encoding to use when reading the file. None means default encoding.
+ This is the same as the `encoding` argument of `Path.read_text()`
+ errors: Error handling to use when reading the file. None means default error handling.
+ This is the same as the `errors` argument of `Path.read_text()`
Returns:
file_contents: Contents of file as string
"""
- r = asyncio.run(self.deployment.runtime.read_file(ReadFileRequest(path=str(path))))
+ r = asyncio.run(
+ self.deployment.runtime.read_file(ReadFileRequest(path=str(path), encoding=encoding, errors=errors))
+ )
return r.content
def write_file(self, path: str | PurePath, content: str) -> None: