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.
75 lines
2.6 KiB
Go
75 lines
2.6 KiB
Go
// Package taskactions adapts legacy task persistence to operator actions.
|
|
package taskactions
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
|
"github.com/samcharles93/archie-core/internal/domain/taskactions"
|
|
)
|
|
|
|
type Store struct{ storecontract.TaskStore }
|
|
|
|
func (s Store) TaskByID(ctx context.Context, id int64) (*taskactions.Task, error) {
|
|
t, err := s.TaskStore.TaskByID(ctx, id)
|
|
if err != nil || t == nil {
|
|
return nil, err
|
|
}
|
|
return &taskactions.Task{ID: t.ID, Owner: t.Owner, Repo: t.Repo, Identity: t.Identity, Status: t.Status, ParkReason: t.ParkReason, IssueNumber: t.IssueNumber, RetryCount: t.RetryCount, Attempt: t.Attempt, ForgeBacked: t.IsForgeBacked()}, nil
|
|
}
|
|
|
|
// CancelExecution delegates to the store's one cancel path
|
|
// (docs/prds/execution-tree-state-machine.md). Both adapters -- the
|
|
// PostgreSQL store and the remote gRPC client -- implement it; the type
|
|
// assertion failing would be a composition bug, so it is named rather than
|
|
// panicked over.
|
|
func (s Store) CancelExecution(ctx context.Context, taskID int64, reason, to string) ([]int64, error) {
|
|
canceller, ok := s.TaskStore.(storecontract.ExecutionCanceller)
|
|
if !ok {
|
|
return nil, fmt.Errorf("task store cannot cancel executions")
|
|
}
|
|
return canceller.CancelExecution(ctx, taskID, reason, to)
|
|
}
|
|
|
|
func MaxRetries(cfg *config.Holder) func(*taskactions.Task) int {
|
|
return func(t *taskactions.Task) int {
|
|
if cfg == nil {
|
|
return 0
|
|
}
|
|
c := cfg.Get()
|
|
// A multi-identity deployment declares its repositories under
|
|
// [[identities.repos]] and has no global [[repos]] at all, so the
|
|
// task's owning identity is the only place a per-repo override can
|
|
// live. Without this lookup the override is never matched and the
|
|
// task dies at the global cap instead of the configured one.
|
|
if t.Identity != "" {
|
|
for _, identity := range c.Identities {
|
|
if identity.Name != t.Identity {
|
|
continue
|
|
}
|
|
if n, ok := repoMaxRetries(identity.Repos, t, c.MaxRetries); ok {
|
|
return n
|
|
}
|
|
break
|
|
}
|
|
}
|
|
if n, ok := repoMaxRetries(c.Repos, t, c.MaxRetries); ok {
|
|
return n
|
|
}
|
|
return c.MaxRetries
|
|
}
|
|
}
|
|
|
|
// repoMaxRetries returns the effective cap for the task's repository within one
|
|
// repository list, and whether that list knows the repository at all.
|
|
func repoMaxRetries(repos []config.Repo, t *taskactions.Task, global int) (int, bool) {
|
|
for _, repo := range repos {
|
|
if repo.Owner == t.Owner && repo.Name == t.Repo {
|
|
return repo.EffectiveMaxRetries(global), true
|
|
}
|
|
}
|
|
return 0, false
|
|
}
|