From bf8abba24d82289d5b29472985f2371226bf2068 Mon Sep 17 00:00:00 2001 From: Jiayuan Zhang Date: Fri, 10 Apr 2026 16:21:20 +0800 Subject: [PATCH] fix(db): relax pending task unique index to per-(issue, agent) (#637) The idx_one_pending_task_per_issue index only allowed one pending task per issue across all agents, causing different agents' queued/dispatched tasks to block each other. This mismatched the code-level dedup which checks per (issue_id, agent_id). Replace with idx_one_pending_task_per_issue_agent on (issue_id, agent_id) so each agent can independently have one pending task. Fixes MUL-495 Co-authored-by: Claude Opus 4.6 (1M context) --- .../migrations/037_fix_pending_task_unique_index.down.sql | 5 +++++ .../migrations/037_fix_pending_task_unique_index.up.sql | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 server/migrations/037_fix_pending_task_unique_index.down.sql create mode 100644 server/migrations/037_fix_pending_task_unique_index.up.sql diff --git a/server/migrations/037_fix_pending_task_unique_index.down.sql b/server/migrations/037_fix_pending_task_unique_index.down.sql new file mode 100644 index 000000000..18b6a7e9a --- /dev/null +++ b/server/migrations/037_fix_pending_task_unique_index.down.sql @@ -0,0 +1,5 @@ +DROP INDEX IF EXISTS idx_one_pending_task_per_issue_agent; + +CREATE UNIQUE INDEX idx_one_pending_task_per_issue + ON agent_task_queue (issue_id) + WHERE status IN ('queued', 'dispatched'); diff --git a/server/migrations/037_fix_pending_task_unique_index.up.sql b/server/migrations/037_fix_pending_task_unique_index.up.sql new file mode 100644 index 000000000..e7e4466c0 --- /dev/null +++ b/server/migrations/037_fix_pending_task_unique_index.up.sql @@ -0,0 +1,8 @@ +-- Fix: the old index only allowed one pending task per issue across ALL agents. +-- This caused different agents' pending tasks to block each other. +-- Change to per-(issue, agent) so each agent can independently have one pending task. +DROP INDEX IF EXISTS idx_one_pending_task_per_issue; + +CREATE UNIQUE INDEX idx_one_pending_task_per_issue_agent + ON agent_task_queue (issue_id, agent_id) + WHERE status IN ('queued', 'dispatched');