fix: create agent execution when moving assigned task to in_progress
Deploy Dashboard (Dev) / deploy-dev (push) Successful in 2m59s
Run Tests / Backend Tests (push) Failing after 59s
Run Tests / Frontend Tests (push) Has started running
Run Tests / Test Summary (push) Has been cancelled

This commit is contained in:
Gan, Jimmy
2026-04-02 21:14:27 +08:00
parent af5b4d8411
commit 8c08ae32cc
+17 -3
View File
@@ -225,15 +225,29 @@ async def move_task(
print(f"[Move] Task {task_id} not assigned, auto-assigning to PM agent") print(f"[Move] Task {task_id} not assigned, auto-assigning to PM agent")
updates["assigned_to"] = "pm" updates["assigned_to"] = "pm"
updates["assigned_type"] = "agent" updates["assigned_type"] = "agent"
# Create agent execution record
# 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,
status="pending",
limit=1
)
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( execution_id = await opc_db.create_agent_execution(
task_id=task_id, task_id=task_id,
agent_id="pm", agent_id=agent_id,
actor=user.username actor=user.username
) )
print(f"[Move] Created agent execution {execution_id} for task {task_id}") print(f"[Move] Created agent execution {execution_id} for task {task_id}")
else: else:
print(f"[Move] Task {task_id} already assigned to {current_task.get('assigned_to')}") print(f"[Move] Pending execution already exists: {existing_executions[0]['id']}")
if old_status == "in_progress" and move.status != "in_progress": if old_status == "in_progress" and move.status != "in_progress":
await opc_db.stop_time_entry(task_id=task_id) await opc_db.stop_time_entry(task_id=task_id)