Process a single instance. Used by ThreadPoolExecutor.
(instance_data: tuple)
| 203 | output_dir.mkdir(parents=True, exist_ok=True) |
| 204 | |
| 205 | def process_single_instance(instance_data: tuple) -> InstanceResult: |
| 206 | """Process a single instance. Used by ThreadPoolExecutor.""" |
| 207 | idx, total, instance = instance_data |
| 208 | instance_id = instance["instance_id"] |
| 209 | |
| 210 | print(f"\n{'='*80}") |
| 211 | print(f"[{idx}/{total}] Starting: {instance_id}") |
| 212 | print(f"{'='*80}") |
| 213 | |
| 214 | docker_client = None |
| 215 | |
| 216 | try: |
| 217 | image = DockerExecClient.resolve_image_name(instance_id) |
| 218 | print(f"[{instance_id}] Starting SWE-bench container: {image}") |
| 219 | docker_client = DockerExecClient(image=image) |
| 220 | agent = AgentSPEX(mcp_client=docker_client) |
| 221 | |
| 222 | result = run_instance( |
| 223 | instance, |
| 224 | agent, |
| 225 | agent.mcp_client, |
| 226 | args, |
| 227 | output_dir, |
| 228 | save_logs=args.save_logs, |
| 229 | ) |
| 230 | print(f"[{instance_id}] Completed successfully") |
| 231 | return result |
| 232 | except Exception as e: |
| 233 | print(f"[{instance_id}] Error: {e}") |
| 234 | return InstanceResult( |
| 235 | instance_id=instance_id, |
| 236 | success=False, |
| 237 | error=str(e), |
| 238 | ) |
| 239 | finally: |
| 240 | if docker_client is not None: |
| 241 | docker_client.close() |
| 242 | |
| 243 | # Prepare instance data with index info |
| 244 | instance_data_list = [ |
no test coverage detected