diff --git a/src/daemon/dispatcher.py b/src/daemon/dispatcher.py index c3092b9..980fe9d 100644 --- a/src/daemon/dispatcher.py +++ b/src/daemon/dispatcher.py @@ -718,15 +718,23 @@ class Dispatcher: return True def _mark_task_status(self, db_path: Path, task_id: str, status: str) -> None: - """更新任务状态""" + """更新任务状态 + 写审计事件""" try: conn = get_connection(db_path) try: conn.execute("BEGIN IMMEDIATE") + old_row = conn.execute( + "SELECT status FROM tasks WHERE id=?", (task_id,) + ).fetchone() + old_status = old_row["status"] if old_row else "unknown" conn.execute( "UPDATE tasks SET status=?, updated_at=datetime('now') WHERE id=?", (status, task_id), ) + conn.execute( + "INSERT INTO events (task_id, event_type, payload) VALUES (?, 'status_change', ?)", + (task_id, f'{{"from": "{old_status}", "to": "{status}", "source": "auto_complete"}}'), + ) conn.commit() finally: conn.close()