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
@@ -166,7 +166,6 @@ func (a chatTaskListerAdapter) ListChatTasks(ctx context.Context, identity strin
|
|||||||
Title: task.Title,
|
Title: task.Title,
|
||||||
Status: task.Status,
|
Status: task.Status,
|
||||||
Workflow: task.Workflow,
|
Workflow: task.Workflow,
|
||||||
Stage: task.Stage,
|
|
||||||
PRNumber: task.PRNumber,
|
PRNumber: task.PRNumber,
|
||||||
Attempt: task.Attempt,
|
Attempt: task.Attempt,
|
||||||
ParkReason: task.ParkReason,
|
ParkReason: task.ParkReason,
|
||||||
|
|||||||
@@ -352,6 +352,9 @@ func (b *boot) stateStoreDeps(grants *staterpc.TaskGrants) staterpc.Deps {
|
|||||||
if ec, ok := b.st.(storecontract.ExecutionCanceller); ok {
|
if ec, ok := b.st.(storecontract.ExecutionCanceller); ok {
|
||||||
deps.Canceller = ec
|
deps.Canceller = ec
|
||||||
}
|
}
|
||||||
|
if sr, ok := b.st.(storecontract.StepReader); ok {
|
||||||
|
deps.StepReader = sr
|
||||||
|
}
|
||||||
b.accessDeps(&deps)
|
b.accessDeps(&deps)
|
||||||
if css, ok := b.st.(storecontract.ConfigSnapshotStore); ok {
|
if css, ok := b.st.(storecontract.ConfigSnapshotStore); ok {
|
||||||
deps.ConfigSnapshots = css
|
deps.ConfigSnapshots = css
|
||||||
|
|||||||
@@ -90,6 +90,9 @@ func compose(d deps) *webui.Server {
|
|||||||
if snapshots, ok := d.Store.(storecontract.ConfigSnapshotStore); ok {
|
if snapshots, ok := d.Store.(storecontract.ConfigSnapshotStore); ok {
|
||||||
srv.ConfigSource = webui.RemoteConfigView(snapshots)
|
srv.ConfigSource = webui.RemoteConfigView(snapshots)
|
||||||
}
|
}
|
||||||
|
if steps, ok := d.Store.(storecontract.StepReader); ok {
|
||||||
|
srv.Steps = steps
|
||||||
|
}
|
||||||
// Channel lifecycle follows the same split as the config view: the process
|
// Channel lifecycle follows the same split as the config view: the process
|
||||||
// hosting the channels publishes, this one reads. Withholding it left
|
// hosting the channels publishes, this one reads. Withholding it left
|
||||||
// /api/channels answering with nothing while channels were running
|
// /api/channels answering with nothing while channels were running
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
||||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||||
"github.com/samcharles93/archie-core/internal/domain/taskactions"
|
"github.com/samcharles93/archie-core/internal/domain/taskactions"
|
||||||
|
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||||
"github.com/samcharles93/archie-core/internal/events"
|
"github.com/samcharles93/archie-core/internal/events"
|
||||||
"github.com/samcharles93/archie-core/internal/gateway"
|
"github.com/samcharles93/archie-core/internal/gateway"
|
||||||
"github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc"
|
"github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc"
|
||||||
@@ -102,10 +103,15 @@ func serveGRPC(t *testing.T, register func(grpc.ServiceRegistrar)) (target strin
|
|||||||
func TestUIServesDashboardAgainstRemoteContracts(t *testing.T) {
|
func TestUIServesDashboardAgainstRemoteContracts(t *testing.T) {
|
||||||
st := pgstore.Open(t)
|
st := pgstore.Open(t)
|
||||||
defer st.Close()
|
defer st.Close()
|
||||||
seeded, err := st.EnqueueChatTask(t.Context(), "acme", "widget", "remote summary", "body", "implement", "")
|
if _, err := st.EnqueueChatTask(t.Context(), "acme", "widget", "remote summary", "body", "implement", ""); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("seed task: %v", err)
|
t.Fatalf("seed task: %v", err)
|
||||||
}
|
}
|
||||||
|
// Claimed (not just enqueued): StartStep guards on the execution's own
|
||||||
|
// current attempt, which a merely-queued task does not have yet.
|
||||||
|
seeded, err := st.ClaimNext(t.Context())
|
||||||
|
if err != nil || seeded == nil {
|
||||||
|
t.Fatalf("claim seeded task: %+v %v", seeded, err)
|
||||||
|
}
|
||||||
// The daemon publishes the configuration page's projection; this process
|
// The daemon publishes the configuration page's projection; this process
|
||||||
// only renders it (archie-core-ymut). The forge host is published too: it
|
// only renders it (archie-core-ymut). The forge host is published too: it
|
||||||
// is what the run-detail reads resolve their repository and pull-request
|
// is what the run-detail reads resolve their repository and pull-request
|
||||||
@@ -129,9 +135,23 @@ func TestUIServesDashboardAgainstRemoteContracts(t *testing.T) {
|
|||||||
// worker's change capture -- attributed to one attempt, so the assertions
|
// worker's change capture -- attributed to one attempt, so the assertions
|
||||||
// further down read them back through the real client rather than a fake.
|
// further down read them back through the real client rather than a fake.
|
||||||
seedAt := time.Now().UTC()
|
seedAt := time.Now().UTC()
|
||||||
|
prepareStepID, _, err := st.StartStep(t.Context(), task.StepStart{ExecutionID: seeded.ID, Attempt: 1, Kind: task.StepKindStage, Name: "prepare"})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("seed prepare step: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := st.FinishStep(t.Context(), task.StepFinish{
|
||||||
|
StepID: prepareStepID, ExecutionID: seeded.ID, From: taskstate.StepRunning, To: taskstate.StepSucceeded,
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatalf("finish prepare step: %v", err)
|
||||||
|
}
|
||||||
|
// Terminal, not left running: the attempt rail reads the task's own
|
||||||
|
// record for "is this still happening" (inFlight), and a run still
|
||||||
|
// marked running would report the attempt "running" regardless of its
|
||||||
|
// finished step, rather than the "ok" a completed run's own stages earn.
|
||||||
|
if err := st.Transition(t.Context(), seeded.ID, taskstate.Running, taskstate.Completed, "done"); err != nil {
|
||||||
|
t.Fatalf("complete seeded task: %v", err)
|
||||||
|
}
|
||||||
for _, e := range []events.Event{
|
for _, e := range []events.Event{
|
||||||
{Kind: events.KindStageStart, TaskID: seeded.ID, Attempt: 1, Stage: "prepare", At: seedAt},
|
|
||||||
{Kind: events.KindStageFinish, TaskID: seeded.ID, Attempt: 1, Stage: "prepare", At: seedAt.Add(time.Second), Data: map[string]any{"duration_ms": 1000}},
|
|
||||||
{Kind: events.KindConfigCaptured, TaskID: seeded.ID, Attempt: 1, At: seedAt, Data: map[string]any{
|
{Kind: events.KindConfigCaptured, TaskID: seeded.ID, Attempt: 1, At: seedAt, Data: map[string]any{
|
||||||
"schema": events.ConfigCapturedSchema, "document": map[string]any{"bot_user": "archie"},
|
"schema": events.ConfigCapturedSchema, "document": map[string]any{"bot_user": "archie"},
|
||||||
}},
|
}},
|
||||||
@@ -150,7 +170,7 @@ func TestUIServesDashboardAgainstRemoteContracts(t *testing.T) {
|
|||||||
|
|
||||||
stateTarget, stopState := serveGRPC(t, func(r grpc.ServiceRegistrar) {
|
stateTarget, stopState := serveGRPC(t, func(r grpc.ServiceRegistrar) {
|
||||||
eda := pgstore.EDA(t, nil)
|
eda := pgstore.EDA(t, nil)
|
||||||
staterpc.RegisterServer(r, staterpc.Deps{Tasks: st, Captures: eda, BindingDispatcher: eda, ConfigSnapshots: st, Log: slog.New(slog.DiscardHandler)})
|
staterpc.RegisterServer(r, staterpc.Deps{Tasks: st, Captures: eda, BindingDispatcher: eda, ConfigSnapshots: st, StepReader: st, Log: slog.New(slog.DiscardHandler)})
|
||||||
})
|
})
|
||||||
defer stopState()
|
defer stopState()
|
||||||
chat := &fakeChat{sessions: []gateway.SessionContext{
|
chat := &fakeChat{sessions: []gateway.SessionContext{
|
||||||
|
|||||||
+1165
-894
File diff suppressed because it is too large.
Load diff
@@ -43,6 +43,7 @@ const (
|
|||||||
StateStoreService_StartStep_FullMethodName = "/state.v1.StateStoreService/StartStep"
|
StateStoreService_StartStep_FullMethodName = "/state.v1.StateStoreService/StartStep"
|
||||||
StateStoreService_FinishStep_FullMethodName = "/state.v1.StateStoreService/FinishStep"
|
StateStoreService_FinishStep_FullMethodName = "/state.v1.StateStoreService/FinishStep"
|
||||||
StateStoreService_CancelExecution_FullMethodName = "/state.v1.StateStoreService/CancelExecution"
|
StateStoreService_CancelExecution_FullMethodName = "/state.v1.StateStoreService/CancelExecution"
|
||||||
|
StateStoreService_ListSteps_FullMethodName = "/state.v1.StateStoreService/ListSteps"
|
||||||
StateStoreService_Requeue_FullMethodName = "/state.v1.StateStoreService/Requeue"
|
StateStoreService_Requeue_FullMethodName = "/state.v1.StateStoreService/Requeue"
|
||||||
StateStoreService_ParkTask_FullMethodName = "/state.v1.StateStoreService/ParkTask"
|
StateStoreService_ParkTask_FullMethodName = "/state.v1.StateStoreService/ParkTask"
|
||||||
StateStoreService_RecoverStale_FullMethodName = "/state.v1.StateStoreService/RecoverStale"
|
StateStoreService_RecoverStale_FullMethodName = "/state.v1.StateStoreService/RecoverStale"
|
||||||
@@ -160,6 +161,9 @@ type StateStoreServiceClient interface {
|
|||||||
// task-scoped grant): a cancel is a dashboard, API and dispatch action
|
// task-scoped grant): a cancel is a dashboard, API and dispatch action
|
||||||
// decided by the Authorizer, not a worker call.
|
// decided by the Authorizer, not a worker call.
|
||||||
CancelExecution(ctx context.Context, in *CancelExecutionRequest, opts ...grpc.CallOption) (*CancelExecutionResponse, error)
|
CancelExecution(ctx context.Context, in *CancelExecutionRequest, opts ...grpc.CallOption) (*CancelExecutionResponse, error)
|
||||||
|
// ListSteps is a dashboard/API/dispatch action (Authorizer: read on the
|
||||||
|
// run), not task-scoped-grant callable like StartStep/FinishStep.
|
||||||
|
ListSteps(ctx context.Context, in *ListStepsRequest, opts ...grpc.CallOption) (*ListStepsResponse, error)
|
||||||
Requeue(ctx context.Context, in *RequeueRequest, opts ...grpc.CallOption) (*RequeueResponse, error)
|
Requeue(ctx context.Context, in *RequeueRequest, opts ...grpc.CallOption) (*RequeueResponse, error)
|
||||||
ParkTask(ctx context.Context, in *ParkTaskRequest, opts ...grpc.CallOption) (*ParkTaskResponse, error)
|
ParkTask(ctx context.Context, in *ParkTaskRequest, opts ...grpc.CallOption) (*ParkTaskResponse, error)
|
||||||
RecoverStale(ctx context.Context, in *RecoverStaleRequest, opts ...grpc.CallOption) (*RecoverStaleResponse, error)
|
RecoverStale(ctx context.Context, in *RecoverStaleRequest, opts ...grpc.CallOption) (*RecoverStaleResponse, error)
|
||||||
@@ -533,6 +537,16 @@ func (c *stateStoreServiceClient) CancelExecution(ctx context.Context, in *Cance
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *stateStoreServiceClient) ListSteps(ctx context.Context, in *ListStepsRequest, opts ...grpc.CallOption) (*ListStepsResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(ListStepsResponse)
|
||||||
|
err := c.cc.Invoke(ctx, StateStoreService_ListSteps_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *stateStoreServiceClient) Requeue(ctx context.Context, in *RequeueRequest, opts ...grpc.CallOption) (*RequeueResponse, error) {
|
func (c *stateStoreServiceClient) Requeue(ctx context.Context, in *RequeueRequest, opts ...grpc.CallOption) (*RequeueResponse, error) {
|
||||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
out := new(RequeueResponse)
|
out := new(RequeueResponse)
|
||||||
@@ -1278,6 +1292,9 @@ type StateStoreServiceServer interface {
|
|||||||
// task-scoped grant): a cancel is a dashboard, API and dispatch action
|
// task-scoped grant): a cancel is a dashboard, API and dispatch action
|
||||||
// decided by the Authorizer, not a worker call.
|
// decided by the Authorizer, not a worker call.
|
||||||
CancelExecution(context.Context, *CancelExecutionRequest) (*CancelExecutionResponse, error)
|
CancelExecution(context.Context, *CancelExecutionRequest) (*CancelExecutionResponse, error)
|
||||||
|
// ListSteps is a dashboard/API/dispatch action (Authorizer: read on the
|
||||||
|
// run), not task-scoped-grant callable like StartStep/FinishStep.
|
||||||
|
ListSteps(context.Context, *ListStepsRequest) (*ListStepsResponse, error)
|
||||||
Requeue(context.Context, *RequeueRequest) (*RequeueResponse, error)
|
Requeue(context.Context, *RequeueRequest) (*RequeueResponse, error)
|
||||||
ParkTask(context.Context, *ParkTaskRequest) (*ParkTaskResponse, error)
|
ParkTask(context.Context, *ParkTaskRequest) (*ParkTaskResponse, error)
|
||||||
RecoverStale(context.Context, *RecoverStaleRequest) (*RecoverStaleResponse, error)
|
RecoverStale(context.Context, *RecoverStaleRequest) (*RecoverStaleResponse, error)
|
||||||
@@ -1483,6 +1500,9 @@ func (UnimplementedStateStoreServiceServer) FinishStep(context.Context, *FinishS
|
|||||||
func (UnimplementedStateStoreServiceServer) CancelExecution(context.Context, *CancelExecutionRequest) (*CancelExecutionResponse, error) {
|
func (UnimplementedStateStoreServiceServer) CancelExecution(context.Context, *CancelExecutionRequest) (*CancelExecutionResponse, error) {
|
||||||
return nil, status.Error(codes.Unimplemented, "method CancelExecution not implemented")
|
return nil, status.Error(codes.Unimplemented, "method CancelExecution not implemented")
|
||||||
}
|
}
|
||||||
|
func (UnimplementedStateStoreServiceServer) ListSteps(context.Context, *ListStepsRequest) (*ListStepsResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method ListSteps not implemented")
|
||||||
|
}
|
||||||
func (UnimplementedStateStoreServiceServer) Requeue(context.Context, *RequeueRequest) (*RequeueResponse, error) {
|
func (UnimplementedStateStoreServiceServer) Requeue(context.Context, *RequeueRequest) (*RequeueResponse, error) {
|
||||||
return nil, status.Error(codes.Unimplemented, "method Requeue not implemented")
|
return nil, status.Error(codes.Unimplemented, "method Requeue not implemented")
|
||||||
}
|
}
|
||||||
@@ -2137,6 +2157,24 @@ func _StateStoreService_CancelExecution_Handler(srv interface{}, ctx context.Con
|
|||||||
return interceptor(ctx, in, info, handler)
|
return interceptor(ctx, in, info, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _StateStoreService_ListSteps_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(ListStepsRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(StateStoreServiceServer).ListSteps(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: StateStoreService_ListSteps_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(StateStoreServiceServer).ListSteps(ctx, req.(*ListStepsRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
func _StateStoreService_Requeue_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
func _StateStoreService_Requeue_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
in := new(RequeueRequest)
|
in := new(RequeueRequest)
|
||||||
if err := dec(in); err != nil {
|
if err := dec(in); err != nil {
|
||||||
@@ -3425,6 +3463,10 @@ var StateStoreService_ServiceDesc = grpc.ServiceDesc{
|
|||||||
MethodName: "CancelExecution",
|
MethodName: "CancelExecution",
|
||||||
Handler: _StateStoreService_CancelExecution_Handler,
|
Handler: _StateStoreService_CancelExecution_Handler,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
MethodName: "ListSteps",
|
||||||
|
Handler: _StateStoreService_ListSteps_Handler,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
MethodName: "Requeue",
|
MethodName: "Requeue",
|
||||||
Handler: _StateStoreService_Requeue_Handler,
|
Handler: _StateStoreService_Requeue_Handler,
|
||||||
|
|||||||
@@ -90,6 +90,15 @@ type ExecutionCanceller interface {
|
|||||||
CancelExecution(ctx context.Context, taskID int64, reason, to string) ([]int64, error)
|
CancelExecution(ctx context.Context, taskID int64, reason, to string) ([]int64, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StepReader lists one execution's recorded steps -- the dashboard run
|
||||||
|
// detail's read (docs/prds/execution-tree-state-machine.md). Separate from
|
||||||
|
// StepRecorder: this is a dashboard/API/dispatch action (Authorizer: read on
|
||||||
|
// the run), never task-scoped-grant callable the way StartStep/FinishStep
|
||||||
|
// are.
|
||||||
|
type StepReader interface {
|
||||||
|
ListSteps(ctx context.Context, executionID int64, attempt int) ([]task.StepExecution, error)
|
||||||
|
}
|
||||||
|
|
||||||
// TaskArchiver removes one terminal task's local record with an optimistic
|
// TaskArchiver removes one terminal task's local record with an optimistic
|
||||||
// status guard. It is separate from the already broad lifecycle contract so
|
// status guard. It is separate from the already broad lifecycle contract so
|
||||||
// consumers that only run tasks do not acquire an operator-only capability.
|
// consumers that only run tasks do not acquire an operator-only capability.
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ var (
|
|||||||
|
|
||||||
// Task is the state needed to authorize and apply an operator action.
|
// Task is the state needed to authorize and apply an operator action.
|
||||||
type Task struct {
|
type Task struct {
|
||||||
ID int64
|
ID int64
|
||||||
Owner, Repo, Identity, Status, Stage, ParkReason string
|
Owner, Repo, Identity, Status, ParkReason string
|
||||||
IssueNumber, RetryCount int
|
IssueNumber, RetryCount int
|
||||||
ForgeBacked bool
|
ForgeBacked bool
|
||||||
// Attempt is the run the operator acted on. It is stamped onto the event
|
// Attempt is the run the operator acted on. It is stamped onto the event
|
||||||
// this action records so an intervention is attributable to the run it
|
// this action records so an intervention is attributable to the run it
|
||||||
// changed course -- without it a retry or a stop is indistinguishable
|
// changed course -- without it a retry or a stop is indistinguishable
|
||||||
@@ -256,7 +256,7 @@ func (s Service) applyRetry(ctx context.Context, task *Task, actor Actor, o outc
|
|||||||
}
|
}
|
||||||
err := s.Store.RetryTask(ctx, task.ID, "parked", "")
|
err := s.Store.RetryTask(ctx, task.ID, "parked", "")
|
||||||
o.event.Kind, o.event.Detail = events.KindTaskRetried, actor.describe("retried")
|
o.event.Kind, o.event.Detail = events.KindTaskRetried, actor.describe("retried")
|
||||||
o.event.Data = map[string]any{"retry_count": task.RetryCount + 1, "previous_stage": task.Stage, "previous_reason": task.ParkReason}
|
o.event.Data = map[string]any{"retry_count": task.RetryCount + 1, "previous_reason": task.ParkReason}
|
||||||
return o, err
|
return o, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -161,8 +161,9 @@ func captureTaskContext(t *testing.T, trees Trees, store Store) *TaskContext {
|
|||||||
return &TaskContext{
|
return &TaskContext{
|
||||||
Task: &Task{
|
Task: &Task{
|
||||||
ID: 11, Attempt: 2, Owner: "acme", Repo: "widget", IssueNumber: 7,
|
ID: 11, Attempt: 2, Owner: "acme", Repo: "widget", IssueNumber: 7,
|
||||||
Stage: "commit-push", Branch: "feat/7-widget",
|
Branch: "feat/7-widget",
|
||||||
},
|
},
|
||||||
|
Stage: "commit-push",
|
||||||
Repo: config.Repo{Owner: "acme", Name: "widget", Base: "main"},
|
Repo: config.Repo{Owner: "acme", Name: "widget", Base: "main"},
|
||||||
Trees: trees,
|
Trees: trees,
|
||||||
Store: store,
|
Store: store,
|
||||||
@@ -278,7 +279,7 @@ func TestStageCommitCapturesTheChangedFiles(t *testing.T) {
|
|||||||
trees := &capturingTrees{commitAllChanged: true, stats: sampleStats()}
|
trees := &capturingTrees{commitAllChanged: true, stats: sampleStats()}
|
||||||
store := &recordingStore{}
|
store := &recordingStore{}
|
||||||
tc := captureTaskContext(t, trees, store)
|
tc := captureTaskContext(t, trees, store)
|
||||||
tc.Task.Stage = "commit-repro"
|
tc.Stage = "commit-repro"
|
||||||
|
|
||||||
if err := StageCommit("commit-repro", func(*TaskContext) string { return "msg" }).Run(context.Background(), tc); err != nil {
|
if err := StageCommit("commit-repro", func(*TaskContext) string { return "msg" }).Run(context.Background(), tc); err != nil {
|
||||||
t.Fatalf("StageCommit.Run() = %v, want nil", err)
|
t.Fatalf("StageCommit.Run() = %v, want nil", err)
|
||||||
@@ -430,7 +431,7 @@ func TestOpenPRCapturesThePullRequestNumber(t *testing.T) {
|
|||||||
forgeClient := &fakeForge{}
|
forgeClient := &fakeForge{}
|
||||||
tc := captureTaskContext(t, trees, store)
|
tc := captureTaskContext(t, trees, store)
|
||||||
tc.Forge = forgeClient
|
tc.Forge = forgeClient
|
||||||
tc.Task.Stage = "open-pr"
|
tc.Stage = "open-pr"
|
||||||
tc.Task.Title = "widget fails"
|
tc.Task.Title = "widget fails"
|
||||||
|
|
||||||
if err := OpenPR(context.Background(), tc, "body"); err != nil {
|
if err := OpenPR(context.Background(), tc, "body"); err != nil {
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ func (tc *TaskContext) captureChanges(ctx context.Context, after string) task.Ch
|
|||||||
// Durable, never bus-only: the worktree this was measured from is gone by
|
// Durable, never bus-only: the worktree this was measured from is gone by
|
||||||
// the time anyone reads it, so a capture that only reached the live feed
|
// the time anyone reads it, so a capture that only reached the live feed
|
||||||
// would be lost with the process.
|
// would be lost with the process.
|
||||||
if err := tc.EmitDurable(ctx, events.KindChangesCaptured, tc.Task.Stage, "", changeCaptureData(tc, after, stats)); err != nil {
|
if err := tc.EmitDurable(ctx, events.KindChangesCaptured, tc.Stage, "", changeCaptureData(tc, after, stats)); err != nil {
|
||||||
tc.Log.Warn("change capture not persisted", "captured_after", after, "err", err)
|
tc.Log.Warn("change capture not persisted", "captured_after", after, "err", err)
|
||||||
}
|
}
|
||||||
return stats
|
return stats
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package task
|
package task
|
||||||
|
|
||||||
import "github.com/samcharles93/archie-core/internal/taskstate"
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||||
|
)
|
||||||
|
|
||||||
// The step-execution vocabulary of docs/prds/execution-tree-state-machine.md:
|
// 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
|
// one stage run, or one agent or workflow.call step an execution's tree
|
||||||
@@ -57,3 +61,22 @@ type StepFinish struct {
|
|||||||
// the agent runtime records its own calls' usage.
|
// the agent runtime records its own calls' usage.
|
||||||
TokensUsed int64
|
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
|
||||||
|
}
|
||||||
@@ -53,7 +53,6 @@ type Task struct {
|
|||||||
WorkflowDefinitionVersion int64 `json:"workflow_definition_version"`
|
WorkflowDefinitionVersion int64 `json:"workflow_definition_version"`
|
||||||
WorkflowDefinitionDigest string `json:"workflow_definition_digest"`
|
WorkflowDefinitionDigest string `json:"workflow_definition_digest"`
|
||||||
WorkflowDefinitionYAML string `json:"workflow_definition_yaml"`
|
WorkflowDefinitionYAML string `json:"workflow_definition_yaml"`
|
||||||
Stage string `json:"stage"`
|
|
||||||
Branch string `json:"branch"`
|
Branch string `json:"branch"`
|
||||||
Plan string `json:"plan"`
|
Plan string `json:"plan"`
|
||||||
Notes string `json:"notes"`
|
Notes string `json:"notes"`
|
||||||
|
|||||||
@@ -109,6 +109,11 @@ type TaskContext struct {
|
|||||||
// Dir/Branch are set by the prepare step.
|
// Dir/Branch are set by the prepare step.
|
||||||
Dir string
|
Dir string
|
||||||
Branch string
|
Branch string
|
||||||
|
// Stage is the name of the stage currently running, kept here (not
|
||||||
|
// persisted on Task -- docs/prds/execution-tree-state-machine.md drops
|
||||||
|
// tasks.stage in favour of the durable StepExecution record StartStep
|
||||||
|
// writes) purely so park/finish can tag the event they emit with it.
|
||||||
|
Stage string
|
||||||
// BuildSummary is the builder agent's finish summary -- the PR body.
|
// BuildSummary is the builder agent's finish summary -- the PR body.
|
||||||
BuildSummary string
|
BuildSummary string
|
||||||
// BuildNoChanges is set when the builder returned StatusPassed but
|
// BuildNoChanges is set when the builder returned StatusPassed but
|
||||||
@@ -302,7 +307,7 @@ func Run(ctx context.Context, wf Workflow, tc *TaskContext) {
|
|||||||
log := tc.Log.With("workflow", wf.Name, "repo", tc.Repo.FullName(), "issue", t.IssueNumber)
|
log := tc.Log.With("workflow", wf.Name, "repo", tc.Repo.FullName(), "issue", t.IssueNumber)
|
||||||
|
|
||||||
for _, stage := range wf.Stages {
|
for _, stage := range wf.Stages {
|
||||||
t.Stage = stage.Name
|
tc.Stage = stage.Name
|
||||||
_ = tc.Store.Update(ctx, t)
|
_ = tc.Store.Update(ctx, t)
|
||||||
// Every stage is a StepExecution (docs/prds/execution-tree-state-machine.md):
|
// Every stage is a StepExecution (docs/prds/execution-tree-state-machine.md):
|
||||||
// the store records pending -> running and writes the stage_start event
|
// the store records pending -> running and writes the stage_start event
|
||||||
@@ -407,7 +412,7 @@ func finish(ctx context.Context, tc *TaskContext, log *slog.Logger) {
|
|||||||
}
|
}
|
||||||
_ = tc.Store.Update(ctx, t)
|
_ = tc.Store.Update(ctx, t)
|
||||||
_ = tc.Store.Transition(ctx, t.ID, StatusRunning, tc.Outcome.Status, tc.Outcome.Detail)
|
_ = tc.Store.Transition(ctx, t.ID, StatusRunning, tc.Outcome.Status, tc.Outcome.Detail)
|
||||||
tc.Emit(events.KindOutcome, t.Stage, tc.Outcome.Detail, map[string]any{"status": tc.Outcome.Status})
|
tc.Emit(events.KindOutcome, tc.Stage, tc.Outcome.Detail, map[string]any{"status": tc.Outcome.Status})
|
||||||
log.Info("workflow finished", "status", tc.Outcome.Status)
|
log.Info("workflow finished", "status", tc.Outcome.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,12 +421,12 @@ func park(ctx context.Context, tc *TaskContext, reason string) {
|
|||||||
t.ParkReason = reason
|
t.ParkReason = reason
|
||||||
_ = tc.Store.Update(ctx, t)
|
_ = tc.Store.Update(ctx, t)
|
||||||
_ = tc.Store.Transition(ctx, t.ID, StatusRunning, StatusParked, reason)
|
_ = tc.Store.Transition(ctx, t.ID, StatusRunning, StatusParked, reason)
|
||||||
tc.Emit(events.KindParked, t.Stage, reason, nil)
|
tc.Emit(events.KindParked, tc.Stage, reason, nil)
|
||||||
// The run's own log is the surface an operator downloads to answer "why did
|
// The run's own log is the surface an operator downloads to answer "why did
|
||||||
// this park?", and the event above lands on the timeline, which the log
|
// this park?", and the event above lands on the timeline, which the log
|
||||||
// never carries. This is the one place a park's reason is final, so it is
|
// never carries. This is the one place a park's reason is final, so it is
|
||||||
// the one place that records it -- the stage names itself in the reason.
|
// the one place that records it -- the stage names itself in the reason.
|
||||||
tc.Log.Error("task parked", "stage", t.Stage, "reason", reason)
|
tc.Log.Error("task parked", "stage", tc.Stage, "reason", reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
func clip(s string, n int) string {
|
func clip(s string, n int) string {
|
||||||
|
|||||||
@@ -712,8 +712,8 @@ func formatTasks(tasks []ChatTaskSummary, now time.Time) string {
|
|||||||
}
|
}
|
||||||
fmt.Fprintf(&b, "%s #%d %s%s", icon, t.ID, t.Title, reportLineBreak)
|
fmt.Fprintf(&b, "%s #%d %s%s", icon, t.ID, t.Title, reportLineBreak)
|
||||||
fmt.Fprintf(&b, " %s", label)
|
fmt.Fprintf(&b, " %s", label)
|
||||||
if stage := workflowStage(t.Workflow, t.Stage); stage != "" {
|
if t.Workflow != "" {
|
||||||
fmt.Fprintf(&b, " · %s", stage)
|
fmt.Fprintf(&b, " · %s", t.Workflow)
|
||||||
}
|
}
|
||||||
if t.Attempt > 1 {
|
if t.Attempt > 1 {
|
||||||
fmt.Fprintf(&b, " · attempt %d", t.Attempt)
|
fmt.Fprintf(&b, " · attempt %d", t.Attempt)
|
||||||
@@ -729,22 +729,6 @@ func formatTasks(tasks []ChatTaskSummary, now time.Time) string {
|
|||||||
return strings.TrimSpace(b.String())
|
return strings.TrimSpace(b.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
// workflowStage joins a task's workflow and stage for display, degrading
|
|
||||||
// gracefully when either is unknown (e.g. a task that hasn't started its
|
|
||||||
// first stage yet).
|
|
||||||
func workflowStage(workflow, stage string) string {
|
|
||||||
switch {
|
|
||||||
case workflow == "" && stage == "":
|
|
||||||
return ""
|
|
||||||
case stage == "":
|
|
||||||
return workflow
|
|
||||||
case workflow == "":
|
|
||||||
return stage
|
|
||||||
default:
|
|
||||||
return workflow + "/" + stage
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type taskStateDisplay struct {
|
type taskStateDisplay struct {
|
||||||
icon string
|
icon string
|
||||||
label string
|
label string
|
||||||
|
|||||||
@@ -250,11 +250,11 @@ func TestFormatTasks(t *testing.T) {
|
|||||||
want string
|
want string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "running task shows workflow/stage and age",
|
name: "running task shows workflow and age",
|
||||||
tasks: []ChatTaskSummary{
|
tasks: []ChatTaskSummary{
|
||||||
{ID: 42, Title: "Fix login bug", Status: taskstate.Running, Workflow: "tdd", Stage: "implement", UpdatedAt: now.Add(-3 * time.Minute)},
|
{ID: 42, Title: "Fix login bug", Status: taskstate.Running, Workflow: "tdd", UpdatedAt: now.Add(-3 * time.Minute)},
|
||||||
},
|
},
|
||||||
want: "🗂 Archie tasks\n\n▶ #42 Fix login bug \n Running · tdd/implement · updated 3m ago",
|
want: "🗂 Archie tasks\n\n▶ #42 Fix login bug \n Running · tdd · updated 3m ago",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// The criterion this command was built for: a bare "Running: 1"
|
// The criterion this command was built for: a bare "Running: 1"
|
||||||
@@ -262,10 +262,10 @@ func TestFormatTasks(t *testing.T) {
|
|||||||
// failure loop, and each task's own age is what tells them apart.
|
// failure loop, and each task's own age is what tells them apart.
|
||||||
name: "a stuck running task does not read like one making progress",
|
name: "a stuck running task does not read like one making progress",
|
||||||
tasks: []ChatTaskSummary{
|
tasks: []ChatTaskSummary{
|
||||||
{ID: 5, Title: "Wedged", Status: taskstate.Running, Workflow: "tdd", Stage: "implement", UpdatedAt: now.Add(-47 * time.Minute)},
|
{ID: 5, Title: "Wedged", Status: taskstate.Running, Workflow: "tdd", UpdatedAt: now.Add(-47 * time.Minute)},
|
||||||
{ID: 6, Title: "Working", Status: taskstate.Running, Workflow: "tdd", Stage: "implement", UpdatedAt: now.Add(-20 * time.Second)},
|
{ID: 6, Title: "Working", Status: taskstate.Running, Workflow: "tdd", UpdatedAt: now.Add(-20 * time.Second)},
|
||||||
},
|
},
|
||||||
want: "🗂 Archie tasks\n\n▶ #5 Wedged \n Running · tdd/implement · updated 47m ago\n\n▶ #6 Working \n Running · tdd/implement · updated just now",
|
want: "🗂 Archie tasks\n\n▶ #5 Wedged \n Running · tdd · updated 47m ago\n\n▶ #6 Working \n Running · tdd · updated just now",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "parked task shows its reason",
|
name: "parked task shows its reason",
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ type ChatTaskSummary struct {
|
|||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Workflow string `json:"workflow,omitempty"`
|
Workflow string `json:"workflow,omitempty"`
|
||||||
Stage string `json:"stage,omitempty"`
|
|
||||||
PRNumber int `json:"pr_number,omitempty"`
|
PRNumber int `json:"pr_number,omitempty"`
|
||||||
// Attempt is the task's current retry attempt. 0 or 1 means it has never
|
// Attempt is the task's current retry attempt. 0 or 1 means it has never
|
||||||
// been retried; the /tasks command only surfaces this once it is
|
// been retried; the /tasks command only surfaces this once it is
|
||||||
|
|||||||
@@ -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
|
const enqueueCallTask = `-- name: EnqueueCallTask :one
|
||||||
WITH caller AS (
|
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)
|
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
|
SELECT
|
||||||
@@ -41,7 +41,7 @@ SELECT
|
|||||||
caller.id, caller.call_depth + 1
|
caller.id, caller.call_depth + 1
|
||||||
FROM caller
|
FROM caller
|
||||||
WHERE caller.status = 'running' AND caller.call_depth + 1 <= $7::int
|
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 {
|
type EnqueueCallTaskParams struct {
|
||||||
@@ -84,7 +84,6 @@ func (q *Queries) EnqueueCallTask(ctx context.Context, arg EnqueueCallTaskParams
|
|||||||
&i.Labels,
|
&i.Labels,
|
||||||
&i.Status,
|
&i.Status,
|
||||||
&i.Workflow,
|
&i.Workflow,
|
||||||
&i.Stage,
|
|
||||||
&i.Branch,
|
&i.Branch,
|
||||||
&i.Plan,
|
&i.Plan,
|
||||||
&i.Notes,
|
&i.Notes,
|
||||||
|
|||||||
@@ -348,7 +348,6 @@ type Task struct {
|
|||||||
Labels string
|
Labels string
|
||||||
Status string
|
Status string
|
||||||
Workflow string
|
Workflow string
|
||||||
Stage string
|
|
||||||
Branch string
|
Branch string
|
||||||
Plan string
|
Plan string
|
||||||
Notes string
|
Notes string
|
||||||
|
|||||||
@@ -157,6 +157,69 @@ func (q *Queries) InterruptAttemptSteps(ctx context.Context, arg InterruptAttemp
|
|||||||
return items, nil
|
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
|
const lockExecutionForStep = `-- name: LockExecutionForStep :one
|
||||||
|
|
||||||
SELECT id, status, org_id, workspace_id, owner, repo, issue_number, workflow, attempt
|
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
|
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'
|
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
|
const claimByIssue = `-- name: ClaimByIssue :one
|
||||||
UPDATE tasks SET status = 'running', attempt = attempt + 1, updated_at = now()
|
UPDATE tasks SET status = 'running', attempt = attempt + 1, updated_at = now()
|
||||||
WHERE owner = $1 AND repo = $2 AND issue_number = $3 AND status = 'queued'
|
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 {
|
type ClaimByIssueParams struct {
|
||||||
@@ -70,7 +70,6 @@ func (q *Queries) ClaimByIssue(ctx context.Context, arg ClaimByIssueParams) (Tas
|
|||||||
&i.Labels,
|
&i.Labels,
|
||||||
&i.Status,
|
&i.Status,
|
||||||
&i.Workflow,
|
&i.Workflow,
|
||||||
&i.Stage,
|
|
||||||
&i.Branch,
|
&i.Branch,
|
||||||
&i.Plan,
|
&i.Plan,
|
||||||
&i.Notes,
|
&i.Notes,
|
||||||
@@ -113,7 +112,7 @@ WHERE id = (
|
|||||||
FOR UPDATE SKIP LOCKED
|
FOR UPDATE SKIP LOCKED
|
||||||
LIMIT 1
|
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
|
// 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.Labels,
|
||||||
&i.Status,
|
&i.Status,
|
||||||
&i.Workflow,
|
&i.Workflow,
|
||||||
&i.Stage,
|
|
||||||
&i.Branch,
|
&i.Branch,
|
||||||
&i.Plan,
|
&i.Plan,
|
||||||
&i.Notes,
|
&i.Notes,
|
||||||
@@ -270,7 +268,7 @@ VALUES (
|
|||||||
'default'
|
'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 {
|
type InsertChatTaskParams struct {
|
||||||
@@ -308,7 +306,6 @@ func (q *Queries) InsertChatTask(ctx context.Context, arg InsertChatTaskParams)
|
|||||||
&i.Labels,
|
&i.Labels,
|
||||||
&i.Status,
|
&i.Status,
|
||||||
&i.Workflow,
|
&i.Workflow,
|
||||||
&i.Stage,
|
|
||||||
&i.Branch,
|
&i.Branch,
|
||||||
&i.Plan,
|
&i.Plan,
|
||||||
&i.Notes,
|
&i.Notes,
|
||||||
@@ -415,7 +412,7 @@ func (q *Queries) ListOpenPRs(ctx context.Context) ([]ListOpenPRsRow, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const listTaskSummaries = `-- name: ListTaskSummaries :many
|
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,
|
pr_number, tokens_used, iterations, attempt, park_reason, retry_count,
|
||||||
created_at, updated_at, plan, source, identity, binding_id, binding_version
|
created_at, updated_at, plan, source, identity, binding_id, binding_version
|
||||||
FROM tasks ORDER BY updated_at DESC LIMIT $1
|
FROM tasks ORDER BY updated_at DESC LIMIT $1
|
||||||
@@ -429,7 +426,6 @@ type ListTaskSummariesRow struct {
|
|||||||
Title string
|
Title string
|
||||||
Status string
|
Status string
|
||||||
Workflow string
|
Workflow string
|
||||||
Stage string
|
|
||||||
PrNumber int64
|
PrNumber int64
|
||||||
TokensUsed int64
|
TokensUsed int64
|
||||||
Iterations int64
|
Iterations int64
|
||||||
@@ -465,7 +461,6 @@ func (q *Queries) ListTaskSummaries(ctx context.Context, limit int32) ([]ListTas
|
|||||||
&i.Title,
|
&i.Title,
|
||||||
&i.Status,
|
&i.Status,
|
||||||
&i.Workflow,
|
&i.Workflow,
|
||||||
&i.Stage,
|
|
||||||
&i.PrNumber,
|
&i.PrNumber,
|
||||||
&i.TokensUsed,
|
&i.TokensUsed,
|
||||||
&i.Iterations,
|
&i.Iterations,
|
||||||
@@ -545,7 +540,7 @@ func (q *Queries) RecoverStaleTasks(ctx context.Context) (int64, error) {
|
|||||||
const requeueTask = `-- name: RequeueTask :execrows
|
const requeueTask = `-- name: RequeueTask :execrows
|
||||||
UPDATE tasks SET status = 'queued',
|
UPDATE tasks SET status = 'queued',
|
||||||
workflow = CASE WHEN $1::text = '' THEN workflow ELSE $1::text END,
|
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
|
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
|
const retryTask = `-- name: RetryTask :execrows
|
||||||
UPDATE tasks SET status = 'queued', retry_count = retry_count + 1,
|
UPDATE tasks SET status = 'queued', retry_count = retry_count + 1,
|
||||||
workflow = CASE WHEN $1::text = '' THEN workflow ELSE $1::text END,
|
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
|
WHERE id = $2 AND status = $3
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -625,7 +620,7 @@ func (q *Queries) StampTaskBinding(ctx context.Context, arg StampTaskBindingPara
|
|||||||
}
|
}
|
||||||
|
|
||||||
const taskByID = `-- name: TaskByID :one
|
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) {
|
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.Labels,
|
||||||
&i.Status,
|
&i.Status,
|
||||||
&i.Workflow,
|
&i.Workflow,
|
||||||
&i.Stage,
|
|
||||||
&i.Branch,
|
&i.Branch,
|
||||||
&i.Plan,
|
&i.Plan,
|
||||||
&i.Notes,
|
&i.Notes,
|
||||||
@@ -675,7 +669,7 @@ func (q *Queries) TaskByID(ctx context.Context, id int64) (Task, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const taskByIssue = `-- name: TaskByIssue :one
|
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 {
|
type TaskByIssueParams struct {
|
||||||
@@ -697,7 +691,6 @@ func (q *Queries) TaskByIssue(ctx context.Context, arg TaskByIssueParams) (Task,
|
|||||||
&i.Labels,
|
&i.Labels,
|
||||||
&i.Status,
|
&i.Status,
|
||||||
&i.Workflow,
|
&i.Workflow,
|
||||||
&i.Stage,
|
|
||||||
&i.Branch,
|
&i.Branch,
|
||||||
&i.Plan,
|
&i.Plan,
|
||||||
&i.Notes,
|
&i.Notes,
|
||||||
@@ -731,7 +724,7 @@ func (q *Queries) TaskByIssue(ctx context.Context, arg TaskByIssueParams) (Task,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const taskByPR = `-- name: TaskByPR :one
|
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 {
|
type TaskByPRParams struct {
|
||||||
@@ -762,7 +755,6 @@ func (q *Queries) TaskByPR(ctx context.Context, arg TaskByPRParams) (Task, error
|
|||||||
&i.Labels,
|
&i.Labels,
|
||||||
&i.Status,
|
&i.Status,
|
||||||
&i.Workflow,
|
&i.Workflow,
|
||||||
&i.Stage,
|
|
||||||
&i.Branch,
|
&i.Branch,
|
||||||
&i.Plan,
|
&i.Plan,
|
||||||
&i.Notes,
|
&i.Notes,
|
||||||
@@ -847,11 +839,11 @@ func (q *Queries) UpdateReviewPayloadTask(ctx context.Context, arg UpdateReviewP
|
|||||||
}
|
}
|
||||||
|
|
||||||
const updateTask = `-- name: UpdateTask :exec
|
const updateTask = `-- name: UpdateTask :exec
|
||||||
UPDATE tasks SET workflow = $2, stage = $3, branch = $4, plan = $5, notes = $6,
|
UPDATE tasks SET workflow = $2, branch = $3, plan = $4, notes = $5,
|
||||||
pr_number = $7, tokens_used = $8, iterations = $9, park_reason = $10,
|
pr_number = $6, tokens_used = $7, iterations = $8, park_reason = $9,
|
||||||
watch_comment_id = $11, retry_count = $12, remediation_rounds = $13,
|
watch_comment_id = $10, retry_count = $11, remediation_rounds = $12,
|
||||||
review_payload = $14, workflow_definition_version = $15,
|
review_payload = $13, workflow_definition_version = $14,
|
||||||
workflow_definition_digest = $16, workflow_definition_yaml = $17,
|
workflow_definition_digest = $15, workflow_definition_yaml = $16,
|
||||||
updated_at = now()
|
updated_at = now()
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`
|
`
|
||||||
@@ -859,7 +851,6 @@ WHERE id = $1
|
|||||||
type UpdateTaskParams struct {
|
type UpdateTaskParams struct {
|
||||||
ID int64
|
ID int64
|
||||||
Workflow string
|
Workflow string
|
||||||
Stage string
|
|
||||||
Branch string
|
Branch string
|
||||||
Plan string
|
Plan string
|
||||||
Notes string
|
Notes string
|
||||||
@@ -880,7 +871,6 @@ func (q *Queries) UpdateTask(ctx context.Context, arg UpdateTaskParams) error {
|
|||||||
_, err := q.db.Exec(ctx, updateTask,
|
_, err := q.db.Exec(ctx, updateTask,
|
||||||
arg.ID,
|
arg.ID,
|
||||||
arg.Workflow,
|
arg.Workflow,
|
||||||
arg.Stage,
|
|
||||||
arg.Branch,
|
arg.Branch,
|
||||||
arg.Plan,
|
arg.Plan,
|
||||||
arg.Notes,
|
arg.Notes,
|
||||||
|
|||||||
@@ -61,3 +61,12 @@ UPDATE step_executions
|
|||||||
SET status = 'interrupted', finished_at = now()
|
SET status = 'interrupted', finished_at = now()
|
||||||
WHERE execution_id = $1 AND attempt = $2 AND status = 'running'
|
WHERE execution_id = $1 AND attempt = $2 AND status = 'running'
|
||||||
RETURNING id, name;
|
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 dashboard's list. This projection is deliberately narrow: Plan gates
|
||||||
-- the "Decision required" panel and Source labels the row, and widening it
|
-- the "Decision required" panel and Source labels the row, and widening it
|
||||||
-- back would send rows without them.
|
-- 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,
|
pr_number, tokens_used, iterations, attempt, park_reason, retry_count,
|
||||||
created_at, updated_at, plan, source, identity, binding_id, binding_version
|
created_at, updated_at, plan, source, identity, binding_id, binding_version
|
||||||
FROM tasks ORDER BY updated_at DESC LIMIT $1;
|
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;
|
UPDATE tasks SET binding_id = $2, binding_version = $3, inputs = $4 WHERE id = $1;
|
||||||
|
|
||||||
-- name: UpdateTask :exec
|
-- name: UpdateTask :exec
|
||||||
UPDATE tasks SET workflow = $2, stage = $3, branch = $4, plan = $5, notes = $6,
|
UPDATE tasks SET workflow = $2, branch = $3, plan = $4, notes = $5,
|
||||||
pr_number = $7, tokens_used = $8, iterations = $9, park_reason = $10,
|
pr_number = $6, tokens_used = $7, iterations = $8, park_reason = $9,
|
||||||
watch_comment_id = $11, retry_count = $12, remediation_rounds = $13,
|
watch_comment_id = $10, retry_count = $11, remediation_rounds = $12,
|
||||||
review_payload = $14, workflow_definition_version = $15,
|
review_payload = $13, workflow_definition_version = $14,
|
||||||
workflow_definition_digest = $16, workflow_definition_yaml = $17,
|
workflow_definition_digest = $15, workflow_definition_yaml = $16,
|
||||||
updated_at = now()
|
updated_at = now()
|
||||||
WHERE id = $1;
|
WHERE id = $1;
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ WHERE owner = $1 AND repo = $2 AND issue_number = $3 AND status = 'queued'
|
|||||||
RETURNING *;
|
RETURNING *;
|
||||||
|
|
||||||
-- name: BeginRemediationTask :execrows
|
-- 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';
|
WHERE id = $1 AND status = 'pr_open';
|
||||||
|
|
||||||
-- name: UpdateReviewPayloadTask :execrows
|
-- name: UpdateReviewPayloadTask :execrows
|
||||||
@@ -143,13 +143,13 @@ WHERE id = $1 AND status = 'pr_open';
|
|||||||
-- name: RequeueTask :execrows
|
-- name: RequeueTask :execrows
|
||||||
UPDATE tasks SET status = 'queued',
|
UPDATE tasks SET status = 'queued',
|
||||||
workflow = CASE WHEN @workflow::text = '' THEN workflow ELSE @workflow::text END,
|
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;
|
WHERE id = @id AND status = @from_status;
|
||||||
|
|
||||||
-- name: RetryTask :execrows
|
-- name: RetryTask :execrows
|
||||||
UPDATE tasks SET status = 'queued', retry_count = retry_count + 1,
|
UPDATE tasks SET status = 'queued', retry_count = retry_count + 1,
|
||||||
workflow = CASE WHEN @workflow::text = '' THEN workflow ELSE @workflow::text END,
|
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;
|
WHERE id = @id AND status = @from_status;
|
||||||
|
|
||||||
-- name: ArchiveTaskDelete :execrows
|
-- name: ArchiveTaskDelete :execrows
|
||||||
|
|||||||
@@ -224,6 +224,41 @@ func stepEventData(to taskstate.StepStatus, durationMS int64, detail string) map
|
|||||||
return data
|
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
|
// 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
|
// 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.
|
// 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
|
// 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.
|
// PRD's named wire behaviour: errors.Is matches on the client too.
|
||||||
func TestFinishStepOffTablePairIsIllegalOverTheTable(t *testing.T) {
|
func TestFinishStepOffTablePairIsIllegalOverTheTable(t *testing.T) {
|
||||||
|
|||||||
@@ -93,7 +93,6 @@ func taskFromRow(t postgresdb.Task) *workflow.Task {
|
|||||||
WorkflowDefinitionVersion: t.WorkflowDefinitionVersion,
|
WorkflowDefinitionVersion: t.WorkflowDefinitionVersion,
|
||||||
WorkflowDefinitionDigest: t.WorkflowDefinitionDigest,
|
WorkflowDefinitionDigest: t.WorkflowDefinitionDigest,
|
||||||
WorkflowDefinitionYAML: t.WorkflowDefinitionYaml,
|
WorkflowDefinitionYAML: t.WorkflowDefinitionYaml,
|
||||||
Stage: t.Stage,
|
|
||||||
Branch: t.Branch,
|
Branch: t.Branch,
|
||||||
Plan: t.Plan,
|
Plan: t.Plan,
|
||||||
Notes: t.Notes,
|
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{
|
return s.queries().UpdateTask(ctx, postgresdb.UpdateTaskParams{
|
||||||
ID: t.ID,
|
ID: t.ID,
|
||||||
Workflow: t.Workflow,
|
Workflow: t.Workflow,
|
||||||
Stage: t.Stage,
|
|
||||||
Branch: t.Branch,
|
Branch: t.Branch,
|
||||||
Plan: t.Plan,
|
Plan: t.Plan,
|
||||||
Notes: t.Notes,
|
Notes: t.Notes,
|
||||||
@@ -527,7 +525,7 @@ func (s *Store) Tasks(ctx context.Context, limit int) ([]workflow.Task, error) {
|
|||||||
for _, r := range rows {
|
for _, r := range rows {
|
||||||
tasks = append(tasks, workflow.Task{
|
tasks = append(tasks, workflow.Task{
|
||||||
ID: r.ID, Owner: r.Owner, Repo: r.Repo, IssueNumber: int(r.IssueNumber),
|
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),
|
PRNumber: int(r.PrNumber), TokensUsed: int(r.TokensUsed), Iterations: int(r.Iterations),
|
||||||
Attempt: int(r.Attempt), ParkReason: r.ParkReason, RetryCount: int(r.RetryCount),
|
Attempt: int(r.Attempt), ParkReason: r.ParkReason, RetryCount: int(r.RetryCount),
|
||||||
CreatedAt: r.CreatedAt, UpdatedAt: r.UpdatedAt, Plan: r.Plan, Source: r.Source,
|
CreatedAt: r.CreatedAt, UpdatedAt: r.UpdatedAt, Plan: r.Plan, Source: r.Source,
|
||||||
|
|||||||
@@ -155,6 +155,18 @@ func (c *Client) FinishStep(ctx context.Context, s task.StepFinish) (events.Even
|
|||||||
return event, nil
|
return event, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) ListSteps(ctx context.Context, executionID int64, attempt int) ([]task.StepExecution, error) {
|
||||||
|
r, err := c.client.ListSteps(ctx, &pb.ListStepsRequest{ExecutionId: executionID, Attempt: int64(attempt)})
|
||||||
|
if err != nil {
|
||||||
|
return nil, unmapError(err)
|
||||||
|
}
|
||||||
|
steps := make([]task.StepExecution, len(r.Steps))
|
||||||
|
for i, s := range r.Steps {
|
||||||
|
steps[i] = stepExecutionValue(s)
|
||||||
|
}
|
||||||
|
return steps, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) Update(ctx context.Context, t *task.Task) error {
|
func (c *Client) Update(ctx context.Context, t *task.Task) error {
|
||||||
_, err := c.client.Update(ctx, &pb.UpdateRequest{Task: taskProto(t)})
|
_, err := c.client.Update(ctx, &pb.UpdateRequest{Task: taskProto(t)})
|
||||||
return unmapError(err)
|
return unmapError(err)
|
||||||
|
|||||||
@@ -106,6 +106,11 @@ type Deps struct {
|
|||||||
// an operator action's guarded write over the execution and its steps.
|
// an operator action's guarded write over the execution and its steps.
|
||||||
// Optional: nil answers the RPC with codes.Unavailable.
|
// Optional: nil answers the RPC with codes.Unavailable.
|
||||||
Canceller storecontract.ExecutionCanceller
|
Canceller storecontract.ExecutionCanceller
|
||||||
|
// StepReader lists an execution's recorded steps for the dashboard/API
|
||||||
|
// (docs/prds/execution-tree-state-machine.md): a plain read, never
|
||||||
|
// task-scoped-grant callable. Optional: nil answers ListSteps with
|
||||||
|
// codes.Unavailable.
|
||||||
|
StepReader storecontract.StepReader
|
||||||
// PlaybookDispatcher is the side-effecting-action idempotency ledger
|
// PlaybookDispatcher is the side-effecting-action idempotency ledger
|
||||||
// (docs/prds/eda-playbook-engine.md gap 2). Optional: nil disables the
|
// (docs/prds/eda-playbook-engine.md gap 2). Optional: nil disables the
|
||||||
// two playbook dispatch RPCs with codes.Unavailable.
|
// two playbook dispatch RPCs with codes.Unavailable.
|
||||||
@@ -247,6 +252,17 @@ func (s *server) FinishStep(ctx context.Context, r *pb.FinishStepRequest) (*pb.F
|
|||||||
return &pb.FinishStepResponse{Event: eventProto(event)}, nil
|
return &pb.FinishStepResponse{Event: eventProto(event)}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *server) ListSteps(ctx context.Context, r *pb.ListStepsRequest) (*pb.ListStepsResponse, error) {
|
||||||
|
if s.deps.StepReader == nil {
|
||||||
|
return nil, status.Error(codes.Unavailable, "step reader unavailable")
|
||||||
|
}
|
||||||
|
steps, err := s.deps.StepReader.ListSteps(ctx, r.ExecutionId, int(r.Attempt))
|
||||||
|
if err != nil {
|
||||||
|
return nil, s.logErr("ListSteps", err)
|
||||||
|
}
|
||||||
|
return &pb.ListStepsResponse{Steps: mapValues(steps, stepExecutionProto)}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *server) Update(ctx context.Context, r *pb.UpdateRequest) (*pb.UpdateResponse, error) {
|
func (s *server) Update(ctx context.Context, r *pb.UpdateRequest) (*pb.UpdateResponse, error) {
|
||||||
if r.Task == nil {
|
if r.Task == nil {
|
||||||
return nil, status.Error(codes.InvalidArgument, "task is required")
|
return nil, status.Error(codes.InvalidArgument, "task is required")
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||||
"github.com/samcharles93/archie-core/internal/events"
|
"github.com/samcharles93/archie-core/internal/events"
|
||||||
"github.com/samcharles93/archie-core/internal/logging"
|
"github.com/samcharles93/archie-core/internal/logging"
|
||||||
|
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||||
)
|
)
|
||||||
|
|
||||||
func timestamp(t time.Time) *timestamppb.Timestamp {
|
func timestamp(t time.Time) *timestamppb.Timestamp {
|
||||||
@@ -65,7 +66,7 @@ func taskProto(t *task.Task) *pb.Task { //nolint:dupl // mirror-image field-by-f
|
|||||||
return &pb.Task{
|
return &pb.Task{
|
||||||
Id: t.ID, Owner: t.Owner, Repo: t.Repo, IssueNumber: int64(t.IssueNumber),
|
Id: t.ID, Owner: t.Owner, Repo: t.Repo, IssueNumber: int64(t.IssueNumber),
|
||||||
Title: t.Title, Body: t.Body, Labels: t.Labels, Status: t.Status,
|
Title: t.Title, Body: t.Body, Labels: t.Labels, Status: t.Status,
|
||||||
Workflow: t.Workflow, Stage: t.Stage, Branch: t.Branch, Plan: t.Plan, Notes: t.Notes,
|
Workflow: t.Workflow, Branch: t.Branch, Plan: t.Plan, Notes: t.Notes,
|
||||||
PrNumber: int64(t.PRNumber), TokensUsed: int64(t.TokensUsed), Iterations: int64(t.Iterations),
|
PrNumber: int64(t.PRNumber), TokensUsed: int64(t.TokensUsed), Iterations: int64(t.Iterations),
|
||||||
Attempt: int64(t.Attempt), ParkReason: t.ParkReason, RetryCount: int64(t.RetryCount),
|
Attempt: int64(t.Attempt), ParkReason: t.ParkReason, RetryCount: int64(t.RetryCount),
|
||||||
WatchCommentId: t.WatchCommentID, Source: t.Source, Identity: t.Identity,
|
WatchCommentId: t.WatchCommentID, Source: t.Source, Identity: t.Identity,
|
||||||
@@ -92,7 +93,7 @@ func taskValue(t *pb.Task) *task.Task { //nolint:dupl // see taskProto above
|
|||||||
return &task.Task{
|
return &task.Task{
|
||||||
ID: t.Id, Owner: t.Owner, Repo: t.Repo, IssueNumber: int(t.IssueNumber),
|
ID: t.Id, Owner: t.Owner, Repo: t.Repo, IssueNumber: int(t.IssueNumber),
|
||||||
Title: t.Title, Body: t.Body, Labels: t.Labels, Status: t.Status,
|
Title: t.Title, Body: t.Body, Labels: t.Labels, Status: t.Status,
|
||||||
Workflow: t.Workflow, Stage: t.Stage, Branch: t.Branch, Plan: t.Plan, Notes: t.Notes,
|
Workflow: t.Workflow, Branch: t.Branch, Plan: t.Plan, Notes: t.Notes,
|
||||||
PRNumber: int(t.PrNumber), TokensUsed: int(t.TokensUsed), Iterations: int(t.Iterations),
|
PRNumber: int(t.PrNumber), TokensUsed: int(t.TokensUsed), Iterations: int(t.Iterations),
|
||||||
Attempt: int(t.Attempt), ParkReason: t.ParkReason, RetryCount: int(t.RetryCount),
|
Attempt: int(t.Attempt), ParkReason: t.ParkReason, RetryCount: int(t.RetryCount),
|
||||||
WatchCommentID: t.WatchCommentId, Source: t.Source, Identity: t.Identity,
|
WatchCommentID: t.WatchCommentId, Source: t.Source, Identity: t.Identity,
|
||||||
@@ -306,6 +307,27 @@ func workflowStatValue(w *pb.WorkflowStat) storecontract.WorkflowStat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stepExecutionProto(s task.StepExecution) *pb.StepExecution {
|
||||||
|
return &pb.StepExecution{
|
||||||
|
Id: s.ID, ExecutionId: s.ExecutionID, Attempt: int64(s.Attempt),
|
||||||
|
ParentId: s.ParentID, Depth: int32(s.Depth), Kind: s.Kind, Name: s.Name,
|
||||||
|
Status: string(s.Status), Detail: s.Detail, TokensUsed: s.TokensUsed,
|
||||||
|
StartedAt: timestamp(s.StartedAt), FinishedAt: timestamp(s.FinishedAt),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func stepExecutionValue(s *pb.StepExecution) task.StepExecution {
|
||||||
|
if s == nil {
|
||||||
|
return task.StepExecution{}
|
||||||
|
}
|
||||||
|
return task.StepExecution{
|
||||||
|
ID: s.Id, ExecutionID: s.ExecutionId, Attempt: int(s.Attempt),
|
||||||
|
ParentID: s.ParentId, Depth: int(s.Depth), Kind: s.Kind, Name: s.Name,
|
||||||
|
Status: taskstate.StepStatus(s.Status), Detail: s.Detail, TokensUsed: s.TokensUsed,
|
||||||
|
StartedAt: timeValue(s.StartedAt), FinishedAt: timeValue(s.FinishedAt),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func stageStatProto(s storecontract.StageStat) *pb.StageStat {
|
func stageStatProto(s storecontract.StageStat) *pb.StageStat {
|
||||||
return &pb.StageStat{Workflow: s.Workflow, Stage: s.Stage, Runs: int64(s.Runs), AvgMs: int64(s.AvgMs), Errors: int64(s.Errors)}
|
return &pb.StageStat{Workflow: s.Workflow, Stage: s.Stage, Runs: int64(s.Runs), AvgMs: int64(s.AvgMs), Errors: int64(s.Errors)}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func (s Store) TaskByID(ctx context.Context, id int64) (*taskactions.Task, error
|
|||||||
if err != nil || t == nil {
|
if err != nil || t == nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &taskactions.Task{ID: t.ID, Owner: t.Owner, Repo: t.Repo, Identity: t.Identity, Status: t.Status, Stage: t.Stage, ParkReason: t.ParkReason, IssueNumber: t.IssueNumber, RetryCount: t.RetryCount, Attempt: t.Attempt, ForgeBacked: t.IsForgeBacked()}, nil
|
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
|
// CancelExecution delegates to the store's one cancel path
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||||
"github.com/samcharles93/archie-core/internal/events"
|
"github.com/samcharles93/archie-core/internal/events"
|
||||||
|
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Stage/attempt statuses the attempt rail reports. They are one vocabulary
|
// Stage/attempt statuses the attempt rail reports. They are one vocabulary
|
||||||
@@ -66,7 +67,12 @@ type taskStageView struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handleTaskAttempts serves the stage rail: one task's attempts, each with the
|
// handleTaskAttempts serves the stage rail: one task's attempts, each with the
|
||||||
// stages it recorded.
|
// stages it recorded. Attempt bounds, event counts and which attempt numbers
|
||||||
|
// exist still come from the task's events (an attempt can carry events with
|
||||||
|
// no step, e.g. agent calls, so events remain the complete attempt index);
|
||||||
|
// the stages themselves are step_executions, the authoritative record
|
||||||
|
// (docs/prds/execution-tree-state-machine.md), not a fold over
|
||||||
|
// stage_start/stage_finish events.
|
||||||
func (s *Server) handleTaskAttempts(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleTaskAttempts(w http.ResponseWriter, r *http.Request) {
|
||||||
t, ok := s.taskByPathID(w, r)
|
t, ok := s.taskByPathID(w, r)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -77,7 +83,15 @@ func (s *Server) handleTaskAttempts(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
attempts, unattributed := attemptsFromEvents(evs, t.Status, t.Attempt)
|
var steps []task.StepExecution
|
||||||
|
if s.Steps != nil {
|
||||||
|
steps, err = s.Steps.ListSteps(r.Context(), t.ID, 0)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
attempts, unattributed := attemptsFromEvents(evs, steps, t.Status, t.Attempt)
|
||||||
writeJSON(w, taskAttemptsView{
|
writeJSON(w, taskAttemptsView{
|
||||||
TaskID: t.ID,
|
TaskID: t.ID,
|
||||||
CurrentAttempt: t.Attempt,
|
CurrentAttempt: t.Attempt,
|
||||||
@@ -143,7 +157,7 @@ func (s *Server) taskAttemptTarget(w http.ResponseWriter, r *http.Request) (*tas
|
|||||||
// unattributed -- every row written before the column existed and every
|
// unattributed -- every row written before the column existed and every
|
||||||
// deliberately task-agnostic producer carries it -- so grouping them would
|
// deliberately task-agnostic producer carries it -- so grouping them would
|
||||||
// present unrelated activity as attempt zero's rail.
|
// present unrelated activity as attempt zero's rail.
|
||||||
func attemptsFromEvents(evs []events.Event, taskStatus string, currentAttempt int) ([]taskAttemptView, int) {
|
func attemptsFromEvents(evs []events.Event, steps []task.StepExecution, taskStatus string, currentAttempt int) ([]taskAttemptView, int) {
|
||||||
grouped := make(map[int][]events.Event)
|
grouped := make(map[int][]events.Event)
|
||||||
numbers := make([]int, 0, 4)
|
numbers := make([]int, 0, 4)
|
||||||
unattributed := 0
|
unattributed := 0
|
||||||
@@ -161,21 +175,34 @@ func attemptsFromEvents(evs []events.Event, taskStatus string, currentAttempt in
|
|||||||
|
|
||||||
attempts := make([]taskAttemptView, 0, len(numbers))
|
attempts := make([]taskAttemptView, 0, len(numbers))
|
||||||
for _, number := range numbers {
|
for _, number := range numbers {
|
||||||
attempts = append(attempts, attemptRail(number, grouped[number], taskStatus, currentAttempt))
|
attempts = append(attempts, attemptRail(number, grouped[number], stepsForAttempt(steps, number), taskStatus, currentAttempt))
|
||||||
}
|
}
|
||||||
return attempts, unattributed
|
return attempts, unattributed
|
||||||
}
|
}
|
||||||
|
|
||||||
// attemptRail derives one attempt's status, bounds and stages from its events.
|
// stepsForAttempt filters ListSteps' full-execution result to one attempt's
|
||||||
func attemptRail(number int, evs []events.Event, taskStatus string, currentAttempt int) taskAttemptView {
|
// steps, in the order the query already returns them (attempt, id).
|
||||||
|
func stepsForAttempt(steps []task.StepExecution, attempt int) []task.StepExecution {
|
||||||
|
var out []task.StepExecution
|
||||||
|
for _, s := range steps {
|
||||||
|
if s.Attempt == attempt {
|
||||||
|
out = append(out, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// attemptRail derives one attempt's status and bounds from its events, and
|
||||||
|
// its stages from its recorded StepExecutions.
|
||||||
|
func attemptRail(number int, evs []events.Event, steps []task.StepExecution, taskStatus string, currentAttempt int) taskAttemptView {
|
||||||
// The task's own record is the only honest source for "is this still
|
// The task's own record is the only honest source for "is this still
|
||||||
// happening": an unpaired start on any other attempt ended without
|
// happening": a step still running on any other attempt ended without
|
||||||
// finishing -- parked, retried, crashed or restarted -- so it is reported
|
// finishing -- parked, retried, crashed or restarted -- so it is reported
|
||||||
// as interrupted rather than left looking permanently in flight.
|
// as interrupted rather than left looking permanently in flight.
|
||||||
inFlight := number == currentAttempt && taskStatus == task.StatusRunning
|
inFlight := number == currentAttempt && taskStatus == task.StatusRunning
|
||||||
|
|
||||||
first, last := attemptBounds(evs)
|
first, last := attemptBounds(evs)
|
||||||
stages := foldStages(evs, inFlight)
|
stages := stageViewsFromSteps(steps, inFlight)
|
||||||
attempt := taskAttemptView{
|
attempt := taskAttemptView{
|
||||||
Attempt: number,
|
Attempt: number,
|
||||||
Status: attemptStatus(stages, inFlight),
|
Status: attemptStatus(stages, inFlight),
|
||||||
@@ -215,34 +242,57 @@ func attemptBounds(evs []events.Event) (first, last time.Time) {
|
|||||||
return first, last
|
return first, last
|
||||||
}
|
}
|
||||||
|
|
||||||
// foldStages builds an attempt's ordered stage occurrences. A stage start is
|
// stageViewsFromSteps builds an attempt's ordered stage occurrences directly
|
||||||
// folded as an OPEN stage (status empty) until a matching finish closes it;
|
// from its recorded StepExecutions -- the authoritative record
|
||||||
// resolving what is left needs the task's own record, so an open stage is
|
// (docs/prds/execution-tree-state-machine.md), not a fold over
|
||||||
// running only while the daemon is executing this attempt and interrupted
|
// stage_start/stage_finish events. Only kind "stage" steps are shown: agent
|
||||||
// otherwise.
|
// and call steps are the tree's own detail, not this rail's.
|
||||||
func foldStages(evs []events.Event, inFlight bool) []taskStageView {
|
func stageViewsFromSteps(steps []task.StepExecution, inFlight bool) []taskStageView {
|
||||||
stages := []taskStageView{}
|
stages := []taskStageView{}
|
||||||
for _, e := range evs {
|
for _, s := range steps {
|
||||||
switch e.Kind {
|
if s.Kind != task.StepKindStage {
|
||||||
case events.KindStageStart:
|
|
||||||
started := e.At
|
|
||||||
stages = append(stages, taskStageView{Name: e.Stage, Seq: len(stages), StartedAt: &started})
|
|
||||||
case events.KindStageFinish:
|
|
||||||
stages = finishStage(stages, e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for i := range stages {
|
|
||||||
if stages[i].Status != "" {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
stages[i].Status = attemptStatusInterrupted
|
view := taskStageView{Name: s.Name, Seq: len(stages), Status: mapStepStatus(s.Status, inFlight)}
|
||||||
if inFlight {
|
if s.Status == taskstate.StepFailed {
|
||||||
stages[i].Status = attemptStatusRunning
|
view.Error = s.Detail
|
||||||
}
|
}
|
||||||
|
if !s.StartedAt.IsZero() {
|
||||||
|
started := s.StartedAt
|
||||||
|
view.StartedAt = &started
|
||||||
|
}
|
||||||
|
if !s.FinishedAt.IsZero() {
|
||||||
|
duration := s.FinishedAt.Sub(s.StartedAt).Milliseconds()
|
||||||
|
view.DurationMS = &duration
|
||||||
|
}
|
||||||
|
stages = append(stages, view)
|
||||||
}
|
}
|
||||||
return stages
|
return stages
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mapStepStatus reads the rail's status vocabulary off a step's own recorded
|
||||||
|
// status. A step still recorded running past this attempt -- the daemon
|
||||||
|
// crashed or restarted without marking it -- reads interrupted rather than
|
||||||
|
// running: RecoverStale is what corrects the row itself, and until it runs
|
||||||
|
// this is the honest read of a stale one.
|
||||||
|
func mapStepStatus(status taskstate.StepStatus, inFlight bool) string {
|
||||||
|
switch status {
|
||||||
|
case taskstate.StepSucceeded:
|
||||||
|
return attemptStatusOK
|
||||||
|
case taskstate.StepFailed:
|
||||||
|
return attemptStatusFailed
|
||||||
|
case taskstate.StepCancelled, taskstate.StepInterrupted:
|
||||||
|
return attemptStatusInterrupted
|
||||||
|
case taskstate.StepRunning:
|
||||||
|
if inFlight {
|
||||||
|
return attemptStatusRunning
|
||||||
|
}
|
||||||
|
return attemptStatusInterrupted
|
||||||
|
default:
|
||||||
|
return attemptStatusUnknown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// attemptStatus reads one status off an attempt's stages. The task's own record
|
// attemptStatus reads one status off an attempt's stages. The task's own record
|
||||||
// outranks the events: an attempt the daemon is executing right now is running
|
// outranks the events: an attempt the daemon is executing right now is running
|
||||||
// whatever its events have recorded so far -- including the ones that have
|
// whatever its events have recorded so far -- including the ones that have
|
||||||
@@ -267,72 +317,6 @@ func attemptStatus(stages []taskStageView, inFlight bool) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// finishStage applies one stage_finish event, closing the earliest still-open
|
|
||||||
// stage of the same name. A finish with no matching start still yields the
|
|
||||||
// stage -- with no start time rather than an invented one -- because the stage
|
|
||||||
// demonstrably ran and dropping it would hide a failure.
|
|
||||||
func finishStage(stages []taskStageView, e events.Event) []taskStageView {
|
|
||||||
status, errText := stageOutcome(e.Data)
|
|
||||||
recorded, hasRecorded := durationMillis(e.Data["duration_ms"])
|
|
||||||
|
|
||||||
idx := -1
|
|
||||||
for i := range stages {
|
|
||||||
if stages[i].Name == e.Stage && stages[i].Status == "" {
|
|
||||||
idx = i
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if idx < 0 {
|
|
||||||
stages = append(stages, taskStageView{Name: e.Stage, Seq: len(stages)})
|
|
||||||
idx = len(stages) - 1
|
|
||||||
}
|
|
||||||
stages[idx].Status = status
|
|
||||||
stages[idx].Error = errText
|
|
||||||
switch {
|
|
||||||
case hasRecorded:
|
|
||||||
// The producer's own measurement of the stage body, preferred over the
|
|
||||||
// gap between two event timestamps.
|
|
||||||
stages[idx].DurationMS = &recorded
|
|
||||||
case stages[idx].StartedAt != nil && !e.At.IsZero():
|
|
||||||
span := e.At.Sub(*stages[idx].StartedAt).Milliseconds()
|
|
||||||
stages[idx].DurationMS = &span
|
|
||||||
}
|
|
||||||
return stages
|
|
||||||
}
|
|
||||||
|
|
||||||
// stageOutcome reads a stage_finish event's own verdict. An interrupted finish
|
|
||||||
// is interrupted even though it also carries the cancellation error text; a
|
|
||||||
// non-empty error is a failure; anything else is ok. There is no exit code
|
|
||||||
// anywhere in this system, so no stage is ever badged as passing -- the status
|
|
||||||
// reports how the stage ended, not how well it went.
|
|
||||||
func stageOutcome(data map[string]any) (status, errText string) {
|
|
||||||
errText, _ = data["error"].(string)
|
|
||||||
if interrupted, _ := data["interrupted"].(bool); interrupted {
|
|
||||||
return attemptStatusInterrupted, errText
|
|
||||||
}
|
|
||||||
if errText != "" {
|
|
||||||
return attemptStatusFailed, errText
|
|
||||||
}
|
|
||||||
return attemptStatusOK, ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// durationMillis reads a millisecond duration a producer recorded in an event's
|
|
||||||
// data. A value that crossed JSON is float64 and one built in this process is
|
|
||||||
// an integer, so both spellings are accepted; anything else is reported as "not
|
|
||||||
// recorded" rather than as zero.
|
|
||||||
func durationMillis(v any) (int64, bool) {
|
|
||||||
switch n := v.(type) {
|
|
||||||
case int:
|
|
||||||
return int64(n), true
|
|
||||||
case int64:
|
|
||||||
return n, true
|
|
||||||
case float64:
|
|
||||||
return int64(n), true
|
|
||||||
default:
|
|
||||||
return 0, false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func anyStageStatus(stages []taskStageView, status string) bool {
|
func anyStageStatus(stages []taskStageView, status string) bool {
|
||||||
for _, s := range stages {
|
for _, s := range stages {
|
||||||
if s.Status == status {
|
if s.Status == status {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package webui
|
package webui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -11,19 +12,29 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||||
|
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||||
"github.com/samcharles93/archie-core/internal/events"
|
"github.com/samcharles93/archie-core/internal/events"
|
||||||
|
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// stepWriter is StepRecorder, asserted against srv.Store here rather than
|
||||||
|
// widened onto storecontract.TaskStore: the dashboard never writes a step
|
||||||
|
// itself, only reads them (Server.Steps, storecontract.StepReader), and this
|
||||||
|
// test needs real rows to exercise the read against.
|
||||||
|
type stepWriter interface {
|
||||||
|
StartStep(ctx context.Context, s task.StepStart) (int64, events.Event, error)
|
||||||
|
FinishStep(ctx context.Context, s task.StepFinish) (events.Event, error)
|
||||||
|
}
|
||||||
|
|
||||||
// railBase is the fixed clock the rail fixtures hang off, so every timestamp
|
// railBase is the fixed clock the rail fixtures hang off, so every timestamp
|
||||||
// and duration asserted below is a literal rather than a tolerance.
|
// and duration asserted below is a literal rather than a tolerance.
|
||||||
var railBase = time.Date(2026, 9, 18, 7, 0, 0, 0, time.UTC)
|
var railBase = time.Date(2026, 9, 18, 7, 0, 0, 0, time.UTC)
|
||||||
|
|
||||||
func stageStartEvent(taskID int64, attempt int, stage string, at time.Time) events.Event {
|
// attemptEvent stands in for the events that still drive attempt bounds and
|
||||||
return events.Event{Kind: events.KindStageStart, TaskID: taskID, Attempt: attempt, Stage: stage, At: at}
|
// counts (attemptsFromEvents), independent of the stage rail those events
|
||||||
}
|
// used to also back.
|
||||||
|
func attemptEvent(taskID int64, attempt int, at time.Time) events.Event {
|
||||||
func stageFinishEvent(taskID int64, attempt int, stage string, at time.Time, data map[string]any) events.Event {
|
return events.Event{Kind: events.KindAgentFinish, TaskID: taskID, Attempt: attempt, At: at}
|
||||||
return events.Event{Kind: events.KindStageFinish, TaskID: taskID, Attempt: attempt, Stage: stage, At: at, Data: data}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func insertTaskEvent(t *testing.T, srv *Server, ev events.Event) {
|
func insertTaskEvent(t *testing.T, srv *Server, ev events.Event) {
|
||||||
@@ -33,6 +44,16 @@ func insertTaskEvent(t *testing.T, srv *Server, ev events.Event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stageStep is a fixture StepExecution the pure-function test builds by
|
||||||
|
// hand -- no store round trip, since stageViewsFromSteps operates on
|
||||||
|
// task.StepExecution values directly.
|
||||||
|
func stageStep(name string, attempt int, status taskstate.StepStatus, startedAt, finishedAt time.Time, detail string) task.StepExecution {
|
||||||
|
return task.StepExecution{
|
||||||
|
Attempt: attempt, Kind: task.StepKindStage, Name: name, Status: status,
|
||||||
|
StartedAt: startedAt, FinishedAt: finishedAt, Detail: detail,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// getTaskAPI issues one task-detail request through the real mux. A route that
|
// getTaskAPI issues one task-detail request through the real mux. A route that
|
||||||
// is not registered falls through to the SPA asset handler and answers 200 with
|
// is not registered falls through to the SPA asset handler and answers 200 with
|
||||||
// an HTML page, so using the mux makes a missing registration fail the shape
|
// an HTML page, so using the mux makes a missing registration fail the shape
|
||||||
@@ -91,26 +112,6 @@ func twoAttemptTask(t *testing.T, srv *Server) *workflow.Task {
|
|||||||
// summarizeAttemptRail renders a folded rail as one line per attempt so a table
|
// summarizeAttemptRail renders a folded rail as one line per attempt so a table
|
||||||
// case states the derivation it expects without a struct literal per stage:
|
// case states the derivation it expects without a struct literal per stage:
|
||||||
// "attempt:status[name:status:duration[#error][@nostart],...] duration".
|
// "attempt:status[name:status:duration[#error][@nostart],...] duration".
|
||||||
func summarizeAttemptRail(attempts []taskAttemptView) string {
|
|
||||||
lines := make([]string, 0, len(attempts))
|
|
||||||
for _, a := range attempts {
|
|
||||||
stages := make([]string, 0, len(a.Stages))
|
|
||||||
for _, s := range a.Stages {
|
|
||||||
stage := s.Name + ":" + s.Status + ":" + durationToken(s.DurationMS)
|
|
||||||
if s.StartedAt == nil {
|
|
||||||
stage += "@nostart"
|
|
||||||
}
|
|
||||||
if s.Error != "" {
|
|
||||||
stage += "#" + s.Error
|
|
||||||
}
|
|
||||||
stages = append(stages, stage)
|
|
||||||
}
|
|
||||||
line := strconv.Itoa(a.Attempt) + ":" + a.Status + "[" + strings.Join(stages, ",") + "] " + durationToken(a.DurationMS)
|
|
||||||
lines = append(lines, line)
|
|
||||||
}
|
|
||||||
return strings.Join(lines, " | ")
|
|
||||||
}
|
|
||||||
|
|
||||||
func durationToken(ms *int64) string {
|
func durationToken(ms *int64) string {
|
||||||
if ms == nil {
|
if ms == nil {
|
||||||
return "?"
|
return "?"
|
||||||
@@ -118,161 +119,158 @@ func durationToken(ms *int64) string {
|
|||||||
return strconv.FormatInt(*ms, 10)
|
return strconv.FormatInt(*ms, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestAttemptsFromEventsDerivesEveryRailRule is the table behind R1: every
|
// summarizeStages renders a stage list the same way summarizeAttemptRail's
|
||||||
// status rule the attempt rail depends on, one case each, plus the cases that
|
// inner loop does, for a test that exercises stageViewsFromSteps alone.
|
||||||
// would otherwise be answered by inventing data (a finish with no start, an
|
func summarizeStages(stages []taskStageView) string {
|
||||||
// event set with no stage information, events carrying no attempt at all).
|
tokens := make([]string, 0, len(stages))
|
||||||
func TestAttemptsFromEventsDerivesEveryRailRule(t *testing.T) {
|
for _, s := range stages {
|
||||||
|
token := s.Name + ":" + s.Status + ":" + durationToken(s.DurationMS)
|
||||||
|
if s.StartedAt == nil {
|
||||||
|
token += "@nostart"
|
||||||
|
}
|
||||||
|
if s.Error != "" {
|
||||||
|
token += "#" + s.Error
|
||||||
|
}
|
||||||
|
tokens = append(tokens, token)
|
||||||
|
}
|
||||||
|
return strings.Join(tokens, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestStageViewsFromStepsDerivesEveryRailRule is the table behind R1: every
|
||||||
|
// status rule the rail depends on, sourced from StepExecutions -- the
|
||||||
|
// authoritative record (docs/prds/execution-tree-state-machine.md) -- rather
|
||||||
|
// than a fold over stage_start/stage_finish events.
|
||||||
|
func TestStageViewsFromStepsDerivesEveryRailRule(t *testing.T) {
|
||||||
|
at := railBase.Add
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
steps []task.StepExecution
|
||||||
|
inFlight bool
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "a succeeded step is ok and reports its measured span",
|
||||||
|
steps: []task.StepExecution{stageStep("prepare", 1, taskstate.StepSucceeded, at(0), at(time.Second), "")},
|
||||||
|
want: "prepare:ok:1000",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "a failed step fails and carries its detail as the error",
|
||||||
|
steps: []task.StepExecution{stageStep("implement", 1, taskstate.StepFailed, at(0), at(2*time.Second), "builder exited 1")},
|
||||||
|
want: "implement:failed:2000#builder exited 1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "a cancelled step reads interrupted",
|
||||||
|
steps: []task.StepExecution{stageStep("implement", 1, taskstate.StepCancelled, at(0), at(time.Second), "stopped by operator")},
|
||||||
|
want: "implement:interrupted:1000",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "an interrupted step reads interrupted",
|
||||||
|
steps: []task.StepExecution{stageStep("implement", 1, taskstate.StepInterrupted, at(0), at(time.Second), "")},
|
||||||
|
want: "implement:interrupted:1000",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "a running step on the task's current in-flight attempt is running",
|
||||||
|
steps: []task.StepExecution{stageStep("implement", 2, taskstate.StepRunning, at(0), time.Time{}, "")},
|
||||||
|
inFlight: true,
|
||||||
|
want: "implement:running:?",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "a running step past the task's live attempt is stale, read as interrupted",
|
||||||
|
steps: []task.StepExecution{stageStep("implement", 1, taskstate.StepRunning, at(0), time.Time{}, "")},
|
||||||
|
inFlight: false,
|
||||||
|
want: "implement:interrupted:?",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "a pending step (never observed in practice) reads unknown rather than a false verdict",
|
||||||
|
steps: []task.StepExecution{stageStep("implement", 1, taskstate.StepPending, time.Time{}, time.Time{}, "")},
|
||||||
|
want: "implement:unknown:?@nostart",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "a repeated stage name yields one rail entry per occurrence",
|
||||||
|
steps: []task.StepExecution{
|
||||||
|
stageStep("implement", 1, taskstate.StepSucceeded, at(0), at(time.Second), ""),
|
||||||
|
{Attempt: 1, Kind: task.StepKindStage, Name: "implement", Status: taskstate.StepRunning, StartedAt: at(2 * time.Second)},
|
||||||
|
},
|
||||||
|
inFlight: true,
|
||||||
|
want: "implement:ok:1000,implement:running:?",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "an agent or call step is not part of the stage rail",
|
||||||
|
steps: []task.StepExecution{
|
||||||
|
stageStep("implement", 1, taskstate.StepSucceeded, at(0), at(time.Second), ""),
|
||||||
|
{Attempt: 1, Kind: task.StepKindAgent, Name: "implement", Status: taskstate.StepSucceeded, StartedAt: at(0), FinishedAt: at(time.Second)},
|
||||||
|
{Attempt: 1, Kind: task.StepKindCall, Name: "callee", Status: taskstate.StepSucceeded, StartedAt: at(0), FinishedAt: at(time.Second)},
|
||||||
|
},
|
||||||
|
want: "implement:ok:1000",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := summarizeStages(stageViewsFromSteps(tt.steps, tt.inFlight)); got != tt.want {
|
||||||
|
t.Errorf("stages = %q, want %q", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestAttemptsFromEventsIndexesAttemptsFromEventsAndUnattributedCount pins
|
||||||
|
// what attemptsFromEvents still owns now that stage derivation moved to
|
||||||
|
// steps: which attempt numbers exist, and the unattributed-event count --
|
||||||
|
// both read from the task's events, since an attempt can carry events (agent
|
||||||
|
// calls, say) with no recorded step at all.
|
||||||
|
func TestAttemptsFromEventsIndexesAttemptsFromEventsAndUnattributedCount(t *testing.T) {
|
||||||
at := railBase.Add
|
at := railBase.Add
|
||||||
duration := func(ms int64) map[string]any { return map[string]any{"duration_ms": ms} }
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
taskStatus string
|
taskStatus string
|
||||||
currentAttempt int
|
currentAttempt int
|
||||||
evs []events.Event
|
evs []events.Event
|
||||||
want string
|
steps []task.StepExecution
|
||||||
|
wantAttempts []int
|
||||||
wantUnattributed int
|
wantUnattributed int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "a finished stage is ok and the attempt reports its measured span",
|
name: "a later attempt does not absorb the earlier attempt's steps",
|
||||||
taskStatus: workflow.StatusParked, currentAttempt: 1,
|
|
||||||
evs: []events.Event{
|
|
||||||
stageStartEvent(1, 1, "prepare", at(0)),
|
|
||||||
stageFinishEvent(1, 1, "prepare", at(time.Second), duration(1000)),
|
|
||||||
},
|
|
||||||
want: "1:ok[prepare:ok:1000] 1000",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "a failed stage fails the attempt and carries the error text",
|
|
||||||
taskStatus: workflow.StatusParked, currentAttempt: 1,
|
|
||||||
evs: []events.Event{
|
|
||||||
stageStartEvent(1, 1, "implement", at(0)),
|
|
||||||
stageFinishEvent(1, 1, "implement", at(2*time.Second), map[string]any{
|
|
||||||
"duration_ms": int64(2000),
|
|
||||||
"error": "stage implement: builder exited 1",
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
want: "1:failed[implement:failed:2000#stage implement: builder exited 1] 2000",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "an interrupted stage reads interrupted even though the error text is recorded",
|
|
||||||
taskStatus: workflow.StatusParked, currentAttempt: 1,
|
|
||||||
evs: []events.Event{
|
|
||||||
stageStartEvent(1, 1, "implement", at(0)),
|
|
||||||
stageFinishEvent(1, 1, "implement", at(time.Second), map[string]any{
|
|
||||||
"duration_ms": int64(1000),
|
|
||||||
"error": "context canceled",
|
|
||||||
"interrupted": true,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
want: "1:interrupted[implement:interrupted:1000#context canceled] 1000",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "a failed stage outranks an interrupted one",
|
|
||||||
taskStatus: workflow.StatusParked, currentAttempt: 1,
|
|
||||||
evs: []events.Event{
|
|
||||||
stageStartEvent(1, 1, "a", at(0)),
|
|
||||||
stageFinishEvent(1, 1, "a", at(time.Second), map[string]any{"duration_ms": int64(1000), "error": "boom"}),
|
|
||||||
stageStartEvent(1, 1, "b", at(2*time.Second)),
|
|
||||||
stageFinishEvent(1, 1, "b", at(3*time.Second), map[string]any{
|
|
||||||
"duration_ms": int64(1000), "error": "canceled", "interrupted": true,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
want: "1:failed[a:failed:1000#boom,b:interrupted:1000#canceled] 3000",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "an unpaired start on the task's current in-flight attempt is running",
|
|
||||||
taskStatus: workflow.StatusRunning, currentAttempt: 2,
|
taskStatus: workflow.StatusRunning, currentAttempt: 2,
|
||||||
evs: []events.Event{stageStartEvent(1, 2, "implement", at(0))},
|
evs: []events.Event{attemptEvent(1, 1, at(0)), attemptEvent(1, 2, at(time.Second))},
|
||||||
want: "2:running[implement:running:?] ?",
|
steps: []task.StepExecution{stageStep("prepare", 1, taskstate.StepSucceeded, at(0), at(time.Second), "")},
|
||||||
},
|
wantAttempts: []int{1, 2},
|
||||||
{
|
|
||||||
name: "an unpaired start on a superseded attempt is interrupted",
|
|
||||||
taskStatus: workflow.StatusRunning, currentAttempt: 2,
|
|
||||||
evs: []events.Event{stageStartEvent(1, 1, "implement", at(0))},
|
|
||||||
want: "1:interrupted[implement:interrupted:?] 0",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "an unpaired start on a parked task's own attempt is interrupted",
|
|
||||||
taskStatus: workflow.StatusParked, currentAttempt: 1,
|
|
||||||
evs: []events.Event{stageStartEvent(1, 1, "implement", at(0))},
|
|
||||||
want: "1:interrupted[implement:interrupted:?] 0",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "a finish with no start yields the stage without an invented start time",
|
|
||||||
taskStatus: workflow.StatusParked, currentAttempt: 1,
|
|
||||||
evs: []events.Event{
|
|
||||||
stageFinishEvent(1, 1, "commit", at(0), duration(4000)),
|
|
||||||
},
|
|
||||||
want: "1:ok[commit:ok:4000@nostart] 0",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "a finish without a recorded duration derives it from its own start",
|
|
||||||
taskStatus: workflow.StatusParked, currentAttempt: 1,
|
|
||||||
evs: []events.Event{
|
|
||||||
stageStartEvent(1, 1, "prepare", at(0)),
|
|
||||||
stageFinishEvent(1, 1, "prepare", at(10*time.Second), nil),
|
|
||||||
},
|
|
||||||
want: "1:ok[prepare:ok:10000] 10000",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "a repeated stage name yields one rail entry per occurrence",
|
|
||||||
taskStatus: workflow.StatusRunning, currentAttempt: 1,
|
|
||||||
evs: []events.Event{
|
|
||||||
stageStartEvent(1, 1, "implement", at(0)),
|
|
||||||
stageFinishEvent(1, 1, "implement", at(time.Second), duration(1000)),
|
|
||||||
stageStartEvent(1, 1, "implement", at(2*time.Second)),
|
|
||||||
},
|
|
||||||
want: "1:running[implement:ok:1000,implement:running:?] ?",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "a later attempt does not absorb the earlier attempt's stages",
|
|
||||||
taskStatus: workflow.StatusRunning, currentAttempt: 2,
|
|
||||||
evs: []events.Event{
|
|
||||||
stageStartEvent(1, 1, "prepare", at(0)),
|
|
||||||
stageFinishEvent(1, 1, "prepare", at(time.Second), duration(1000)),
|
|
||||||
stageStartEvent(1, 2, "implement", at(2*time.Second)),
|
|
||||||
},
|
|
||||||
want: "1:ok[prepare:ok:1000] 1000 | 2:running[implement:running:?] ?",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "events carrying no attempt are counted, never grouped",
|
name: "events carrying no attempt are counted, never grouped",
|
||||||
taskStatus: workflow.StatusQueued, currentAttempt: 0,
|
taskStatus: workflow.StatusQueued, currentAttempt: 0,
|
||||||
evs: []events.Event{
|
evs: []events.Event{{Kind: events.KindAgentFinish, TaskID: 1, At: at(0)}, {Kind: events.KindAgentFinish, TaskID: 1, At: at(time.Second)}},
|
||||||
{Kind: events.KindStageStart, TaskID: 1, Stage: "prepare", At: at(0)},
|
|
||||||
{Kind: events.KindStageFinish, TaskID: 1, Stage: "prepare", At: at(time.Second), Data: duration(1000)},
|
|
||||||
},
|
|
||||||
wantUnattributed: 2,
|
wantUnattributed: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "a task with no events has no attempts and nothing unattributed",
|
name: "a task with no events has no attempts and nothing unattributed",
|
||||||
taskStatus: workflow.StatusQueued, currentAttempt: 0,
|
taskStatus: workflow.StatusQueued, currentAttempt: 0,
|
||||||
want: "",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "an attempt whose events carry no stage information is unknown",
|
name: "an attempt with events but no recorded step still appears, with no stages",
|
||||||
taskStatus: workflow.StatusParked, currentAttempt: 1,
|
taskStatus: workflow.StatusParked, currentAttempt: 1,
|
||||||
evs: []events.Event{
|
evs: []events.Event{attemptEvent(1, 1, at(0))},
|
||||||
{Kind: events.KindAgentFinish, TaskID: 1, Attempt: 1, At: at(0), Data: map[string]any{"status": "ok"}},
|
wantAttempts: []int{1},
|
||||||
},
|
|
||||||
want: "1:unknown[] ?",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "the task's own record keeps the current attempt running with no stage events",
|
|
||||||
taskStatus: workflow.StatusRunning, currentAttempt: 1,
|
|
||||||
evs: []events.Event{
|
|
||||||
{Kind: events.KindAgentFinish, TaskID: 1, Attempt: 1, At: at(0), Data: map[string]any{"status": "ok"}},
|
|
||||||
},
|
|
||||||
want: "1:running[] ?",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
attempts, unattributed := attemptsFromEvents(tt.evs, tt.taskStatus, tt.currentAttempt)
|
attempts, unattributed := attemptsFromEvents(tt.evs, tt.steps, tt.taskStatus, tt.currentAttempt)
|
||||||
if got := summarizeAttemptRail(attempts); got != tt.want {
|
var got []int
|
||||||
t.Errorf("rail = %q, want %q", got, tt.want)
|
for _, a := range attempts {
|
||||||
|
got = append(got, a.Attempt)
|
||||||
|
}
|
||||||
|
if len(got) != len(tt.wantAttempts) {
|
||||||
|
t.Fatalf("attempts = %v, want %v", got, tt.wantAttempts)
|
||||||
|
}
|
||||||
|
for i, want := range tt.wantAttempts {
|
||||||
|
if got[i] != want {
|
||||||
|
t.Errorf("attempts = %v, want %v", got, tt.wantAttempts)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if unattributed != tt.wantUnattributed {
|
if unattributed != tt.wantUnattributed {
|
||||||
t.Errorf("unattributed = %d, want %d", unattributed, tt.wantUnattributed)
|
t.Errorf("unattributed = %d, want %d", unattributed, tt.wantUnattributed)
|
||||||
@@ -287,17 +285,67 @@ func TestAttemptsFromEventsDerivesEveryRailRule(t *testing.T) {
|
|||||||
// attempt 2's stages.
|
// attempt 2's stages.
|
||||||
func TestHandleTaskAttemptsRendersBothAttemptsOfARetry(t *testing.T) {
|
func TestHandleTaskAttemptsRendersBothAttemptsOfARetry(t *testing.T) {
|
||||||
srv := newTestServer(t)
|
srv := newTestServer(t)
|
||||||
current := twoAttemptTask(t, srv)
|
ctx := t.Context()
|
||||||
at := railBase.Add
|
steps, ok := srv.Store.(stepWriter)
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("test store does not implement stepWriter")
|
||||||
|
}
|
||||||
|
|
||||||
insertTaskEvent(t, srv, stageStartEvent(current.ID, 1, "prepare", at(0)))
|
// Not twoAttemptTask: StartStep guards on the execution's own current
|
||||||
insertTaskEvent(t, srv, stageFinishEvent(current.ID, 1, "prepare", at(1200*time.Millisecond),
|
// attempt (a step named for a superseded attempt is a stale transition
|
||||||
map[string]any{"duration_ms": int64(1200)}))
|
// by design -- steps.go, "a caller naming one the execution no longer
|
||||||
insertTaskEvent(t, srv, stageStartEvent(current.ID, 1, "implement", at(1323*time.Millisecond)))
|
// runs is describing a run that is over"), so attempt 1's steps have to
|
||||||
insertTaskEvent(t, srv, stageFinishEvent(current.ID, 1, "implement", at(231323*time.Millisecond),
|
// be recorded while the task is actually on attempt 1, before the retry
|
||||||
map[string]any{"duration_ms": int64(230000), "error": "stage implement: builder exited 1"}))
|
// that moves it to attempt 2.
|
||||||
insertTaskEvent(t, srv, stageStartEvent(current.ID, 2, "implement", at(time.Hour)))
|
if _, err := srv.Store.EnqueueIssue(ctx, "acme", "widget", 1, "task", "", "", ""); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
claimed1, err := srv.Store.ClaimNext(ctx)
|
||||||
|
if err != nil || claimed1 == nil || claimed1.Attempt != 1 {
|
||||||
|
t.Fatalf("ClaimNext = (%+v, %v), want attempt 1", claimed1, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
prepareID, _, err := steps.StartStep(ctx, task.StepStart{ExecutionID: claimed1.ID, Attempt: 1, Kind: task.StepKindStage, Name: "prepare"})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("StartStep prepare: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := steps.FinishStep(ctx, task.StepFinish{
|
||||||
|
StepID: prepareID, ExecutionID: claimed1.ID, From: taskstate.StepRunning, To: taskstate.StepSucceeded,
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatalf("FinishStep prepare: %v", err)
|
||||||
|
}
|
||||||
|
implementID, _, err := steps.StartStep(ctx, task.StepStart{ExecutionID: claimed1.ID, Attempt: 1, Kind: task.StepKindStage, Name: "implement"})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("StartStep implement: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := steps.FinishStep(ctx, task.StepFinish{
|
||||||
|
StepID: implementID, ExecutionID: claimed1.ID, From: taskstate.StepRunning, To: taskstate.StepFailed,
|
||||||
|
Detail: "stage implement: builder exited 1",
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatalf("FinishStep implement: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := srv.Store.Transition(ctx, claimed1.ID, workflow.StatusRunning, workflow.StatusParked, "stage implement: builder exited 1"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := srv.Store.RetryTask(ctx, claimed1.ID, workflow.StatusParked, ""); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
current, err := srv.Store.ClaimNext(ctx)
|
||||||
|
if err != nil || current == nil || current.Attempt != 2 {
|
||||||
|
t.Fatalf("second ClaimNext = (%+v, %v), want attempt 2", current, err)
|
||||||
|
}
|
||||||
|
if _, _, err := steps.StartStep(ctx, task.StepStart{ExecutionID: current.ID, Attempt: 2, Kind: task.StepKindStage, Name: "implement"}); err != nil {
|
||||||
|
t.Fatalf("StartStep attempt 2 implement: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// No hand-inserted events: StartStep/FinishStep already write
|
||||||
|
// stage_start/stage_finish events in the same transaction as the step
|
||||||
|
// row (steps.go), which is what attemptBounds and event_count read --
|
||||||
|
// attempt 1 gets exactly the 4 those two StartStep+FinishStep pairs
|
||||||
|
// produce, attempt 2 the 1 its lone StartStep produces. Their
|
||||||
|
// timestamps are the store's own clock, so bounds are checked for
|
||||||
|
// presence and order below rather than against a literal railBase time.
|
||||||
w := getTaskAPI(t, srv, taskRoute(current.ID, "/attempts"))
|
w := getTaskAPI(t, srv, taskRoute(current.ID, "/attempts"))
|
||||||
if w.Code != http.StatusOK {
|
if w.Code != http.StatusOK {
|
||||||
t.Fatalf("status = %d, body %s", w.Code, w.Body)
|
t.Fatalf("status = %d, body %s", w.Code, w.Body)
|
||||||
@@ -345,14 +393,13 @@ func TestHandleTaskAttemptsRendersBothAttemptsOfARetry(t *testing.T) {
|
|||||||
if first.EventCount != 4 {
|
if first.EventCount != 4 {
|
||||||
t.Errorf("attempt 1 event_count = %d, want 4", first.EventCount)
|
t.Errorf("attempt 1 event_count = %d, want 4", first.EventCount)
|
||||||
}
|
}
|
||||||
if first.StartedAt == nil || !first.StartedAt.Equal(at(0)) {
|
// StartStep/FinishStep stamp their events with the store's own clock, so
|
||||||
t.Errorf("attempt 1 started_at = %v, want %v", first.StartedAt, at(0))
|
// only presence, order and non-negativity are checked here.
|
||||||
|
if first.StartedAt == nil || first.FinishedAt == nil || first.FinishedAt.Before(*first.StartedAt) {
|
||||||
|
t.Errorf("attempt 1 bounds = started %v finished %v, want finished not before started", first.StartedAt, first.FinishedAt)
|
||||||
}
|
}
|
||||||
if first.FinishedAt == nil || !first.FinishedAt.Equal(at(231323*time.Millisecond)) {
|
if first.DurationMS == nil || *first.DurationMS < 0 {
|
||||||
t.Errorf("attempt 1 finished_at = %v, want %v", first.FinishedAt, at(231323*time.Millisecond))
|
t.Errorf("attempt 1 duration_ms = %v, want a non-negative measured span", first.DurationMS)
|
||||||
}
|
|
||||||
if first.DurationMS == nil || *first.DurationMS != 231323 {
|
|
||||||
t.Errorf("attempt 1 duration_ms = %v, want 231323", first.DurationMS)
|
|
||||||
}
|
}
|
||||||
if len(first.Stages) != 2 {
|
if len(first.Stages) != 2 {
|
||||||
t.Fatalf("attempt 1 stages = %d, want 2 (%s)", len(first.Stages), w.Body)
|
t.Fatalf("attempt 1 stages = %d, want 2 (%s)", len(first.Stages), w.Body)
|
||||||
@@ -361,11 +408,12 @@ func TestHandleTaskAttemptsRendersBothAttemptsOfARetry(t *testing.T) {
|
|||||||
if prepare.Name != "prepare" || prepare.Seq != 0 || prepare.Status != "ok" || prepare.Error != "" {
|
if prepare.Name != "prepare" || prepare.Seq != 0 || prepare.Status != "ok" || prepare.Error != "" {
|
||||||
t.Errorf("stage 0 = %+v, want prepare/0/ok with no error", prepare)
|
t.Errorf("stage 0 = %+v, want prepare/0/ok with no error", prepare)
|
||||||
}
|
}
|
||||||
if prepare.DurationMS == nil || *prepare.DurationMS != 1200 {
|
// StartStep/FinishStep stamp started_at/finished_at with the store's own
|
||||||
t.Errorf("stage 0 duration_ms = %v, want 1200", prepare.DurationMS)
|
// clock (now()), not a caller-supplied time, so only their presence and
|
||||||
}
|
// non-negativity are checked here -- railBase no longer applies to a step
|
||||||
if prepare.StartedAt == nil || !prepare.StartedAt.Equal(at(0)) {
|
// row the way it did to a hand-inserted event.
|
||||||
t.Errorf("stage 0 started_at = %v, want %v", prepare.StartedAt, at(0))
|
if prepare.StartedAt == nil || prepare.DurationMS == nil || *prepare.DurationMS < 0 {
|
||||||
|
t.Errorf("stage 0 = %+v, want a recorded start and a non-negative duration", prepare)
|
||||||
}
|
}
|
||||||
implement := first.Stages[1]
|
implement := first.Stages[1]
|
||||||
if implement.Name != "implement" || implement.Seq != 1 || implement.Status != "failed" {
|
if implement.Name != "implement" || implement.Seq != 1 || implement.Status != "failed" {
|
||||||
@@ -374,8 +422,8 @@ func TestHandleTaskAttemptsRendersBothAttemptsOfARetry(t *testing.T) {
|
|||||||
if implement.Error != "stage implement: builder exited 1" {
|
if implement.Error != "stage implement: builder exited 1" {
|
||||||
t.Errorf("stage 1 error = %q, want the recorded error text", implement.Error)
|
t.Errorf("stage 1 error = %q, want the recorded error text", implement.Error)
|
||||||
}
|
}
|
||||||
if implement.DurationMS == nil || *implement.DurationMS != 230000 {
|
if implement.DurationMS == nil || *implement.DurationMS < 0 {
|
||||||
t.Errorf("stage 1 duration_ms = %v, want 230000", implement.DurationMS)
|
t.Errorf("stage 1 duration_ms = %v, want a non-negative measured duration", implement.DurationMS)
|
||||||
}
|
}
|
||||||
|
|
||||||
second := body.Attempts[1]
|
second := body.Attempts[1]
|
||||||
@@ -431,9 +479,8 @@ func TestHandleTaskAttemptsSeparatesUnattributedEventsFromAFirstRun(t *testing.T
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
insertTaskEvent(t, srv, stageStartEvent(task.ID, 0, "prepare", railBase))
|
insertTaskEvent(t, srv, attemptEvent(task.ID, 0, railBase))
|
||||||
insertTaskEvent(t, srv, stageFinishEvent(task.ID, 0, "prepare", railBase.Add(time.Second),
|
insertTaskEvent(t, srv, attemptEvent(task.ID, 0, railBase.Add(time.Second)))
|
||||||
map[string]any{"duration_ms": int64(1000)}))
|
|
||||||
|
|
||||||
w := getTaskAPI(t, srv, taskRoute(task.ID, "/attempts"))
|
w := getTaskAPI(t, srv, taskRoute(task.ID, "/attempts"))
|
||||||
if w.Code != http.StatusOK {
|
if w.Code != http.StatusOK {
|
||||||
|
|||||||
@@ -26,6 +26,14 @@ type Server struct {
|
|||||||
Store storecontract.TaskStore
|
Store storecontract.TaskStore
|
||||||
Log *slog.Logger
|
Log *slog.Logger
|
||||||
|
|
||||||
|
// Steps lists one execution's recorded StepExecutions
|
||||||
|
// (docs/prds/execution-tree-state-machine.md): the run detail's
|
||||||
|
// authoritative source, GET /api/tasks/{id}/attempts. Nil degrades the
|
||||||
|
// route to reporting no steps rather than folding stage_start/
|
||||||
|
// stage_finish events, which tasks.stage used to back and no longer
|
||||||
|
// exists to fall back to.
|
||||||
|
Steps storecontract.StepReader
|
||||||
|
|
||||||
// ConfigSource supplies the configuration projection GET /api/config
|
// ConfigSource supplies the configuration projection GET /api/config
|
||||||
// renders. Composition sets it to RemoteConfigView in a process that
|
// renders. Composition sets it to RemoteConfigView in a process that
|
||||||
// only displays configuration; unset means this process builds the view
|
// only displays configuration; unset means this process builds the view
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func newTestServer(t *testing.T) *Server {
|
|||||||
t.Helper()
|
t.Helper()
|
||||||
s := pgstore.Open(t)
|
s := pgstore.Open(t)
|
||||||
t.Cleanup(func() { _ = s.Close() })
|
t.Cleanup(func() { _ = s.Close() })
|
||||||
srv := &Server{Store: s, Log: slog.New(slog.DiscardHandler)}
|
srv := &Server{Store: s, Steps: s, Log: slog.New(slog.DiscardHandler)}
|
||||||
// Composition always gives the dashboard a Gateway contract; task
|
// Composition always gives the dashboard a Gateway contract; task
|
||||||
// actions travel through it now, so a test server without one could
|
// actions travel through it now, so a test server without one could
|
||||||
// only ever answer 503.
|
// only ever answer 503.
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ service StateStoreService {
|
|||||||
// task-scoped grant): a cancel is a dashboard, API and dispatch action
|
// task-scoped grant): a cancel is a dashboard, API and dispatch action
|
||||||
// decided by the Authorizer, not a worker call.
|
// decided by the Authorizer, not a worker call.
|
||||||
rpc CancelExecution(CancelExecutionRequest) returns (CancelExecutionResponse);
|
rpc CancelExecution(CancelExecutionRequest) returns (CancelExecutionResponse);
|
||||||
|
// ListSteps is a dashboard/API/dispatch action (Authorizer: read on the
|
||||||
|
// run), not task-scoped-grant callable like StartStep/FinishStep.
|
||||||
|
rpc ListSteps(ListStepsRequest) returns (ListStepsResponse);
|
||||||
rpc Requeue(RequeueRequest) returns (RequeueResponse);
|
rpc Requeue(RequeueRequest) returns (RequeueResponse);
|
||||||
rpc ParkTask(ParkTaskRequest) returns (ParkTaskResponse);
|
rpc ParkTask(ParkTaskRequest) returns (ParkTaskResponse);
|
||||||
rpc RecoverStale(RecoverStaleRequest) returns (RecoverStaleResponse);
|
rpc RecoverStale(RecoverStaleRequest) returns (RecoverStaleResponse);
|
||||||
@@ -262,7 +265,11 @@ message Task {
|
|||||||
string labels = 7;
|
string labels = 7;
|
||||||
string status = 8;
|
string status = 8;
|
||||||
string workflow = 9;
|
string workflow = 9;
|
||||||
string stage = 10;
|
// Retired: the per-task "current stage" column was overwritten as
|
||||||
|
// workflow.Run advanced and carried no history. step_executions is the
|
||||||
|
// durable per-step record now (docs/prds/execution-tree-state-machine.md);
|
||||||
|
// ListSteps is its read.
|
||||||
|
string stage = 10 [deprecated = true];
|
||||||
string branch = 11;
|
string branch = 11;
|
||||||
string plan = 12;
|
string plan = 12;
|
||||||
string notes = 13;
|
string notes = 13;
|
||||||
@@ -576,6 +583,32 @@ message CancelExecutionResponse {
|
|||||||
repeated int64 cancelled_step_ids = 1;
|
repeated int64 cancelled_step_ids = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StepExecution mirrors internal/domain/workflow/task.StepExecution.
|
||||||
|
message StepExecution {
|
||||||
|
int64 id = 1;
|
||||||
|
int64 execution_id = 2;
|
||||||
|
int64 attempt = 3;
|
||||||
|
// parent_id is 0 for a stage at the tree's root.
|
||||||
|
int64 parent_id = 4;
|
||||||
|
int32 depth = 5;
|
||||||
|
string kind = 6;
|
||||||
|
string name = 7;
|
||||||
|
string status = 8;
|
||||||
|
string detail = 9;
|
||||||
|
int64 tokens_used = 10;
|
||||||
|
google.protobuf.Timestamp started_at = 11;
|
||||||
|
google.protobuf.Timestamp finished_at = 12;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ListStepsRequest {
|
||||||
|
int64 execution_id = 1;
|
||||||
|
// attempt selects one attempt's steps; 0 lists every attempt of the
|
||||||
|
// execution, oldest first -- the dashboard's run-detail rail renders every
|
||||||
|
// attempt from a single call rather than one per attempt.
|
||||||
|
int64 attempt = 2;
|
||||||
|
}
|
||||||
|
message ListStepsResponse { repeated StepExecution steps = 1; }
|
||||||
|
|
||||||
message UpdateRequest { Task task = 1; }
|
message UpdateRequest { Task task = 1; }
|
||||||
message UpdateResponse {}
|
message UpdateResponse {}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user