Skip to content

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

Go

fix(comments): retain delivered supplement root owners (#9061)

Dantea790bc8c0846
diff --git a/server/internal/handler/comment_root_projection_test.go b/server/internal/handler/comment_root_projection_test.go
index 0d2c8c7c90..a8b372c40f 100644
--- a/server/internal/handler/comment_root_projection_test.go
+++ b/server/internal/handler/comment_root_projection_test.go
@@ -136,6 +136,33 @@ func TestConversationRootOwnersReadOnlyRoutingData(t *testing.T) {
if got, owned := h.routeConversationOwnersForRoot(ctx, issue, empty, testUserID, commentTriggerComputeOptions{}); owned || len(got) != 0 {
t.Fatal("invented empty root owner")
}
+ // A delivered top-level supplement retains its turn owner after completion
+ // even though the comment did not start a separate task (#9060).
+ supplementTask := dbfx.Task(t, agentA, testutil.Cols{
+ "issue_id": issueID, "trigger_comment_id": otherRootID,
+ "runtime_id": handlerTestRuntimeID(t), "status": "completed", "squad_id": newSquad,
+ })
+ dbfx.Exec(t, `INSERT INTO task_supplement
+ (task_id, workspace_id, issue_id, comment_id, author_id, client_request_id, status)
+ VALUES ($1,$2,$3,$4,$5,gen_random_uuid(),'pending')`,
+ supplementTask, testWorkspaceID, issueID, emptyID, testUserID)
+ dbfx.Cleanup(t, `DELETE FROM task_supplement WHERE task_id=$1`, supplementTask)
+ for _, status := range []string{"pending", "delivering", "failed", "delivered"} {
+ dbfx.Exec(t, `UPDATE task_supplement SET status=$1 WHERE task_id=$2`, status, supplementTask)
+ got, owned := h.routeConversationOwnersForRoot(ctx, issue, empty, testUserID, commentTriggerComputeOptions{})
+ if status == "delivered" {
+ if !owned || len(got) != 1 || uuidToString(got[0].Agent.ID) != agentA || got[0].Squad == nil || uuidToString(got[0].Squad.ID) != newSquad {
+ t.Fatalf("delivered supplement lost its terminal turn owner: owned=%t triggers=%d", owned, len(got))
+ }
+ } else if owned || len(got) != 0 {
+ t.Fatalf("%s supplement invented a root owner", status)
+ }
+ }
+ 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")
+ }
+
observer.fail = true
if got, owned := h.routeConversationOwnersForRoot(ctx, issue, root, testUserID, commentTriggerComputeOptions{}); owned || len(got) != 0 {
t.Fatal("read failure routed an owner")
diff --git a/server/pkg/db/generated/conversation_root.sql.go b/server/pkg/db/generated/conversation_root.sql.go
index 3fb884b6d0..43171061cb 100644
--- a/server/pkg/db/generated/conversation_root.sql.go
+++ b/server/pkg/db/generated/conversation_root.sql.go
@@ -13,8 +13,13 @@ import (
const listConversationRootOwners = `-- name: ListConversationRootOwners :many
SELECT DISTINCT ON (agent_id) agent_id, squad_id
-FROM agent_task_queue
-WHERE issue_id = $1 AND trigger_comment_id = $2 AND agent_id IS NOT NULL
+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 (
+ 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'
+ ))
ORDER BY agent_id, (squad_id IS NOT NULL) DESC, created_at DESC, id DESC
`
@@ -29,6 +34,8 @@ type ListConversationRootOwnersRow struct {
}
// Preserve the newest non-null squad per agent, including terminal tasks.
+// 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.
func (q *Queries) ListConversationRootOwners(ctx context.Context, arg ListConversationRootOwnersParams) ([]ListConversationRootOwnersRow, error) {
rows, err := q.db.Query(ctx, listConversationRootOwners, arg.IssueID, arg.TriggerCommentID)
diff --git a/server/pkg/db/queries/conversation_root.sql b/server/pkg/db/queries/conversation_root.sql
index be1543f388..7869260885 100644
--- a/server/pkg/db/queries/conversation_root.sql
+++ b/server/pkg/db/queries/conversation_root.sql
@@ -1,7 +1,14 @@
-- name: ListConversationRootOwners :many
-- Preserve the newest non-null squad per agent, including terminal tasks.
+-- 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
-WHERE issue_id = $1 AND trigger_comment_id = $2 AND agent_id IS NOT NULL
+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 (
+ 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'
+ ))
ORDER BY agent_id, (squad_id IS NOT NULL) DESC, created_at DESC, id DESC;