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: Do not allow persistent container with cache task imgs (#551)

Kilian Lieret1fbfebb93fa3
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.py
index 50f53264..05bb3c04 100644
--- a/sweagent/environment/swe_env.py
+++ b/sweagent/environment/swe_env.py
@@ -99,6 +99,12 @@ class EnvironmentArguments(FrozenSerializable):
def __post_init__(self):
if self.timeout is not None:
logger.warning("The 'timeout' argument is deprecated and has no effect.")
+ if self.cache_task_images and self.container_name:
+ msg = (
+ "Not allowed to use persistent container with caching task images "
+ "(probably doesn't make sense and takes excessive space)."
+ )
+ raise ValueError(msg)
class EnvHook:
diff --git a/tests/test_env.py b/tests/test_env.py
index 94f57cc1..2ad93c67 100644
--- a/tests/test_env.py
+++ b/tests/test_env.py
@@ -72,7 +72,7 @@ def test_init_swe_env_non_persistent(test_env_args):
@pytest.mark.slow()
def test_init_swe_env_cached_task_image(test_env_args):
- test_env_args = dataclasses.replace(test_env_args, cache_task_images=True)
+ test_env_args = dataclasses.replace(test_env_args, cache_task_images=True, container_name=None)
start = time.perf_counter()
with swe_env_context(test_env_args) as env:
env.reset()
@@ -153,3 +153,12 @@ def test_env_with_hook(test_env_args):
with swe_env_context(test_env_args) as env:
env.add_hook(EnvHook())
env.reset()
+
+
+def test_invalid_config():
+ with pytest.raises(ValueError, match=".*Not allowed.*"):
+ EnvironmentArguments(
+ data_path=".",
+ container_name="test",
+ cache_task_images=True,
+ )