Files
archie/internal/domain/workflow/task/step.go
T
sam 5f375f8a14 feat(state-store): ListSteps, dashboard run detail reads it; drop tasks.stage
docs/prds/execution-tree-state-machine.md: step_executions (0017) is now the
durable per-step record; the dashboard's run detail (GET /api/tasks/{id}/
attempts) still folded stage_start/stage_finish events into a rail by hand,
and tasks.stage duplicated what StartStep/FinishStep already record properly.

Added the missing read:
- ListSteps(execution_id, attempt) -- attempt 0 lists every attempt of the
  execution, oldest first, so the rail renders every attempt from one call.
  New storecontract.StepReader (separate from StepRecorder: this is a
  dashboard/API/dispatch action per the PRD's wire contract, never
  task-scoped-grant callable), postgresdb.ListStepExecutions, staterpc
  client/server/values.go plumbing, wired through state_store.go's Deps and
  archieui/compose.go's Server.Steps the same optional-capability pattern
  every other dashboard read uses.
- internal/webui/api_tasks_attempts.go: stageViewsFromSteps replaces
  foldStages/finishStage/stageOutcome. Attempt bounds, event_count and which
  attempt numbers exist stay sourced from events (an attempt can carry
  events -- agent calls -- with no step), only the stage list itself moves.
  The wire JSON contract is unchanged, so no frontend change was needed;
  `task ui` confirms ui/dist still matches a fresh build.
- A running step past the task's own current attempt reads interrupted, not
  running: RecoverStale (archie-core, still open per #1214) is what corrects
  a crashed run's stale "running" row, and until it does this is the honest
  read rather than trusting a row that may be stale.

Dropped tasks.stage and every reader, no fallback:
- Migration 0018 drops the column; tasks.sql's INSERT/UPDATE/RETURNING lists
  and the sqlc-generated code no longer carry it.
- workflow.Task.Stage is gone; workflow.Run's in-flight "which stage is this"
  bookkeeping moves to TaskContext.Stage (execution-time only, never
  persisted -- park/finish's event tagging is its only reader).
- pb.Task.stage (wire field 10) is `[deprecated = true]`, not deleted (never
  reuse a field number); staterpc's taskProto/taskValue no longer map it.
- taskactions.Task.Stage and the retry event's "previous_stage" data field
  are gone: the operator-action package had no reader for the column beyond
  echoing it.
- The chat /tasks command's per-task "workflow/stage" display drops to
  workflow-only (ChatTaskSummary.Stage removed, workflowStage() deleted):
  it was a genuine reader with no replacement in scope for this change.

Read the archie-web-ui skill and the state-store/daemon docs/development
pages first, per instruction. Stayed out of cancel/stop code throughout
(Pi's concurrent CancelExecution work); the only shared files touched
(workflow.go, daemon-adjacent SQL) got the smallest possible diff.
2026-09-27 06:57:47 +10:00

83 lines
2.6 KiB
Go

package task
import (
"time"
"github.com/samcharles93/archie-core/internal/taskstate"
)
// The step-execution vocabulary of docs/prds/execution-tree-state-machine.md:
// one stage run, or one agent or workflow.call step an execution's tree
// records, started and finished through the State Store under the run's own
// credential.
// Step kinds. `stage` is what workflow.Run records for every stage it runs;
// `agent` is what the agent runtime records for one agent call; `call` is the
// workflow.call step in a caller's tree, which names its callee's execution.
// A new kind needs a named consumer before it is added.
const (
StepKindStage = "stage"
StepKindAgent = "agent"
StepKindCall = "call"
)
// ValidStepKind reports whether kind is one the store records.
func ValidStepKind(kind string) bool {
switch kind {
case StepKindStage, StepKindAgent, StepKindCall:
return true
default:
return false
}
}
// StepStart names the step a caller is starting. ExecutionID is the
// WorkflowExecution (the tasks row); Attempt is the run of it the step
// belongs to; ParentID is 0 for a stage and names the enclosing StepExecution
// otherwise, from which the store derives depth.
type StepStart struct {
ExecutionID int64
Attempt int
// ParentID is 0 when the step is a stage at the tree's root.
ParentID int64
Kind string
Name string
}
// StepFinish moves one step from From to its outcome. ExecutionID names the
// run the step belongs to: the task-scoped grant check verifies it, and the
// store verifies the step really is that execution's, so a caller cannot move
// another run's step by naming it.
type StepFinish struct {
StepID int64
ExecutionID int64
// From and To are the step transition table's statuses (taskstate).
From taskstate.StepStatus
To taskstate.StepStatus
// Detail is the step's outcome line: an error's text for a failed step, a
// summary otherwise. Clipped store-side like every detail.
Detail string
// TokensUsed is the usage the step itself accounted. Stages record none;
// the agent runtime records its own calls' usage.
TokensUsed int64
}
// StepExecution is one recorded step: ListSteps' read, the dashboard run
// detail's authoritative source (docs/prds/execution-tree-state-machine.md;
// replaces folding stage_start/stage_finish events, which tasks.stage used to
// back). ParentID is 0 for a stage at the tree's root.
type StepExecution struct {
ID int64
ExecutionID int64
Attempt int
ParentID int64
Depth int
Kind string
Name string
Status taskstate.StepStatus
Detail string
TokensUsed int64
StartedAt time.Time
FinishedAt time.Time
}