refactor!: waiting_human becomes waiting_approval, with the approval kind on each task

This commit is contained in:
sam committed 2026-10-24 23:45:20 +11:00
1 parent 1f8a9964c1
commit e8a60c4abd
29 files changed
+229 -183

No files matched your search

+2 -2
View File
@@ -86,10 +86,10 @@ func manualRequeueTask(ctx context.Context, st storecontract.TaskStore, taskID i
return fmt.Errorf("task %d not found", taskID)
}
switch task.Status {
case workflow.StatusParked, workflow.StatusWaitingHuman:
case workflow.StatusParked, workflow.StatusWaitingApproval:
return st.Requeue(ctx, taskID, task.Status, "")
default:
return fmt.Errorf("task %d has status %q; only parked or waiting_human tasks can be requeued", taskID, task.Status)
return fmt.Errorf("task %d has status %q; only parked or waiting_approval tasks can be requeued", taskID, task.Status)
}
}
+2 -2
View File
@@ -797,7 +797,7 @@ func (d *Daemon) botUserForTask(task *workflowtask.Task) string {
}
// drainNATS processes tasks from NATS, falling back to the task store's ClaimNext for
// requeued tasks (waiting_human approval, retry-parked) that didn't come
// requeued tasks (waiting_approval approval, retry-parked) that didn't come
// through a NATS publish. It returns once the stream and the claim fallback
// are both empty: in-flight tasks keep running, so a task waiting on a callee
// does not hold up the pass that would claim it. Shutdown waits for them
@@ -816,7 +816,7 @@ func (d *Daemon) drainNATS(ctx context.Context) {
}
// ErrNoMessage means the stream is drained. That is precisely when
// the SQLite fallback must run: requeued tasks (waiting_human
// the SQLite fallback must run: requeued tasks (waiting_approval
// approval, retry-parked) never went through a NATS publish, so
// nothing will ever arrive on the stream to trigger them.
task, claimErr := d.Store.ClaimNext(ctx)
+2 -2
View File
@@ -62,7 +62,7 @@ type approveSettings struct {
}
// newApproveStage delivers the plan to the decision surfaces and waits: the
// task parks in waiting_human until an operator approves or rejects it.
// task parks in waiting_approval until an operator approves or rejects it.
func newApproveStage(settings yaml.Node) (Stage, error) {
s, err := decodeSettings[approveSettings](ApproveStepName, settings)
if err != nil {
@@ -75,7 +75,7 @@ func newApproveStage(settings yaml.Node) (Stage, error) {
tc.Task.Plan = s.Plan
notify(ctx, tc, "approval")
tc.Task.Workflow = s.Then
tc.Outcome = Outcome{Status: StatusWaitingHuman, Detail: "plan delivered, awaiting go/no-go"}
tc.Outcome = Outcome{Status: StatusWaitingApproval, Detail: "plan delivered, awaiting go/no-go"}
return nil
}}, nil
}
+6 -6
View File
@@ -12,14 +12,14 @@ const FinishStepName = "workflow.finish"
// finishStatuses are the outcomes a workflow.finish step may choose.
var finishStatuses = map[string]string{
"completed": StatusCompleted,
"parked": StatusParked,
"waiting_human": StatusWaitingHuman,
"declined": StatusClosedWontDo,
"completed": StatusCompleted,
"parked": StatusParked,
"waiting_approval": StatusWaitingApproval,
"declined": StatusClosedWontDo,
}
type finishSettings struct {
Status string `yaml:"status" enum:"completed,parked,waiting_human,declined" doc:"How the run ends. Empty means completed."`
Status string `yaml:"status" enum:"completed,parked,waiting_approval,declined" doc:"How the run ends. Empty means completed."`
Detail string `yaml:"detail" doc:"What the operator reads about the outcome."`
}
@@ -38,7 +38,7 @@ func newFinishStage(settings yaml.Node) (Stage, error) {
}
status, ok := finishStatuses[s.Status]
if !ok {
return Stage{}, fmt.Errorf("%s: settings.status is completed, parked, waiting_human or declined, not %q", FinishStepName, s.Status)
return Stage{}, fmt.Errorf("%s: settings.status is completed, parked, waiting_approval or declined, not %q", FinishStepName, s.Status)
}
return Stage{Name: FinishStepName, Run: func(_ context.Context, tc *TaskContext) error {
tc.Outcome = Outcome{Status: status, Detail: s.Detail}
@@ -150,7 +150,7 @@ func stagePROperatorApproval(enabled bool) Stage {
Workflow: tc.Task.Workflow,
})
tc.Outcome = Outcome{
Status: StatusWaitingHuman,
Status: StatusWaitingApproval,
Detail: fmt.Sprintf("%d finding(s) awaiting operator review before posting", len(tc.prReview.scored)),
}
return nil
+10 -10
View File
@@ -19,16 +19,16 @@ const (
// Defined in internal/taskstate so the dashboard, chat and the store
// share one vocabulary. These names are kept as the workflow domain's
// public spelling; the values live in one place.
StatusQueued = taskstate.Queued
StatusRunning = taskstate.Running
StatusWaitingHuman = taskstate.WaitingHuman
StatusPROpen = taskstate.PROpen
StatusMerged = taskstate.Merged
StatusParked = taskstate.Parked
StatusDead = taskstate.Dead
StatusRejected = taskstate.Rejected
StatusClosedWontDo = taskstate.Declined
StatusCompleted = taskstate.Completed
StatusQueued = taskstate.Queued
StatusRunning = taskstate.Running
StatusWaitingApproval = taskstate.WaitingApproval
StatusPROpen = taskstate.PROpen
StatusMerged = taskstate.Merged
StatusParked = taskstate.Parked
StatusDead = taskstate.Dead
StatusRejected = taskstate.Rejected
StatusClosedWontDo = taskstate.Declined
StatusCompleted = taskstate.Completed
)
// Task is the task-execution record the workflow domain operates on.
+10 -10
View File
@@ -27,16 +27,16 @@ const (
// Task lifecycle statuses. Defined in internal/taskstate; these names are
// the workflow domain's public spelling.
const (
StatusQueued = task.StatusQueued
StatusRunning = task.StatusRunning
StatusWaitingHuman = task.StatusWaitingHuman
StatusPROpen = task.StatusPROpen
StatusMerged = task.StatusMerged
StatusParked = task.StatusParked
StatusDead = task.StatusDead
StatusRejected = task.StatusRejected
StatusClosedWontDo = task.StatusClosedWontDo
StatusCompleted = task.StatusCompleted
StatusQueued = task.StatusQueued
StatusRunning = task.StatusRunning
StatusWaitingApproval = task.StatusWaitingApproval
StatusPROpen = task.StatusPROpen
StatusMerged = task.StatusMerged
StatusParked = task.StatusParked
StatusDead = task.StatusDead
StatusRejected = task.StatusRejected
StatusClosedWontDo = task.StatusClosedWontDo
StatusCompleted = task.StatusCompleted
)
// Task.Source values.
+1 -1
View File
@@ -275,7 +275,7 @@ type Workflow struct {
type Registry map[string]Workflow
// Route picks the workflow for a task. A pre-assigned workflow wins
// (the waiting_human → approved handoff requeues under "implement");
// (the waiting_approval → approved handoff requeues under "implement");
// otherwise labels decide, then the default.
func Route(t *Task, reg Registry) Workflow {
if t.Workflow != "" {
+15 -15
View File
@@ -99,9 +99,9 @@ type AgentReader interface {
}
type TaskController interface {
// Approve moves a waiting_human task back to queued. Returns an
// Approve moves a waiting_approval task back to queued. Returns an
// error (surfaced to the user, not the LLM) if the task doesn't
// exist, isn't owned by identity, or isn't in waiting_human.
// exist, isn't owned by identity, or isn't in waiting_approval.
Approve(ctx context.Context, taskID int64, identity string) error
// Cancel cancels an active task owned by identity. It errors if the task is
// missing, not owned or already terminal.
@@ -697,22 +697,22 @@ type taskStateDisplay struct {
}
var taskStateDisplays = map[string]taskStateDisplay{
taskstate.Running: {icon: "▶", label: "Running"},
taskstate.WaitingHuman: {icon: "👤", label: "Waiting"},
taskstate.Parked: {icon: "⏸", label: "Parked"},
taskstate.Queued: {icon: "⏳", label: "Queued"},
taskstate.PROpen: {icon: "🔀", label: "PR open"},
taskstate.Merged: {icon: "✅", label: "Merged"},
taskstate.Completed: {icon: "✅", label: "Completed"},
taskstate.Rejected: {icon: "❌", label: "Rejected"},
taskstate.Declined: {icon: "🚫", label: "Declined"},
"declined": {icon: "🚫", label: "Declined"},
taskstate.Dead: {icon: "🛑", label: "Dead"},
taskstate.Running: {icon: "▶", label: "Running"},
taskstate.WaitingApproval: {icon: "👤", label: "Waiting"},
taskstate.Parked: {icon: "⏸", label: "Parked"},
taskstate.Queued: {icon: "⏳", label: "Queued"},
taskstate.PROpen: {icon: "🔀", label: "PR open"},
taskstate.Merged: {icon: "✅", label: "Merged"},
taskstate.Completed: {icon: "✅", label: "Completed"},
taskstate.Rejected: {icon: "❌", label: "Rejected"},
taskstate.Declined: {icon: "🚫", label: "Declined"},
"declined": {icon: "🚫", label: "Declined"},
taskstate.Dead: {icon: "🛑", label: "Dead"},
}
var statusOrder = []string{
taskstate.Running,
taskstate.WaitingHuman,
taskstate.WaitingApproval,
taskstate.Parked,
taskstate.Queued,
taskstate.PROpen,
@@ -852,7 +852,7 @@ func formatStatus(ctx context.Context, counts map[string]int, report HealthRepor
// /status to surface.
func formatQueueDepth(counts map[string]int) string {
running := counts[taskstate.Running]
waiting := counts[taskstate.WaitingHuman]
waiting := counts[taskstate.WaitingApproval]
parked := counts[taskstate.Parked]
inFlight := running + waiting + parked
if inFlight == 0 {
+1 -1
View File
@@ -165,7 +165,7 @@ func taskListTool(lister ChatTaskLister, identity string) tools.ToolEntry {
Toolset: "tasks",
Description: "List the tasks this instance is working on, most recent first. " +
"Use it to answer questions about current, queued, parked or finished work. " +
"Optionally filter by status (queued, running, waiting_human, parked, pr_open, merged, rejected).",
"Optionally filter by status (queued, running, waiting_approval, parked, pr_open, merged, rejected).",
Classification: tools.ClassIdempotent,
Schema: tools.JSONSchema{
"type": "object",
+1 -1
View File
@@ -108,7 +108,7 @@ type chatTaskController interface {
// ChatTaskStatus returns the task's status and owning identity, and
// false if no task with that ID exists.
ChatTaskStatus(ctx context.Context, taskID int64) (ChatTaskStatus, bool, error)
// ApproveChatTask approves a waiting_human task through the task-action
// ApproveChatTask approves a waiting_approval task through the task-action
// service, posting every offered finding.
ApproveChatTask(ctx context.Context, taskID int64, actor taskactions.Actor) error
// CancelChatTask transitions an active task to a rejected/terminal
@@ -0,0 +1,12 @@
-- A task waiting on an operator decision is waiting_approval; the kind of
-- approval is derived from what it waits on (a plan or a review gate).
-- +goose Up
UPDATE tasks SET status = 'waiting_approval' WHERE status = 'waiting_human';
UPDATE transitions SET from_status = 'waiting_approval' WHERE from_status = 'waiting_human';
UPDATE transitions SET to_status = 'waiting_approval' WHERE to_status = 'waiting_human';
-- +goose Down
UPDATE tasks SET status = 'waiting_human' WHERE status = 'waiting_approval';
UPDATE transitions SET from_status = 'waiting_human' WHERE from_status = 'waiting_approval';
UPDATE transitions SET to_status = 'waiting_human' WHERE to_status = 'waiting_approval';
@@ -31,7 +31,7 @@ func recordTransition(ctx context.Context, q *postgresdb.Queries, p postgresdb.I
// needsHuman 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.StatusWaitingHuman || (status == workflow.StatusParked && class == taskstate.ParkNeedsHuman)
return status == workflow.StatusWaitingApproval || (status == workflow.StatusParked && class == taskstate.ParkNeedsHuman)
}
// failed reports whether a task in status, parked with class, will not
@@ -41,8 +41,8 @@ func failed(status, class string) bool {
}
func syncTaskAlerts(ctx context.Context, q *postgresdb.Queries, p postgresdb.InsertTransitionParams) error {
leaving := p.FromStatus == workflow.StatusWaitingHuman || p.FromStatus == workflow.StatusParked
if !leaving && p.ToStatus != workflow.StatusWaitingHuman && p.ToStatus != workflow.StatusParked && p.ToStatus != workflow.StatusDead {
leaving := p.FromStatus == workflow.StatusWaitingApproval || p.FromStatus == workflow.StatusParked
if !leaving && p.ToStatus != workflow.StatusWaitingApproval && p.ToStatus != workflow.StatusParked && p.ToStatus != workflow.StatusDead {
return nil
}
info, err := q.TaskAlertInfo(ctx, p.TaskID)
+32 -11
View File
@@ -30,13 +30,13 @@ const (
// Task lifecycle statuses. The store persists these strings, so they are
// part of the on-disk format: renaming one is a migration, not a rename.
const (
Queued = "queued"
Running = "running"
WaitingHuman = "waiting_human"
PROpen = "pr_open"
Merged = "merged"
Parked = "parked"
Dead = "dead"
Queued = "queued"
Running = "running"
WaitingApproval = "waiting_approval"
PROpen = "pr_open"
Merged = "merged"
Parked = "parked"
Dead = "dead"
// Rejected means the forge closed the pull request without merging it.
// It is an outcome archie observed, not a decision an operator made --
@@ -61,7 +61,7 @@ func Actions(status string) []Action {
actions = []Action{ActionCancel, ActionReject}
case Running:
actions = []Action{ActionStop, ActionReject}
case WaitingHuman:
case WaitingApproval:
actions = []Action{ActionApprove, ActionReject, ActionRereview}
case Parked:
actions = []Action{ActionRetry, ActionAbandon, ActionReject}
@@ -98,14 +98,35 @@ func CheckAction(status string, action Action) error {
return fmt.Errorf("action %q is not available while task is %s", action, status)
}
// CheckApprove allows approval only from WaitingHuman.
// CheckApprove allows approval only from WaitingApproval.
func CheckApprove(status string) error {
if status != WaitingHuman {
if status != WaitingApproval {
return fmt.Errorf("task is %s, not awaiting approval", status)
}
return nil
}
// Approval kinds: what a task in WaitingApproval asks the operator to decide.
const (
// ApprovalPlan is a plan from a human.approve step, read as task.plan.
ApprovalPlan = "plan"
// ApprovalReview is a review gate's findings.
ApprovalReview = "review"
)
// ApprovalKind is what a task waits on the operator to approve, or "" when it
// is not waiting for approval.
func ApprovalKind(status, reviewGate string) string {
switch {
case status != WaitingApproval:
return ""
case reviewGate != "":
return ApprovalReview
default:
return ApprovalPlan
}
}
// RetryMode is the worktree mode for a retried task's next dispatch. Stored
// on the task row.
type RetryMode string
@@ -203,7 +224,7 @@ func Statuses() []StatusMeta {
return []StatusMeta{
{ID: Queued, Label: "Queued", Kind: "idle"},
{ID: Running, Label: "Running", Kind: "info"},
{ID: WaitingHuman, Label: "Waiting on operator", Kind: "warn", NeedsYou: true},
{ID: WaitingApproval, Label: "Waiting for approval", Kind: "warn", NeedsYou: true},
{ID: PROpen, Label: "In review", Kind: "ok"},
{ID: Merged, Label: "Merged", Kind: "ok"},
{ID: Completed, Label: "Done", Kind: "ok"},
+5 -5
View File
@@ -24,11 +24,11 @@ const (
// executionTransitions lists every legal execution status move. Terminal
// statuses have empty rows.
var executionTransitions = map[string][]string{
Queued: {Running, Declined},
Running: {Queued, WaitingHuman, PROpen, Completed, Parked, Declined},
WaitingHuman: {Queued, Declined},
Parked: {Queued, Dead, Declined},
PROpen: {Merged, Rejected, Queued, Declined},
Queued: {Running, Declined},
Running: {Queued, WaitingApproval, PROpen, Completed, Parked, Declined},
WaitingApproval: {Queued, Declined},
Parked: {Queued, Dead, Declined},
PROpen: {Merged, Rejected, Queued, Declined},
Merged: nil,
Rejected: nil,
+2 -1
View File
@@ -86,7 +86,7 @@ func (s *Server) handleTasks(w http.ResponseWriter, r *http.Request) {
views := make([]taskView, len(tasks))
for i := range tasks {
repoURL, issueURL, prURL := taskURLs(tasks[i], forge(tasks[i]))
views[i] = taskView{Task: tasks[i], Actions: taskstate.Actions(tasks[i].Status), RepoURL: repoURL, IssueURL: issueURL, PRURL: prURL}
views[i] = taskView{Task: tasks[i], Actions: taskstate.Actions(tasks[i].Status), Approval: taskstate.ApprovalKind(tasks[i].Status, tasks[i].ReviewGate), RepoURL: repoURL, IssueURL: issueURL, PRURL: prURL}
}
writeJSON(w, views)
}
@@ -125,6 +125,7 @@ func taskPageFrom(q url.Values) (storecontract.TaskPage, error) {
type taskView struct {
task.Task
Actions []taskstate.Action `json:"actions"`
Approval string `json:"approval,omitempty"`
RepoURL string `json:"repo_url,omitempty"`
IssueURL string `json:"issue_url,omitempty"`
PRURL string `json:"pr_url,omitempty"`
+1 -1
View File
@@ -264,7 +264,7 @@ func earlyAttemptOutcome(evs []events.Event, number int, taskStatus string, curr
}
if number == currentAttempt {
switch taskStatus {
case task.StatusParked, task.StatusDead, task.StatusWaitingHuman:
case task.StatusParked, task.StatusDead, task.StatusWaitingApproval:
status = taskStatus
}
}