From db454bec8e5fed41740d989d06d073f4c148ffea Mon Sep 17 00:00:00 2001 From: jcfs Date: Mon, 12 Jan 2026 16:15:45 +0000 Subject: [PATCH] fix: only show active worktrees in task API response - GetWorktreeByTaskID now filters by status = 'active' - Deleted worktrees won't appear in task responses --- apps/backend/internal/agent/worktree/store.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/backend/internal/agent/worktree/store.go b/apps/backend/internal/agent/worktree/store.go index bcc1bb6ac6..d28466a299 100644 --- a/apps/backend/internal/agent/worktree/store.go +++ b/apps/backend/internal/agent/worktree/store.go @@ -108,8 +108,8 @@ func (s *SQLiteStore) GetWorktreeByID(ctx context.Context, id string) (*Worktree return wt, nil } -// GetWorktreeByTaskID retrieves the most recent worktree by task ID. -// Since multiple worktrees can exist per task, this returns the most recently created one. +// GetWorktreeByTaskID retrieves the most recent active worktree by task ID. +// Since multiple worktrees can exist per task, this returns the most recently created active one. func (s *SQLiteStore) GetWorktreeByTaskID(ctx context.Context, taskID string) (*Worktree, error) { wt := &Worktree{} var mergedAt, deletedAt sql.NullTime @@ -117,8 +117,8 @@ func (s *SQLiteStore) GetWorktreeByTaskID(ctx context.Context, taskID string) (* err := s.db.QueryRowContext(ctx, ` SELECT id, task_id, repository_id, repository_path, path, branch, base_branch, status, created_at, updated_at, merged_at, deleted_at - FROM worktrees WHERE task_id = ? ORDER BY created_at DESC LIMIT 1 - `, taskID).Scan( + FROM worktrees WHERE task_id = ? AND status = ? ORDER BY created_at DESC LIMIT 1 + `, taskID, StatusActive).Scan( &wt.ID, &wt.TaskID, &wt.RepositoryID, &wt.RepositoryPath, &wt.Path, &wt.Branch, &wt.BaseBranch, &wt.Status, &wt.CreatedAt, &wt.UpdatedAt, &mergedAt, &deletedAt,