From 8c08ae32cc04805d2f66add4d3a65a525280a1d6 Mon Sep 17 00:00:00 2001 From: "Gan, Jimmy" Date: Thu, 2 Apr 2026 21:14:27 +0800 Subject: [PATCH] fix: create agent execution when moving assigned task to in_progress --- dashboard/backend/routers/opc_tasks.py | 28 +++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/dashboard/backend/routers/opc_tasks.py b/dashboard/backend/routers/opc_tasks.py index a4571ac..7ff192b 100644 --- a/dashboard/backend/routers/opc_tasks.py +++ b/dashboard/backend/routers/opc_tasks.py @@ -225,15 +225,29 @@ async def move_task( print(f"[Move] Task {task_id} not assigned, auto-assigning to PM agent") updates["assigned_to"] = "pm" updates["assigned_type"] = "agent" - # Create agent execution record - execution_id = await opc_db.create_agent_execution( + + # If assigned to an agent, ensure there's a pending execution + if current_task.get("assigned_type") == "agent" or updates.get("assigned_type") == "agent": + agent_id = updates.get("assigned_to") or current_task.get("assigned_to") + print(f"[Move] Task {task_id} assigned to agent {agent_id}, checking for existing execution") + + # Check if there's already a pending execution + existing_executions = await opc_db.get_agent_executions( task_id=task_id, - agent_id="pm", - actor=user.username + status="pending", + limit=1 ) - print(f"[Move] Created agent execution {execution_id} for task {task_id}") - else: - print(f"[Move] Task {task_id} already assigned to {current_task.get('assigned_to')}") + + if not existing_executions: + print(f"[Move] No pending execution found, creating one for agent {agent_id}") + execution_id = await opc_db.create_agent_execution( + task_id=task_id, + agent_id=agent_id, + actor=user.username + ) + print(f"[Move] Created agent execution {execution_id} for task {task_id}") + else: + print(f"[Move] Pending execution already exists: {existing_executions[0]['id']}") if old_status == "in_progress" and move.status != "in_progress": await opc_db.stop_time_entry(task_id=task_id)