Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(comments): surface thread resolution on roots-only list (#9858)
AstralSolipsism049ca20ec5b8
diff --git a/server/internal/handler/comment.go b/server/internal/handler/comment.goindex 0739d6345a..009eb9d91c 100644--- a/server/internal/handler/comment.go+++ b/server/internal/handler/comment.go@@ -62,6 +62,10 @@ type CommentResponse struct {// replies.ReplyCount *int `json:"reply_count,omitempty"`LastActivityAt *string `json:"last_activity_at,omitempty"`+ // Populated on roots_only for reply-resolved threads.+ ResolutionID *string `json:"resolution_id,omitempty"`+ ResolutionContent *string `json:"resolution_content,omitempty"`+ ResolutionContentTruncated *bool `json:"resolution_content_truncated,omitempty"`// ContentTruncated is set only under summary=true: true when Content was// clipped to the summary budget, false when it fit. nil (omitted) means the// caller did not request a summary projection, so Content is verbatim.@@ -592,6 +596,20 @@ func (h *Handler) ListComments(w http.ResponseWriter, r *http.Request) {la := timestampToString(st.LastActivityAt)resp[i].LastActivityAt = &la}+ if c.ResolvedAt.Valid || st.ResolutionID.Valid {+ resolved := true+ resp[i].ThreadResolved = &resolved+ }+ if !c.ResolvedAt.Valid && st.ResolutionID.Valid {+ resp[i].ResolutionID = uuidToPtr(st.ResolutionID)+ content := st.ResolutionContent.String+ if summary {+ clipped, truncated := summarizeContent(content)+ content = clipped+ resp[i].ResolutionContentTruncated = &truncated+ }+ resp[i].ResolutionContent = &content+ }}// Attach fold annotations on a resolved thread's root (nil map elsewhere;// keyed by root id, so only root comments match).@@ -672,8 +690,10 @@ type fetchCommentsResult struct {// rootStat is the per-thread orientation metadata attached to each root comment// on the roots_only path. See CommentResponse.ReplyCount / LastActivityAt.type rootStat struct {- ReplyCount int- LastActivityAt pgtype.Timestamptz+ ReplyCount int+ LastActivityAt pgtype.Timestamptz+ ResolutionID pgtype.UUID+ ResolutionContent pgtype.Text}var (@@ -995,7 +1015,12 @@ func (h *Handler) fetchCommentsForList(ctx context.Context, args fetchCommentsArSourceTaskID: r.SourceTaskID, QuickActionID: r.QuickActionID, Revision: r.Revision,DeletedAt: r.DeletedAt,}- stats[uuidToString(r.ID)] = rootStat{ReplyCount: int(r.ReplyCount), LastActivityAt: r.LastActivityAt}+ stats[uuidToString(r.ID)] = rootStat{+ ReplyCount: int(r.ReplyCount),+ LastActivityAt: r.LastActivityAt,+ ResolutionID: r.ResolutionID,+ ResolutionContent: r.ResolutionContent,+ }}return fetchCommentsResult{Comments: comments, RootStats: stats, CommentsTruncated: truncated,@@ -1026,7 +1051,12 @@ func (h *Handler) fetchCommentsForList(ctx context.Context, args fetchCommentsArSourceTaskID: r.SourceTaskID, QuickActionID: r.QuickActionID, Revision: r.Revision,DeletedAt: r.DeletedAt,}- stats[uuidToString(r.ID)] = rootStat{ReplyCount: int(r.ReplyCount), LastActivityAt: r.LastActivityAt}+ stats[uuidToString(r.ID)] = rootStat{+ ReplyCount: int(r.ReplyCount),+ LastActivityAt: r.LastActivityAt,+ ResolutionID: r.ResolutionID,+ ResolutionContent: r.ResolutionContent,+ }}return fetchCommentsResult{Comments: comments, RootStats: stats, CommentsTruncated: truncated,diff --git a/server/internal/handler/comment_list_test.go b/server/internal/handler/comment_list_test.goindex 80fe3ee78c..120f2203c3 100644--- a/server/internal/handler/comment_list_test.go+++ b/server/internal/handler/comment_list_test.go@@ -1531,3 +1531,105 @@ func TestCreateCommentPreservesDirectParent(t *testing.T) {t.Fatalf("reply-to-reply parent_id: want direct parent %s, got %v (root was %s)", reply.ID, nested.ParentID, root.ID)}}++// TestListComments_RootsOnlyReturnsThreadResolution pins the roots-only+// resolution projection: unresolved threads carry none of the new fields, a+// resolved root closes its own thread (thread_resolved only), and otherwise+// the latest-resolved reply — at any nesting depth — is the conclusion.+func TestListComments_RootsOnlyReturnsThreadResolution(t *testing.T) {+ if testHandler == nil || testPool == nil {+ t.Skip("requires DB")+ }+ fx := newCommentListFixture(t)+ base := fx.Base++ // Baseline: nothing resolved — no new fields anywhere.+ w, rows := listComments(t, fx.IssueID, "roots_only=true")+ for _, key := range []string{"thread_resolved", "resolution_id", "resolution_content", "resolution_content_truncated"} {+ if strings.Contains(w.Body.String(), "\""+key+"\"") {+ t.Fatalf("unresolved roots_only response must not contain %q", key)+ }+ }++ // Root1 resolves on its nested reply r1b1 (depth 2); Root2 has two+ // resolved replies, the newer (r2b) must win.+ setCommentResolvedAt(t, fx.R1b1, base.Add(20*time.Minute))+ setCommentResolvedAt(t, fx.R2a, base.Add(21*time.Minute))+ setCommentResolvedAt(t, fx.R2b, base.Add(22*time.Minute))++ _, rows = listComments(t, fx.IssueID, "roots_only=true")+ m := byID(rows)++ r1 := m[fx.Root1]+ if r1.ThreadResolved == nil || !*r1.ThreadResolved || r1.ResolutionID == nil || *r1.ResolutionID != fx.R1b1 {+ t.Fatalf("nested reply resolution: got resolved=%v id=%v want %s", r1.ThreadResolved, r1.ResolutionID, fx.R1b1)+ }+ if r1.ResolutionContent == nil || *r1.ResolutionContent != "r1b1" {+ t.Fatalf("nested reply resolution content got=%v want r1b1", r1.ResolutionContent)+ }++ if r2 := m[fx.Root2]; r2.ResolutionID == nil || *r2.ResolutionID != fx.R2b {+ t.Fatalf("latest resolved_at must win: resolution_id got=%v want=%s", r2.ResolutionID, fx.R2b)+ }++ // A resolved root ignores resolutions on its replies: thread_resolved+ // only, no resolution_id/content.+ setCommentResolvedAt(t, fx.Root2, base.Add(30*time.Minute))+ _, rows = listComments(t, fx.IssueID, "roots_only=true")+ if rr := byID(rows)[fx.Root2]; rr.ThreadResolved == nil || !*rr.ThreadResolved || rr.ResolutionID != nil || rr.ResolutionContent != nil {+ t.Fatalf("root-resolved thread: want thread_resolved only, got %+v", rr)+ }++ // The default (non-roots) list must not leak the new fields.+ _, all := listComments(t, fx.IssueID, "")+ for _, c := range all {+ if c.ResolutionID != nil || c.ResolutionContent != nil || c.ResolutionContentTruncated != nil {+ t.Fatalf("default list leaked resolution fields on %s", c.ID)+ }+ }+}++// TestListComments_RootsOnlyResolutionSinceAndSummary covers the two allowed+// compositions: --roots-only --since still reports a returned root's thread+// resolution, and --roots-only --summary clips resolution_content like+// content with resolution_content_truncated set.+func TestListComments_RootsOnlyResolutionSinceAndSummary(t *testing.T) {+ if testHandler == nil || testPool == nil {+ t.Skip("requires DB")+ }+ fx := newCommentListFixture(t)+ base := fx.Base++ setCommentResolvedAt(t, fx.R1b1, base.Add(20*time.Minute)) // short conclusion+ setCommentResolvedAt(t, fx.R2b, base.Add(21*time.Minute))+ if _, err := testPool.Exec(context.Background(),+ `UPDATE comment SET content = $1 WHERE id = $2`, strings.Repeat("y", 500), fx.R2b,+ ); err != nil {+ t.Fatalf("lengthen r2b: %v", err)+ }++ // since between the two roots: only Root2 returns, with its resolution.+ v := url.Values{}+ v.Set("roots_only", "true")+ v.Set("since", base.Add(5*time.Minute).UTC().Format(time.RFC3339Nano))+ _, rows := listComments(t, fx.IssueID, v.Encode())+ if len(rows) != 1 || rows[0].ID != fx.Root2 {+ t.Fatalf("roots_only+since: want only %s, got %v", fx.Root2, ids(rows))+ }+ if rows[0].ResolutionID == nil || *rows[0].ResolutionID != fx.R2b {+ t.Fatalf("roots_only+since: resolution_id got=%v want=%s", rows[0].ResolutionID, fx.R2b)+ }++ _, rows = listComments(t, fx.IssueID, "roots_only=true&summary=true")+ m := byID(rows)+ l := m[fx.Root2]+ if l.ResolutionContentTruncated == nil || !*l.ResolutionContentTruncated {+ t.Fatalf("summary: long resolution should be truncated, got %v", l.ResolutionContentTruncated)+ }+ if rc := utf8.RuneCountInString(*l.ResolutionContent); rc != summaryContentRunes+1 {+ t.Fatalf("summary: clipped resolution rune count got=%d want=%d", rc, summaryContentRunes+1)+ }+ if s := m[fx.Root1]; s.ResolutionContentTruncated == nil || *s.ResolutionContentTruncated || *s.ResolutionContent != "r1b1" {+ t.Fatalf("summary: short resolution should be untruncated, got %v %v", s.ResolutionContentTruncated, s.ResolutionContent)+ }+}diff --git a/server/pkg/db/generated/comment.sql.go b/server/pkg/db/generated/comment.sql.goindex cf04dd9680..d1142b5b11 100644--- a/server/pkg/db/generated/comment.sql.go+++ b/server/pkg/db/generated/comment.sql.go@@ -1522,16 +1522,30 @@ thread_stats AS (MAX(comment_created_at)::timestamptz AS last_activity_atFROM membershipGROUP BY root_id+),+thread_resolutions AS (+ SELECT DISTINCT ON (m.root_id)+ m.root_id,+ c.id AS resolution_id,+ c.content AS resolution_content+ FROM membership m+ JOIN comment c ON c.id = m.id+ WHERE m.id <> m.root_id+ AND c.resolved_at IS NOT NULL+ ORDER BY m.root_id, c.resolved_at DESC, c.created_at ASC, c.id ASC)SELECT c.id, c.issue_id, c.author_type, c.author_id, c.content, c.type,c.created_at, c.updated_at, c.parent_id, c.workspace_id,c.resolved_at, c.resolved_by_type, c.resolved_by_id,c.source_task_id, c.quick_action_id, c.revision, c.deleted_at,ts.reply_count AS reply_count,- ts.last_activity_at AS last_activity_at+ ts.last_activity_at AS last_activity_at,+ tr.resolution_id AS resolution_id,+ tr.resolution_content AS resolution_contentFROM selected_roots srJOIN comment c ON c.id = sr.idJOIN thread_stats ts ON ts.root_id = sr.id+LEFT JOIN thread_resolutions tr ON tr.root_id = sr.idORDER BY c.created_at ASC, c.id ASC`@@ -1542,25 +1556,27 @@ type ListRootCommentsForIssueParams struct {}type ListRootCommentsForIssueRow struct {- ID pgtype.UUID `json:"id"`- IssueID pgtype.UUID `json:"issue_id"`- AuthorType string `json:"author_type"`- AuthorID pgtype.UUID `json:"author_id"`- Content string `json:"content"`- Type string `json:"type"`- CreatedAt pgtype.Timestamptz `json:"created_at"`- UpdatedAt pgtype.Timestamptz `json:"updated_at"`- ParentID pgtype.UUID `json:"parent_id"`- WorkspaceID pgtype.UUID `json:"workspace_id"`- ResolvedAt pgtype.Timestamptz `json:"resolved_at"`- ResolvedByType pgtype.Text `json:"resolved_by_type"`- ResolvedByID pgtype.UUID `json:"resolved_by_id"`- SourceTaskID pgtype.UUID `json:"source_task_id"`- QuickActionID pgtype.UUID `json:"quick_action_id"`- Revision int64 `json:"revision"`- DeletedAt pgtype.Timestamptz `json:"deleted_at"`- ReplyCount int32 `json:"reply_count"`- LastActivityAt pgtype.Timestamptz `json:"last_activity_at"`+ ID pgtype.UUID `json:"id"`+ IssueID pgtype.UUID `json:"issue_id"`+ AuthorType string `json:"author_type"`+ AuthorID pgtype.UUID `json:"author_id"`+ Content string `json:"content"`+ Type string `json:"type"`+ CreatedAt pgtype.Timestamptz `json:"created_at"`+ UpdatedAt pgtype.Timestamptz `json:"updated_at"`+ ParentID pgtype.UUID `json:"parent_id"`+ WorkspaceID pgtype.UUID `json:"workspace_id"`+ ResolvedAt pgtype.Timestamptz `json:"resolved_at"`+ ResolvedByType pgtype.Text `json:"resolved_by_type"`+ ResolvedByID pgtype.UUID `json:"resolved_by_id"`+ SourceTaskID pgtype.UUID `json:"source_task_id"`+ QuickActionID pgtype.UUID `json:"quick_action_id"`+ Revision int64 `json:"revision"`+ DeletedAt pgtype.Timestamptz `json:"deleted_at"`+ ReplyCount int32 `json:"reply_count"`+ LastActivityAt pgtype.Timestamptz `json:"last_activity_at"`+ ResolutionID pgtype.UUID `json:"resolution_id"`+ ResolutionContent pgtype.Text `json:"resolution_content"`}// Top-level comments only, in issue chronological order, each annotated with@@ -1604,6 +1620,8 @@ func (q *Queries) ListRootCommentsForIssue(ctx context.Context, arg ListRootComm&i.DeletedAt,&i.ReplyCount,&i.LastActivityAt,+ &i.ResolutionID,+ &i.ResolutionContent,); err != nil {return nil, err}@@ -1642,16 +1660,30 @@ thread_stats AS (MAX(comment_created_at)::timestamptz AS last_activity_atFROM membershipGROUP BY root_id+),+thread_resolutions AS (+ SELECT DISTINCT ON (m.root_id)+ m.root_id,+ c.id AS resolution_id,+ c.content AS resolution_content+ FROM membership m+ JOIN comment c ON c.id = m.id+ WHERE m.id <> m.root_id+ AND c.resolved_at IS NOT NULL+ ORDER BY m.root_id, c.resolved_at DESC, c.created_at ASC, c.id ASC)SELECT c.id, c.issue_id, c.author_type, c.author_id, c.content, c.type,c.created_at, c.updated_at, c.parent_id, c.workspace_id,c.resolved_at, c.resolved_by_type, c.resolved_by_id,c.source_task_id, c.quick_action_id, c.revision, c.deleted_at,ts.reply_count AS reply_count,- ts.last_activity_at AS last_activity_at+ ts.last_activity_at AS last_activity_at,+ tr.resolution_id AS resolution_id,+ tr.resolution_content AS resolution_contentFROM selected_roots srJOIN comment c ON c.id = sr.idJOIN thread_stats ts ON ts.root_id = sr.id+LEFT JOIN thread_resolutions tr ON tr.root_id = sr.idORDER BY c.created_at ASC, c.id ASC`@@ -1663,25 +1695,27 @@ type ListRootCommentsSinceForIssueParams struct {}type ListRootCommentsSinceForIssueRow struct {- ID pgtype.UUID `json:"id"`- IssueID pgtype.UUID `json:"issue_id"`- AuthorType string `json:"author_type"`- AuthorID pgtype.UUID `json:"author_id"`- Content string `json:"content"`- Type string `json:"type"`- CreatedAt pgtype.Timestamptz `json:"created_at"`- UpdatedAt pgtype.Timestamptz `json:"updated_at"`- ParentID pgtype.UUID `json:"parent_id"`- WorkspaceID pgtype.UUID `json:"workspace_id"`- ResolvedAt pgtype.Timestamptz `json:"resolved_at"`- ResolvedByType pgtype.Text `json:"resolved_by_type"`- ResolvedByID pgtype.UUID `json:"resolved_by_id"`- SourceTaskID pgtype.UUID `json:"source_task_id"`- QuickActionID pgtype.UUID `json:"quick_action_id"`- Revision int64 `json:"revision"`- DeletedAt pgtype.Timestamptz `json:"deleted_at"`- ReplyCount int32 `json:"reply_count"`- LastActivityAt pgtype.Timestamptz `json:"last_activity_at"`+ ID pgtype.UUID `json:"id"`+ IssueID pgtype.UUID `json:"issue_id"`+ AuthorType string `json:"author_type"`+ AuthorID pgtype.UUID `json:"author_id"`+ Content string `json:"content"`+ Type string `json:"type"`+ CreatedAt pgtype.Timestamptz `json:"created_at"`+ UpdatedAt pgtype.Timestamptz `json:"updated_at"`+ ParentID pgtype.UUID `json:"parent_id"`+ WorkspaceID pgtype.UUID `json:"workspace_id"`+ ResolvedAt pgtype.Timestamptz `json:"resolved_at"`+ ResolvedByType pgtype.Text `json:"resolved_by_type"`+ ResolvedByID pgtype.UUID `json:"resolved_by_id"`+ SourceTaskID pgtype.UUID `json:"source_task_id"`+ QuickActionID pgtype.UUID `json:"quick_action_id"`+ Revision int64 `json:"revision"`+ DeletedAt pgtype.Timestamptz `json:"deleted_at"`+ ReplyCount int32 `json:"reply_count"`+ LastActivityAt pgtype.Timestamptz `json:"last_activity_at"`+ ResolutionID pgtype.UUID `json:"resolution_id"`+ ResolutionContent pgtype.Text `json:"resolution_content"`}// Top-level comments created strictly after @since, each annotated with the@@ -1725,6 +1759,8 @@ func (q *Queries) ListRootCommentsSinceForIssue(ctx context.Context, arg ListRoo&i.DeletedAt,&i.ReplyCount,&i.LastActivityAt,+ &i.ResolutionID,+ &i.ResolutionContent,); err != nil {return nil, err}diff --git a/server/pkg/db/queries/comment.sql b/server/pkg/db/queries/comment.sqlindex 056edc6052..c014e57ecf 100644--- a/server/pkg/db/queries/comment.sql+++ b/server/pkg/db/queries/comment.sql@@ -104,16 +104,30 @@ thread_stats AS (MAX(comment_created_at)::timestamptz AS last_activity_atFROM membershipGROUP BY root_id+),+thread_resolutions AS (+ SELECT DISTINCT ON (m.root_id)+ m.root_id,+ c.id AS resolution_id,+ c.content AS resolution_content+ FROM membership m+ JOIN comment c ON c.id = m.id+ WHERE m.id <> m.root_id+ AND c.resolved_at IS NOT NULL+ ORDER BY m.root_id, c.resolved_at DESC, c.created_at ASC, c.id ASC)SELECT c.id, c.issue_id, c.author_type, c.author_id, c.content, c.type,c.created_at, c.updated_at, c.parent_id, c.workspace_id,c.resolved_at, c.resolved_by_type, c.resolved_by_id,c.source_task_id, c.quick_action_id, c.revision, c.deleted_at,ts.reply_count AS reply_count,- ts.last_activity_at AS last_activity_at+ ts.last_activity_at AS last_activity_at,+ tr.resolution_id AS resolution_id,+ tr.resolution_content AS resolution_contentFROM selected_roots srJOIN comment c ON c.id = sr.idJOIN thread_stats ts ON ts.root_id = sr.id+LEFT JOIN thread_resolutions tr ON tr.root_id = sr.idORDER BY c.created_at ASC, c.id ASC;-- name: ListRootCommentsSinceForIssue :many@@ -150,16 +164,30 @@ thread_stats AS (MAX(comment_created_at)::timestamptz AS last_activity_atFROM membershipGROUP BY root_id+),+thread_resolutions AS (+ SELECT DISTINCT ON (m.root_id)+ m.root_id,+ c.id AS resolution_id,+ c.content AS resolution_content+ FROM membership m+ JOIN comment c ON c.id = m.id+ WHERE m.id <> m.root_id+ AND c.resolved_at IS NOT NULL+ ORDER BY m.root_id, c.resolved_at DESC, c.created_at ASC, c.id ASC)SELECT c.id, c.issue_id, c.author_type, c.author_id, c.content, c.type,c.created_at, c.updated_at, c.parent_id, c.workspace_id,c.resolved_at, c.resolved_by_type, c.resolved_by_id,c.source_task_id, c.quick_action_id, c.revision, c.deleted_at,ts.reply_count AS reply_count,- ts.last_activity_at AS last_activity_at+ ts.last_activity_at AS last_activity_at,+ tr.resolution_id AS resolution_id,+ tr.resolution_content AS resolution_contentFROM selected_roots srJOIN comment c ON c.id = sr.idJOIN thread_stats ts ON ts.root_id = sr.id+LEFT JOIN thread_resolutions tr ON tr.root_id = sr.idORDER BY c.created_at ASC, c.id ASC;-- name: ListThreadCommentsForIssuePaged :many