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: Don't print patch msg for exit_cost patch (#343)
Kilian Lieret33f51a2cb4f9
diff --git a/inspector/server.py b/inspector/server.pyindex 18d5a7b6..17a97b0f 100644--- a/inspector/server.py+++ b/inspector/server.py@@ -2,6 +2,7 @@ import http.serverimport jsonimport osimport socketserver+from typing import Listimport yamlfrom pathlib import Path@@ -47,8 +48,8 @@ def append_patch(instance_id, content, patches, patch_type):return content-def append_results(traj_path, instance_id, content, results, results_file, scorecards, scorecards_file):- stats = []+def append_results(traj_path: Path, instance_id: str, content, results, results_file, scorecards, scorecards_file):+ stats: List[str] = []model_stats = {}if traj_path.exists():data = json.loads(traj_path.read_text())diff --git a/run.py b/run.pyindex d88218fc..f21d0027 100644--- a/run.py+++ b/run.py@@ -123,6 +123,16 @@ class _ContinueLoop(Exception):class MainHook:"""Hook structure for the web server or other addons to interface with"""++ @staticmethod+ def _is_promising_patch(info: Dict[str, Any]) -> bool:+ """Do we actually believe that the patch will solve the issue?+ Or are we just submitting the last patch we generated before hitting an error?+ """+ # The exit status can also be `submitted (exit_cost)` etc.+ return info["exit_status"] == "submitted" and info.get("submission") is not None++def on_init(self, *, args: ScriptArguments, agent: Agent, env: SWEEnv, traj_dir: Path):"""Called when hook is initialized"""...@@ -166,6 +176,8 @@ class SaveApplyPatchHook(MainHook):if patch_path:if not self._apply_patch_locally:return+ if not self._is_promising_patch(info):+ returnassert self._instance # mypyif not self._instance["repo_type"] == "local":return@@ -211,7 +223,10 @@ class SaveApplyPatchHook(MainHook):returnmodel_patch = info["submission"]patch_output_file.write_text(model_patch)- self._print_patch_message(patch_output_file)+ if self._is_promising_patch(info):+ # Only print big congratulations if we actually believe+ # the patch will solve the issue+ self._print_patch_message(patch_output_file)return patch_output_filedef _apply_patch(self, patch_file: Path, local_dir: Path) -> None: