Skip to content

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

Go

MUL-8416 fix(comments): keep thread owner when root folds into a queued task (#9735)

Jiayuan Zhangac131c55cb83
diff --git a/server/cmd/server/comment_trigger_integration_test.go b/server/cmd/server/comment_trigger_integration_test.go
index 9cf4955527..b1f10a37e2 100644
--- a/server/cmd/server/comment_trigger_integration_test.go
+++ b/server/cmd/server/comment_trigger_integration_test.go
@@ -379,6 +379,32 @@ func TestCommentTriggerOnComment(t *testing.T) {
}
})
+ // MUL-8416: a reply that merges into the root's still-queued task takes
+ // over trigger_comment_id. Later replies under the root must still reach
+ // the agent once that task has finished.
+ t.Run("reply to member thread whose root was folded into a queued task continues agent", func(t *testing.T) {
+ clearTasks(t, issueID)
+ threadID := postComment(t, issueID, "Please fix this bug", nil)
+ followUpID := postComment(t, issueID, "Also check the spacing", strPtr(threadID))
+ if n := countPendingTasks(t, issueID); n != 1 {
+ t.Fatalf("expected the follow-up to merge into the root's task, got %d pending tasks", n)
+ }
+ if got := latestTriggerCommentID(t, issueID); got != followUpID {
+ t.Fatalf("trigger_comment_id = %q, want merged follow-up %q", got, followUpID)
+ }
+ if _, err := testPool.Exec(context.Background(), `
+ UPDATE agent_task_queue
+ SET status = 'completed', completed_at = now()
+ WHERE issue_id = $1 AND trigger_comment_id = $2
+ `, issueID, followUpID); err != nil {
+ t.Fatalf("failed to complete merged task: %v", err)
+ }
+ postComment(t, issueID, "Should the page header go too?", strPtr(threadID))
+ if n := countPendingTasks(t, issueID); n != 1 {
+ t.Errorf("expected 1 pending task (conversation continuation), got %d", n)
+ }
+ })
+
t.Run("reply to member thread mentioning assignee triggers agent", func(t *testing.T) {
clearTasks(t, issueID)
// Member starts a thread.
diff --git a/server/internal/handler/comment_root_projection_test.go b/server/internal/handler/comment_root_projection_test.go
index a8b372c40f..6e4b1d1cb0 100644
--- a/server/internal/handler/comment_root_projection_test.go
+++ b/server/internal/handler/comment_root_projection_test.go
@@ -158,6 +158,25 @@ func TestConversationRootOwnersReadOnlyRoutingData(t *testing.T) {
t.Fatalf("%s supplement invented a root owner", status)
}
}
+ // A root folded into a queued task keeps its owner after the merge moved
+ // trigger_comment_id to the newer comment (MUL-8416).
+ foldedID := dbfx.Comment(t, issueID, "Root folded into a queued task")
+ followUpID := dbfx.Comment(t, issueID, "Follow-up that took over the trigger", testutil.Cols{"parent_id": foldedID})
+ folded, err := testHandler.Queries.GetComment(ctx, parseUUID(foldedID))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if got, owned := h.routeConversationOwnersForRoot(ctx, issue, folded, testUserID, commentTriggerComputeOptions{}); owned || len(got) != 0 {
+ t.Fatal("unrouted root invented an owner")
+ }
+ dbfx.Task(t, agentA, testutil.Cols{
+ "issue_id": issueID, "trigger_comment_id": followUpID,
+ "coalesced_comment_ids": testutil.Raw(fmt.Sprintf("ARRAY['%s']::uuid[]", foldedID)),
+ "runtime_id": handlerTestRuntimeID(t), "status": "completed",
+ })
+ if got, owned := h.routeConversationOwnersForRoot(ctx, issue, folded, testUserID, commentTriggerComputeOptions{}); !owned || len(got) != 1 || uuidToString(got[0].Agent.ID) != agentA {
+ t.Fatalf("folded root lost its owner: owned=%t triggers=%d", owned, len(got))
+ }
empty.Content = fmt.Sprintf("[@Other](mention://agent/%s)", otherAgent)
if got, owned := h.routeConversationOwnersForRoot(ctx, issue, empty, testUserID, commentTriggerComputeOptions{}); !owned || len(got) != 1 || uuidToString(got[0].Agent.ID) != otherAgent {
t.Fatal("delivered supplement overrode explicit owner")
diff --git a/server/pkg/db/generated/conversation_root.sql.go b/server/pkg/db/generated/conversation_root.sql.go
index 43171061cb..e2dfb54c8c 100644
--- a/server/pkg/db/generated/conversation_root.sql.go
+++ b/server/pkg/db/generated/conversation_root.sql.go
@@ -15,7 +15,7 @@ const listConversationRootOwners = `-- name: ListConversationRootOwners :many
SELECT DISTINCT ON (agent_id) agent_id, squad_id
FROM agent_task_queue t
WHERE t.issue_id = $1 AND t.agent_id IS NOT NULL
- AND (t.trigger_comment_id = $2 OR EXISTS (
+ AND (t.trigger_comment_id = $2 OR $2 = ANY(t.coalesced_comment_ids) OR EXISTS (
SELECT 1 FROM task_supplement s
WHERE s.task_id = t.id AND s.issue_id = t.issue_id
AND s.comment_id = $2 AND s.status = 'delivered'
@@ -34,6 +34,9 @@ type ListConversationRootOwnersRow struct {
}
// Preserve the newest non-null squad per agent, including terminal tasks.
+// A root folded into a queued task keeps its owner after the merge repoints
+// trigger_comment_id at the newer comment and moves the root into
+// coalesced_comment_ids (MUL-8416).
// A delivered supplement establishes ownership even when the root did not
// start a separate task. Pending or failed delivery does not establish it.
// Routing does not need execution context, results, or other issue threads.
diff --git a/server/pkg/db/queries/conversation_root.sql b/server/pkg/db/queries/conversation_root.sql
index 7869260885..dc61bb10e9 100644
--- a/server/pkg/db/queries/conversation_root.sql
+++ b/server/pkg/db/queries/conversation_root.sql
@@ -1,12 +1,15 @@
-- name: ListConversationRootOwners :many
-- Preserve the newest non-null squad per agent, including terminal tasks.
+-- A root folded into a queued task keeps its owner after the merge repoints
+-- trigger_comment_id at the newer comment and moves the root into
+-- coalesced_comment_ids (MUL-8416).
-- A delivered supplement establishes ownership even when the root did not
-- start a separate task. Pending or failed delivery does not establish it.
-- Routing does not need execution context, results, or other issue threads.
SELECT DISTINCT ON (agent_id) agent_id, squad_id
FROM agent_task_queue t
WHERE t.issue_id = $1 AND t.agent_id IS NOT NULL
- AND (t.trigger_comment_id = $2 OR EXISTS (
+ AND (t.trigger_comment_id = $2 OR $2 = ANY(t.coalesced_comment_ids) OR EXISTS (
SELECT 1 FROM task_supplement s
WHERE s.task_id = t.id AND s.issue_id = t.issue_id
AND s.comment_id = $2 AND s.status = 'delivered'