Let task agents create and manage subtasks

This commit is contained in:
Ian Gulliver
2026-10-16 10:36:38 -07:00
parent fd63a0dfbc
commit 0f2415570c
30 changed files with 1067 additions and 287 deletions
+16 -3
View File
@@ -19,8 +19,12 @@ const (
)
var (
ErrDiscardPending = errors.New("the task is already being discarded")
ErrMerging = errors.New("the task is merging")
ErrDiscardPending = errors.New("the task is already being discarded")
ErrMerging = errors.New("the task is merging")
ErrMergingIntoParent = errors.New("the task is merging into its parent task")
ErrHasSubtasks = errors.New("the task has active subtasks")
ErrParentNotOpen = errors.New("the parent task is closed or being discarded")
ErrParentMergeRequested = errors.New("the subtask is already merging into its parent")
)
type Discard struct {
@@ -44,7 +48,12 @@ func (s *Store) RequestDiscard(ctx context.Context, taskID, actor string) (Disca
projectID := ""
status := ""
mergingBy := ""
err := tx.QueryRowContext(ctx, `SELECT project_id, status, merging_by, discard_state FROM tasks WHERE id = ?`, taskID).Scan(&projectID, &status, &mergingBy, &state)
parentMergeBy := ""
subtasks := 0
err := tx.QueryRowContext(ctx, `
SELECT project_id, status, merging_by, parent_merge_by, discard_state,
(SELECT count(*) FROM tasks AS sub WHERE sub.parent_task_id = tasks.id AND sub.status = ?)
FROM tasks WHERE id = ?`, string(api.TaskStatusActive), taskID).Scan(&projectID, &status, &mergingBy, &parentMergeBy, &state, &subtasks)
if errors.Is(err, sql.ErrNoRows) {
return ErrNotFound
}
@@ -60,6 +69,10 @@ func (s *Store) RequestDiscard(ctx context.Context, taskID, actor string) (Disca
return ErrDiscardPending
case mergingBy != "":
return ErrMerging
case parentMergeBy != "":
return ErrMergingIntoParent
case subtasks > 0:
return ErrHasSubtasks
}
state = DiscardHeld
_, err = tx.ExecContext(ctx, `UPDATE tasks SET discard_state = ?, discarding_by = ?, discard_session = '', merge_queued_by = '', merge_queued_at = '' WHERE id = ?`,