fix(task): enforce per-issue serial execution in task claiming (#330)
Add NOT EXISTS check to ClaimAgentTask SQL to prevent claiming a queued task when the same issue already has a dispatched/running task. This ensures serial execution within an issue while preserving parallel execution across different issues (concurrency group pattern). Also add defensive guard in the frontend task:dispatch handler to avoid replacing an active task's LiveLog timeline mid-execution. Closes MUL-183 Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ff616de82b
commit
a80d61f8e1
3 changed files with 23 additions and 2 deletions
|
|
@ -59,6 +59,11 @@ SET status = 'dispatched', dispatched_at = now()
|
|||
WHERE id = (
|
||||
SELECT atq.id FROM agent_task_queue atq
|
||||
WHERE atq.agent_id = $1 AND atq.status = 'queued'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM agent_task_queue active
|
||||
WHERE active.issue_id = atq.issue_id
|
||||
AND active.status IN ('dispatched', 'running')
|
||||
)
|
||||
ORDER BY atq.priority DESC, atq.created_at ASC
|
||||
LIMIT 1
|
||||
FOR UPDATE SKIP LOCKED
|
||||
|
|
@ -66,6 +71,10 @@ WHERE id = (
|
|||
RETURNING id, agent_id, issue_id, status, priority, dispatched_at, started_at, completed_at, result, error, created_at, context, runtime_id, session_id, work_dir, trigger_comment_id
|
||||
`
|
||||
|
||||
// Claims the next queued task for an agent, enforcing per-issue serialization:
|
||||
// a task is only claimable when no other task for the same issue is already
|
||||
// dispatched or running. This guarantees serial execution within an issue
|
||||
// while allowing parallel execution across different issues.
|
||||
func (q *Queries) ClaimAgentTask(ctx context.Context, agentID pgtype.UUID) (AgentTaskQueue, error) {
|
||||
row := q.db.QueryRow(ctx, claimAgentTask, agentID)
|
||||
var i AgentTaskQueue
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue