From 8f91f88a06b96526bb9fa935558a1eff3b2d0447 Mon Sep 17 00:00:00 2001 From: cfdaily Date: Thu, 21 May 2026 20:57:39 +0800 Subject: [PATCH] auto-sync: 2026-05-21 20:57:39 --- src/daemon/ticker.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/daemon/ticker.py b/src/daemon/ticker.py index f87e4f4..d201712 100644 --- a/src/daemon/ticker.py +++ b/src/daemon/ticker.py @@ -545,6 +545,23 @@ class Ticker: logger.info("Broadcasting %d tasks to %d idle agents: %s", len(broadcastable), len(idle_agents), task_ids) + # 广播前为每个任务写审计事件 + try: + conn = get_connection(db_path) + try: + for task in broadcastable: + conn.execute( + "INSERT INTO events (task_id, agent, event_type, detail) " + "VALUES (?,?,?,?)", + (task.id, "daemon", "broadcast_claim", + json.dumps({"agents": idle_agents, "task_title": task.title})), + ) + conn.commit() + finally: + conn.close() + except Exception: + pass # 审计记录失败不影响广播 + spawned = [] for agent_id in idle_agents: if not await self.counter.can_acquire(agent_id): @@ -559,22 +576,6 @@ class Ticker: ) spawned.append(agent_id) logger.info("Broadcast spawned %s (session=%s)", agent_id, session_id) - # 写广播路由审计记录 - try: - conn = get_connection(db_path) - try: - conn.execute( - "INSERT INTO routing_decisions " - "(task_id, mode, selected_agent, reason, outcome, created_at) " - "VALUES (?,?,?,?,?,datetime('now'))", - (t.id, "broadcast", agent_id, - f"Broadcast claim prompt sent", "dispatched"), - ) - conn.commit() - finally: - conn.close() - except Exception: - pass # 审计记录失败不影响广播 except Exception: self.counter.release(agent_id) logger.exception("Broadcast spawn failed for %s", agent_id)