From 8de712786f90f3b6e468aa88b3b590f249067efb Mon Sep 17 00:00:00 2001 From: cfdaily Date: Thu, 28 May 2026 13:07:43 +0800 Subject: [PATCH] auto-sync: 2026-05-28 13:07:43 --- src/daemon/dispatcher.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/daemon/dispatcher.py b/src/daemon/dispatcher.py index 71c98bc..d8c7023 100644 --- a/src/daemon/dispatcher.py +++ b/src/daemon/dispatcher.py @@ -555,6 +555,27 @@ class Dispatcher: logger.error("Mail %s: failed to mark working: %s", task_id, e) return False + def _mail_revert_to_pending(self, task_id: str, db_path: Path) -> None: + """Mail spawn 失败时回退 working → pending,避免永久死锁""" + try: + conn = get_connection(db_path) + try: + conn.execute("BEGIN IMMEDIATE") + row = conn.execute("SELECT status FROM tasks WHERE id=?", (task_id,)).fetchone() + if row and row["status"] == "working": + conn.execute( + "UPDATE tasks SET status='pending', updated_at=datetime('now') WHERE id=?", + (task_id,), + ) + conn.commit() + logger.info("Mail %s: reverted working → pending (spawn failed)", task_id) + else: + logger.debug("Mail %s: skip revert (status=%s)", task_id, row["status"] if row else "?") + finally: + conn.close() + except Exception as e: + logger.error("Mail %s: failed to revert to pending: %s", task_id, e) + def _mail_auto_complete(self, task_id: str, agent_id: str, db_path: Path, must_haves: str) -> None: """Mail 任务:on_complete 后自动标 done/failed(含幻觉门控)"""