refactor: cut remaining long comments down to what the code does
This commit is contained in:
1 parent
0cbb65c684
commit
cb6b8618c2
141 files changed
+610
-2622
No files matched your search
@@ -1,18 +1,5 @@
|
||||
// Package taskstate owns the task lifecycle vocabulary and the rules for
|
||||
// operator-initiated actions on a task.
|
||||
//
|
||||
// It exists because those rules had two implementations. The dashboard and
|
||||
// chat both offer approve and reject, and they had drifted: rejecting from
|
||||
// the dashboard left a task ClosedWontDo, cancelling the same task from chat
|
||||
// left it Rejected. Two operators looking at the same queue saw different
|
||||
// states for the same decision, and Rejected -- which the PR reconciler uses
|
||||
// for "the pull request was closed without merging" -- no longer meant one
|
||||
// thing.
|
||||
//
|
||||
// internal/gateway deliberately does not import the task store, so it kept a
|
||||
// hand-synced copy of the status strings with a comment asking future editors
|
||||
// to keep them aligned. That is the same defect one level down. This package
|
||||
// has no dependencies, so both can import it and the copy can go.
|
||||
// Package taskstate defines task statuses and which operator actions each
|
||||
// allows. It has no dependencies.
|
||||
package taskstate
|
||||
|
||||
import (
|
||||
@@ -75,13 +62,8 @@ 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.
|
||||
// Actions returns the actions valid for status, as a new slice. Reject is
|
||||
// available in every non-terminal state; terminal states offer archive.
|
||||
func Actions(status string) []Action {
|
||||
var actions []Action
|
||||
switch status {
|
||||
@@ -124,11 +106,7 @@ func CheckAction(status string, action Action) error {
|
||||
return fmt.Errorf("action %q is not available while task is %s", action, status)
|
||||
}
|
||||
|
||||
// CheckApprove reports whether a task in this status can be approved.
|
||||
//
|
||||
// Approval releases work that is waiting on a human decision, so it is only
|
||||
// meaningful from WaitingHuman. Approving anything else would either restart
|
||||
// finished work or race a task that is already running.
|
||||
// CheckApprove allows approval only from WaitingHuman.
|
||||
func CheckApprove(status string) error {
|
||||
if status != WaitingHuman {
|
||||
return fmt.Errorf("task is %s, not awaiting approval", status)
|
||||
@@ -136,11 +114,7 @@ func CheckApprove(status string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckRetry reports whether a task in this status can be retried.
|
||||
//
|
||||
// Only a parked task can be retried: parking is how archie says "this failed
|
||||
// in a way a human might fix". A dead task has spent its retries and needs
|
||||
// the cap raised or the work re-filed, not another attempt.
|
||||
// CheckRetry allows retry only from Parked.
|
||||
func CheckRetry(status string) error {
|
||||
if status != Parked {
|
||||
return fmt.Errorf("task is %s, not parked", status)
|
||||
@@ -148,12 +122,8 @@ func CheckRetry(status string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RetryMode is the operator's worktree choice for the next dispatch of a
|
||||
// retried task. It is a dispatch directive: the daemon resolves it to the
|
||||
// commit the worktree is prepared at, never infers it from the workflow.
|
||||
//
|
||||
// The values are persisted on the task row (tasks.retry_mode) and cross the
|
||||
// wire, so they are part of the on-disk format: renaming one is a migration.
|
||||
// RetryMode is the worktree mode for a retried task's next dispatch. Stored
|
||||
// on the task row.
|
||||
type RetryMode string
|
||||
|
||||
const (
|
||||
@@ -178,11 +148,8 @@ func NormalizeRetryMode(mode string) RetryMode {
|
||||
return RetryRefreshOntoBase
|
||||
}
|
||||
|
||||
// ResolveRetryMode validates a retry mode arriving from a caller. Unlike
|
||||
// stored data, a wire value that names no mode is rejected rather than
|
||||
// defaulted: silently reading a typo as "refresh onto base" would reset a task
|
||||
// the operator asked to continue. The empty string is accepted and means the
|
||||
// explicit default, RetryRefreshOntoBase.
|
||||
// ResolveRetryMode validates a retry mode; "" means RetryRefreshOntoBase and
|
||||
// unknown values are rejected.
|
||||
func ResolveRetryMode(mode string) (RetryMode, bool) {
|
||||
switch RetryMode(mode) {
|
||||
case "", RetryRefreshOntoBase:
|
||||
@@ -216,12 +183,7 @@ func RetryModes() []RetryModeMeta {
|
||||
}
|
||||
}
|
||||
|
||||
// CheckDecline reports whether a task in this status can be declined.
|
||||
//
|
||||
// The legacy chat command expresses cancel, stop, reject and abandon as one
|
||||
// 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.
|
||||
// CheckDecline allows declining any non-terminal task.
|
||||
func CheckDecline(status string) error {
|
||||
for _, action := range Actions(status) {
|
||||
switch action {
|
||||
|
||||
@@ -6,17 +6,7 @@ import (
|
||||
"slices"
|
||||
)
|
||||
|
||||
// StepStatus is the lifecycle of a StepExecution -- one stage run, or one agent
|
||||
// call a stage makes, inside a WorkflowExecution.
|
||||
// It is part of the on-disk
|
||||
// format, like the execution statuses above.
|
||||
//
|
||||
// It is a distinct type from those statuses even though the two vocabularies
|
||||
// share the word "running": an execution status says what the task is doing,
|
||||
// a step status says what one stage is doing, and the two move through
|
||||
// different tables. One shared string type would let either status be passed
|
||||
// where the other belongs, which is the mistake the separate tables exist to
|
||||
// catch.
|
||||
// StepStatus is a step execution's status. Stored.
|
||||
type StepStatus string
|
||||
|
||||
const (
|
||||
@@ -28,14 +18,8 @@ const (
|
||||
StepInterrupted StepStatus = "interrupted"
|
||||
)
|
||||
|
||||
// executionTransitions is the WorkflowExecution table: the complete set of
|
||||
// legal status moves, held as data so no writer carries its own conditional
|
||||
// copy of the rules.
|
||||
//
|
||||
// Terminal statuses appear as empty rows rather than being absent, so the
|
||||
// table is total over the vocabulary: a status that is missing here is
|
||||
// unroutable, and the difference between "goes nowhere" and "nobody wrote a
|
||||
// row" stays visible.
|
||||
// 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},
|
||||
@@ -86,13 +70,8 @@ func StepTerminal(status StepStatus) bool {
|
||||
}
|
||||
}
|
||||
|
||||
// CheckStepStart reports whether a StepExecution may enter StepRunning under
|
||||
// the execution it belongs to.
|
||||
//
|
||||
// A step only runs while its execution is running, and never under a parent
|
||||
// that has already finished: work a terminal parent had going was cancelled or
|
||||
// interrupted when it finished, so a step starting afterwards would be recorded
|
||||
// against a decision that has already been taken.
|
||||
// CheckStepStart allows a step to start only while its execution is running
|
||||
// and its parent has not finished.
|
||||
func CheckStepStart(executionStatus string, parentTerminal bool) error {
|
||||
if executionStatus != Running {
|
||||
return fmt.Errorf("step cannot start while its execution is %s", executionStatus)
|
||||
|
||||
Reference in new issue
Block a user