auto-sync: 2026-05-21 20:57:39
This commit is contained in:
+17
-16
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user