Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(server): skip auto-comment when agent already posted during task (#712)
Jiayuan Zhangb3f98ef95d8b
diff --git a/server/internal/service/task.go b/server/internal/service/task.goindex 822977b44e..b15893fc82 100644--- a/server/internal/service/task.go+++ b/server/internal/service/task.go@@ -268,15 +268,23 @@ func (s *TaskService) CompleteTask(ctx context.Context, taskID pgtype.UUID, resuslog.Info("task completed", "task_id", util.UUIDToString(task.ID), "issue_id", util.UUIDToString(task.IssueID))- // Post agent output as a comment, but only for issue tasks with assignment triggers.+ // Post agent output as a comment, but only for assignment-triggered issue tasks+ // where the agent did NOT already post a comment during execution.// Comment-triggered tasks: the agent replies via CLI with --parent, so// posting here would create a duplicate.// Chat tasks: no comment posting needed.if task.IssueID.Valid && !task.TriggerCommentID.Valid {- var payload protocol.TaskCompletedPayload- if err := json.Unmarshal(result, &payload); err == nil {- if payload.Output != "" {- s.createAgentComment(ctx, task.IssueID, task.AgentID, redact.Text(payload.Output), "comment", task.TriggerCommentID)+ agentCommented, _ := s.Queries.HasAgentCommentedSince(ctx, db.HasAgentCommentedSinceParams{+ IssueID: task.IssueID,+ AuthorID: task.AgentID,+ Since: task.StartedAt,+ })+ if !agentCommented {+ var payload protocol.TaskCompletedPayload+ if err := json.Unmarshal(result, &payload); err == nil {+ if payload.Output != "" {+ s.createAgentComment(ctx, task.IssueID, task.AgentID, redact.Text(payload.Output), "comment", task.TriggerCommentID)+ }}}}diff --git a/server/pkg/db/generated/comment.sql.go b/server/pkg/db/generated/comment.sql.goindex c4b8e9b9e9..9dd26060e6 100644--- a/server/pkg/db/generated/comment.sql.go+++ b/server/pkg/db/generated/comment.sql.go@@ -130,6 +130,29 @@ func (q *Queries) GetCommentInWorkspace(ctx context.Context, arg GetCommentInWorreturn i, err}+const hasAgentCommentedSince = `-- name: HasAgentCommentedSince :one+SELECT EXISTS (+ SELECT 1 FROM comment+ WHERE issue_id = $1+ AND author_type = 'agent'+ AND author_id = $2+ AND created_at >= $3+) AS commented+`++type HasAgentCommentedSinceParams struct {+ IssueID pgtype.UUID `json:"issue_id"`+ AuthorID pgtype.UUID `json:"author_id"`+ Since pgtype.Timestamptz `json:"since"`+}++func (q *Queries) HasAgentCommentedSince(ctx context.Context, arg HasAgentCommentedSinceParams) (bool, error) {+ row := q.db.QueryRow(ctx, hasAgentCommentedSince, arg.IssueID, arg.AuthorID, arg.Since)+ var commented bool+ err := row.Scan(&commented)+ return commented, err+}+const listComments = `-- name: ListComments :manySELECT id, issue_id, author_type, author_id, content, type, created_at, updated_at, parent_id, workspace_id FROM commentWHERE issue_id = $1 AND workspace_id = $2diff --git a/server/pkg/db/queries/comment.sql b/server/pkg/db/queries/comment.sqlindex 20dd4b952d..3120810e61 100644--- a/server/pkg/db/queries/comment.sql+++ b/server/pkg/db/queries/comment.sql@@ -44,5 +44,14 @@ UPDATE comment SETWHERE id = $1RETURNING *;+-- name: HasAgentCommentedSince :one+SELECT EXISTS (+ SELECT 1 FROM comment+ WHERE issue_id = @issue_id+ AND author_type = 'agent'+ AND author_id = @author_id+ AND created_at >= @since+) AS commented;+-- name: DeleteComment :execDELETE FROM comment WHERE id = $1;