Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(issues): skip blocker checks when a top-level issue is created (#11516)
pseudoyu20a135bd9990
diff --git a/server/internal/handler/issue_blocker_test.go b/server/internal/handler/issue_blocker_test.goindex 4ed352ddbf..516c351e3b 100644--- a/server/internal/handler/issue_blocker_test.go+++ b/server/internal/handler/issue_blocker_test.go@@ -97,6 +97,46 @@ func TestIssueBlockerAtomicAPIAndFilter(t *testing.T) {testutil.Call(t, testHandler.UpdateIssue, req).Want(http.StatusBadRequest)}+// A bulk insert of top-level issues took minutes under stale planner statistics+// when every row ran the blocker checks.+func TestIssueBlockerChecksSkipNewTopLevelIssues(t *testing.T) {+ ctx := context.Background()+ parent := blockerTestIssue(t, map[string]any{})+ tx, err := testPool.Begin(ctx)+ if err != nil {+ t.Fatal(err)+ }+ defer tx.Rollback(ctx)+ // Both checks fail loudly inside this transaction only.+ if _, err := tx.Exec(ctx, `+ CREATE OR REPLACE FUNCTION check_issue_blocker_graph(ws uuid, target uuid) RETURNS void+ LANGUAGE plpgsql AS $$ BEGIN RAISE EXCEPTION 'blocker checks ran'; END $$;+ CREATE OR REPLACE FUNCTION arm_issue_blocker_wakeup(ws uuid, target uuid) RETURNS void+ LANGUAGE plpgsql AS $$ BEGIN RAISE EXCEPTION 'blocker checks ran'; END $$;+ `); err != nil {+ t.Fatal(err)+ }+ insert := func(parentID any) error {+ sub, err := tx.Begin(ctx)+ if err != nil {+ t.Fatal(err)+ }+ defer sub.Rollback(ctx)+ _, err = sub.Exec(ctx, `+ INSERT INTO issue (workspace_id, title, status, priority, creator_type, creator_id, position, number, parent_issue_id)+ SELECT $1, 'blocker checks', 'todo', 'none', 'member', $2, 0, COALESCE(MAX(number), 0) + 1, $3::uuid+ FROM issue WHERE workspace_id = $1+ `, testWorkspaceID, testUserID, parentID)+ return err+ }+ if err := insert(nil); err != nil {+ t.Fatalf("top-level insert: %v", err)+ }+ if err := insert(parent.ID); err == nil || !strings.Contains(err.Error(), "blocker checks ran") {+ t.Fatalf("sub-issue insert skipped the blocker checks: %v", err)+ }+}+func TestIssueBlockerRejectsMissingReferenceAtomically(t *testing.T) {title := "missing blocker " + uuid.NewString()testutil.Call(t, testHandler.CreateIssue, newRequest("POST", "/api/issues?workspace_id="+testWorkspaceID, map[string]any{"title": title, "blocked_by": []string{uuid.NewString()}})).Want(400)diff --git a/server/migrations/754_issue_stage_blockers_skip_top_level.down.sql b/server/migrations/754_issue_stage_blockers_skip_top_level.down.sqlnew file mode 100644index 0000000000..0c5f6e88e5--- /dev/null+++ b/server/migrations/754_issue_stage_blockers_skip_top_level.down.sql@@ -0,0 +1,18 @@+CREATE OR REPLACE FUNCTION record_issue_stage_blockers() RETURNS trigger LANGUAGE plpgsql AS $$+DECLARE candidate uuid; previous_parent uuid;+BEGIN+ IF TG_OP='UPDATE' THEN previous_parent:=OLD.parent_issue_id; END IF;+ IF TG_OP='UPDATE' AND NEW.parent_issue_id IS NOT DISTINCT FROM OLD.parent_issue_id+ AND NEW.stage IS NOT DISTINCT FROM OLD.stage AND NEW.status IS NOT DISTINCT FROM OLD.status THEN RETURN NULL; END IF;+ IF TG_OP='INSERT' OR NEW.parent_issue_id IS DISTINCT FROM OLD.parent_issue_id OR NEW.stage IS DISTINCT FROM OLD.stage THEN+ PERFORM check_issue_blocker_graph(NEW.workspace_id,NEW.id);+ END IF;+ FOR candidate IN+ SELECT NEW.id UNION+ SELECT b.issue_id FROM issue_blocker b WHERE b.workspace_id=NEW.workspace_id AND b.blocker_issue_id=NEW.id UNION+ SELECT i.id FROM issue i WHERE i.workspace_id=NEW.workspace_id AND (i.parent_issue_id=NEW.parent_issue_id OR i.parent_issue_id=previous_parent) AND i.stage IS NOT NULL+ LOOP+ PERFORM arm_issue_blocker_wakeup(NEW.workspace_id,candidate);+ END LOOP;+ RETURN NULL;+END $$;diff --git a/server/migrations/754_issue_stage_blockers_skip_top_level.up.sql b/server/migrations/754_issue_stage_blockers_skip_top_level.up.sqlnew file mode 100644index 0000000000..85d963627d--- /dev/null+++ b/server/migrations/754_issue_stage_blockers_skip_top_level.up.sql@@ -0,0 +1,22 @@+-- A new issue without a parent has no manual edges yet and no stage siblings, so+-- there is no graph to check and nothing to arm. Looking anyway scans the+-- workspace's issues for every inserted row when planner statistics are stale.+CREATE OR REPLACE FUNCTION record_issue_stage_blockers() RETURNS trigger LANGUAGE plpgsql AS $$+DECLARE candidate uuid; previous_parent uuid;+BEGIN+ IF TG_OP='INSERT' AND NEW.parent_issue_id IS NULL THEN RETURN NULL; END IF;+ IF TG_OP='UPDATE' THEN previous_parent:=OLD.parent_issue_id; END IF;+ IF TG_OP='UPDATE' AND NEW.parent_issue_id IS NOT DISTINCT FROM OLD.parent_issue_id+ AND NEW.stage IS NOT DISTINCT FROM OLD.stage AND NEW.status IS NOT DISTINCT FROM OLD.status THEN RETURN NULL; END IF;+ IF TG_OP='INSERT' OR NEW.parent_issue_id IS DISTINCT FROM OLD.parent_issue_id OR NEW.stage IS DISTINCT FROM OLD.stage THEN+ PERFORM check_issue_blocker_graph(NEW.workspace_id,NEW.id);+ END IF;+ FOR candidate IN+ SELECT NEW.id UNION+ SELECT b.issue_id FROM issue_blocker b WHERE b.workspace_id=NEW.workspace_id AND b.blocker_issue_id=NEW.id UNION+ SELECT i.id FROM issue i WHERE i.workspace_id=NEW.workspace_id AND (i.parent_issue_id=NEW.parent_issue_id OR i.parent_issue_id=previous_parent) AND i.stage IS NOT NULL+ LOOP+ PERFORM arm_issue_blocker_wakeup(NEW.workspace_id,candidate);+ END LOOP;+ RETURN NULL;+END $$;