fix: fallback если Claude не отправил result event
Проблема: Claude Code Docker иногда завершается без отправки result event в stream-json — UI зависал на "Claude анализирует..." Теперь после завершения процесса проверяем наличие файлов batch_script.py и batch_summary.json на диске. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+17
-5
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user