diff --git a/cmd/archied/task_action_adapter_test.go b/cmd/archied/task_action_adapter_test.go index 5ad1e8488..47b3a86d9 100644 --- a/cmd/archied/task_action_adapter_test.go +++ b/cmd/archied/task_action_adapter_test.go @@ -121,8 +121,8 @@ func TestChatTaskActorAdapterRefusesDisallowedStateAction(t *testing.T) { attemptAction: taskstate.ActionApprove, }, { - name: "cannot reject queued task", - initialStatus: store.StatusQueued, + name: "cannot reject merged task", + initialStatus: store.StatusMerged, attemptAction: taskstate.ActionReject, }, } diff --git a/internal/gateway/tasks_test.go b/internal/gateway/tasks_test.go index 454fc49a8..2abc39b3f 100644 --- a/internal/gateway/tasks_test.go +++ b/internal/gateway/tasks_test.go @@ -361,9 +361,11 @@ func TestStoreTaskControllerStopRunningWithoutRuntime(t *testing.T) { } } +// PROpen is deliberately absent: it is not a terminal state, and reject is +// now available there so an operator can refuse work still sitting in review. +// The genuine terminal states must keep refusing cancel. func TestStoreTaskControllerCancelRejectsTerminalStates(t *testing.T) { for _, status := range []string{ - taskstate.PROpen, taskstate.Merged, taskstate.Rejected, taskstate.Dead, diff --git a/internal/taskstate/taskstate.go b/internal/taskstate/taskstate.go index bc1cdc501..b9cc8542a 100644 --- a/internal/taskstate/taskstate.go +++ b/internal/taskstate/taskstate.go @@ -72,19 +72,24 @@ func Terminal(status string) bool { // Actions returns the ordered controls valid for status. Callers receive a // fresh slice so presentation code cannot mutate the lifecycle table. +// +// Reject is deliberately present in every non-terminal state: an operator can +// refuse work no matter where it currently sits, and the refusal always lands +// in the terminal Declined state. Terminal states are already resolved, so +// they only expose archive. func Actions(status string) []Action { var actions []Action switch status { case Queued: - actions = []Action{ActionCancel} + actions = []Action{ActionCancel, ActionReject} case Running: - actions = []Action{ActionStop} + actions = []Action{ActionStop, ActionReject} case WaitingHuman: actions = []Action{ActionApprove, ActionReject} case Parked: - actions = []Action{ActionRetry, ActionAbandon} + actions = []Action{ActionRetry, ActionAbandon, ActionReject} case PROpen: - actions = []Action{ActionOpenPR, ActionOpenIssue} + actions = []Action{ActionOpenPR, ActionOpenIssue, ActionReject} case Merged, Rejected, Dead, Declined: actions = []Action{ActionArchive} } @@ -126,9 +131,9 @@ func CheckRetry(status string) error { // CheckDecline reports whether a task in this status can be declined. // // The legacy chat command expresses cancel, stop, reject and abandon as one -// operation. It remains available only where the canonical action table -// exposes one of those controls; unknown, PR-open and terminal states fail -// closed instead of permitting an arbitrary transition. +// operation. Because Reject is now offered in every non-terminal state, that +// command is available everywhere a task is still live; unknown and terminal +// states fail closed instead of permitting an arbitrary transition. func CheckDecline(status string) error { for _, action := range Actions(status) { switch action { diff --git a/internal/taskstate/taskstate_test.go b/internal/taskstate/taskstate_test.go index 256739f64..c2aa92e39 100644 --- a/internal/taskstate/taskstate_test.go +++ b/internal/taskstate/taskstate_test.go @@ -15,11 +15,11 @@ func TestActionRules(t *testing.T) { terminal bool actions []Action }{ - {status: Queued, decline: true, actions: []Action{ActionCancel}}, - {status: Running, decline: true, actions: []Action{ActionStop}}, + {status: Queued, decline: true, actions: []Action{ActionCancel, ActionReject}}, + {status: Running, decline: true, actions: []Action{ActionStop, ActionReject}}, {status: WaitingHuman, approve: true, decline: true, actions: []Action{ActionApprove, ActionReject}}, - {status: PROpen, actions: []Action{ActionOpenPR, ActionOpenIssue}}, - {status: Parked, retry: true, decline: true, actions: []Action{ActionRetry, ActionAbandon}}, + {status: PROpen, decline: true, actions: []Action{ActionOpenPR, ActionOpenIssue, ActionReject}}, + {status: Parked, retry: true, decline: true, actions: []Action{ActionRetry, ActionAbandon, ActionReject}}, {status: Merged, terminal: true, actions: []Action{ActionArchive}}, {status: Rejected, terminal: true, actions: []Action{ActionArchive}}, {status: Dead, terminal: true, actions: []Action{ActionArchive}}, diff --git a/internal/webui/api_tasks.go b/internal/webui/api_tasks.go index d39cc9aea..a6faf563c 100644 --- a/internal/webui/api_tasks.go +++ b/internal/webui/api_tasks.go @@ -458,13 +458,14 @@ func (s *Server) retireTask(ctx context.Context, task *store.Task, reason string } func (s *Server) rejectTask(ctx context.Context, w http.ResponseWriter, task *store.Task) *actionOutcome { - // The dashboard only offers Reject on a waiting_human task, but the rule - // is the shared one so the two surfaces cannot drift apart again. - if err := taskstate.CheckApprove(task.Status); err != nil { - http.Error(w, err.Error(), http.StatusConflict) - return nil + // Reject is available from any non-terminal lifecycle state: work the + // operator refuses belongs in the terminal Declined state regardless of + // where it currently sits. Running work is interrupted first so nothing + // keeps executing against a task that is being closed out. + if task.Status == store.StatusRunning && s.TaskStopper != nil { + s.TaskStopper.CancelTask(task.ID) } - err := s.Store.Transition(ctx, task.ID, store.StatusWaitingHuman, store.StatusClosedWontDo, "declined from the dashboard") + err := s.Store.Transition(ctx, task.ID, task.Status, store.StatusClosedWontDo, "declined from the dashboard") if s.storeFailed(w, err) { return nil } diff --git a/internal/webui/api_tasks_actions_test.go b/internal/webui/api_tasks_actions_test.go index 15216fb63..e9c13151c 100644 --- a/internal/webui/api_tasks_actions_test.go +++ b/internal/webui/api_tasks_actions_test.go @@ -397,11 +397,11 @@ func TestTaskListExposesLifecycleActions(t *testing.T) { srv := newTestServer(t) ctx := t.Context() want := map[string][]string{ - store.StatusQueued: {"cancel"}, - store.StatusRunning: {"stop"}, + store.StatusQueued: {"cancel", "reject"}, + store.StatusRunning: {"stop", "reject"}, store.StatusWaitingHuman: {"approve", "reject"}, - store.StatusParked: {"retry", "abandon"}, - store.StatusPROpen: {"open_pr", "open_issue"}, + store.StatusParked: {"retry", "abandon", "reject"}, + store.StatusPROpen: {"open_pr", "open_issue", "reject"}, store.StatusMerged: {"archive"}, store.StatusRejected: {"archive"}, store.StatusDead: {"archive"}, @@ -455,6 +455,13 @@ func TestLifecycleSpecificTaskActions(t *testing.T) { {name: "stop running", from: store.StatusRunning, action: "stop", want: store.StatusParked, stopperResult: true}, {name: "park stale running row", from: store.StatusRunning, action: "stop", want: store.StatusParked}, {name: "abandon parked", from: store.StatusParked, action: "abandon", want: store.StatusClosedWontDo, closesIssue: true}, + // Reject is available from every non-terminal state and always lands in + // the terminal Declined state, closing the forge issue. + {name: "reject queued", from: store.StatusQueued, action: "reject", want: store.StatusClosedWontDo, closesIssue: true}, + {name: "reject running stops execution", from: store.StatusRunning, action: "reject", want: store.StatusClosedWontDo, closesIssue: true, stopperResult: true}, + {name: "reject waiting_human", from: store.StatusWaitingHuman, action: "reject", want: store.StatusClosedWontDo, closesIssue: true}, + {name: "reject parked", from: store.StatusParked, action: "reject", want: store.StatusClosedWontDo, closesIssue: true}, + {name: "reject pr_open", from: store.StatusPROpen, action: "reject", want: store.StatusClosedWontDo, closesIssue: true}, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { @@ -478,7 +485,7 @@ func TestLifecycleSpecificTaskActions(t *testing.T) { t.Cleanup(bus.Close) srv.Events = bus sub := bus.Subscribe(1) - if tc.action == "stop" { + if tc.action == "stop" || (tc.action == "reject" && tc.from == store.StatusRunning) { setTaskStopper(t, srv, &recordingTaskStopper{result: tc.stopperResult}) } if w := postAction(t, srv, task.ID, tc.action); w.Code != http.StatusOK {