Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix task failure recovery comment threading (#7519)
ZIce5dec16f42b66
diff --git a/server/internal/service/delegated_failure_recovery_test.go b/server/internal/service/delegated_failure_recovery_test.goindex b87afe7bbc..6475991525 100644--- a/server/internal/service/delegated_failure_recovery_test.go+++ b/server/internal/service/delegated_failure_recovery_test.go@@ -15,15 +15,16 @@ import ()type delegatedFailureFixture struct {- pool *pgxpool.Pool- workspaceID string- userID string- issueID string- workerIssue string- runtimeID string- coordinator string- worker string- sourceTask string+ pool *pgxpool.Pool+ workspaceID string+ userID string+ issueID string+ workerIssue string+ runtimeID string+ coordinator string+ worker string+ sourceTrigger string+ sourceTask string}func seedDelegatedFailureFixture(t *testing.T) (*delegatedFailureFixture, *TaskService) {@@ -60,27 +61,36 @@ func seedDelegatedFailureFixture(t *testing.T) (*delegatedFailureFixture, *TaskSt.Fatalf("seed worker issue: %v", err)}+ var sourceTriggerID string+ if err := pool.QueryRow(ctx, `+ INSERT INTO comment (workspace_id, issue_id, author_type, author_id, content)+ VALUES ($1, $2, 'member', $3, 'coordinate delegated work')+ RETURNING id`, workspaceID, issueID, userID).Scan(&sourceTriggerID); err != nil {+ t.Fatalf("seed source trigger comment: %v", err)+ }+var sourceTaskID stringif err := pool.QueryRow(ctx, `INSERT INTO agent_task_queue (agent_id, runtime_id, issue_id, status, priority,- originator_user_id, accountable_user_id, originator_source+ trigger_comment_id, originator_user_id, accountable_user_id, originator_source)- VALUES ($1, $2, $3, 'completed', 0, $4, $4, 'direct_human')- RETURNING id`, coordinatorID, runtimeID, issueID, userID).Scan(&sourceTaskID); err != nil {+ VALUES ($1, $2, $3, 'completed', 0, $4, $5, $5, 'direct_human')+ RETURNING id`, coordinatorID, runtimeID, issueID, sourceTriggerID, userID).Scan(&sourceTaskID); err != nil {t.Fatalf("seed source task: %v", err)}return &delegatedFailureFixture{- pool: pool,- workspaceID: workspaceID,- userID: userID,- issueID: issueID,- workerIssue: workerIssueID,- runtimeID: runtimeID,- coordinator: coordinatorID,- worker: workerID,- sourceTask: sourceTaskID,+ pool: pool,+ workspaceID: workspaceID,+ userID: userID,+ issueID: issueID,+ workerIssue: workerIssueID,+ runtimeID: runtimeID,+ coordinator: coordinatorID,+ worker: workerID,+ sourceTrigger: sourceTriggerID,+ sourceTask: sourceTaskID,}, NewTaskService(db.New(pool), pool, nil, events.New())}@@ -139,16 +149,19 @@ func TestFailTaskFinalDelegatedFailureWakesCoordinatorOnce(t *testing.T) {}var commentCount int- var content string+ var content, parentID stringif err := f.pool.QueryRow(ctx, `- SELECT count(*), COALESCE(max(content), '') FROM comment+ SELECT count(*), COALESCE(max(content), ''), COALESCE(max(parent_id::text), '') FROM commentWHERE issue_id = $1 AND author_type = 'system' AND type = 'progress_update' AND source_task_id = $2`, f.issueID, failedID).- Scan(&commentCount, &content); err != nil {+ Scan(&commentCount, &content, &parentID); err != nil {t.Fatalf("read recovery comment: %v", err)}if commentCount != 1 {t.Fatalf("recovery comment count = %d, want 1", commentCount)}+ if parentID != f.sourceTrigger {+ t.Fatalf("recovery comment parent_id = %q, want source trigger %s", parentID, f.sourceTrigger)+ }if strings.Contains(content, secret) || !strings.Contains(content, "[REDACTED API KEY]") {t.Fatalf("recovery comment did not redact error: %q", content)}@@ -509,17 +522,20 @@ func TestDelegatedFailureRecoveryStopsAfterBoundedUndeliveredAttempts(t *testing}var exhaustionComments int- var exhaustionContent string+ var exhaustionContent, exhaustionParentID stringif err := f.pool.QueryRow(ctx, `- SELECT count(*), COALESCE(max(content), '')+ SELECT count(*), COALESCE(max(content), ''), COALESCE(max(parent_id::text), '')FROM commentWHERE issue_id = $1 AND author_type = 'system' AND type = 'system' AND source_task_id = $2`, f.issueID, failedID).- Scan(&exhaustionComments, &exhaustionContent); err != nil {+ Scan(&exhaustionComments, &exhaustionContent, &exhaustionParentID); err != nil {t.Fatalf("read exhaustion comment: %v", err)}if exhaustionComments != 1 || !strings.Contains(exhaustionContent, "stopped after 3") {t.Fatalf("exhaustion comment = count %d content %q, want one visible bounded-stop explanation", exhaustionComments, exhaustionContent)}+ if exhaustionParentID != f.sourceTrigger {+ t.Fatalf("exhaustion comment parent_id = %q, want source trigger %s", exhaustionParentID, f.sourceTrigger)+ }var inboxItems intvar inboxSeverity, inboxBody stringif err := f.pool.QueryRow(ctx, `diff --git a/server/internal/service/task.go b/server/internal/service/task.goindex ea5dc82b5d..e7300ee9c3 100644--- a/server/internal/service/task.go+++ b/server/internal/service/task.go@@ -5697,6 +5697,7 @@ func (s *TaskService) ensureDelegatedFailureRecoveryComment(ctx context.Context,AuthorID: pgtype.UUID{Valid: true},Content: delegatedFailureRecoveryContent(target.failed, target.source),Type: delegatedFailureRecoveryCommentType,+ ParentID: target.source.TriggerCommentID,SourceTaskID: failed.ID,})if err != nil {@@ -5793,6 +5794,7 @@ func (s *TaskService) exhaustDelegatedFailureRecovery(ctx context.Context, targeAuthorID: pgtype.UUID{Valid: true},Content: delegatedFailureRecoveryExhaustionContent(target),Type: "system",+ ParentID: target.source.TriggerCommentID,SourceTaskID: target.failed.ID,})if err != nil {