diff --git a/batch_v2.py b/batch_v2.py index 5c89ad1..3c67f9f 100644 --- a/batch_v2.py +++ b/batch_v2.py @@ -367,13 +367,25 @@ async def run_claude_analysis( finally: if proc.returncode is None: proc.terminate() - await proc.wait() + await proc.wait() - # If Claude exited without result event — read stderr + # If Claude exited without emitting a result event — check files directly if not got_result: - stderr = await proc.stderr.read() - err_msg = stderr.decode()[:500] if stderr else "Claude exited without result" - yield {"type": "done", "script": "", "result": f"Error: {err_msg}"} + script_path = job_dir / "batch_script.py" + summary_path = job_dir / "batch_summary.json" + summary = {} + if summary_path.exists(): + try: + summary = json.loads(summary_path.read_text(encoding="utf-8")) + except (json.JSONDecodeError, OSError): + pass + if script_path.exists(): + script = script_path.read_text(encoding="utf-8") + yield {"type": "done", "script": script, "summary": summary} + else: + stderr = await proc.stderr.read() + err_msg = stderr.decode()[:500] if stderr else "Claude exited without generating script" + yield {"type": "done", "script": "", "result": f"Error: {err_msg}", "summary": summary} def run_batch_v2(job_id: str, script: str, source_dir: str, target_file: str):