refactor(workflow): stop assuming a human decides
An approval, ask or park can be resolved by an operator, a rule, a classifier or automatically, so the vocabulary stops naming a person: - step type human.approve -> workflow.approve - park class needs_human -> needs_decision (ParkNeedsDecision) - event kinds human_* -> operator_* - alert kind task.needs_human -> task.needs_decision - status grouping "needs you" -> "needs attention" 0061 rewrites the stored values, including the approval step type in the workflow-definitions resource and each task's pinned definition, with the digest recomputed so resumed tasks still match.
This commit is contained in:
1 parent
fc609171ca
commit
f2b8681611
76 files changed
+373
-329
No files matched your search
@@ -39,7 +39,7 @@ CREATE TABLE tasks (
|
||||
attempt bigint NOT NULL DEFAULT 0,
|
||||
park_reason text NOT NULL DEFAULT '',
|
||||
watch_comment_id bigint NOT NULL DEFAULT 0,
|
||||
park_class text NOT NULL DEFAULT 'needs_human',
|
||||
park_class text NOT NULL DEFAULT 'needs_decision',
|
||||
remediation_rounds bigint NOT NULL DEFAULT 0,
|
||||
retry_count bigint NOT NULL DEFAULT 0,
|
||||
source text NOT NULL DEFAULT 'forge',
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
-- One vocabulary for whatever decides an approval, an ask or a park. A person
|
||||
-- was never the only decider, so the stored values stop naming one: the park
|
||||
-- class, the approval event kinds, the task alert kind and the approval step
|
||||
-- type all move. Stored workflow definitions keep working because the step
|
||||
-- type is rewritten in both the resource document and each task's pinned copy.
|
||||
|
||||
-- +goose Up
|
||||
UPDATE tasks SET park_class = 'needs_decision' WHERE park_class = 'needs_human';
|
||||
ALTER TABLE tasks ALTER COLUMN park_class SET DEFAULT 'needs_decision';
|
||||
|
||||
UPDATE events SET kind = 'operator_' || substr(kind, 7)
|
||||
WHERE kind IN ('human_approved', 'human_rejected', 'human_rereviewed');
|
||||
|
||||
UPDATE alerts SET kind = 'task.needs_decision' WHERE kind = 'task.needs_human';
|
||||
|
||||
UPDATE tasks
|
||||
SET workflow_definition_yaml = replace(workflow_definition_yaml, 'human.approve', 'workflow.approve'),
|
||||
workflow_definition_digest = CASE
|
||||
WHEN workflow_definition_digest = '' THEN ''
|
||||
ELSE encode(sha256(convert_to(replace(workflow_definition_yaml, 'human.approve', 'workflow.approve'), 'UTF8')), 'hex')
|
||||
END
|
||||
WHERE workflow_definition_yaml LIKE '%human.approve%';
|
||||
|
||||
UPDATE resources
|
||||
SET value = convert_to(replace(convert_from(value, 'UTF8'), 'human.approve', 'workflow.approve'), 'UTF8')
|
||||
WHERE kind = 'workflow-definitions' AND convert_from(value, 'UTF8') LIKE '%human.approve%';
|
||||
|
||||
-- +goose Down
|
||||
UPDATE tasks SET park_class = 'needs_human' WHERE park_class = 'needs_decision';
|
||||
ALTER TABLE tasks ALTER COLUMN park_class SET DEFAULT 'needs_human';
|
||||
|
||||
UPDATE events SET kind = 'human_' || substr(kind, 10)
|
||||
WHERE kind IN ('operator_approved', 'operator_rejected', 'operator_rereviewed');
|
||||
|
||||
UPDATE alerts SET kind = 'task.needs_human' WHERE kind = 'task.needs_decision';
|
||||
|
||||
UPDATE tasks
|
||||
SET workflow_definition_yaml = replace(workflow_definition_yaml, 'workflow.approve', 'human.approve'),
|
||||
workflow_definition_digest = CASE
|
||||
WHEN workflow_definition_digest = '' THEN ''
|
||||
ELSE encode(sha256(convert_to(replace(workflow_definition_yaml, 'workflow.approve', 'human.approve'), 'UTF8')), 'hex')
|
||||
END
|
||||
WHERE workflow_definition_yaml LIKE '%workflow.approve%';
|
||||
|
||||
UPDATE resources
|
||||
SET value = convert_to(replace(convert_from(value, 'UTF8'), 'workflow.approve', 'human.approve'), 'UTF8')
|
||||
WHERE kind = 'workflow-definitions' AND convert_from(value, 'UTF8') LIKE '%workflow.approve%';
|
||||
@@ -141,7 +141,7 @@ func (q *Queries) ArchiveTaskDelete(ctx context.Context, arg ArchiveTaskDeletePa
|
||||
}
|
||||
|
||||
const beginRemediationTask = `-- name: BeginRemediationTask :execrows
|
||||
UPDATE tasks SET status = 'queued', workflow = 'remediate', park_reason = '', park_class = 'needs_human', review_payload = $2, retry_mode = 'continue_pushed_work', resume_from = '', resume_results = '{}', updated_at = now()
|
||||
UPDATE tasks SET status = 'queued', workflow = 'remediate', park_reason = '', park_class = 'needs_decision', review_payload = $2, retry_mode = 'continue_pushed_work', resume_from = '', resume_results = '{}', updated_at = now()
|
||||
WHERE id = $1 AND status = 'pr_open'
|
||||
`
|
||||
|
||||
@@ -802,7 +802,7 @@ func (q *Queries) ParkTask(ctx context.Context, arg ParkTaskParams) (int64, erro
|
||||
|
||||
const promotePendingReview = `-- name: PromotePendingReview :execrows
|
||||
UPDATE tasks SET status = 'queued', workflow = 'remediate', park_reason = '',
|
||||
park_class = 'needs_human',
|
||||
park_class = 'needs_decision',
|
||||
review_payload = pending_reviews->>0, pending_reviews = pending_reviews - 0,
|
||||
retry_mode = 'continue_pushed_work', resume_from = '', resume_results = '{}',
|
||||
updated_at = now()
|
||||
@@ -836,7 +836,7 @@ func (q *Queries) RecoverStaleTasks(ctx context.Context) (int64, error) {
|
||||
const requeueTask = `-- name: RequeueTask :execrows
|
||||
UPDATE tasks SET status = 'queued',
|
||||
workflow = CASE WHEN $1::text = '' THEN workflow ELSE $1::text END,
|
||||
park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
park_reason = '', park_class = 'needs_decision', updated_at = now()
|
||||
WHERE id = $2 AND status = $3
|
||||
`
|
||||
|
||||
@@ -872,7 +872,7 @@ const respondReviewGateTask = `-- name: RespondReviewGateTask :execrows
|
||||
UPDATE tasks SET status = 'queued',
|
||||
review_gate = $1::text,
|
||||
rereview_rounds = rereview_rounds + CASE WHEN $2::bool THEN 1 ELSE 0 END,
|
||||
park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
park_reason = '', park_class = 'needs_decision', updated_at = now()
|
||||
WHERE id = $3 AND status = $4
|
||||
AND ($2::bool = false OR rereview_rounds < $5::bigint)
|
||||
`
|
||||
@@ -913,7 +913,7 @@ UPDATE tasks SET status = 'queued', retry_count = retry_count + 1,
|
||||
workflow_definition_yaml = CASE WHEN $5::bool THEN '' ELSE workflow_definition_yaml END,
|
||||
workflow_definition_digest = CASE WHEN $5::bool THEN '' ELSE workflow_definition_digest END,
|
||||
workflow_definition_version = CASE WHEN $5::bool THEN 0 ELSE workflow_definition_version END,
|
||||
park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
park_reason = '', park_class = 'needs_decision', updated_at = now()
|
||||
WHERE id = $6 AND status = $7
|
||||
`
|
||||
|
||||
@@ -1249,7 +1249,7 @@ type TransitionTaskParams struct {
|
||||
}
|
||||
|
||||
// Arriving at 'parked' also records why. The class is normalized by the
|
||||
// caller, so an unknown value persists as needs_human rather than as itself.
|
||||
// caller, so an unknown value persists as needs_decision rather than as itself.
|
||||
func (q *Queries) TransitionTask(ctx context.Context, arg TransitionTaskParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, transitionTask,
|
||||
arg.ID,
|
||||
|
||||
@@ -154,7 +154,7 @@ SELECT status FROM tasks WHERE id = $1 FOR UPDATE;
|
||||
|
||||
-- name: TransitionTask :execrows
|
||||
-- Arriving at 'parked' also records why. The class is normalized by the
|
||||
-- caller, so an unknown value persists as needs_human rather than as itself.
|
||||
-- caller, so an unknown value persists as needs_decision rather than as itself.
|
||||
UPDATE tasks
|
||||
SET status = $2,
|
||||
park_reason = CASE WHEN $2 = 'parked' THEN $3 ELSE park_reason END,
|
||||
@@ -210,7 +210,7 @@ RETURNING *;
|
||||
-- A remediation must continue the branch its pull request lives on, so it
|
||||
-- records that dispatch mode explicitly (taskstate.RetryContinuePushedWork)
|
||||
-- rather than leaving prepareWorkspace to infer it from the workflow.
|
||||
UPDATE tasks SET status = 'queued', workflow = 'remediate', park_reason = '', park_class = 'needs_human', review_payload = $2, retry_mode = 'continue_pushed_work', resume_from = '', resume_results = '{}', updated_at = now()
|
||||
UPDATE tasks SET status = 'queued', workflow = 'remediate', park_reason = '', park_class = 'needs_decision', review_payload = $2, retry_mode = 'continue_pushed_work', resume_from = '', resume_results = '{}', updated_at = now()
|
||||
WHERE id = $1 AND status = 'pr_open';
|
||||
|
||||
-- name: AppendPendingReview :execrows
|
||||
@@ -231,7 +231,7 @@ WHERE id = $1 AND status IN ('queued', 'running') AND workflow = 'remediate';
|
||||
-- waiting: the oldest becomes the active payload and the task is queued
|
||||
-- again, so it is remediated after the run that just finished.
|
||||
UPDATE tasks SET status = 'queued', workflow = 'remediate', park_reason = '',
|
||||
park_class = 'needs_human',
|
||||
park_class = 'needs_decision',
|
||||
review_payload = pending_reviews->>0, pending_reviews = pending_reviews - 0,
|
||||
retry_mode = 'continue_pushed_work', resume_from = '', resume_results = '{}',
|
||||
updated_at = now()
|
||||
@@ -255,7 +255,7 @@ WHERE id = $1 AND status = 'pr_open';
|
||||
-- name: RequeueTask :execrows
|
||||
UPDATE tasks SET status = 'queued',
|
||||
workflow = CASE WHEN @workflow::text = '' THEN workflow ELSE @workflow::text END,
|
||||
park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
park_reason = '', park_class = 'needs_decision', updated_at = now()
|
||||
WHERE id = @id AND status = @from_status;
|
||||
|
||||
-- name: RetryTask :execrows
|
||||
@@ -266,7 +266,7 @@ UPDATE tasks SET status = 'queued', retry_count = retry_count + 1,
|
||||
workflow_definition_yaml = CASE WHEN @current_definition::bool THEN '' ELSE workflow_definition_yaml END,
|
||||
workflow_definition_digest = CASE WHEN @current_definition::bool THEN '' ELSE workflow_definition_digest END,
|
||||
workflow_definition_version = CASE WHEN @current_definition::bool THEN 0 ELSE workflow_definition_version END,
|
||||
park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
park_reason = '', park_class = 'needs_decision', updated_at = now()
|
||||
WHERE id = @id AND status = @from_status;
|
||||
|
||||
-- name: RespondReviewGateTask :execrows
|
||||
@@ -279,7 +279,7 @@ WHERE id = @id AND status = @from_status;
|
||||
UPDATE tasks SET status = 'queued',
|
||||
review_gate = @gate::text,
|
||||
rereview_rounds = rereview_rounds + CASE WHEN @rereview::bool THEN 1 ELSE 0 END,
|
||||
park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
park_reason = '', park_class = 'needs_decision', updated_at = now()
|
||||
WHERE id = @id AND status = @from_status
|
||||
AND (@rereview::bool = false OR rereview_rounds < @cap::bigint);
|
||||
|
||||
|
||||
@@ -330,7 +330,7 @@ func (s *Store) CancelExecution(ctx context.Context, taskID int64, reason, to st
|
||||
|
||||
n, err := q.TransitionTask(ctx, postgresdb.TransitionTaskParams{
|
||||
ID: taskID, Status: to, ParkReason: clip(reason, 4000),
|
||||
ParkClass: taskstate.ParkNeedsHuman, Status_2: execution.Status,
|
||||
ParkClass: taskstate.ParkNeedsDecision, Status_2: execution.Status,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -282,7 +282,7 @@ func (s *Store) Transition(ctx context.Context, taskID int64, from, to, detail s
|
||||
}
|
||||
n, err := q.TransitionTask(ctx, postgresdb.TransitionTaskParams{
|
||||
ID: taskID, Status: to, ParkReason: clip(detail, 4000),
|
||||
ParkClass: taskstate.ParkNeedsHuman, Status_2: from,
|
||||
ParkClass: taskstate.ParkNeedsDecision, Status_2: from,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -28,10 +28,10 @@ func recordTransition(ctx context.Context, q *postgresdb.Queries, p postgresdb.I
|
||||
return syncTaskAlerts(ctx, q, p)
|
||||
}
|
||||
|
||||
// needsHuman reports whether a task in status, parked with class, is waiting
|
||||
// needsDecision reports whether a task in status, parked with class, is waiting
|
||||
// on an operator's decision.
|
||||
func needsHuman(status, class string) bool {
|
||||
return status == workflow.StatusWaitingApproval || (status == workflow.StatusParked && class == taskstate.ParkNeedsHuman)
|
||||
func needsDecision(status, class string) bool {
|
||||
return status == workflow.StatusWaitingApproval || (status == workflow.StatusParked && class == taskstate.ParkNeedsDecision)
|
||||
}
|
||||
|
||||
// failed reports whether a task in status, parked with class, will not
|
||||
@@ -63,20 +63,20 @@ func syncTaskAlerts(ctx context.Context, q *postgresdb.Queries, p postgresdb.Ins
|
||||
return alert.Key{Org: org.OrgID(info.OrgID), Kind: kind, Subject: subject}
|
||||
}
|
||||
|
||||
if needsHuman(p.ToStatus, info.ParkClass) {
|
||||
if needsDecision(p.ToStatus, info.ParkClass) {
|
||||
body := name + " is waiting for approval or review."
|
||||
if p.ToStatus == workflow.StatusParked {
|
||||
body = name + " is parked and needs a decision."
|
||||
}
|
||||
_, err := raiseAlert(ctx, q, alert.Input{
|
||||
Key: key(alert.KindTaskNeedsHuman), Severity: alert.SeverityAction, Condition: true,
|
||||
Key: key(alert.KindTaskNeedsDecision), Severity: alert.SeverityAction, Condition: true,
|
||||
Title: title, Body: body, Link: link,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if leaving {
|
||||
if err := resolveAlert(ctx, q, key(alert.KindTaskNeedsHuman), systemResolver); err != nil {
|
||||
if err := resolveAlert(ctx, q, key(alert.KindTaskNeedsDecision), systemResolver); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user