From d9d8862706f624e459d116a1d98bdc5a6750bf9c Mon Sep 17 00:00:00 2001 From: cfdaily Date: Mon, 25 May 2026 13:20:31 +0800 Subject: [PATCH] auto-sync: 2026-05-25 13:20:31 --- src/daemon/spawner.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/daemon/spawner.py b/src/daemon/spawner.py index e570da9..a62b9e4 100644 --- a/src/daemon/spawner.py +++ b/src/daemon/spawner.py @@ -625,6 +625,25 @@ curl -X POST http://{api_host}:{api_port}/api/projects/{project_id}/tasks/{task_ async def _do_retry(self, session_id, agent_id, task_id, on_complete, db_path, retry_field="retry_count"): """续杯:用同一 session_id 再 spawn 一次""" + # Bug-6: 续杯前检查任务状态,已终态则跳过 + if db_path and task_id: + try: + conn = get_connection(db_path) + try: + row = conn.execute( + "SELECT status FROM tasks WHERE id=?", (task_id,) + ).fetchone() + if row and row["status"] in ("done", "failed", "cancelled", "review"): + logger.info("Retry skip: task %s already %s (agent=%s)", + task_id, row["status"], agent_id) + # counter 仍然占用,通过 on_complete release + await self._do_on_complete_async(on_complete, agent_id, "task_already_done") + return + finally: + conn.close() + except Exception: + logger.warning("Retry status check failed for %s, proceeding", task_id) + # 直接读写 tasks 表的 retry_count(广播场景下所有 Agent 共享同一 tasks 记录) # task_attempts metadata 的 retry_count 不可靠(多 Agent 互相覆盖) if retry_field == "retry_count" and db_path and task_id: