Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(db): drop FK on agent_task_queue.initiator_user_id (MUL-2645) (#3959)

Bohan Jiang2e0b0bb77646
diff --git a/server/migrations/117_agent_task_queue_initiator_user_id.up.sql b/server/migrations/117_agent_task_queue_initiator_user_id.up.sql
index 0c85fb907a..2af7a54621 100644
--- a/server/migrations/117_agent_task_queue_initiator_user_id.up.sql
+++ b/server/migrations/117_agent_task_queue_initiator_user_id.up.sql
@@ -8,5 +8,12 @@
-- NULL for non-chat tasks and for chat tasks queued before this column existed;
-- the brief simply omits the `## Task Initiator` section in that case. See
-- MUL-2645.
+--
+-- Plain UUID, no FK to "user": adding a foreign key here also takes a lock on
+-- the (hot) "user" table at migration time, which made this ALTER time out on a
+-- busy production deploy. The column only feeds a best-effort name/email lookup
+-- at claim time (a stale id just yields no initiator section), so referential
+-- integrity is not load-bearing. Migration 118 drops the FK on environments
+-- that already applied the original constraint-bearing version of this file.
ALTER TABLE agent_task_queue
- ADD COLUMN initiator_user_id UUID REFERENCES "user"(id) ON DELETE SET NULL;
+ ADD COLUMN initiator_user_id UUID;
diff --git a/server/migrations/118_agent_task_queue_initiator_user_id_drop_fk.down.sql b/server/migrations/118_agent_task_queue_initiator_user_id_drop_fk.down.sql
new file mode 100644
index 0000000000..3e4171f45c
--- /dev/null
+++ b/server/migrations/118_agent_task_queue_initiator_user_id_drop_fk.down.sql
@@ -0,0 +1,7 @@
+-- Intentionally empty. The up is a convergence step ("ensure no FK on
+-- initiator_user_id") whose effect is conditional (DROP CONSTRAINT IF EXISTS),
+-- so it has no single inverse: on a database first migrated with the FK-free
+-- 117 there was never a constraint to restore, and re-adding the FK on rollback
+-- would reintroduce the exact lock-on-"user" timeout this migration removed.
+-- The FK is non-essential, so leaving the column FK-less on rollback is correct.
+-- Full rollback drops the column via 117's down migration.
diff --git a/server/migrations/118_agent_task_queue_initiator_user_id_drop_fk.up.sql b/server/migrations/118_agent_task_queue_initiator_user_id_drop_fk.up.sql
new file mode 100644
index 0000000000..11ba9f1266
--- /dev/null
+++ b/server/migrations/118_agent_task_queue_initiator_user_id_drop_fk.up.sql
@@ -0,0 +1,13 @@
+-- Converge environments that already applied the original constraint-bearing
+-- version of migration 117 (which added `initiator_user_id` with a foreign key
+-- to "user"). Those environments skip the now-edited 117 by version, so the FK
+-- still exists there; this drops it so every environment ends up with a plain
+-- `initiator_user_id` column and no FK.
+--
+-- The FK to the hot "user" table is what made 117 time out on a busy deploy, and
+-- the column only feeds a best-effort name/email lookup at claim time, so the
+-- constraint is not needed. DROP CONSTRAINT only touches catalog metadata (a
+-- brief lock on agent_task_queue, no table scan, no lock on "user"). IF EXISTS
+-- makes this a no-op where 117 already ran in its FK-free form. See MUL-2645.
+ALTER TABLE agent_task_queue
+ DROP CONSTRAINT IF EXISTS agent_task_queue_initiator_user_id_fkey;