Merge crew/claude-997: dashboard run detail reads ListSteps; tasks.stage removed
This commit is contained in:
commit
f3ab29570f
39 files changed
+1930
-1275
No files matched your search
@@ -166,7 +166,6 @@ func (a chatTaskListerAdapter) ListChatTasks(ctx context.Context, identity strin
|
||||
Title: task.Title,
|
||||
Status: task.Status,
|
||||
Workflow: task.Workflow,
|
||||
Stage: task.Stage,
|
||||
PRNumber: task.PRNumber,
|
||||
Attempt: task.Attempt,
|
||||
ParkReason: task.ParkReason,
|
||||
|
||||
@@ -343,15 +343,7 @@ func (b *boot) stateStoreDeps(grants *staterpc.TaskGrants) staterpc.Deps {
|
||||
if btc, ok := b.st.(storecontract.BindingTaskCreator); ok {
|
||||
deps.BindingTaskCreator = btc
|
||||
}
|
||||
if wc, ok := b.st.(storecontract.WorkflowCaller); ok {
|
||||
deps.WorkflowCalls = wc
|
||||
}
|
||||
if sr, ok := b.st.(storecontract.StepRecorder); ok {
|
||||
deps.Steps = sr
|
||||
}
|
||||
if ec, ok := b.st.(storecontract.ExecutionCanceller); ok {
|
||||
deps.Canceller = ec
|
||||
}
|
||||
b.executionDeps(&deps)
|
||||
b.accessDeps(&deps)
|
||||
if css, ok := b.st.(storecontract.ConfigSnapshotStore); ok {
|
||||
deps.ConfigSnapshots = css
|
||||
@@ -365,6 +357,24 @@ func (b *boot) stateStoreDeps(grants *staterpc.TaskGrants) staterpc.Deps {
|
||||
return deps
|
||||
}
|
||||
|
||||
// executionDeps wires the execution-tree surfaces (workflow calls, step
|
||||
// recording/reading, cancellation) from the same store, degrading each one
|
||||
// independently the store lacks it rather than failing the boot.
|
||||
func (b *boot) executionDeps(deps *staterpc.Deps) {
|
||||
if wc, ok := b.st.(storecontract.WorkflowCaller); ok {
|
||||
deps.WorkflowCalls = wc
|
||||
}
|
||||
if sr, ok := b.st.(storecontract.StepRecorder); ok {
|
||||
deps.Steps = sr
|
||||
}
|
||||
if ec, ok := b.st.(storecontract.ExecutionCanceller); ok {
|
||||
deps.Canceller = ec
|
||||
}
|
||||
if sr, ok := b.st.(storecontract.StepReader); ok {
|
||||
deps.StepReader = sr
|
||||
}
|
||||
}
|
||||
|
||||
// accessDeps wires the policy chain and its denial records from the same
|
||||
// store (docs/prds/orgs-and-access.md). A store without them -- one that owns
|
||||
// no tenant boundary yet -- degrades the access RPCs rather than failing the
|
||||
|
||||
@@ -90,6 +90,9 @@ func compose(d deps) *webui.Server {
|
||||
if snapshots, ok := d.Store.(storecontract.ConfigSnapshotStore); ok {
|
||||
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
|
||||
// hosting the channels publishes, this one reads. Withholding it left
|
||||
// /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/storecontract"
|
||||
"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/gateway"
|
||||
"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) {
|
||||
st := pgstore.Open(t)
|
||||
defer st.Close()
|
||||
seeded, err := st.EnqueueChatTask(t.Context(), "acme", "widget", "remote summary", "body", "implement", "")
|
||||
if err != nil {
|
||||
if _, err := st.EnqueueChatTask(t.Context(), "acme", "widget", "remote summary", "body", "implement", ""); err != nil {
|
||||
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
|
||||
// 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
|
||||
@@ -129,9 +135,23 @@ func TestUIServesDashboardAgainstRemoteContracts(t *testing.T) {
|
||||
// worker's change capture -- attributed to one attempt, so the assertions
|
||||
// further down read them back through the real client rather than a fake.
|
||||
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{
|
||||
{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{
|
||||
"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) {
|
||||
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()
|
||||
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_FinishStep_FullMethodName = "/state.v1.StateStoreService/FinishStep"
|
||||
StateStoreService_CancelExecution_FullMethodName = "/state.v1.StateStoreService/CancelExecution"
|
||||
StateStoreService_ListSteps_FullMethodName = "/state.v1.StateStoreService/ListSteps"
|
||||
StateStoreService_Requeue_FullMethodName = "/state.v1.StateStoreService/Requeue"
|
||||
StateStoreService_ParkTask_FullMethodName = "/state.v1.StateStoreService/ParkTask"
|
||||
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
|
||||
// decided by the Authorizer, not a worker call.
|
||||
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)
|
||||
ParkTask(ctx context.Context, in *ParkTaskRequest, opts ...grpc.CallOption) (*ParkTaskResponse, 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
|
||||
}
|
||||
|
||||
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) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(RequeueResponse)
|
||||
@@ -1278,6 +1292,9 @@ type StateStoreServiceServer interface {
|
||||
// task-scoped grant): a cancel is a dashboard, API and dispatch action
|
||||
// decided by the Authorizer, not a worker call.
|
||||
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)
|
||||
ParkTask(context.Context, *ParkTaskRequest) (*ParkTaskResponse, 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) {
|
||||
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) {
|
||||
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)
|
||||
}
|
||||
|
||||
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) {
|
||||
in := new(RequeueRequest)
|
||||
if err := dec(in); err != nil {
|
||||
@@ -3425,6 +3463,10 @@ var StateStoreService_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "CancelExecution",
|
||||
Handler: _StateStoreService_CancelExecution_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListSteps",
|
||||
Handler: _StateStoreService_ListSteps_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Requeue",
|
||||
Handler: _StateStoreService_Requeue_Handler,
|
||||
|
||||
@@ -90,6 +90,15 @@ type ExecutionCanceller interface {
|
||||
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
|
||||
// status guard. It is separate from the already broad lifecycle contract so
|
||||
// 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.
|
||||
type Task struct {
|
||||
ID int64
|
||||
Owner, Repo, Identity, Status, Stage, ParkReason string
|
||||
IssueNumber, RetryCount int
|
||||
ForgeBacked bool
|
||||
ID int64
|
||||
Owner, Repo, Identity, Status, ParkReason string
|
||||
IssueNumber, RetryCount int
|
||||
ForgeBacked bool
|
||||
// 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
|
||||
// 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", "")
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -161,8 +161,9 @@ func captureTaskContext(t *testing.T, trees Trees, store Store) *TaskContext {
|
||||
return &TaskContext{
|
||||
Task: &Task{
|
||||
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"},
|
||||
Trees: trees,
|
||||
Store: store,
|
||||
@@ -278,7 +279,7 @@ func TestStageCommitCapturesTheChangedFiles(t *testing.T) {
|
||||
trees := &capturingTrees{commitAllChanged: true, stats: sampleStats()}
|
||||
store := &recordingStore{}
|
||||
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 {
|
||||
t.Fatalf("StageCommit.Run() = %v, want nil", err)
|
||||
@@ -430,7 +431,7 @@ func TestOpenPRCapturesThePullRequestNumber(t *testing.T) {
|
||||
forgeClient := &fakeForge{}
|
||||
tc := captureTaskContext(t, trees, store)
|
||||
tc.Forge = forgeClient
|
||||
tc.Task.Stage = "open-pr"
|
||||
tc.Stage = "open-pr"
|
||||
tc.Task.Title = "widget fails"
|
||||
|
||||
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
|
||||
// the time anyone reads it, so a capture that only reached the live feed
|
||||
// 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)
|
||||
}
|
||||
return stats
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
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:
|
||||
// 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.
|
||||
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"`
|
||||
WorkflowDefinitionDigest string `json:"workflow_definition_digest"`
|
||||
WorkflowDefinitionYAML string `json:"workflow_definition_yaml"`
|
||||
Stage string `json:"stage"`
|
||||
Branch string `json:"branch"`
|
||||
Plan string `json:"plan"`
|
||||
Notes string `json:"notes"`
|
||||
|
||||
@@ -109,6 +109,11 @@ type TaskContext struct {
|
||||
// Dir/Branch are set by the prepare step.
|
||||
Dir 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 string
|
||||
// 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)
|
||||
|
||||
for _, stage := range wf.Stages {
|
||||
t.Stage = stage.Name
|
||||
tc.Stage = stage.Name
|
||||
_ = tc.Store.Update(ctx, t)
|
||||
// Every stage is a StepExecution (docs/prds/execution-tree-state-machine.md):
|
||||
// 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.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)
|
||||
}
|
||||
|
||||
@@ -416,12 +421,12 @@ func park(ctx context.Context, tc *TaskContext, reason string) {
|
||||
t.ParkReason = reason
|
||||
_ = tc.Store.Update(ctx, t)
|
||||
_ = 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
|
||||
// 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
|
||||
// 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 {
|
||||
|
||||
@@ -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", label)
|
||||
if stage := workflowStage(t.Workflow, t.Stage); stage != "" {
|
||||
fmt.Fprintf(&b, " · %s", stage)
|
||||
if t.Workflow != "" {
|
||||
fmt.Fprintf(&b, " · %s", t.Workflow)
|
||||
}
|
||||
if t.Attempt > 1 {
|
||||
fmt.Fprintf(&b, " · attempt %d", t.Attempt)
|
||||
@@ -729,22 +729,6 @@ func formatTasks(tasks []ChatTaskSummary, now time.Time) 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 {
|
||||
icon string
|
||||
label string
|
||||
|
||||
@@ -250,11 +250,11 @@ func TestFormatTasks(t *testing.T) {
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "running task shows workflow/stage and age",
|
||||
name: "running task shows workflow and age",
|
||||
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"
|
||||
@@ -262,10 +262,10 @@ func TestFormatTasks(t *testing.T) {
|
||||
// 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",
|
||||
tasks: []ChatTaskSummary{
|
||||
{ID: 5, Title: "Wedged", Status: taskstate.Running, Workflow: "tdd", Stage: "implement", UpdatedAt: now.Add(-47 * time.Minute)},
|
||||
{ID: 6, Title: "Working", Status: taskstate.Running, Workflow: "tdd", Stage: "implement", UpdatedAt: now.Add(-20 * time.Second)},
|
||||
{ID: 5, Title: "Wedged", Status: taskstate.Running, Workflow: "tdd", UpdatedAt: now.Add(-47 * time.Minute)},
|
||||
{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",
|
||||
|
||||
@@ -35,7 +35,6 @@ type ChatTaskSummary struct {
|
||||
Title string `json:"title"`
|
||||
Status string `json:"status"`
|
||||
Workflow string `json:"workflow,omitempty"`
|
||||
Stage string `json:"stage,omitempty"`
|
||||
PRNumber int `json:"pr_number,omitempty"`
|
||||
// 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
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
-- tasks.stage was the one mutable column recording "which stage is this task
|
||||
-- on", overwritten as workflow.Run advanced and carrying no history: a failed
|
||||
-- attempt could not say which step failed or what ran before it without
|
||||
-- replaying the event stream (docs/prds/execution-tree-state-machine.md,
|
||||
-- "Problem"). step_executions (0017) is now the durable per-step record the
|
||||
-- dashboard's run detail reads (ListSteps), so this column has no remaining
|
||||
-- reader.
|
||||
|
||||
-- +goose Up
|
||||
ALTER TABLE tasks DROP COLUMN stage;
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE tasks ADD COLUMN stage text NOT NULL DEFAULT '';
|
||||
@@ -24,7 +24,7 @@ func (q *Queries) CallStatusDetail(ctx context.Context, taskID int64) (string, e
|
||||
|
||||
const enqueueCallTask = `-- name: EnqueueCallTask :one
|
||||
WITH caller AS (
|
||||
SELECT t.id, t.owner, t.repo, t.issue_number, t.title, t.body, t.labels, t.status, t.workflow, t.stage, t.branch, t.plan, t.notes, t.pr_number, t.tokens_used, t.iterations, t.attempt, t.park_reason, t.watch_comment_id, t.park_class, t.remediation_rounds, t.retry_count, t.source, t.identity, t.binding_id, t.binding_version, t.review_payload, t.workflow_definition_version, t.workflow_definition_digest, t.workflow_definition_yaml, t.created_at, t.updated_at, t.review_cursor, t.inputs, t.org_id, t.workspace_id, t.call_parent_task_id, t.call_depth FROM tasks t WHERE t.id = $1 FOR UPDATE
|
||||
SELECT t.id, t.owner, t.repo, t.issue_number, t.title, t.body, t.labels, t.status, t.workflow, t.branch, t.plan, t.notes, t.pr_number, t.tokens_used, t.iterations, t.attempt, t.park_reason, t.watch_comment_id, t.park_class, t.remediation_rounds, t.retry_count, t.source, t.identity, t.binding_id, t.binding_version, t.review_payload, t.workflow_definition_version, t.workflow_definition_digest, t.workflow_definition_yaml, t.created_at, t.updated_at, t.review_cursor, t.inputs, t.org_id, t.workspace_id, t.call_parent_task_id, t.call_depth FROM tasks t WHERE t.id = $1 FOR UPDATE
|
||||
)
|
||||
INSERT INTO tasks (owner, repo, issue_number, title, body, labels, workflow, source, identity, org_id, workspace_id, inputs, call_parent_task_id, call_depth)
|
||||
SELECT
|
||||
@@ -41,7 +41,7 @@ SELECT
|
||||
caller.id, caller.call_depth + 1
|
||||
FROM caller
|
||||
WHERE caller.status = 'running' AND caller.call_depth + 1 <= $7::int
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, stage, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
|
||||
`
|
||||
|
||||
type EnqueueCallTaskParams struct {
|
||||
@@ -84,7 +84,6 @@ func (q *Queries) EnqueueCallTask(ctx context.Context, arg EnqueueCallTaskParams
|
||||
&i.Labels,
|
||||
&i.Status,
|
||||
&i.Workflow,
|
||||
&i.Stage,
|
||||
&i.Branch,
|
||||
&i.Plan,
|
||||
&i.Notes,
|
||||
|
||||
@@ -348,7 +348,6 @@ type Task struct {
|
||||
Labels string
|
||||
Status string
|
||||
Workflow string
|
||||
Stage string
|
||||
Branch string
|
||||
Plan string
|
||||
Notes string
|
||||
|
||||
@@ -157,6 +157,69 @@ func (q *Queries) InterruptAttemptSteps(ctx context.Context, arg InterruptAttemp
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listStepExecutions = `-- name: ListStepExecutions :many
|
||||
SELECT id, execution_id, attempt, parent_id, depth, kind, name, status, detail, tokens_used, started_at, finished_at
|
||||
FROM step_executions
|
||||
WHERE execution_id = $1::bigint AND ($2::bigint = 0 OR attempt = $2::bigint)
|
||||
ORDER BY attempt, id
|
||||
`
|
||||
|
||||
type ListStepExecutionsParams struct {
|
||||
ExecutionID int64
|
||||
Attempt int64
|
||||
}
|
||||
|
||||
type ListStepExecutionsRow struct {
|
||||
ID int64
|
||||
ExecutionID int64
|
||||
Attempt int64
|
||||
ParentID pgtype.Int8
|
||||
Depth int32
|
||||
Kind string
|
||||
Name string
|
||||
Status string
|
||||
Detail string
|
||||
TokensUsed int64
|
||||
StartedAt pgtype.Timestamptz
|
||||
FinishedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
// attempt = 0 lists every attempt of the execution, oldest first; the index
|
||||
// (execution_id, attempt, id) makes both this and the single-attempt form a
|
||||
// straight index scan.
|
||||
func (q *Queries) ListStepExecutions(ctx context.Context, arg ListStepExecutionsParams) ([]ListStepExecutionsRow, error) {
|
||||
rows, err := q.db.Query(ctx, listStepExecutions, arg.ExecutionID, arg.Attempt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListStepExecutionsRow
|
||||
for rows.Next() {
|
||||
var i ListStepExecutionsRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ExecutionID,
|
||||
&i.Attempt,
|
||||
&i.ParentID,
|
||||
&i.Depth,
|
||||
&i.Kind,
|
||||
&i.Name,
|
||||
&i.Status,
|
||||
&i.Detail,
|
||||
&i.TokensUsed,
|
||||
&i.StartedAt,
|
||||
&i.FinishedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const lockExecutionForStep = `-- name: LockExecutionForStep :one
|
||||
|
||||
SELECT id, status, org_id, workspace_id, owner, repo, issue_number, workflow, attempt
|
||||
|
||||
@@ -28,7 +28,7 @@ func (q *Queries) ArchiveTaskDelete(ctx context.Context, arg ArchiveTaskDeletePa
|
||||
}
|
||||
|
||||
const beginRemediationTask = `-- name: BeginRemediationTask :execrows
|
||||
UPDATE tasks SET status = 'queued', workflow = 'remediate', stage = '', park_reason = '', park_class = 'needs_human', review_payload = $2, updated_at = now()
|
||||
UPDATE tasks SET status = 'queued', workflow = 'remediate', park_reason = '', park_class = 'needs_human', review_payload = $2, updated_at = now()
|
||||
WHERE id = $1 AND status = 'pr_open'
|
||||
`
|
||||
|
||||
@@ -48,7 +48,7 @@ func (q *Queries) BeginRemediationTask(ctx context.Context, arg BeginRemediation
|
||||
const claimByIssue = `-- name: ClaimByIssue :one
|
||||
UPDATE tasks SET status = 'running', attempt = attempt + 1, updated_at = now()
|
||||
WHERE owner = $1 AND repo = $2 AND issue_number = $3 AND status = 'queued'
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, stage, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
|
||||
`
|
||||
|
||||
type ClaimByIssueParams struct {
|
||||
@@ -70,7 +70,6 @@ func (q *Queries) ClaimByIssue(ctx context.Context, arg ClaimByIssueParams) (Tas
|
||||
&i.Labels,
|
||||
&i.Status,
|
||||
&i.Workflow,
|
||||
&i.Stage,
|
||||
&i.Branch,
|
||||
&i.Plan,
|
||||
&i.Notes,
|
||||
@@ -113,7 +112,7 @@ WHERE id = (
|
||||
FOR UPDATE SKIP LOCKED
|
||||
LIMIT 1
|
||||
)
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, stage, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
|
||||
`
|
||||
|
||||
// FOR UPDATE SKIP LOCKED replaces the SQLite single-writer assumption: two
|
||||
@@ -132,7 +131,6 @@ func (q *Queries) ClaimNextTask(ctx context.Context) (Task, error) {
|
||||
&i.Labels,
|
||||
&i.Status,
|
||||
&i.Workflow,
|
||||
&i.Stage,
|
||||
&i.Branch,
|
||||
&i.Plan,
|
||||
&i.Notes,
|
||||
@@ -270,7 +268,7 @@ VALUES (
|
||||
'default'
|
||||
)
|
||||
)
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, stage, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
|
||||
`
|
||||
|
||||
type InsertChatTaskParams struct {
|
||||
@@ -308,7 +306,6 @@ func (q *Queries) InsertChatTask(ctx context.Context, arg InsertChatTaskParams)
|
||||
&i.Labels,
|
||||
&i.Status,
|
||||
&i.Workflow,
|
||||
&i.Stage,
|
||||
&i.Branch,
|
||||
&i.Plan,
|
||||
&i.Notes,
|
||||
@@ -415,7 +412,7 @@ func (q *Queries) ListOpenPRs(ctx context.Context) ([]ListOpenPRsRow, error) {
|
||||
}
|
||||
|
||||
const listTaskSummaries = `-- name: ListTaskSummaries :many
|
||||
SELECT id, owner, repo, issue_number, title, status, workflow, stage,
|
||||
SELECT id, owner, repo, issue_number, title, status, workflow,
|
||||
pr_number, tokens_used, iterations, attempt, park_reason, retry_count,
|
||||
created_at, updated_at, plan, source, identity, binding_id, binding_version
|
||||
FROM tasks ORDER BY updated_at DESC LIMIT $1
|
||||
@@ -429,7 +426,6 @@ type ListTaskSummariesRow struct {
|
||||
Title string
|
||||
Status string
|
||||
Workflow string
|
||||
Stage string
|
||||
PrNumber int64
|
||||
TokensUsed int64
|
||||
Iterations int64
|
||||
@@ -465,7 +461,6 @@ func (q *Queries) ListTaskSummaries(ctx context.Context, limit int32) ([]ListTas
|
||||
&i.Title,
|
||||
&i.Status,
|
||||
&i.Workflow,
|
||||
&i.Stage,
|
||||
&i.PrNumber,
|
||||
&i.TokensUsed,
|
||||
&i.Iterations,
|
||||
@@ -545,7 +540,7 @@ func (q *Queries) RecoverStaleTasks(ctx context.Context) (int64, error) {
|
||||
const requeueTask = `-- name: RequeueTask :execrows
|
||||
UPDATE tasks SET status = 'queued',
|
||||
workflow = CASE WHEN $1::text = '' THEN workflow ELSE $1::text END,
|
||||
stage = '', park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
WHERE id = $2 AND status = $3
|
||||
`
|
||||
|
||||
@@ -566,7 +561,7 @@ func (q *Queries) RequeueTask(ctx context.Context, arg RequeueTaskParams) (int64
|
||||
const retryTask = `-- name: RetryTask :execrows
|
||||
UPDATE tasks SET status = 'queued', retry_count = retry_count + 1,
|
||||
workflow = CASE WHEN $1::text = '' THEN workflow ELSE $1::text END,
|
||||
stage = '', park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
WHERE id = $2 AND status = $3
|
||||
`
|
||||
|
||||
@@ -625,7 +620,7 @@ func (q *Queries) StampTaskBinding(ctx context.Context, arg StampTaskBindingPara
|
||||
}
|
||||
|
||||
const taskByID = `-- name: TaskByID :one
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, stage, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth FROM tasks WHERE id = $1
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth FROM tasks WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) TaskByID(ctx context.Context, id int64) (Task, error) {
|
||||
@@ -641,7 +636,6 @@ func (q *Queries) TaskByID(ctx context.Context, id int64) (Task, error) {
|
||||
&i.Labels,
|
||||
&i.Status,
|
||||
&i.Workflow,
|
||||
&i.Stage,
|
||||
&i.Branch,
|
||||
&i.Plan,
|
||||
&i.Notes,
|
||||
@@ -675,7 +669,7 @@ func (q *Queries) TaskByID(ctx context.Context, id int64) (Task, error) {
|
||||
}
|
||||
|
||||
const taskByIssue = `-- name: TaskByIssue :one
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, stage, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth FROM tasks WHERE owner = $1 AND repo = $2 AND issue_number = $3
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth FROM tasks WHERE owner = $1 AND repo = $2 AND issue_number = $3
|
||||
`
|
||||
|
||||
type TaskByIssueParams struct {
|
||||
@@ -697,7 +691,6 @@ func (q *Queries) TaskByIssue(ctx context.Context, arg TaskByIssueParams) (Task,
|
||||
&i.Labels,
|
||||
&i.Status,
|
||||
&i.Workflow,
|
||||
&i.Stage,
|
||||
&i.Branch,
|
||||
&i.Plan,
|
||||
&i.Notes,
|
||||
@@ -731,7 +724,7 @@ func (q *Queries) TaskByIssue(ctx context.Context, arg TaskByIssueParams) (Task,
|
||||
}
|
||||
|
||||
const taskByPR = `-- name: TaskByPR :one
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, stage, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth FROM tasks WHERE owner = $1 AND repo = $2 AND pr_number = $3 AND status = $4
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth FROM tasks WHERE owner = $1 AND repo = $2 AND pr_number = $3 AND status = $4
|
||||
`
|
||||
|
||||
type TaskByPRParams struct {
|
||||
@@ -762,7 +755,6 @@ func (q *Queries) TaskByPR(ctx context.Context, arg TaskByPRParams) (Task, error
|
||||
&i.Labels,
|
||||
&i.Status,
|
||||
&i.Workflow,
|
||||
&i.Stage,
|
||||
&i.Branch,
|
||||
&i.Plan,
|
||||
&i.Notes,
|
||||
@@ -847,11 +839,11 @@ func (q *Queries) UpdateReviewPayloadTask(ctx context.Context, arg UpdateReviewP
|
||||
}
|
||||
|
||||
const updateTask = `-- name: UpdateTask :exec
|
||||
UPDATE tasks SET workflow = $2, stage = $3, branch = $4, plan = $5, notes = $6,
|
||||
pr_number = $7, tokens_used = $8, iterations = $9, park_reason = $10,
|
||||
watch_comment_id = $11, retry_count = $12, remediation_rounds = $13,
|
||||
review_payload = $14, workflow_definition_version = $15,
|
||||
workflow_definition_digest = $16, workflow_definition_yaml = $17,
|
||||
UPDATE tasks SET workflow = $2, branch = $3, plan = $4, notes = $5,
|
||||
pr_number = $6, tokens_used = $7, iterations = $8, park_reason = $9,
|
||||
watch_comment_id = $10, retry_count = $11, remediation_rounds = $12,
|
||||
review_payload = $13, workflow_definition_version = $14,
|
||||
workflow_definition_digest = $15, workflow_definition_yaml = $16,
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
`
|
||||
@@ -859,7 +851,6 @@ WHERE id = $1
|
||||
type UpdateTaskParams struct {
|
||||
ID int64
|
||||
Workflow string
|
||||
Stage string
|
||||
Branch string
|
||||
Plan string
|
||||
Notes string
|
||||
@@ -880,7 +871,6 @@ func (q *Queries) UpdateTask(ctx context.Context, arg UpdateTaskParams) error {
|
||||
_, err := q.db.Exec(ctx, updateTask,
|
||||
arg.ID,
|
||||
arg.Workflow,
|
||||
arg.Stage,
|
||||
arg.Branch,
|
||||
arg.Plan,
|
||||
arg.Notes,
|
||||
|
||||
@@ -61,3 +61,12 @@ UPDATE step_executions
|
||||
SET status = 'interrupted', finished_at = now()
|
||||
WHERE execution_id = $1 AND attempt = $2 AND status = 'running'
|
||||
RETURNING id, name;
|
||||
|
||||
-- name: ListStepExecutions :many
|
||||
-- attempt = 0 lists every attempt of the execution, oldest first; the index
|
||||
-- (execution_id, attempt, id) makes both this and the single-attempt form a
|
||||
-- straight index scan.
|
||||
SELECT id, execution_id, attempt, parent_id, depth, kind, name, status, detail, tokens_used, started_at, finished_at
|
||||
FROM step_executions
|
||||
WHERE execution_id = @execution_id::bigint AND (@attempt::bigint = 0 OR attempt = @attempt::bigint)
|
||||
ORDER BY attempt, id;
|
||||
@@ -29,7 +29,7 @@ SELECT * FROM tasks WHERE owner = $1 AND repo = $2 AND pr_number = $3 AND status
|
||||
-- The dashboard's list. This projection is deliberately narrow: Plan gates
|
||||
-- the "Decision required" panel and Source labels the row, and widening it
|
||||
-- back would send rows without them.
|
||||
SELECT id, owner, repo, issue_number, title, status, workflow, stage,
|
||||
SELECT id, owner, repo, issue_number, title, status, workflow,
|
||||
pr_number, tokens_used, iterations, attempt, park_reason, retry_count,
|
||||
created_at, updated_at, plan, source, identity, binding_id, binding_version
|
||||
FROM tasks ORDER BY updated_at DESC LIMIT $1;
|
||||
@@ -65,11 +65,11 @@ RETURNING *;
|
||||
UPDATE tasks SET binding_id = $2, binding_version = $3, inputs = $4 WHERE id = $1;
|
||||
|
||||
-- name: UpdateTask :exec
|
||||
UPDATE tasks SET workflow = $2, stage = $3, branch = $4, plan = $5, notes = $6,
|
||||
pr_number = $7, tokens_used = $8, iterations = $9, park_reason = $10,
|
||||
watch_comment_id = $11, retry_count = $12, remediation_rounds = $13,
|
||||
review_payload = $14, workflow_definition_version = $15,
|
||||
workflow_definition_digest = $16, workflow_definition_yaml = $17,
|
||||
UPDATE tasks SET workflow = $2, branch = $3, plan = $4, notes = $5,
|
||||
pr_number = $6, tokens_used = $7, iterations = $8, park_reason = $9,
|
||||
watch_comment_id = $10, retry_count = $11, remediation_rounds = $12,
|
||||
review_payload = $13, workflow_definition_version = $14,
|
||||
workflow_definition_digest = $15, workflow_definition_yaml = $16,
|
||||
updated_at = now()
|
||||
WHERE id = $1;
|
||||
|
||||
@@ -129,7 +129,7 @@ WHERE owner = $1 AND repo = $2 AND issue_number = $3 AND status = 'queued'
|
||||
RETURNING *;
|
||||
|
||||
-- name: BeginRemediationTask :execrows
|
||||
UPDATE tasks SET status = 'queued', workflow = 'remediate', stage = '', park_reason = '', park_class = 'needs_human', review_payload = $2, updated_at = now()
|
||||
UPDATE tasks SET status = 'queued', workflow = 'remediate', park_reason = '', park_class = 'needs_human', review_payload = $2, updated_at = now()
|
||||
WHERE id = $1 AND status = 'pr_open';
|
||||
|
||||
-- name: UpdateReviewPayloadTask :execrows
|
||||
@@ -143,13 +143,13 @@ WHERE id = $1 AND status = 'pr_open';
|
||||
-- name: RequeueTask :execrows
|
||||
UPDATE tasks SET status = 'queued',
|
||||
workflow = CASE WHEN @workflow::text = '' THEN workflow ELSE @workflow::text END,
|
||||
stage = '', park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
WHERE id = @id AND status = @from_status;
|
||||
|
||||
-- name: RetryTask :execrows
|
||||
UPDATE tasks SET status = 'queued', retry_count = retry_count + 1,
|
||||
workflow = CASE WHEN @workflow::text = '' THEN workflow ELSE @workflow::text END,
|
||||
stage = '', park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
WHERE id = @id AND status = @from_status;
|
||||
|
||||
-- name: ArchiveTaskDelete :execrows
|
||||
|
||||
@@ -224,6 +224,41 @@ func stepEventData(to taskstate.StepStatus, durationMS int64, detail string) map
|
||||
return data
|
||||
}
|
||||
|
||||
// ListSteps reads one execution's recorded steps, every attempt oldest first
|
||||
// when attempt is 0, or just the one it names. It is the dashboard run
|
||||
// detail's authoritative source (docs/prds/execution-tree-state-machine.md),
|
||||
// replacing the fold over stage_start/stage_finish events tasks.stage used to
|
||||
// back -- unlike StartStep/FinishStep, this is a plain read with no
|
||||
// transition to guard, so it takes no transaction.
|
||||
func (s *Store) ListSteps(ctx context.Context, executionID int64, attempt int) ([]task.StepExecution, error) {
|
||||
rows, err := s.queries().ListStepExecutions(ctx, postgresdb.ListStepExecutionsParams{
|
||||
ExecutionID: executionID, Attempt: int64(attempt),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
steps := make([]task.StepExecution, len(rows))
|
||||
for i, r := range rows {
|
||||
steps[i] = task.StepExecution{
|
||||
ID: r.ID, ExecutionID: r.ExecutionID, Attempt: int(r.Attempt),
|
||||
ParentID: nullableInt64(r.ParentID), Depth: int(r.Depth),
|
||||
Kind: r.Kind, Name: r.Name, Status: taskstate.StepStatus(r.Status),
|
||||
Detail: r.Detail, TokensUsed: r.TokensUsed,
|
||||
StartedAt: r.StartedAt.Time, FinishedAt: r.FinishedAt.Time,
|
||||
}
|
||||
}
|
||||
return steps, nil
|
||||
}
|
||||
|
||||
// nullableInt64 reads a pgtype.Int8 the way stepParentID wrote it: absent
|
||||
// means 0, a stage at the tree's root.
|
||||
func nullableInt64(v pgtype.Int8) int64 {
|
||||
if !v.Valid {
|
||||
return 0
|
||||
}
|
||||
return v.Int64
|
||||
}
|
||||
|
||||
// stepParentID encodes the nullable parent id an insert takes: 0 means "no
|
||||
// parent" -- a stage at the tree's root -- which the column stores as NULL
|
||||
// rather than as a reference to a row that does not exist.
|
||||
|
||||
@@ -237,6 +237,71 @@ func TestFinishStepRefusesStaleAndForeign(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestListStepsOrdersByAttemptThenID is the dashboard run detail's
|
||||
// authoritative read (docs/prds/execution-tree-state-machine.md): every
|
||||
// attempt in one call when attempt is 0, one attempt's steps when it names
|
||||
// one, both ordered oldest first.
|
||||
func TestListStepsOrdersByAttemptThenID(t *testing.T) {
|
||||
s := storeFor(t)
|
||||
execution := runningExecution(t, s)
|
||||
|
||||
firstStepID, _, err := s.StartStep(t.Context(), task.StepStart{
|
||||
ExecutionID: execution.ID, Attempt: execution.Attempt, Kind: task.StepKindStage, Name: "plan",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("StartStep: %v", err)
|
||||
}
|
||||
if _, err := s.FinishStep(t.Context(), task.StepFinish{
|
||||
StepID: firstStepID, ExecutionID: execution.ID,
|
||||
From: taskstate.StepRunning, To: taskstate.StepSucceeded, Detail: "planned", TokensUsed: 42,
|
||||
}); err != nil {
|
||||
t.Fatalf("FinishStep: %v", err)
|
||||
}
|
||||
secondStepID, _, err := s.StartStep(t.Context(), task.StepStart{
|
||||
ExecutionID: execution.ID, Attempt: execution.Attempt, Kind: task.StepKindStage, Name: "implement",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("StartStep: %v", err)
|
||||
}
|
||||
|
||||
steps, err := s.ListSteps(t.Context(), execution.ID, execution.Attempt)
|
||||
if err != nil {
|
||||
t.Fatalf("ListSteps: %v", err)
|
||||
}
|
||||
if len(steps) != 2 {
|
||||
t.Fatalf("ListSteps len = %d, want 2", len(steps))
|
||||
}
|
||||
if steps[0].ID != firstStepID || steps[0].Name != "plan" || steps[0].Status != taskstate.StepSucceeded ||
|
||||
steps[0].Detail != "planned" || steps[0].TokensUsed != 42 || steps[0].StartedAt.IsZero() || steps[0].FinishedAt.IsZero() {
|
||||
t.Fatalf("steps[0] = %+v, want the finished plan step", steps[0])
|
||||
}
|
||||
if steps[1].ID != secondStepID || steps[1].Name != "implement" || steps[1].Status != taskstate.StepRunning ||
|
||||
steps[1].StartedAt.IsZero() || !steps[1].FinishedAt.IsZero() {
|
||||
t.Fatalf("steps[1] = %+v, want the still-running implement step", steps[1])
|
||||
}
|
||||
|
||||
// attempt 0 lists every attempt; there is only one here, so the result is
|
||||
// the same, proving the "list everything" branch is reachable and correct
|
||||
// rather than coincidentally equal to a hardcoded attempt.
|
||||
all, err := s.ListSteps(t.Context(), execution.ID, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("ListSteps(attempt=0): %v", err)
|
||||
}
|
||||
if len(all) != 2 {
|
||||
t.Fatalf("ListSteps(attempt=0) len = %d, want 2", len(all))
|
||||
}
|
||||
|
||||
// A different execution's steps never appear, however queried.
|
||||
other := runningExecution(t, s)
|
||||
otherSteps, err := s.ListSteps(t.Context(), other.ID, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("ListSteps other execution: %v", err)
|
||||
}
|
||||
if len(otherSteps) != 0 {
|
||||
t.Fatalf("ListSteps other execution = %+v, want none", otherSteps)
|
||||
}
|
||||
}
|
||||
|
||||
// A late FinishStep for a step another path already finished is stale, the
|
||||
// PRD's named wire behaviour: errors.Is matches on the client too.
|
||||
func TestFinishStepOffTablePairIsIllegalOverTheTable(t *testing.T) {
|
||||
|
||||
@@ -93,7 +93,6 @@ func taskFromRow(t postgresdb.Task) *workflow.Task {
|
||||
WorkflowDefinitionVersion: t.WorkflowDefinitionVersion,
|
||||
WorkflowDefinitionDigest: t.WorkflowDefinitionDigest,
|
||||
WorkflowDefinitionYAML: t.WorkflowDefinitionYaml,
|
||||
Stage: t.Stage,
|
||||
Branch: t.Branch,
|
||||
Plan: t.Plan,
|
||||
Notes: t.Notes,
|
||||
@@ -282,7 +281,6 @@ func (s *Store) Update(ctx context.Context, t *workflow.Task) error {
|
||||
return s.queries().UpdateTask(ctx, postgresdb.UpdateTaskParams{
|
||||
ID: t.ID,
|
||||
Workflow: t.Workflow,
|
||||
Stage: t.Stage,
|
||||
Branch: t.Branch,
|
||||
Plan: t.Plan,
|
||||
Notes: t.Notes,
|
||||
@@ -527,7 +525,7 @@ func (s *Store) Tasks(ctx context.Context, limit int) ([]workflow.Task, error) {
|
||||
for _, r := range rows {
|
||||
tasks = append(tasks, workflow.Task{
|
||||
ID: r.ID, Owner: r.Owner, Repo: r.Repo, IssueNumber: int(r.IssueNumber),
|
||||
Title: r.Title, Status: r.Status, Workflow: r.Workflow, Stage: r.Stage,
|
||||
Title: r.Title, Status: r.Status, Workflow: r.Workflow,
|
||||
PRNumber: int(r.PrNumber), TokensUsed: int(r.TokensUsed), Iterations: int(r.Iterations),
|
||||
Attempt: int(r.Attempt), ParkReason: r.ParkReason, RetryCount: int(r.RetryCount),
|
||||
CreatedAt: r.CreatedAt, UpdatedAt: r.UpdatedAt, Plan: r.Plan, Source: r.Source,
|
||||
|
||||
@@ -155,6 +155,18 @@ func (c *Client) FinishStep(ctx context.Context, s task.StepFinish) (events.Even
|
||||
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 {
|
||||
_, err := c.client.Update(ctx, &pb.UpdateRequest{Task: taskProto(t)})
|
||||
return unmapError(err)
|
||||
|
||||
@@ -106,6 +106,11 @@ type Deps struct {
|
||||
// an operator action's guarded write over the execution and its steps.
|
||||
// Optional: nil answers the RPC with codes.Unavailable.
|
||||
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
|
||||
// (docs/prds/eda-playbook-engine.md gap 2). Optional: nil disables the
|
||||
// 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
|
||||
}
|
||||
|
||||
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) {
|
||||
if r.Task == nil {
|
||||
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/events"
|
||||
"github.com/samcharles93/archie-core/internal/logging"
|
||||
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||
)
|
||||
|
||||
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{
|
||||
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,
|
||||
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),
|
||||
Attempt: int64(t.Attempt), ParkReason: t.ParkReason, RetryCount: int64(t.RetryCount),
|
||||
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{
|
||||
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,
|
||||
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),
|
||||
Attempt: int(t.Attempt), ParkReason: t.ParkReason, RetryCount: int(t.RetryCount),
|
||||
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 {
|
||||
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 {
|
||||
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
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||
"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
|
||||
@@ -66,7 +67,12 @@ type taskStageView struct {
|
||||
}
|
||||
|
||||
// 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) {
|
||||
t, ok := s.taskByPathID(w, r)
|
||||
if !ok {
|
||||
@@ -77,7 +83,15 @@ func (s *Server) handleTaskAttempts(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
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{
|
||||
TaskID: t.ID,
|
||||
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
|
||||
// deliberately task-agnostic producer carries it -- so grouping them would
|
||||
// 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)
|
||||
numbers := make([]int, 0, 4)
|
||||
unattributed := 0
|
||||
@@ -161,21 +175,34 @@ func attemptsFromEvents(evs []events.Event, taskStatus string, currentAttempt in
|
||||
|
||||
attempts := make([]taskAttemptView, 0, len(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
|
||||
}
|
||||
|
||||
// attemptRail derives one attempt's status, bounds and stages from its events.
|
||||
func attemptRail(number int, evs []events.Event, taskStatus string, currentAttempt int) taskAttemptView {
|
||||
// stepsForAttempt filters ListSteps' full-execution result to one attempt's
|
||||
// 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
|
||||
// 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
|
||||
// as interrupted rather than left looking permanently in flight.
|
||||
inFlight := number == currentAttempt && taskStatus == task.StatusRunning
|
||||
|
||||
first, last := attemptBounds(evs)
|
||||
stages := foldStages(evs, inFlight)
|
||||
stages := stageViewsFromSteps(steps, inFlight)
|
||||
attempt := taskAttemptView{
|
||||
Attempt: number,
|
||||
Status: attemptStatus(stages, inFlight),
|
||||
@@ -215,34 +242,57 @@ func attemptBounds(evs []events.Event) (first, last time.Time) {
|
||||
return first, last
|
||||
}
|
||||
|
||||
// foldStages builds an attempt's ordered stage occurrences. A stage start is
|
||||
// folded as an OPEN stage (status empty) until a matching finish closes it;
|
||||
// resolving what is left needs the task's own record, so an open stage is
|
||||
// running only while the daemon is executing this attempt and interrupted
|
||||
// otherwise.
|
||||
func foldStages(evs []events.Event, inFlight bool) []taskStageView {
|
||||
// stageViewsFromSteps builds an attempt's ordered stage occurrences directly
|
||||
// from its recorded StepExecutions -- the authoritative record
|
||||
// (docs/prds/execution-tree-state-machine.md), not a fold over
|
||||
// stage_start/stage_finish events. Only kind "stage" steps are shown: agent
|
||||
// and call steps are the tree's own detail, not this rail's.
|
||||
func stageViewsFromSteps(steps []task.StepExecution, inFlight bool) []taskStageView {
|
||||
stages := []taskStageView{}
|
||||
for _, e := range evs {
|
||||
switch e.Kind {
|
||||
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 != "" {
|
||||
for _, s := range steps {
|
||||
if s.Kind != task.StepKindStage {
|
||||
continue
|
||||
}
|
||||
stages[i].Status = attemptStatusInterrupted
|
||||
if inFlight {
|
||||
stages[i].Status = attemptStatusRunning
|
||||
view := taskStageView{Name: s.Name, Seq: len(stages), Status: mapStepStatus(s.Status, inFlight)}
|
||||
if s.Status == taskstate.StepFailed {
|
||||
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
|
||||
}
|
||||
|
||||
// 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
|
||||
// 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
|
||||
@@ -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 {
|
||||
for _, s := range stages {
|
||||
if s.Status == status {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -11,19 +12,29 @@ import (
|
||||
"time"
|
||||
|
||||
"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/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
|
||||
// and duration asserted below is a literal rather than a tolerance.
|
||||
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 {
|
||||
return events.Event{Kind: events.KindStageStart, TaskID: taskID, Attempt: attempt, Stage: stage, At: at}
|
||||
}
|
||||
|
||||
func stageFinishEvent(taskID int64, attempt int, stage string, at time.Time, data map[string]any) events.Event {
|
||||
return events.Event{Kind: events.KindStageFinish, TaskID: taskID, Attempt: attempt, Stage: stage, At: at, Data: data}
|
||||
// attemptEvent stands in for the events that still drive attempt bounds and
|
||||
// counts (attemptsFromEvents), independent of the stage rail those events
|
||||
// used to also back.
|
||||
func attemptEvent(taskID int64, attempt int, at time.Time) events.Event {
|
||||
return events.Event{Kind: events.KindAgentFinish, TaskID: taskID, Attempt: attempt, At: at}
|
||||
}
|
||||
|
||||
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
|
||||
// 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
|
||||
@@ -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
|
||||
// case states the derivation it expects without a struct literal per stage:
|
||||
// "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 {
|
||||
if ms == nil {
|
||||
return "?"
|
||||
@@ -118,161 +119,158 @@ func durationToken(ms *int64) string {
|
||||
return strconv.FormatInt(*ms, 10)
|
||||
}
|
||||
|
||||
// TestAttemptsFromEventsDerivesEveryRailRule is the table behind R1: every
|
||||
// status rule the attempt rail depends on, one case each, plus the cases that
|
||||
// would otherwise be answered by inventing data (a finish with no start, an
|
||||
// event set with no stage information, events carrying no attempt at all).
|
||||
func TestAttemptsFromEventsDerivesEveryRailRule(t *testing.T) {
|
||||
// summarizeStages renders a stage list the same way summarizeAttemptRail's
|
||||
// inner loop does, for a test that exercises stageViewsFromSteps alone.
|
||||
func summarizeStages(stages []taskStageView) string {
|
||||
tokens := make([]string, 0, len(stages))
|
||||
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
|
||||
duration := func(ms int64) map[string]any { return map[string]any{"duration_ms": ms} }
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
taskStatus string
|
||||
currentAttempt int
|
||||
evs []events.Event
|
||||
want string
|
||||
steps []task.StepExecution
|
||||
wantAttempts []int
|
||||
wantUnattributed int
|
||||
}{
|
||||
{
|
||||
name: "a finished stage is ok and the attempt reports its measured span",
|
||||
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",
|
||||
name: "a later attempt does not absorb the earlier attempt's steps",
|
||||
taskStatus: workflow.StatusRunning, currentAttempt: 2,
|
||||
evs: []events.Event{stageStartEvent(1, 2, "implement", at(0))},
|
||||
want: "2:running[implement:running:?] ?",
|
||||
},
|
||||
{
|
||||
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:?] ?",
|
||||
evs: []events.Event{attemptEvent(1, 1, at(0)), attemptEvent(1, 2, at(time.Second))},
|
||||
steps: []task.StepExecution{stageStep("prepare", 1, taskstate.StepSucceeded, at(0), at(time.Second), "")},
|
||||
wantAttempts: []int{1, 2},
|
||||
},
|
||||
{
|
||||
name: "events carrying no attempt are counted, never grouped",
|
||||
taskStatus: workflow.StatusQueued, currentAttempt: 0,
|
||||
evs: []events.Event{
|
||||
{Kind: events.KindStageStart, TaskID: 1, Stage: "prepare", At: at(0)},
|
||||
{Kind: events.KindStageFinish, TaskID: 1, Stage: "prepare", At: at(time.Second), Data: duration(1000)},
|
||||
},
|
||||
evs: []events.Event{{Kind: events.KindAgentFinish, TaskID: 1, At: at(0)}, {Kind: events.KindAgentFinish, TaskID: 1, At: at(time.Second)}},
|
||||
wantUnattributed: 2,
|
||||
},
|
||||
{
|
||||
name: "a task with no events has no attempts and nothing unattributed",
|
||||
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,
|
||||
evs: []events.Event{
|
||||
{Kind: events.KindAgentFinish, TaskID: 1, Attempt: 1, At: at(0), Data: map[string]any{"status": "ok"}},
|
||||
},
|
||||
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[] ?",
|
||||
evs: []events.Event{attemptEvent(1, 1, at(0))},
|
||||
wantAttempts: []int{1},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
attempts, unattributed := attemptsFromEvents(tt.evs, tt.taskStatus, tt.currentAttempt)
|
||||
if got := summarizeAttemptRail(attempts); got != tt.want {
|
||||
t.Errorf("rail = %q, want %q", got, tt.want)
|
||||
attempts, unattributed := attemptsFromEvents(tt.evs, tt.steps, tt.taskStatus, tt.currentAttempt)
|
||||
var got []int
|
||||
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 {
|
||||
t.Errorf("unattributed = %d, want %d", unattributed, tt.wantUnattributed)
|
||||
@@ -287,17 +285,67 @@ func TestAttemptsFromEventsDerivesEveryRailRule(t *testing.T) {
|
||||
// attempt 2's stages.
|
||||
func TestHandleTaskAttemptsRendersBothAttemptsOfARetry(t *testing.T) {
|
||||
srv := newTestServer(t)
|
||||
current := twoAttemptTask(t, srv)
|
||||
at := railBase.Add
|
||||
ctx := t.Context()
|
||||
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)))
|
||||
insertTaskEvent(t, srv, stageFinishEvent(current.ID, 1, "prepare", at(1200*time.Millisecond),
|
||||
map[string]any{"duration_ms": int64(1200)}))
|
||||
insertTaskEvent(t, srv, stageStartEvent(current.ID, 1, "implement", at(1323*time.Millisecond)))
|
||||
insertTaskEvent(t, srv, stageFinishEvent(current.ID, 1, "implement", at(231323*time.Millisecond),
|
||||
map[string]any{"duration_ms": int64(230000), "error": "stage implement: builder exited 1"}))
|
||||
insertTaskEvent(t, srv, stageStartEvent(current.ID, 2, "implement", at(time.Hour)))
|
||||
// Not twoAttemptTask: StartStep guards on the execution's own current
|
||||
// attempt (a step named for a superseded attempt is a stale transition
|
||||
// by design -- steps.go, "a caller naming one the execution no longer
|
||||
// runs is describing a run that is over"), so attempt 1's steps have to
|
||||
// be recorded while the task is actually on attempt 1, before the retry
|
||||
// that moves it to attempt 2.
|
||||
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"))
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d, body %s", w.Code, w.Body)
|
||||
@@ -345,14 +393,13 @@ func TestHandleTaskAttemptsRendersBothAttemptsOfARetry(t *testing.T) {
|
||||
if first.EventCount != 4 {
|
||||
t.Errorf("attempt 1 event_count = %d, want 4", first.EventCount)
|
||||
}
|
||||
if first.StartedAt == nil || !first.StartedAt.Equal(at(0)) {
|
||||
t.Errorf("attempt 1 started_at = %v, want %v", first.StartedAt, at(0))
|
||||
// StartStep/FinishStep stamp their events with the store's own clock, so
|
||||
// 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)) {
|
||||
t.Errorf("attempt 1 finished_at = %v, want %v", first.FinishedAt, at(231323*time.Millisecond))
|
||||
}
|
||||
if first.DurationMS == nil || *first.DurationMS != 231323 {
|
||||
t.Errorf("attempt 1 duration_ms = %v, want 231323", first.DurationMS)
|
||||
if first.DurationMS == nil || *first.DurationMS < 0 {
|
||||
t.Errorf("attempt 1 duration_ms = %v, want a non-negative measured span", first.DurationMS)
|
||||
}
|
||||
if len(first.Stages) != 2 {
|
||||
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 != "" {
|
||||
t.Errorf("stage 0 = %+v, want prepare/0/ok with no error", prepare)
|
||||
}
|
||||
if prepare.DurationMS == nil || *prepare.DurationMS != 1200 {
|
||||
t.Errorf("stage 0 duration_ms = %v, want 1200", prepare.DurationMS)
|
||||
}
|
||||
if prepare.StartedAt == nil || !prepare.StartedAt.Equal(at(0)) {
|
||||
t.Errorf("stage 0 started_at = %v, want %v", prepare.StartedAt, at(0))
|
||||
// StartStep/FinishStep stamp started_at/finished_at with the store's own
|
||||
// clock (now()), not a caller-supplied time, so only their presence and
|
||||
// non-negativity are checked here -- railBase no longer applies to a step
|
||||
// row the way it did to a hand-inserted event.
|
||||
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]
|
||||
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" {
|
||||
t.Errorf("stage 1 error = %q, want the recorded error text", implement.Error)
|
||||
}
|
||||
if implement.DurationMS == nil || *implement.DurationMS != 230000 {
|
||||
t.Errorf("stage 1 duration_ms = %v, want 230000", implement.DurationMS)
|
||||
if implement.DurationMS == nil || *implement.DurationMS < 0 {
|
||||
t.Errorf("stage 1 duration_ms = %v, want a non-negative measured duration", implement.DurationMS)
|
||||
}
|
||||
|
||||
second := body.Attempts[1]
|
||||
@@ -431,9 +479,8 @@ func TestHandleTaskAttemptsSeparatesUnattributedEventsFromAFirstRun(t *testing.T
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
insertTaskEvent(t, srv, stageStartEvent(task.ID, 0, "prepare", railBase))
|
||||
insertTaskEvent(t, srv, stageFinishEvent(task.ID, 0, "prepare", railBase.Add(time.Second),
|
||||
map[string]any{"duration_ms": int64(1000)}))
|
||||
insertTaskEvent(t, srv, attemptEvent(task.ID, 0, railBase))
|
||||
insertTaskEvent(t, srv, attemptEvent(task.ID, 0, railBase.Add(time.Second)))
|
||||
|
||||
w := getTaskAPI(t, srv, taskRoute(task.ID, "/attempts"))
|
||||
if w.Code != http.StatusOK {
|
||||
|
||||
@@ -26,6 +26,14 @@ type Server struct {
|
||||
Store storecontract.TaskStore
|
||||
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
|
||||
// renders. Composition sets it to RemoteConfigView in a process that
|
||||
// only displays configuration; unset means this process builds the view
|
||||
|
||||
@@ -35,7 +35,7 @@ func newTestServer(t *testing.T) *Server {
|
||||
t.Helper()
|
||||
s := pgstore.Open(t)
|
||||
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
|
||||
// actions travel through it now, so a test server without one could
|
||||
// only ever answer 503.
|
||||
|
||||
@@ -48,6 +48,9 @@ service StateStoreService {
|
||||
// task-scoped grant): a cancel is a dashboard, API and dispatch action
|
||||
// decided by the Authorizer, not a worker call.
|
||||
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 ParkTask(ParkTaskRequest) returns (ParkTaskResponse);
|
||||
rpc RecoverStale(RecoverStaleRequest) returns (RecoverStaleResponse);
|
||||
@@ -262,7 +265,11 @@ message Task {
|
||||
string labels = 7;
|
||||
string status = 8;
|
||||
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 plan = 12;
|
||||
string notes = 13;
|
||||
@@ -576,6 +583,32 @@ message CancelExecutionResponse {
|
||||
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 UpdateResponse {}
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -16,5 +16,5 @@ Defaulting to \`null\`.`),null)}function BS(e){return RS(e)&&!Number.isNaN(e)&&e
|
||||
`),r=[],i=null,a=null,o=()=>{r.length&&(t.push({kind:`p`,inline:HE(r.join(` `))}),r=[])},s=()=>{i&&=(t.push({kind:i.tag,items:i.items.map(e=>HE(e))}),null)};for(let e=0;e<n.length;e++){let c=n[e];if(c.startsWith("```")){o(),s(),a?(t.push({kind:`pre`,code:a.join(`
|
||||
`)}),a=null):a=[];continue}if(a){a.push(c);continue}let l=WE(c),u=e+1<n.length?WE(n[e+1]):null;if(l&&u&&GE(u)&&l.length===u.length){o(),s();let r=[];for(e+=2;e<n.length;e++){let t=WE(n[e]);if(!t||t.length!==l.length){e--;break}r.push(t)}t.push({kind:`table`,head:l.map(e=>HE(e)),rows:r.map(e=>e.map(e=>HE(e)))});continue}if(!c.trim()){o(),s();continue}let d=c.match(/^(#{1,3})\s+(.+)$/);if(d){o(),s(),t.push({kind:`h${d[1].length}`,inline:HE(d[2])});continue}let f=c.match(/^\s*[-*]\s+(.+)$/),p=c.match(/^\s*\d+[.)]\s+(.+)$/);if(f||p){o();let e=p?`ol`:`ul`;(!i||i.tag!==e)&&(s(),i={tag:e,items:[]}),i.items.push((f||p)[1]);continue}if(c.startsWith(`>`)){o(),s(),t.push({kind:`blockquote`,inline:HE(c.replace(/^>\s?/,``))});continue}r.push(c)}return o(),s(),a&&t.push({kind:`pre`,code:a.join(`
|
||||
`)}),t}function WE(e){let t=String(e||``).trim();if(!t.includes(`|`))return null;let n=t.replace(/^\|/,``).replace(/\|$/,``).split(`|`).map(e=>e.trim());return n.length>1&&n.every(e=>e!==``)?n:null}function GE(e){return e.every(e=>/^:?-{3,}:?$/.test(e))}var KE={class:`[overflow-wrap:anywhere]`},qE={key:0,class:`my-2 overflow-auto rounded-md border border-border bg-background/60 p-3`},JE={class:`font-mono text-[0.85em]`},YE={key:1,class:`my-3 w-full border-collapse text-[0.92em]`},XE={key:2,class:`my-2 border-l-[3px] border-primary pl-3 text-fg-muted`},ZE={key:3,class:`mt-1 mb-2 text-xl leading-tight font-semibold tracking-[-0.02em]`},QE={key:4,class:`mt-1 mb-2 text-lg leading-tight font-semibold tracking-[-0.02em]`},$E={key:5,class:`mt-1 mb-2 text-base leading-tight font-semibold tracking-[-0.02em]`},eD={key:6,class:`my-2.5 flex list-disc flex-col gap-1 pl-5`},tD={key:7,class:`my-2.5 flex list-decimal flex-col gap-1 pl-5`},nD={key:8,class:`mb-2.5 last:mb-0`},rD=j({__name:`ChatMarkdown`,props:{text:{}},setup(e){let t=e,n=U(()=>UE(t.text));return(e,t)=>(F(),I(`div`,KE,[(F(!0),I(P,null,M(n.value,(e,t)=>(F(),I(P,{key:t},[e.kind===`pre`?(F(),I(`pre`,qE,[R(`code`,JE,E(e.code),1)])):e.kind===`table`?(F(),I(`table`,YE,[R(`thead`,null,[R(`tr`,null,[(F(!0),I(P,null,M(e.head,(e,t)=>(F(),I(`th`,{key:t,class:`border border-border bg-muted px-2 py-1.5 text-left font-semibold`},[z(BE,{inline:e},null,8,[`inline`])]))),128))])]),R(`tbody`,null,[(F(!0),I(P,null,M(e.rows,(e,t)=>(F(),I(`tr`,{key:t},[(F(!0),I(P,null,M(e,(e,t)=>(F(),I(`td`,{key:t,class:`border border-border px-2 py-1.5 text-left`},[z(BE,{inline:e},null,8,[`inline`])]))),128))]))),128))])])):e.kind===`blockquote`?(F(),I(`blockquote`,XE,[z(BE,{inline:e.inline},null,8,[`inline`])])):e.kind===`h1`?(F(),I(`h1`,ZE,[z(BE,{inline:e.inline},null,8,[`inline`])])):e.kind===`h2`?(F(),I(`h2`,QE,[z(BE,{inline:e.inline},null,8,[`inline`])])):e.kind===`h3`?(F(),I(`h3`,$E,[z(BE,{inline:e.inline},null,8,[`inline`])])):e.kind===`ul`?(F(),I(`ul`,eD,[(F(!0),I(P,null,M(e.items,(e,t)=>(F(),I(`li`,{key:t},[z(BE,{inline:e},null,8,[`inline`])]))),128))])):e.kind===`ol`?(F(),I(`ol`,tD,[(F(!0),I(P,null,M(e.items,(e,t)=>(F(),I(`li`,{key:t},[z(BE,{inline:e},null,8,[`inline`])]))),128))])):e.kind===`p`?(F(),I(`p`,nD,[z(BE,{inline:e.inline},null,8,[`inline`])])):V(``,!0)],64))),128))]))}}),iD={class:`truncate`},aD=j({__name:`ChatNavChip`,props:{path:{},label:{}},setup(e){return(t,n)=>{let r=ha(`RouterLink`);return F(),L(r,{to:e.path,title:`Go to ${e.label||e.path}`,class:`inline-flex max-w-full items-center gap-1.5 rounded-full border border-primary/45 bg-primary-soft px-2.5 py-1 text-xs font-semibold text-link transition-colors hover:border-primary hover:bg-primary/15 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary`},{default:k(()=>[z(O(xd),{"aria-hidden":`true`,class:`size-3.5 shrink-0`}),R(`span`,iD,E(e.label||e.path),1)]),_:1},8,[`to`,`title`])}}}),oD={key:1,class:`flex items-baseline gap-1.5 [overflow-wrap:anywhere]`},sD={class:`font-semibold text-foreground`},cD={key:0,class:`font-mono text-[0.95em] text-fg-subtle`},lD=j({__name:`ChatToolCall`,props:{tool:{},streaming:{type:Boolean}},setup(e){let t=e,n=U(()=>t.tool.name||t.tool.Name||t.tool.tool||`tool`),r=U(()=>t.tool.parameters||t.tool.Parameters||``),i=U(()=>!!(t.tool.err||t.tool.Err||t.tool.failed)),a=U(()=>t.tool.summary||t.tool.Summary||t.tool.text||t.tool.err||t.tool.Err||(t.streaming?i.value?`failed`:`running…`:`done`));return(t,o)=>e.tool.path?(F(),L(aD,{key:0,path:e.tool.path,label:e.tool.label},null,8,[`path`,`label`])):(F(),I(`div`,oD,[z(O(lf),{"aria-hidden":`true`,class:`size-3.5 shrink-0 self-center text-fg-subtle`}),R(`span`,sD,E(n.value),1),r.value?(F(),I(`code`,cD,E(r.value),1)):V(``,!0),R(`span`,{class:T(O(K)(`text-fg-muted`,i.value&&`text-danger`))},E(a.value),3)]))}}),uD={key:0,class:`mb-2 grid gap-0.5 text-xs`},dD={key:2,class:`whitespace-pre-wrap`},fD=j({__name:`ChatBubble`,props:{text:{},tools:{default:()=>[]},assistant:{type:Boolean,default:!1},streaming:{type:Boolean,default:!1}},setup(e){return(t,n)=>(F(),I(`div`,{class:T([`flex`,e.assistant?`justify-start`:`justify-end`])},[R(`div`,{class:T(O(K)(`max-w-[min(78ch,86%)] rounded-[0.85rem] px-4 py-3 leading-normal [overflow-wrap:anywhere]`,e.assistant?`bg-muted`:`bg-primary/15`))},[e.assistant&&e.tools.length?(F(),I(`div`,uD,[(F(!0),I(P,null,M(e.tools,(t,n)=>(F(),L(lD,{key:n,tool:t,streaming:e.streaming},null,8,[`tool`,`streaming`]))),128))])):V(``,!0),e.assistant?(F(),L(rD,{key:1,text:e.text},null,8,[`text`])):(F(),I(`div`,dD,E(e.text),1)),N(t.$slots,`default`)],2)],2))}}),pD={class:`w-full self-center justify-self-center py-6 text-center`},mD={class:`grid gap-2`},hD=[`onClick`],gD=j({__name:`ChatEmptyState`,emits:[`prompt`],setup(e,{emit:t}){let n=t,r=[`Summarise active tasks`,`Show running agents`,`Check system status`];return(e,t)=>(F(),I(`div`,pD,[t[0]||=R(`span`,{"aria-hidden":`true`,class:`mx-auto mb-3 grid size-9 placLine truncated
|
||||
`).map(e=>e.trim()).find(Boolean)||``,r=n.length>DM?`${n.slice(0,DM).trimEnd()}…`:n;return{text:r,full:t,truncated:r!==t}}var kM=[`title`],AM=j({__name:`ActivityRow`,props:{event:{}},emits:[`open`],setup(e,{emit:t}){let n=e,r=t,i=U(()=>aM(n.event)),a=U(()=>OM(n.event));function o(){i.value>0&&r(`open`,i.value)}let s=U(()=>n.event.at?hj(n.event.at):`—`);return(e,t)=>(F(),L(O(wM),{class:T(i.value>0?`cursor-pointer`:``),role:i.value>0?`link`:void 0,tabindex:i.value>0?0:void 0,title:i.value>0?`Open task details`:void 0,onClick:o,onKeydown:[fu(uu(o,[`prevent`]),[`enter`]),fu(uu(o,[`prevent`]),[`space`])]},{default:k(()=>[z(O($),{class:`font-medium`},{default:k(()=>[B(E(n.event.kind||n.event.type||`event`),1)]),_:1}),z(O($),{class:`font-mono`},{default:k(()=>[B(E(i.value>0?`#${i.value}`:`—`),1)]),_:1}),z(O($),{class:`w-[55%] max-w-0`},{default:k(()=>[R(`span`,{class:`block truncate`,title:a.value.truncated?a.value.full:void 0},E(a.value.text),9,kM)]),_:1}),z(O($),null,{default:k(()=>[B(E(s.value),1)]),_:1})]),_:1},8,[`class`,`role`,`tabindex`,`title`,`onKeydown`]))}});function jM(e,t){return`${e}:${t??0}`}function MM(e){let t=[];for(let n of e){let e=n.kind||n.type||`event`,r=Number(n.task_id)||0,i=jM(OM(n).text,r),a=t[t.length-1];if(a&&a.key===i){a.count+=1,a.events.push(n);continue}t.push({key:i,label:e,taskID:r,count:1,representative:n,events:[n]})}return t}var NM={role:`region`,"aria-label":`Live activity`,"aria-live":`polite`},PM={class:`max-h-[28rem] overflow-y-auto`},FM=[`aria-expanded`,`aria-label`,`onClick`],IM=[`title`],LM=j({__name:`LiveActivityCard`,setup(e){let t=zD(),{activity:n,streamKind:r,streamState:i}=od(CA()),a=rn(new Set),o=U(()=>MM(n.value));function s(e){a.has(e)?a.delete(e):a.add(e)}function c(e){return a.has(e.key)}function l(e){return OM(e.representative)}function u(e){return e.representative.at?hj(e.representative.at):`—`}function d(e){t.push(`/tasks?task=${encodeURIComponent(e)}`)}return(e,t)=>(F(),L(O(cj),null,{default:k(()=>[z(O(pj),null,{default:k(()=>[z(O(mj),null,{default:k(()=>[...t[0]||=[B(`Live activity`,-1)]]),_:1}),z(O(lj),null,{default:k(()=>[z(O(aj),{variant:O(r)},{default:k(()=>[B(E(O(i)),1)]),_:1},8,[`variant`])]),_:1})]),_:1}),z(O(uj),null,{default:k(()=>[R(`div`,NM,[R(`div`,PM,[z(O(SM),null,{default:k(()=>[z(O(EM),{class:`sticky top-0 z-10 bg-card`},{default:k(()=>[z(O(wM),null,{default:k(()=>[z(O(TM),null,{default:k(()=>[...t[1]||=[B(`Event`,-1)]]),_:1}),z(O(TM),null,{default:k(()=>[...t[2]||=[B(`Task`,-1)]]),_:1}),z(O(TM),null,{default:k(()=>[...t[3]||=[B(`Detail`,-1)]]),_:1}),z(O(TM),null,{default:k(()=>[...t[4]||=[B(`When`,-1)]]),_:1})]),_:1})]),_:1}),z(O(CM),null,{default:k(()=>[O(n).length?V(``,!0):(F(),L(O(wM),{key:0},{default:k(()=>[z(O($),{colspan:`4`},{default:k(()=>[z(O(ZA),null,{default:k(()=>[z(O(ej),null,{default:k(()=>[z(O(rj),null,{default:k(()=>[...t[5]||=[B(`Waiting for activity`,-1)]]),_:1})]),_:1})]),_:1})]),_:1})]),_:1})),O(n).length?(F(!0),I(P,{key:1},M(o.value,e=>(F(),I(P,{key:e.key},[e.count===1?(F(),L(AM,{key:0,event:e.representative,onOpen:d},null,8,[`event`])):(F(),I(P,{key:1},[z(O(wM),{class:T(e.taskID>0?`cursor-pointer`:``),role:e.taskID>0?`link`:void 0,tabindex:e.taskID>0?0:void 0,title:e.taskID>0?`Open task details`:void 0,onClick:t=>e.taskID>0&&d(e.taskID),onKeydown:[fu(uu(t=>e.taskID>0&&d(e.taskID),[`prevent`]),[`enter`]),fu(uu(t=>e.taskID>0&&d(e.taskID),[`prevent`]),[`space`])]},{default:k(()=>[z(O($),{class:`font-medium`},{default:k(()=>[R(`button`,{type:`button`,class:`inline-flex items-center gap-1 rounded hover:opacity-80`,"aria-expanded":c(e),"aria-label":`${c(e)?`Hide`:`Show`} ${e.count} ${e.label} events`,onClick:uu(t=>s(e.key),[`stop`])},[c(e)?(F(),L(O(Td),{key:0,class:`size-3.5 shrink-0 text-fg-subtle`})):(F(),L(O(Ed),{key:1,class:`size-3.5 shrink-0 text-fg-subtle`})),B(` `+E(e.label)+` `,1),z(O(aj),{variant:`idle`},{default:k(()=>[B(`×`+E(e.count),1)]),_:2},1024)],8,FM)]),_:2},1024),z(O($),{class:`font-mono`},{default:k(()=>[B(E(e.taskID>0?`#${e.taskID}`:`—`),1)]),_:2},1024),z(O($),{class:`w-[55%] max-w-0`},{default:k(()=>[R(`span`,{class:`block truncate`,title:l(e).truncated?l(e).full:void 0},E(l(e).text),9,IM)]),_:2},1024),z(O($),null,{default:k(()=>[B(E(u(e)),1)]),_:2},1024)]),_:2},1032,[`class`,`role`,`tabindex`,`title`,`onClick`,`onKeydown`]),c(e)?(F(!0),I(P,{key:0},M(e.events,(t,n)=>(F(),L(AM,{key:`${e.key}:${n}`,event:t,onOpen:d},null,8,[`event`]))),128)):V(``,!0)],64))],64))),128)):V(``,!0)]),_:1})]),_:1})])])]),_:1})]),_:1}))}}),RM=j({__name:`Alert`,props:{class:{type:[Boolean,null,String,Object,Array]},variant:{}},setup(e){let t=e;return(n,r)=>(F(),I(`div`,{"data-slot":`alert`,class:T(O(K)(O(HM)({variant:e.variant}),t.class)),role:`alert`},[N(n.$slots,`default`)],2))}}),zM=j({__name:`AlertAction`,props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){let t=e;return(e,n)=>(F(),I(`div`,{"data-slot":`alert-action`,class:T(O(K)(`absolute top-2 right-2`,t.class))},[N(e.$slots,`default`)],2))}}),BM=j(
Line truncated
|
||||
`)){let e=n.indexOf(`:`);if(e<=0)continue;let r=n.slice(0,e).trim();r&&(t[r]=n.slice(e+1).trim())}return t}function zN(e,t){if(!e.event_type)return{label:`Unidentified`,identified:!1};let n=t.find(t=>t.id===e.event_type);return{label:n?n.name:`Deleted type`,identified:!0}}function BN(e,t){if(!e)return`No event type`;let n=t.find(t=>t.id===e);return n?`${n.source} / ${n.name}`:`Deleted type`}function VN(e){let t=[...(e.headers||[]).map(e=>`${e.name} = ${e.value}`),...(e.payload||[]).map(e=>e.op===`present`?`${e.path} present`:`${e.path} = ${e.value??``}`)];return t.length?t.join(` · `):`any event`}function HN(e){return{headers:(e.headers||[]).filter(e=>e.name.trim()!==``).map(e=>({name:e.name.trim(),value:e.value})),payload:(e.payload||[]).filter(e=>e.path.trim()!==``).map(e=>e.op===`present`?{path:e.path.trim(),op:e.op}:{path:e.path.trim(),op:e.op,value:e.value??``})}}var UN=D([]),WN=D([]),GN=D(!0),KN=D(null),qN=D(null),JN=D(!1),YN=D(null);async function XN(){try{let e=await q.eventTypes();GN.value=e.enabled!==!1,UN.value=e.event_types||[],WN.value=e.proposals||[],KN.value=null}catch(e){KN.value=e.message||String(e)}}function ZN(e){return{headers:(e.headers||[]).map(e=>({...e})),payload:(e.payload||[]).map(e=>({...e}))}}function QN(e){YN.value=null,qN.value=e}function $N(e){let t=sP.value.find(t=>String(t.id)===e.sample_id);QN({mode:`proposal`,id:null,source:e.source,name:``,rule:ZN(e.rule),headersText:``,body:t?.body||``,exampleHeaders:e.headers||{}})}function eP(e=``){QN({mode:`paste`,id:null,source:e,name:``,rule:{headers:[],payload:[]},headersText:``,body:``,exampleHeaders:{}})}function tP(e){QN({mode:`edit`,id:e.id,source:e.source,name:e.name,rule:ZN(e.rule),headersText:``,body:``,exampleHeaders:{}})}function nP(){qN.value=null}async function rP(){let e=qN.value;if(e){JN.value=!0;try{if(e.mode===`edit`&&e.id)await q.eventTypeUpdate(e.id,{name:e.name,rule:HN(e.rule)});else{let t=e.mode===`paste`?RN(e.headersText):e.exampleHeaders;await q.eventTypeCreate({source:e.source,name:e.name,rule:e.mode===`paste`?void 0:HN(e.rule),example:{headers:t,body:e.body}})}qN.value=null,await XN()}catch(e){YN.value=e.message||String(e)}finally{JN.value=!1}}}var iP=D(null);async function aP(){let e=iP.value;if(iP.value=null,e)try{await q.eventTypeDelete(e.id),await XN()}catch(e){KN.value=e.message||String(e)}}var oP=100,sP=D([]),cP=D(!0),lP=D(null),uP=D(!0),dP=D(null);async function fP(){try{let e=await q.captures(oP);cP.value=e.enabled!==!1,sP.value=e.captures||[],lP.value=null}catch(e){lP.value=e.message||String(e)}finally{uP.value=!1}}function pP(e){let t=sP.value.find(t=>t.id===e);return t&&(dP.value=t),!!t}function mP(){sP.value.length&&(dP.value=sP.value[0])}function hP(){wA(`captures`,()=>{fP(),XN()})}var gP=j({__name:`Tabs`,props:{defaultValue:{},orientation:{},dir:{},activationMode:{},modelValue:{},unmountOnHide:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},emits:[`update:modelValue`],setup(e,{emit:t}){let n=e,r=t,i=bg(Pw(n,`class`),r);return(e,t)=>(F(),L(O(VC),H({"data-slot":`tabs`,"data-orientation":O(i).orientation||`horizontal`},O(i),{class:O(K)(`gap-2 group/tabs flex data-horizontal:flex-col`,n.class)}),{default:k(t=>[N(e.$slots,`default`,we(Os(t)))]),_:3},16,[`data-orientation`,`class`]))}}),_P=j({__name:`TabsContent`,props:{value:{},forceMount:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){let t=e,n=Pw(t,`class`);return(e,r)=>(F(),L(O(WC),H({"data-slot":`tabs-content`,class:O(K)(`text-sm flex-1 outline-none`,t.class)},O(n)),{default:k(()=>[N(e.$slots,`default`)]),_:3},16,[`class`]))}}),vP=j({__name:`TabsList`,props:{loop:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]},variant:{default:`default`}},setup(e){let t=e,n=Pw(t,`class`,`variant`);return(r,i)=>(F(),L(O(GC),H({"data-slot":`tabs-list`,"data-variant":e.variant},O(n),{class:O(K)(O(bP)({variant:e.variant}),t.class)}),{default:k(()=>[N(r.$slots,`default`)]),_:3},16,[`data-variant`,`class`]))}}),yP=j({__name:`TabsTrigger`,props:{value:{},disabled:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){let t=e,n=yg(Pw(t,`class`));return(e,r)=>(F(),L(O(KC),H({"data-slot":`tabs-trigger`,class:O(K)(`gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg:not([class*=size-])]:size-4 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabledLine truncated
|
||||
`).map(e=>e.trim()).find(Boolean)||``,r=n.length>DM?`${n.slice(0,DM).trimEnd()}…`:n;return{text:r,full:t,truncated:r!==t}}var kM=[`title`],AM=j({__name:`ActivityRow`,props:{event:{}},emits:[`open`],setup(e,{emit:t}){let n=e,r=t,i=U(()=>aM(n.event)),a=U(()=>OM(n.event));function o(){i.value>0&&r(`open`,i.value)}let s=U(()=>n.event.at?hj(n.event.at):`—`);return(e,t)=>(F(),L(O(wM),{class:T(i.value>0?`cursor-pointer`:``),role:i.value>0?`link`:void 0,tabindex:i.value>0?0:void 0,title:i.value>0?`Open task details`:void 0,onClick:o,onKeydown:[fu(uu(o,[`prevent`]),[`enter`]),fu(uu(o,[`prevent`]),[`space`])]},{default:k(()=>[z(O($),{class:`font-medium`},{default:k(()=>[B(E(n.event.kind||n.event.type||`event`),1)]),_:1}),z(O($),{class:`font-mono`},{default:k(()=>[B(E(i.value>0?`#${i.value}`:`—`),1)]),_:1}),z(O($),{class:`w-[55%] max-w-0`},{default:k(()=>[R(`span`,{class:`block truncate`,title:a.value.truncated?a.value.full:void 0},E(a.value.text),9,kM)]),_:1}),z(O($),null,{default:k(()=>[B(E(s.value),1)]),_:1})]),_:1},8,[`class`,`role`,`tabindex`,`title`,`onKeydown`]))}});function jM(e,t){return`${e}:${t??0}`}function MM(e){let t=[];for(let n of e){let e=n.kind||n.type||`event`,r=Number(n.task_id)||0,i=jM(OM(n).text,r),a=t[t.length-1];if(a&&a.key===i){a.count+=1,a.events.push(n);continue}t.push({key:i,label:e,taskID:r,count:1,representative:n,events:[n]})}return t}var NM={role:`region`,"aria-label":`Live activity`,"aria-live":`polite`},PM={class:`max-h-[28rem] overflow-y-auto`},FM=[`aria-expanded`,`aria-label`,`onClick`],IM=[`title`],LM=j({__name:`LiveActivityCard`,setup(e){let t=zD(),{activity:n,streamKind:r,streamState:i}=od(CA()),a=rn(new Set),o=U(()=>MM(n.value));function s(e){a.has(e)?a.delete(e):a.add(e)}function c(e){return a.has(e.key)}function l(e){return OM(e.representative)}function u(e){return e.representative.at?hj(e.representative.at):`—`}function d(e){t.push(`/tasks?task=${encodeURIComponent(e)}`)}return(e,t)=>(F(),L(O(cj),null,{default:k(()=>[z(O(pj),null,{default:k(()=>[z(O(mj),null,{default:k(()=>[...t[0]||=[B(`Live activity`,-1)]]),_:1}),z(O(lj),null,{default:k(()=>[z(O(aj),{variant:O(r)},{default:k(()=>[B(E(O(i)),1)]),_:1},8,[`variant`])]),_:1})]),_:1}),z(O(uj),null,{default:k(()=>[R(`div`,NM,[R(`div`,PM,[z(O(SM),null,{default:k(()=>[z(O(EM),{class:`sticky top-0 z-10 bg-card`},{default:k(()=>[z(O(wM),null,{default:k(()=>[z(O(TM),null,{default:k(()=>[...t[1]||=[B(`Event`,-1)]]),_:1}),z(O(TM),null,{default:k(()=>[...t[2]||=[B(`Task`,-1)]]),_:1}),z(O(TM),null,{default:k(()=>[...t[3]||=[B(`Detail`,-1)]]),_:1}),z(O(TM),null,{default:k(()=>[...t[4]||=[B(`When`,-1)]]),_:1})]),_:1})]),_:1}),z(O(CM),null,{default:k(()=>[O(n).length?V(``,!0):(F(),L(O(wM),{key:0},{default:k(()=>[z(O($),{colspan:`4`},{default:k(()=>[z(O(ZA),null,{default:k(()=>[z(O(ej),null,{default:k(()=>[z(O(rj),null,{default:k(()=>[...t[5]||=[B(`Waiting for activity`,-1)]]),_:1})]),_:1})]),_:1})]),_:1})]),_:1})),O(n).length?(F(!0),I(P,{key:1},M(o.value,e=>(F(),I(P,{key:e.key},[e.count===1?(F(),L(AM,{key:0,event:e.representative,onOpen:d},null,8,[`event`])):(F(),I(P,{key:1},[z(O(wM),{class:T(e.taskID>0?`cursor-pointer`:``),role:e.taskID>0?`link`:void 0,tabindex:e.taskID>0?0:void 0,title:e.taskID>0?`Open task details`:void 0,onClick:t=>e.taskID>0&&d(e.taskID),onKeydown:[fu(uu(t=>e.taskID>0&&d(e.taskID),[`prevent`]),[`enter`]),fu(uu(t=>e.taskID>0&&d(e.taskID),[`prevent`]),[`space`])]},{default:k(()=>[z(O($),{class:`font-medium`},{default:k(()=>[R(`button`,{type:`button`,class:`inline-flex items-center gap-1 rounded hover:opacity-80`,"aria-expanded":c(e),"aria-label":`${c(e)?`Hide`:`Show`} ${e.count} ${e.label} events`,onClick:uu(t=>s(e.key),[`stop`])},[c(e)?(F(),L(O(Td),{key:0,class:`size-3.5 shrink-0 text-fg-subtle`})):(F(),L(O(Ed),{key:1,class:`size-3.5 shrink-0 text-fg-subtle`})),B(` `+E(e.label)+` `,1),z(O(aj),{variant:`idle`},{default:k(()=>[B(`×`+E(e.count),1)]),_:2},1024)],8,FM)]),_:2},1024),z(O($),{class:`font-mono`},{default:k(()=>[B(E(e.taskID>0?`#${e.taskID}`:`—`),1)]),_:2},1024),z(O($),{class:`w-[55%] max-w-0`},{default:k(()=>[R(`span`,{class:`block truncate`,title:l(e).truncated?l(e).full:void 0},E(l(e).text),9,IM)]),_:2},1024),z(O($),null,{default:k(()=>[B(E(u(e)),1)]),_:2},1024)]),_:2},1032,[`class`,`role`,`tabindex`,`title`,`onClick`,`onKeydown`]),c(e)?(F(!0),I(P,{key:0},M(e.events,(t,n)=>(F(),L(AM,{key:`${e.key}:${n}`,event:t,onOpen:d},null,8,[`event`]))),128)):V(``,!0)],64))],64))),128)):V(``,!0)]),_:1})]),_:1})])])]),_:1})]),_:1}))}}),RM=j({__name:`Alert`,props:{class:{type:[Boolean,null,String,Object,Array]},variant:{}},setup(e){let t=e;return(n,r)=>(F(),I(`div`,{"data-slot":`alert`,class:T(O(K)(O(HM)({variant:e.variant}),t.class)),role:`alert`},[N(n.$slots,`default`)],2))}}),zM=j({__name:`AlertAction`,props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){let t=e;return(e,n)=>(F(),I(`div`,{"data-slot":`alert-action`,class:T(O(K)(`absolute top-2 right-2`,t.class))},[N(e.$slots,`default`)],2))}}),BM=j(
Line truncated
|
||||
`)){let e=n.indexOf(`:`);if(e<=0)continue;let r=n.slice(0,e).trim();r&&(t[r]=n.slice(e+1).trim())}return t}function zN(e,t){if(!e.event_type)return{label:`Unidentified`,identified:!1};let n=t.find(t=>t.id===e.event_type);return{label:n?n.name:`Deleted type`,identified:!0}}function BN(e,t){if(!e)return`No event type`;let n=t.find(t=>t.id===e);return n?`${n.source} / ${n.name}`:`Deleted type`}function VN(e){let t=[...(e.headers||[]).map(e=>`${e.name} = ${e.value}`),...(e.payload||[]).map(e=>e.op===`present`?`${e.path} present`:`${e.path} = ${e.value??``}`)];return t.length?t.join(` · `):`any event`}function HN(e){return{headers:(e.headers||[]).filter(e=>e.name.trim()!==``).map(e=>({name:e.name.trim(),value:e.value})),payload:(e.payload||[]).filter(e=>e.path.trim()!==``).map(e=>e.op===`present`?{path:e.path.trim(),op:e.op}:{path:e.path.trim(),op:e.op,value:e.value??``})}}var UN=D([]),WN=D([]),GN=D(!0),KN=D(null),qN=D(null),JN=D(!1),YN=D(null);async function XN(){try{let e=await q.eventTypes();GN.value=e.enabled!==!1,UN.value=e.event_types||[],WN.value=e.proposals||[],KN.value=null}catch(e){KN.value=e.message||String(e)}}function ZN(e){return{headers:(e.headers||[]).map(e=>({...e})),payload:(e.payload||[]).map(e=>({...e}))}}function QN(e){YN.value=null,qN.value=e}function $N(e){let t=sP.value.find(t=>String(t.id)===e.sample_id);QN({mode:`proposal`,id:null,source:e.source,name:``,rule:ZN(e.rule),headersText:``,body:t?.body||``,exampleHeaders:e.headers||{}})}function eP(e=``){QN({mode:`paste`,id:null,source:e,name:``,rule:{headers:[],payload:[]},headersText:``,body:``,exampleHeaders:{}})}function tP(e){QN({mode:`edit`,id:e.id,source:e.source,name:e.name,rule:ZN(e.rule),headersText:``,body:``,exampleHeaders:{}})}function nP(){qN.value=null}async function rP(){let e=qN.value;if(e){JN.value=!0;try{if(e.mode===`edit`&&e.id)await q.eventTypeUpdate(e.id,{name:e.name,rule:HN(e.rule)});else{let t=e.mode===`paste`?RN(e.headersText):e.exampleHeaders;await q.eventTypeCreate({source:e.source,name:e.name,rule:e.mode===`paste`?void 0:HN(e.rule),example:{headers:t,body:e.body}})}qN.value=null,await XN()}catch(e){YN.value=e.message||String(e)}finally{JN.value=!1}}}var iP=D(null);async function aP(){let e=iP.value;if(iP.value=null,e)try{await q.eventTypeDelete(e.id),await XN()}catch(e){KN.value=e.message||String(e)}}var oP=100,sP=D([]),cP=D(!0),lP=D(null),uP=D(!0),dP=D(null);async function fP(){try{let e=await q.captures(oP);cP.value=e.enabled!==!1,sP.value=e.captures||[],lP.value=null}catch(e){lP.value=e.message||String(e)}finally{uP.value=!1}}function pP(e){let t=sP.value.find(t=>t.id===e);return t&&(dP.value=t),!!t}function mP(){sP.value.length&&(dP.value=sP.value[0])}function hP(){wA(`captures`,()=>{fP(),XN()})}var gP=j({__name:`Tabs`,props:{defaultValue:{},orientation:{},dir:{},activationMode:{},modelValue:{},unmountOnHide:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},emits:[`update:modelValue`],setup(e,{emit:t}){let n=e,r=t,i=bg(Pw(n,`class`),r);return(e,t)=>(F(),L(O(VC),H({"data-slot":`tabs`,"data-orientation":O(i).orientation||`horizontal`},O(i),{class:O(K)(`gap-2 group/tabs flex data-horizontal:flex-col`,n.class)}),{default:k(t=>[N(e.$slots,`default`,we(Os(t)))]),_:3},16,[`data-orientation`,`class`]))}}),_P=j({__name:`TabsContent`,props:{value:{},forceMount:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){let t=e,n=Pw(t,`class`);return(e,r)=>(F(),L(O(WC),H({"data-slot":`tabs-content`,class:O(K)(`text-sm flex-1 outline-none`,t.class)},O(n)),{default:k(()=>[N(e.$slots,`default`)]),_:3},16,[`class`]))}}),vP=j({__name:`TabsList`,props:{loop:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]},variant:{default:`default`}},setup(e){let t=e,n=Pw(t,`class`,`variant`);return(r,i)=>(F(),L(O(GC),H({"data-slot":`tabs-list`,"data-variant":e.variant},O(n),{class:O(K)(O(bP)({variant:e.variant}),t.class)}),{default:k(()=>[N(r.$slots,`default`)]),_:3},16,[`data-variant`,`class`]))}}),yP=j({__name:`TabsTrigger`,props:{value:{},disabled:{type:Boolean},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){let t=e,n=yg(Pw(t,`class`));return(e,r)=>(F(),L(O(KC),H({"data-slot":`tabs-trigger`,class:O(K)(`gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg:not([class*=size-])]:size-4 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabledLine truncated
|
||||
@@ -18,7 +18,7 @@ const waiting = computed(() => {
|
||||
|
||||
function meta(task: AttentionTask): string {
|
||||
const where = task.owner && task.repo ? `${task.owner}/${task.repo}${task.issue_number ? ` #${task.issue_number}` : ""}` : "";
|
||||
return [where, task.workflow, task.park_reason || task.stage].filter(Boolean).join(" · ");
|
||||
return [where, task.workflow, task.park_reason].filter(Boolean).join(" · ");
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ export interface Task {
|
||||
park_reason?: string;
|
||||
tokens_used?: number;
|
||||
workflow?: string;
|
||||
stage?: string;
|
||||
attempt?: number;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
@@ -173,7 +172,6 @@ function open() {
|
||||
<TableCell class="text-fg-muted">{{
|
||||
props.task.workflow || "—"
|
||||
}}</TableCell>
|
||||
<TableCell class="text-fg-muted">{{ props.task.stage || "—" }}</TableCell>
|
||||
<TableCell
|
||||
class="text-fg-muted"
|
||||
:title="
|
||||
|
||||
@@ -24,7 +24,7 @@ const props = withDefaults(
|
||||
|
||||
const emit = defineEmits<{ done: [taskId: Task["id"]] }>();
|
||||
|
||||
const columns = computed(() => (props.showRepo ? 8 : 7));
|
||||
const columns = computed(() => (props.showRepo ? 7 : 6));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -38,7 +38,6 @@ const columns = computed(() => (props.showRepo ? 8 : 7));
|
||||
<TableHead class="w-full">Title</TableHead>
|
||||
<TableHead>Status</TableHead>
|
||||
<TableHead>Workflow</TableHead>
|
||||
<TableHead>Stage</TableHead>
|
||||
<TableHead>Last activity</TableHead>
|
||||
<TableHead>Action</TableHead>
|
||||
</TableRow>
|
||||
|
||||
Reference in new issue
Block a user