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:
35 files changed
+1910
-1259
No files matched your search
@@ -0,0 +1,13 @@
|
||||
-- tasks.stage was the one mutable column recording "which stage is this task
|
||||
-- on", overwritten as workflow.Run advanced and carrying no history: a failed
|
||||
-- attempt could not say which step failed or what ran before it without
|
||||
-- replaying the event stream (docs/prds/execution-tree-state-machine.md,
|
||||
-- "Problem"). step_executions (0017) is now the durable per-step record the
|
||||
-- dashboard's run detail reads (ListSteps), so this column has no remaining
|
||||
-- reader.
|
||||
|
||||
-- +goose Up
|
||||
ALTER TABLE tasks DROP COLUMN stage;
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE tasks ADD COLUMN stage text NOT NULL DEFAULT '';
|
||||
@@ -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,
|
||||
|
||||
@@ -61,3 +61,12 @@ UPDATE step_executions
|
||||
SET status = 'interrupted', finished_at = now()
|
||||
WHERE execution_id = $1 AND attempt = $2 AND status = 'running'
|
||||
RETURNING id, name;
|
||||
|
||||
-- name: ListStepExecutions :many
|
||||
-- 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.
|
||||
SELECT id, execution_id, attempt, parent_id, depth, kind, name, status, detail, tokens_used, started_at, finished_at
|
||||
FROM step_executions
|
||||
WHERE execution_id = @execution_id::bigint AND (@attempt::bigint = 0 OR attempt = @attempt::bigint)
|
||||
ORDER BY attempt, id;
|
||||
@@ -29,7 +29,7 @@ SELECT * FROM tasks WHERE owner = $1 AND repo = $2 AND pr_number = $3 AND status
|
||||
-- The dashboard's list. This projection is deliberately narrow: Plan gates
|
||||
-- the "Decision required" panel and Source labels the row, and widening it
|
||||
-- back would send rows without them.
|
||||
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;
|
||||
@@ -65,11 +65,11 @@ RETURNING *;
|
||||
UPDATE tasks SET binding_id = $2, binding_version = $3, inputs = $4 WHERE id = $1;
|
||||
|
||||
-- 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;
|
||||
|
||||
@@ -129,7 +129,7 @@ WHERE owner = $1 AND repo = $2 AND issue_number = $3 AND status = 'queued'
|
||||
RETURNING *;
|
||||
|
||||
-- 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';
|
||||
|
||||
-- name: UpdateReviewPayloadTask :execrows
|
||||
@@ -143,13 +143,13 @@ WHERE id = $1 AND status = 'pr_open';
|
||||
-- name: RequeueTask :execrows
|
||||
UPDATE tasks SET status = 'queued',
|
||||
workflow = CASE WHEN @workflow::text = '' THEN workflow ELSE @workflow::text END,
|
||||
stage = '', park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
WHERE id = @id AND status = @from_status;
|
||||
|
||||
-- name: RetryTask :execrows
|
||||
UPDATE tasks SET status = 'queued', retry_count = retry_count + 1,
|
||||
workflow = CASE WHEN @workflow::text = '' THEN workflow ELSE @workflow::text END,
|
||||
stage = '', park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
WHERE id = @id AND status = @from_status;
|
||||
|
||||
-- name: ArchiveTaskDelete :execrows
|
||||
|
||||
@@ -224,6 +224,41 @@ func stepEventData(to taskstate.StepStatus, durationMS int64, detail string) map
|
||||
return data
|
||||
}
|
||||
|
||||
// ListSteps reads one execution's recorded steps, every attempt oldest first
|
||||
// when attempt is 0, or just the one it names. It is the dashboard run
|
||||
// detail's authoritative source (docs/prds/execution-tree-state-machine.md),
|
||||
// replacing the fold over stage_start/stage_finish events tasks.stage used to
|
||||
// back -- unlike StartStep/FinishStep, this is a plain read with no
|
||||
// transition to guard, so it takes no transaction.
|
||||
func (s *Store) ListSteps(ctx context.Context, executionID int64, attempt int) ([]task.StepExecution, error) {
|
||||
rows, err := s.queries().ListStepExecutions(ctx, postgresdb.ListStepExecutionsParams{
|
||||
ExecutionID: executionID, Attempt: int64(attempt),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
steps := make([]task.StepExecution, len(rows))
|
||||
for i, r := range rows {
|
||||
steps[i] = task.StepExecution{
|
||||
ID: r.ID, ExecutionID: r.ExecutionID, Attempt: int(r.Attempt),
|
||||
ParentID: nullableInt64(r.ParentID), Depth: int(r.Depth),
|
||||
Kind: r.Kind, Name: r.Name, Status: taskstate.StepStatus(r.Status),
|
||||
Detail: r.Detail, TokensUsed: r.TokensUsed,
|
||||
StartedAt: r.StartedAt.Time, FinishedAt: r.FinishedAt.Time,
|
||||
}
|
||||
}
|
||||
return steps, nil
|
||||
}
|
||||
|
||||
// nullableInt64 reads a pgtype.Int8 the way stepParentID wrote it: absent
|
||||
// means 0, a stage at the tree's root.
|
||||
func nullableInt64(v pgtype.Int8) int64 {
|
||||
if !v.Valid {
|
||||
return 0
|
||||
}
|
||||
return v.Int64
|
||||
}
|
||||
|
||||
// stepParentID encodes the nullable parent id an insert takes: 0 means "no
|
||||
// parent" -- a stage at the tree's root -- which the column stores as NULL
|
||||
// rather than as a reference to a row that does not exist.
|
||||
|
||||
@@ -237,6 +237,71 @@ func TestFinishStepRefusesStaleAndForeign(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestListStepsOrdersByAttemptThenID is the dashboard run detail's
|
||||
// authoritative read (docs/prds/execution-tree-state-machine.md): every
|
||||
// attempt in one call when attempt is 0, one attempt's steps when it names
|
||||
// one, both ordered oldest first.
|
||||
func TestListStepsOrdersByAttemptThenID(t *testing.T) {
|
||||
s := storeFor(t)
|
||||
execution := runningExecution(t, s)
|
||||
|
||||
firstStepID, _, err := s.StartStep(t.Context(), task.StepStart{
|
||||
ExecutionID: execution.ID, Attempt: execution.Attempt, Kind: task.StepKindStage, Name: "plan",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("StartStep: %v", err)
|
||||
}
|
||||
if _, err := s.FinishStep(t.Context(), task.StepFinish{
|
||||
StepID: firstStepID, ExecutionID: execution.ID,
|
||||
From: taskstate.StepRunning, To: taskstate.StepSucceeded, Detail: "planned", TokensUsed: 42,
|
||||
}); err != nil {
|
||||
t.Fatalf("FinishStep: %v", err)
|
||||
}
|
||||
secondStepID, _, err := s.StartStep(t.Context(), task.StepStart{
|
||||
ExecutionID: execution.ID, Attempt: execution.Attempt, Kind: task.StepKindStage, Name: "implement",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("StartStep: %v", err)
|
||||
}
|
||||
|
||||
steps, err := s.ListSteps(t.Context(), execution.ID, execution.Attempt)
|
||||
if err != nil {
|
||||
t.Fatalf("ListSteps: %v", err)
|
||||
}
|
||||
if len(steps) != 2 {
|
||||
t.Fatalf("ListSteps len = %d, want 2", len(steps))
|
||||
}
|
||||
if steps[0].ID != firstStepID || steps[0].Name != "plan" || steps[0].Status != taskstate.StepSucceeded ||
|
||||
steps[0].Detail != "planned" || steps[0].TokensUsed != 42 || steps[0].StartedAt.IsZero() || steps[0].FinishedAt.IsZero() {
|
||||
t.Fatalf("steps[0] = %+v, want the finished plan step", steps[0])
|
||||
}
|
||||
if steps[1].ID != secondStepID || steps[1].Name != "implement" || steps[1].Status != taskstate.StepRunning ||
|
||||
steps[1].StartedAt.IsZero() || !steps[1].FinishedAt.IsZero() {
|
||||
t.Fatalf("steps[1] = %+v, want the still-running implement step", steps[1])
|
||||
}
|
||||
|
||||
// attempt 0 lists every attempt; there is only one here, so the result is
|
||||
// the same, proving the "list everything" branch is reachable and correct
|
||||
// rather than coincidentally equal to a hardcoded attempt.
|
||||
all, err := s.ListSteps(t.Context(), execution.ID, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("ListSteps(attempt=0): %v", err)
|
||||
}
|
||||
if len(all) != 2 {
|
||||
t.Fatalf("ListSteps(attempt=0) len = %d, want 2", len(all))
|
||||
}
|
||||
|
||||
// A different execution's steps never appear, however queried.
|
||||
other := runningExecution(t, s)
|
||||
otherSteps, err := s.ListSteps(t.Context(), other.ID, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("ListSteps other execution: %v", err)
|
||||
}
|
||||
if len(otherSteps) != 0 {
|
||||
t.Fatalf("ListSteps other execution = %+v, want none", otherSteps)
|
||||
}
|
||||
}
|
||||
|
||||
// A late FinishStep for a step another path already finished is stale, the
|
||||
// PRD's named wire behaviour: errors.Is matches on the client too.
|
||||
func TestFinishStepOffTablePairIsIllegalOverTheTable(t *testing.T) {
|
||||
|
||||
@@ -93,7 +93,6 @@ func taskFromRow(t postgresdb.Task) *workflow.Task {
|
||||
WorkflowDefinitionVersion: t.WorkflowDefinitionVersion,
|
||||
WorkflowDefinitionDigest: t.WorkflowDefinitionDigest,
|
||||
WorkflowDefinitionYAML: t.WorkflowDefinitionYaml,
|
||||
Stage: t.Stage,
|
||||
Branch: t.Branch,
|
||||
Plan: t.Plan,
|
||||
Notes: t.Notes,
|
||||
@@ -282,7 +281,6 @@ func (s *Store) Update(ctx context.Context, t *workflow.Task) error {
|
||||
return s.queries().UpdateTask(ctx, postgresdb.UpdateTaskParams{
|
||||
ID: t.ID,
|
||||
Workflow: t.Workflow,
|
||||
Stage: t.Stage,
|
||||
Branch: t.Branch,
|
||||
Plan: t.Plan,
|
||||
Notes: t.Notes,
|
||||
@@ -527,7 +525,7 @@ func (s *Store) Tasks(ctx context.Context, limit int) ([]workflow.Task, error) {
|
||||
for _, r := range rows {
|
||||
tasks = append(tasks, workflow.Task{
|
||||
ID: r.ID, Owner: r.Owner, Repo: r.Repo, IssueNumber: int(r.IssueNumber),
|
||||
Title: r.Title, Status: r.Status, Workflow: r.Workflow, Stage: r.Stage,
|
||||
Title: r.Title, Status: r.Status, Workflow: r.Workflow,
|
||||
PRNumber: int(r.PrNumber), TokensUsed: int(r.TokensUsed), Iterations: int(r.Iterations),
|
||||
Attempt: int(r.Attempt), ParkReason: r.ParkReason, RetryCount: int(r.RetryCount),
|
||||
CreatedAt: r.CreatedAt, UpdatedAt: r.UpdatedAt, Plan: r.Plan, Source: r.Source,
|
||||
|
||||
Reference in new issue
Block a user