Skip to content

Commit 60fed54

Browse files
committed
add: coarse retries for agent run
1 parent 583dd10 commit 60fed54

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

codegen-examples/examples/swebench_agent_run/eval_cli.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,6 @@ def run_eval(
294294
@click.option("--local", help="Run the evaluation locally.", is_flag=True, default=False)
295295
@click.option("--push-metrics", help="Push metrics to the database.", is_flag=True, default=False)
296296
@click.option("--repo", help="The repo to use.", type=str, default=None)
297-
@click.option(
298-
"--num-workers",
299-
help="The number of workers to use. This is the number of examples that will be processed concurrently. A large number may lead to rate limiting issues.",
300-
type=int,
301-
default=5,
302-
)
303297
@click.option("--model", help="The model to use.", type=str, default="claude-3-7-sonnet-latest")
304298
def main(
305299
use_existing_preds: Optional[str],
@@ -308,7 +302,6 @@ def main(
308302
instance_id: Optional[str],
309303
local: bool,
310304
repo: Optional[str],
311-
num_workers: int,
312305
model: str,
313306
push_metrics: bool,
314307
) -> None:
@@ -324,7 +317,6 @@ def main(
324317
codebases=None,
325318
local=local,
326319
repo=repo,
327-
num_workers=num_workers,
328320
model=model,
329321
)
330322
)

codegen-examples/examples/swebench_agent_run/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies = [
1010
"click>=8.1.0",
1111
"codegen",
1212
"swebench>=3.0.15",
13+
"tenacity>=9.0.0",
1314
]
1415

1516
[project.optional-dependencies]

codegen-examples/examples/swebench_agent_run/swebench_agent_run/modal_harness/entry_point.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from unittest.mock import patch
1414

1515
import modal as modal_lib
16+
import tenacity
1617
from swebench.harness.constants import (
1718
APPLY_PATCH_FAIL,
1819
APPLY_PATCH_PASS,
@@ -83,12 +84,38 @@
8384
)
8485

8586

87+
class ShouldRetry(Exception):
88+
pass
89+
90+
8691
@app.function(timeout=43200)
8792
async def run_agent_modal(entry: "SweBenchExample", run_id: str, model: str):
8893
from codegen.extensions.swebench.harness import run_agent_on_entry
8994

9095
"""Modal function to process a single example from the SWE-bench dataset."""
91-
return run_agent_on_entry(entry, run_id=run_id, model=model)
96+
for attempt in tenacity.Retrying(
97+
wait=tenacity.wait_exponential_jitter(max=600),
98+
retry=tenacity.retry_if_exception_type(ShouldRetry),
99+
):
100+
with attempt:
101+
try:
102+
return run_agent_on_entry(entry, run_id=run_id, model=model)
103+
except Exception as e:
104+
if any(
105+
msg in str(e).lower()
106+
for msg in (
107+
"rate limit",
108+
"too many requests",
109+
"429",
110+
"throttle",
111+
"quota exceeded",
112+
"capacity",
113+
"limit exceeded",
114+
)
115+
):
116+
raise ShouldRetry() from e
117+
else:
118+
raise e
92119

93120

94121
@app.function(

codegen-examples/examples/swebench_agent_run/uv.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)