From 72027b70639c983d606279bc7d67ec54c16c712d Mon Sep 17 00:00:00 2001 From: cfdaily Date: Sat, 23 May 2026 00:39:34 +0800 Subject: [PATCH] auto-sync: 2026-05-23 00:39:34 --- src/daemon/spawner.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/daemon/spawner.py b/src/daemon/spawner.py index 05b3051..9163920 100644 --- a/src/daemon/spawner.py +++ b/src/daemon/spawner.py @@ -803,6 +803,33 @@ curl -X POST http://{api_host}:{api_port}/api/projects/{project_id}/tasks/{task_ pass return defaults + def _update_retry_counts(self, db_path: Optional[Path], + task_id: Optional[str], counts: dict): + """将 retry counts 写回最新 task_attempt 的 metadata""" + if not db_path or not task_id: + return + try: + conn = get_connection(db_path) + try: + conn.execute("BEGIN IMMEDIATE") + row = conn.execute( + "SELECT rowid, metadata FROM task_attempts " + "WHERE task_id=? ORDER BY attempt_number DESC LIMIT 1", + (task_id,) + ).fetchone() + if row: + meta = json.loads(row["metadata"]) if row["metadata"] else {} + meta.update(counts) + conn.execute( + "UPDATE task_attempts SET metadata=? WHERE rowid=?", + (json.dumps(meta), row["rowid"]) + ) + conn.commit() + finally: + conn.close() + except Exception: + logger.exception("Failed to update retry counts for task %s", task_id) + def _mark_task(self, db_path: Optional[Path], task_id: Optional[str], status: str, detail: Optional[dict] = None): """标记任务状态(用于 failed/escalate)"""