diff --git a/src/daemon/ticker.py b/src/daemon/ticker.py index f4eaf4b..4896e52 100644 --- a/src/daemon/ticker.py +++ b/src/daemon/ticker.py @@ -1501,19 +1501,22 @@ Parent Task ID: {parent_task.id} ).fetchall() for task in rows: - action = self._determine_recovery_action(conn, task, status, db_path) - if action: - self._execute_recovery(conn, task["id"], action, db_path) - recovered.append({"task_id": task["id"], "from": status, "action": action}) - else: - # 审计:保持原状的任务也记录事件 - noop_count += 1 - conn.execute( - "INSERT INTO events (task_id, agent, event_type, detail) VALUES (?, ?, ?, ?)", - (task["id"], "daemon", "startup_recovery_noop", - json.dumps({"status": status, "reason": "no_action_needed"})) - ) - conn.commit() + try: + action = self._determine_recovery_action(conn, task, status, db_path) + if action: + self._execute_recovery(conn, task["id"], action, db_path) + recovered.append({"task_id": task["id"], "from": status, "action": action}) + else: + # 审计:保持原状的任务也记录事件 + noop_count += 1 + conn.execute( + "INSERT INTO events (task_id, agent, event_type, detail) VALUES (?, ?, ?, ?)", + (task["id"], "daemon", "startup_recovery_noop", + json.dumps({"status": status, "reason": "no_action_needed"})) + ) + conn.commit() + except Exception: + logger.exception("Startup recovery failed for task %s", task["id"]) finally: conn.close()