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]

Add random sleep before every batch instance

Kilian Lieret078e51b84e17
diff --git a/sweagent/run/_progress.py b/sweagent/run/_progress.py
index b85d0e06..3abd51b1 100644
--- a/sweagent/run/_progress.py
+++ b/sweagent/run/_progress.py
@@ -19,8 +19,11 @@ from rich.table import Table
from sweagent.agent.models import GLOBAL_STATS
-def _shorten_str(s: str, max_len: int) -> str:
- s = s[: max_len - 3] + "..." if len(s) > max_len else s
+def _shorten_str(s: str, max_len: int, shorten_left=False) -> str:
+ if not shorten_left:
+ s = s[: max_len - 3] + "..." if len(s) > max_len else s
+ else:
+ s = "..." + s[-max_len + 3 :] if len(s) > max_len else s
return f"{s:<{max_len}}"
@@ -93,7 +96,7 @@ class RunBatchProgressManager:
self._task_progress_bar.update(
self._spinner_tasks[instance_id],
status=_shorten_str(message, 30),
- instance_id=_shorten_str(instance_id, 25),
+ instance_id=_shorten_str(instance_id, 25, shorten_left=True),
)
self._update_total_costs()
diff --git a/sweagent/run/run_batch.py b/sweagent/run/run_batch.py
index d7ddda6c..6a008772 100644
--- a/sweagent/run/run_batch.py
+++ b/sweagent/run/run_batch.py
@@ -5,7 +5,9 @@ Run on a batch of instances/issues. For example run on all of SWE-bench.
import getpass
import json
import logging
+import random
import sys
+import time
import traceback
from concurrent.futures import ThreadPoolExecutor, as_completed
from pathlib import Path
@@ -39,6 +41,11 @@ class RunBatchConfig(BaseSettings, cli_implicit_flags=True):
"""Path to a .env file to load environment variables from."""
num_workers: int = 1
"""Number of parallel workers to use. Default is 1 (sequential execution)."""
+ random_delay_multiplier: float = 0.3
+ """We will wait for a random amount of time between 0 and `random_delay_multiplier`
+ times the number of instances at the start of each instance. This is to avoid any
+ potential race conditions.
+ """
def set_default_output_dir(self) -> None:
# Needs to be called explicitly, because self._config_files will be setup
@@ -164,6 +171,9 @@ class RunBatch:
self._progress_manager.print_report()
def run_instance(self, instance: BatchInstance) -> None:
+ # Let's add some randomness to avoid any potential race conditions
+ time.sleep(random.random() * 0.3 * (len(self.instances) - 1))
+
self._progress_manager.on_instance_start(instance.problem_statement.id)
if self.should_skip(instance):