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.
This commit is contained in:
sam committed 2026-09-27 06:57:47 +10:00
1 parent ed12d4de78
commit 5f375f8a14
35 files changed
+1910 -1259

No files matched your search

@@ -24,7 +24,7 @@ func (q *Queries) CallStatusDetail(ctx context.Context, taskID int64) (string, e
const enqueueCallTask = `-- name: EnqueueCallTask :one
WITH caller AS (
SELECT t.id, t.owner, t.repo, t.issue_number, t.title, t.body, t.labels, t.status, t.workflow, t.stage, t.branch, t.plan, t.notes, t.pr_number, t.tokens_used, t.iterations, t.attempt, t.park_reason, t.watch_comment_id, t.park_class, t.remediation_rounds, t.retry_count, t.source, t.identity, t.binding_id, t.binding_version, t.review_payload, t.workflow_definition_version, t.workflow_definition_digest, t.workflow_definition_yaml, t.created_at, t.updated_at, t.review_cursor, t.inputs, t.org_id, t.workspace_id, t.call_parent_task_id, t.call_depth FROM tasks t WHERE t.id = $1 FOR UPDATE
SELECT t.id, t.owner, t.repo, t.issue_number, t.title, t.body, t.labels, t.status, t.workflow, t.branch, t.plan, t.notes, t.pr_number, t.tokens_used, t.iterations, t.attempt, t.park_reason, t.watch_comment_id, t.park_class, t.remediation_rounds, t.retry_count, t.source, t.identity, t.binding_id, t.binding_version, t.review_payload, t.workflow_definition_version, t.workflow_definition_digest, t.workflow_definition_yaml, t.created_at, t.updated_at, t.review_cursor, t.inputs, t.org_id, t.workspace_id, t.call_parent_task_id, t.call_depth FROM tasks t WHERE t.id = $1 FOR UPDATE
)
INSERT INTO tasks (owner, repo, issue_number, title, body, labels, workflow, source, identity, org_id, workspace_id, inputs, call_parent_task_id, call_depth)
SELECT
@@ -41,7 +41,7 @@ SELECT
caller.id, caller.call_depth + 1
FROM caller
WHERE caller.status = 'running' AND caller.call_depth + 1 <= $7::int
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, stage, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
`
type EnqueueCallTaskParams struct {
@@ -84,7 +84,6 @@ func (q *Queries) EnqueueCallTask(ctx context.Context, arg EnqueueCallTaskParams
&i.Labels,
&i.Status,
&i.Workflow,
&i.Stage,
&i.Branch,
&i.Plan,
&i.Notes,
@@ -348,7 +348,6 @@ type Task struct {
Labels string
Status string
Workflow string
Stage string
Branch string
Plan string
Notes string
@@ -157,6 +157,69 @@ func (q *Queries) InterruptAttemptSteps(ctx context.Context, arg InterruptAttemp
return items, nil
}
const listStepExecutions = `-- name: ListStepExecutions :many
SELECT id, execution_id, attempt, parent_id, depth, kind, name, status, detail, tokens_used, started_at, finished_at
FROM step_executions
WHERE execution_id = $1::bigint AND ($2::bigint = 0 OR attempt = $2::bigint)
ORDER BY attempt, id
`
type ListStepExecutionsParams struct {
ExecutionID int64
Attempt int64
}
type ListStepExecutionsRow struct {
ID int64
ExecutionID int64
Attempt int64
ParentID pgtype.Int8
Depth int32
Kind string
Name string
Status string
Detail string
TokensUsed int64
StartedAt pgtype.Timestamptz
FinishedAt pgtype.Timestamptz
}
// attempt = 0 lists every attempt of the execution, oldest first; the index
// (execution_id, attempt, id) makes both this and the single-attempt form a
// straight index scan.
func (q *Queries) ListStepExecutions(ctx context.Context, arg ListStepExecutionsParams) ([]ListStepExecutionsRow, error) {
rows, err := q.db.Query(ctx, listStepExecutions, arg.ExecutionID, arg.Attempt)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListStepExecutionsRow
for rows.Next() {
var i ListStepExecutionsRow
if err := rows.Scan(
&i.ID,
&i.ExecutionID,
&i.Attempt,
&i.ParentID,
&i.Depth,
&i.Kind,
&i.Name,
&i.Status,
&i.Detail,
&i.TokensUsed,
&i.StartedAt,
&i.FinishedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const lockExecutionForStep = `-- name: LockExecutionForStep :one
SELECT id, status, org_id, workspace_id, owner, repo, issue_number, workflow, attempt
@@ -28,7 +28,7 @@ func (q *Queries) ArchiveTaskDelete(ctx context.Context, arg ArchiveTaskDeletePa
}
const beginRemediationTask = `-- name: BeginRemediationTask :execrows
UPDATE tasks SET status = 'queued', workflow = 'remediate', stage = '', park_reason = '', park_class = 'needs_human', review_payload = $2, updated_at = now()
UPDATE tasks SET status = 'queued', workflow = 'remediate', park_reason = '', park_class = 'needs_human', review_payload = $2, updated_at = now()
WHERE id = $1 AND status = 'pr_open'
`
@@ -48,7 +48,7 @@ func (q *Queries) BeginRemediationTask(ctx context.Context, arg BeginRemediation
const claimByIssue = `-- name: ClaimByIssue :one
UPDATE tasks SET status = 'running', attempt = attempt + 1, updated_at = now()
WHERE owner = $1 AND repo = $2 AND issue_number = $3 AND status = 'queued'
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, stage, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
`
type ClaimByIssueParams struct {
@@ -70,7 +70,6 @@ func (q *Queries) ClaimByIssue(ctx context.Context, arg ClaimByIssueParams) (Tas
&i.Labels,
&i.Status,
&i.Workflow,
&i.Stage,
&i.Branch,
&i.Plan,
&i.Notes,
@@ -113,7 +112,7 @@ WHERE id = (
FOR UPDATE SKIP LOCKED
LIMIT 1
)
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, stage, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
`
// FOR UPDATE SKIP LOCKED replaces the SQLite single-writer assumption: two
@@ -132,7 +131,6 @@ func (q *Queries) ClaimNextTask(ctx context.Context) (Task, error) {
&i.Labels,
&i.Status,
&i.Workflow,
&i.Stage,
&i.Branch,
&i.Plan,
&i.Notes,
@@ -270,7 +268,7 @@ VALUES (
'default'
)
)
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, stage, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
`
type InsertChatTaskParams struct {
@@ -308,7 +306,6 @@ func (q *Queries) InsertChatTask(ctx context.Context, arg InsertChatTaskParams)
&i.Labels,
&i.Status,
&i.Workflow,
&i.Stage,
&i.Branch,
&i.Plan,
&i.Notes,
@@ -415,7 +412,7 @@ func (q *Queries) ListOpenPRs(ctx context.Context) ([]ListOpenPRsRow, error) {
}
const listTaskSummaries = `-- name: ListTaskSummaries :many
SELECT id, owner, repo, issue_number, title, status, workflow, stage,
SELECT id, owner, repo, issue_number, title, status, workflow,
pr_number, tokens_used, iterations, attempt, park_reason, retry_count,
created_at, updated_at, plan, source, identity, binding_id, binding_version
FROM tasks ORDER BY updated_at DESC LIMIT $1
@@ -429,7 +426,6 @@ type ListTaskSummariesRow struct {
Title string
Status string
Workflow string
Stage string
PrNumber int64
TokensUsed int64
Iterations int64
@@ -465,7 +461,6 @@ func (q *Queries) ListTaskSummaries(ctx context.Context, limit int32) ([]ListTas
&i.Title,
&i.Status,
&i.Workflow,
&i.Stage,
&i.PrNumber,
&i.TokensUsed,
&i.Iterations,
@@ -545,7 +540,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,
stage = '', park_reason = '', park_class = 'needs_human', updated_at = now()
park_reason = '', park_class = 'needs_human', updated_at = now()
WHERE id = $2 AND status = $3
`
@@ -566,7 +561,7 @@ func (q *Queries) RequeueTask(ctx context.Context, arg RequeueTaskParams) (int64
const retryTask = `-- name: RetryTask :execrows
UPDATE tasks SET status = 'queued', retry_count = retry_count + 1,
workflow = CASE WHEN $1::text = '' THEN workflow ELSE $1::text END,
stage = '', park_reason = '', park_class = 'needs_human', updated_at = now()
park_reason = '', park_class = 'needs_human', updated_at = now()
WHERE id = $2 AND status = $3
`
@@ -625,7 +620,7 @@ func (q *Queries) StampTaskBinding(ctx context.Context, arg StampTaskBindingPara
}
const taskByID = `-- name: TaskByID :one
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, stage, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth FROM tasks WHERE id = $1
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth FROM tasks WHERE id = $1
`
func (q *Queries) TaskByID(ctx context.Context, id int64) (Task, error) {
@@ -641,7 +636,6 @@ func (q *Queries) TaskByID(ctx context.Context, id int64) (Task, error) {
&i.Labels,
&i.Status,
&i.Workflow,
&i.Stage,
&i.Branch,
&i.Plan,
&i.Notes,
@@ -675,7 +669,7 @@ func (q *Queries) TaskByID(ctx context.Context, id int64) (Task, error) {
}
const taskByIssue = `-- name: TaskByIssue :one
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, stage, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth FROM tasks WHERE owner = $1 AND repo = $2 AND issue_number = $3
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth FROM tasks WHERE owner = $1 AND repo = $2 AND issue_number = $3
`
type TaskByIssueParams struct {
@@ -697,7 +691,6 @@ func (q *Queries) TaskByIssue(ctx context.Context, arg TaskByIssueParams) (Task,
&i.Labels,
&i.Status,
&i.Workflow,
&i.Stage,
&i.Branch,
&i.Plan,
&i.Notes,
@@ -731,7 +724,7 @@ func (q *Queries) TaskByIssue(ctx context.Context, arg TaskByIssueParams) (Task,
}
const taskByPR = `-- name: TaskByPR :one
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, stage, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth FROM tasks WHERE owner = $1 AND repo = $2 AND pr_number = $3 AND status = $4
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth FROM tasks WHERE owner = $1 AND repo = $2 AND pr_number = $3 AND status = $4
`
type TaskByPRParams struct {
@@ -762,7 +755,6 @@ func (q *Queries) TaskByPR(ctx context.Context, arg TaskByPRParams) (Task, error
&i.Labels,
&i.Status,
&i.Workflow,
&i.Stage,
&i.Branch,
&i.Plan,
&i.Notes,
@@ -847,11 +839,11 @@ func (q *Queries) UpdateReviewPayloadTask(ctx context.Context, arg UpdateReviewP
}
const updateTask = `-- name: UpdateTask :exec
UPDATE tasks SET workflow = $2, stage = $3, branch = $4, plan = $5, notes = $6,
pr_number = $7, tokens_used = $8, iterations = $9, park_reason = $10,
watch_comment_id = $11, retry_count = $12, remediation_rounds = $13,
review_payload = $14, workflow_definition_version = $15,
workflow_definition_digest = $16, workflow_definition_yaml = $17,
UPDATE tasks SET workflow = $2, branch = $3, plan = $4, notes = $5,
pr_number = $6, tokens_used = $7, iterations = $8, park_reason = $9,
watch_comment_id = $10, retry_count = $11, remediation_rounds = $12,
review_payload = $13, workflow_definition_version = $14,
workflow_definition_digest = $15, workflow_definition_yaml = $16,
updated_at = now()
WHERE id = $1
`
@@ -859,7 +851,6 @@ WHERE id = $1
type UpdateTaskParams struct {
ID int64
Workflow string
Stage string
Branch string
Plan string
Notes string
@@ -880,7 +871,6 @@ func (q *Queries) UpdateTask(ctx context.Context, arg UpdateTaskParams) error {
_, err := q.db.Exec(ctx, updateTask,
arg.ID,
arg.Workflow,
arg.Stage,
arg.Branch,
arg.Plan,
arg.Notes,