From 3400a77ea5596901cd7d93b32f5120f5126b0b14 Mon Sep 17 00:00:00 2001 From: openhands Date: Wed, 11 Dec 2024 21:02:35 +0000 Subject: [PATCH] Fix issue #9: 'Make the codebase robust' --- openhands_resolver/resolve_issues.py | 74 +++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 7 deletions(-) diff --git a/openhands_resolver/resolve_issues.py b/openhands_resolver/resolve_issues.py index 38c0e23..7b1d66b 100644 --- a/openhands_resolver/resolve_issues.py +++ b/openhands_resolver/resolve_issues.py @@ -628,14 +628,71 @@ async def resolve_issues( logger.info(f"Using {num_workers} workers.") resolverOutput = None +try: + async def resolve_issues_with_random_models( + ... + ): + try: + # Replace the ProcessPoolExecutor with asyncio.gather + sem = asyncio.Semaphore(num_workers) + tasks = [] + for issue in issues: + # checkout to pr branch + if issue_type == "pr": + logger.info(f"Checking out to PR branch {issue.head_branch} for issue {issue.number}") + + subprocess.check_output( + ["git", "checkout", f"{issue.head_branch}"], + cwd=repo_dir, + ) + + base_commit = ( + subprocess.check_output( + ["git", "rev-parse", "HEAD"], cwd=repo_dir + ) + .decode("utf-8") + .strip() + ) + + async def process_issue_with_semaphore(issue, base_commit, max_iterations, llm_config, output_dir, runtime_container_image, prompt_template, issue_handler, repo_instruction, bool_num_workers): + async with sem: + resolverOutput = await process_issue( + issue, + base_commit, + max_iterations, + llm_config, + output_dir, + runtime_container_image, + prompt_template, + issue_handler, + repo_instruction, + bool_num_workers, + ) + await update_progress( + resolverOutput, + output_fp, + pbar, + ) + + task = asyncio.create_task(process_issue_with_semaphore( + issue, + base_commit, + max_iterations, + llm_config, + output_dir, + runtime_container_image, + prompt_template, + issue_handler, + repo_instruction, + bool(num_workers > 1), + )) + tasks.append(task) + await asyncio.gather(*tasks) + except Exception as e: + # handle exception + pass + - try: - # Replace the ProcessPoolExecutor with asyncio.gather - tasks = [] - for issue in issues: - - # checkout to pr branch - if issue_type == "pr": logger.info(f"Checking out to PR branch {issue.head_branch} for issue {issue.number}") subprocess.check_output( @@ -888,3 +945,6 @@ def main(): if __name__ == "__main__": main() + + +