fix(ui): repair settings editing and workflow diagnostics
This commit is contained in:
1 parent
3229de9b3b
commit
41cd938748
46 files changed
+708
-240
No files matched your search
+26
-30
@@ -1585,11 +1585,11 @@ func (d *Daemon) process(ctx context.Context, task *workflow.Task, hold *taskHol
|
||||
trees := d.treesFor(task)
|
||||
repo, ok := d.repoFor(task)
|
||||
if !ok && task.HasRepository() {
|
||||
d.parkRunningTask(ctx, task.ID, "repo no longer in config", taskstate.ParkTerminal)
|
||||
d.parkRunningTask(ctx, task, "repo no longer in config", taskstate.ParkTerminal)
|
||||
return
|
||||
}
|
||||
if d.ContainerPool == nil || d.Tasks == nil {
|
||||
d.parkCapabilityUnavailable(ctx, task, repo)
|
||||
d.parkCapabilityUnavailable(ctx, task)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1663,7 +1663,7 @@ func (d *Daemon) prepareWorkspace(ctx context.Context, task *workflow.Task, tree
|
||||
dir, err := trees.PrepareScratch(task.ID)
|
||||
if err != nil {
|
||||
d.Log.Error("scratch workspace prepare failed", "err", err)
|
||||
d.parkRunningTask(ctx, task.ID, "scratch workspace prepare failed: "+err.Error(), taskstate.ParkTransient)
|
||||
d.parkRunningTask(ctx, task, "scratch workspace prepare failed: "+err.Error(), taskstate.ParkTransient)
|
||||
return "", false
|
||||
}
|
||||
return dir, true
|
||||
@@ -1676,7 +1676,7 @@ func (d *Daemon) prepareWorkspace(ctx context.Context, task *workflow.Task, tree
|
||||
// The action refuses this combination, so an empty branch here is a
|
||||
// dispatch bug upstream and no retry can fix it.
|
||||
d.Log.Error("task has no persisted branch to continue", "task", task.ID)
|
||||
d.parkRunningTask(ctx, task.ID, "worktree resume failed: task has no branch to continue", taskstate.ParkNeedsHuman)
|
||||
d.parkRunningTask(ctx, task, "worktree resume failed: task has no branch to continue", taskstate.ParkNeedsHuman)
|
||||
return "", false
|
||||
}
|
||||
target = worktree.Target(task.Branch)
|
||||
@@ -1695,7 +1695,7 @@ func (d *Daemon) prepareWorkspace(ctx context.Context, task *workflow.Task, tree
|
||||
reason = "worktree resume failed: " + err.Error()
|
||||
}
|
||||
d.Log.Error("worktree prepare failed", "task", task.ID, "err", err)
|
||||
d.parkRunningTask(ctx, task.ID, reason, taskstate.ParkTransient)
|
||||
d.parkRunningTask(ctx, task, reason, taskstate.ParkTransient)
|
||||
return "", false
|
||||
}
|
||||
task.Branch = branch
|
||||
@@ -1787,7 +1787,7 @@ func (d *Daemon) acquireTaskContainer(
|
||||
) (*container.Container, string, func(), bool) {
|
||||
park := func(reason string, err error) {
|
||||
d.Log.Error(reason, "err", err)
|
||||
d.parkRunningTask(ctx, task.ID, reason+": "+err.Error(), taskstate.ParkTransient)
|
||||
d.parkRunningTask(ctx, task, reason+": "+err.Error(), taskstate.ParkTransient)
|
||||
}
|
||||
|
||||
// Resolve the PR number from inputs before the brief is written.
|
||||
@@ -1813,7 +1813,7 @@ func (d *Daemon) acquireTaskContainer(
|
||||
// normal operation, Storage is always set when ContainerPool is set.
|
||||
if d.Storage == nil {
|
||||
d.Log.Error("storage backend is nil -- cannot acquire container")
|
||||
d.parkRunningTask(ctx, task.ID, "storage backend not configured", taskstate.ParkTransient)
|
||||
d.parkRunningTask(ctx, task, "storage backend not configured", taskstate.ParkTransient)
|
||||
return nil, "", nil, false
|
||||
}
|
||||
|
||||
@@ -1875,7 +1875,7 @@ func writeTaskBrief(workDir string, task *workflow.Task) error {
|
||||
// missing (container pool or task transport): both are environmental, so
|
||||
// the park class is transient and the KindParked event carries the class
|
||||
// for the dashboard. The reason distinguishes the two in logs and events.
|
||||
func (d *Daemon) parkCapabilityUnavailable(ctx context.Context, task *workflow.Task, repo config.Repo) {
|
||||
func (d *Daemon) parkCapabilityUnavailable(ctx context.Context, task *workflow.Task) {
|
||||
var reason string
|
||||
if d.ContainerPool == nil {
|
||||
reason = "managed agent container pool is unavailable; refusing to run this task on the host"
|
||||
@@ -1885,38 +1885,34 @@ func (d *Daemon) parkCapabilityUnavailable(ctx context.Context, task *workflow.T
|
||||
reason = "agent task transport is unavailable; refusing to run this task on the host"
|
||||
d.Log.Error("task parked: agent task transport unavailable", "task", task.ID)
|
||||
}
|
||||
if err := d.Store.ParkTask(ctx, task.ID, workflow.StatusRunning, reason, taskstate.ParkTransient); err != nil {
|
||||
d.Log.Warn("capability park transition failed", "task", task.ID, "err", err)
|
||||
return
|
||||
}
|
||||
d.recordPark(ctx, task.ID, reason)
|
||||
d.emit(events.Event{
|
||||
Kind: events.KindParked, TaskID: task.ID, Attempt: task.Attempt,
|
||||
Repo: repo.FullName(), Issue: task.IssueNumber, Detail: reason,
|
||||
Data: map[string]any{"park_class": taskstate.ParkTransient},
|
||||
})
|
||||
d.parkRunningTask(ctx, task, reason, taskstate.ParkTransient)
|
||||
}
|
||||
|
||||
// parkRunningTask moves a running task to parked with class, using a
|
||||
// bounded context that ignores cancellation. ErrStaleTransition is ignored;
|
||||
// other errors are logged.
|
||||
func (d *Daemon) parkRunningTask(ctx context.Context, taskID int64, reason string, class taskstate.ParkClass) {
|
||||
func (d *Daemon) parkRunningTask(ctx context.Context, task *workflow.Task, reason string, class taskstate.ParkClass) {
|
||||
if d.Store == nil {
|
||||
return
|
||||
}
|
||||
writeCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
if err := d.Store.ParkTask(writeCtx, taskID, workflow.StatusRunning, reason, class); err != nil {
|
||||
if err := d.Store.ParkTask(writeCtx, task.ID, workflow.StatusRunning, reason, class); err != nil {
|
||||
if !errors.Is(err, storecontract.ErrStaleTransition) {
|
||||
d.Log.Warn("terminal park transition failed", "task", taskID, "reason", reason, "err", err)
|
||||
d.Log.Warn("terminal park transition failed", "task", task.ID, "reason", reason, "err", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
// Recorded only once the transition landed. An entry claiming the task
|
||||
// parked would be a lie when another actor moved it out of running first
|
||||
// -- the same race the parked event is withheld for.
|
||||
d.recordPark(ctx, taskID, reason)
|
||||
d.recordPark(ctx, task.ID, reason)
|
||||
d.emit(events.Event{
|
||||
Kind: events.KindParked, TaskID: task.ID, Attempt: task.Attempt,
|
||||
Repo: strings.Trim(task.Owner+"/"+task.Repo, "/"), Issue: task.IssueNumber, Workflow: task.Workflow,
|
||||
Detail: reason, Data: map[string]any{"park_class": class},
|
||||
})
|
||||
}
|
||||
|
||||
// recordPark writes a park reason to the attempt's log. Dropped when no sink
|
||||
@@ -1939,7 +1935,7 @@ func (d *Daemon) recordPark(ctx context.Context, taskID int64, reason string) {
|
||||
func (d *Daemon) runViaAgent(ctx context.Context, task *workflow.Task, repo config.Repo, profile config.AgentProfile, harness *agentrun.HarnessSpec, credential string) {
|
||||
cfg, err := d.taskConfig(ctx, task)
|
||||
if err != nil {
|
||||
d.parkRunningTask(ctx, task.ID, err.Error(), taskstate.ParkTransient)
|
||||
d.parkRunningTask(ctx, task, err.Error(), taskstate.ParkTransient)
|
||||
return
|
||||
}
|
||||
taskCfg := cfg.ForTask()
|
||||
@@ -1958,7 +1954,7 @@ func (d *Daemon) runViaAgent(ctx context.Context, task *workflow.Task, repo conf
|
||||
data, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
d.Log.Error("taskrun encode failed", "task", task.ID, "err", err)
|
||||
d.parkRunningTask(ctx, task.ID, "taskrun encode failed: "+err.Error(), taskstate.ParkTransient)
|
||||
d.parkRunningTask(ctx, task, "taskrun encode failed: "+err.Error(), taskstate.ParkTransient)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1968,19 +1964,19 @@ func (d *Daemon) runViaAgent(ctx context.Context, task *workflow.Task, repo conf
|
||||
}
|
||||
if err != nil {
|
||||
d.Log.Error("taskrun request failed", "task", task.ID, "err", err)
|
||||
d.parkRunningTask(ctx, task.ID, "taskrun request failed: "+err.Error(), taskstate.ParkTransient)
|
||||
d.parkRunningTask(ctx, task, "taskrun request failed: "+err.Error(), taskstate.ParkTransient)
|
||||
return
|
||||
}
|
||||
|
||||
var resp taskrun.Response
|
||||
if err := json.Unmarshal(reply, &resp); err != nil {
|
||||
d.Log.Error("taskrun decode response failed", "task", task.ID, "err", err)
|
||||
d.parkRunningTask(ctx, task.ID, "taskrun decode response failed: "+err.Error(), taskstate.ParkTransient)
|
||||
d.parkRunningTask(ctx, task, "taskrun decode response failed: "+err.Error(), taskstate.ParkTransient)
|
||||
return
|
||||
}
|
||||
if resp.Error != "" {
|
||||
d.Log.Error("taskrun run failed", "task", task.ID, "err", resp.Error)
|
||||
d.parkRunningTask(ctx, task.ID, "taskrun run failed: "+resp.Error, taskstate.ParkTransient)
|
||||
d.parkRunningTask(ctx, task, "taskrun run failed: "+resp.Error, taskstate.ParkTransient)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2000,7 +1996,7 @@ func (d *Daemon) runViaAgent(ctx context.Context, task *workflow.Task, repo conf
|
||||
func (d *Daemon) pinTaskProfile(ctx context.Context, task *workflow.Task) (config.AgentProfile, bool) {
|
||||
if err := d.pinWorkflowDefinition(ctx, task); err != nil {
|
||||
d.Log.Error("pin workflow definition failed", "task", task.ID, "err", err)
|
||||
d.parkRunningTask(ctx, task.ID, "pin workflow definition: "+err.Error(), pinParkClass(err))
|
||||
d.parkRunningTask(ctx, task, "pin workflow definition: "+err.Error(), pinParkClass(err))
|
||||
return config.AgentProfile{}, false
|
||||
}
|
||||
iface, err := workflowtask.ParseWorkflowInterface(task.WorkflowDefinitionYAML)
|
||||
@@ -2019,7 +2015,7 @@ func (d *Daemon) pinTaskProfile(ctx context.Context, task *workflow.Task) (confi
|
||||
}
|
||||
}
|
||||
d.Log.Error("agent profile unavailable", "task", task.ID, "err", err)
|
||||
d.parkRunningTask(ctx, task.ID, "workflow "+task.Workflow+": "+err.Error(), taskstate.ParkNeedsHuman)
|
||||
d.parkRunningTask(ctx, task, "workflow "+task.Workflow+": "+err.Error(), taskstate.ParkNeedsHuman)
|
||||
return config.AgentProfile{}, false
|
||||
}
|
||||
|
||||
@@ -2382,7 +2378,7 @@ func (d *Daemon) parkIfIdentityUnresolvable(ctx context.Context, task *workflow.
|
||||
if ok {
|
||||
return false
|
||||
}
|
||||
d.parkRunningTask(ctx, task.ID, reason, class)
|
||||
d.parkRunningTask(ctx, task, reason, class)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ type KitLauncher interface {
|
||||
func (d *Daemon) runKitTask(ctx context.Context, task *workflow.Task, repo config.Repo, workDir string, profile config.AgentProfile) {
|
||||
park := func(reason string, err error) {
|
||||
d.Log.Error(reason, "task", task.ID, "err", err)
|
||||
d.parkRunningTask(ctx, task.ID, reason+": "+err.Error(), taskstate.ParkTransient)
|
||||
d.parkRunningTask(ctx, task, reason+": "+err.Error(), taskstate.ParkTransient)
|
||||
}
|
||||
if d.KitLauncher == nil {
|
||||
park("kit profile", fmt.Errorf("kit harness runs are unavailable on this daemon"))
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package daemon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
"github.com/samcharles93/archie-core/internal/events"
|
||||
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||
)
|
||||
|
||||
type parkStore struct {
|
||||
storecontract.TaskStore
|
||||
err error
|
||||
}
|
||||
|
||||
func (s parkStore) ParkTask(context.Context, int64, string, string, taskstate.ParkClass) error {
|
||||
return s.err
|
||||
}
|
||||
|
||||
func TestEarlyParkRecordsAttempt(t *testing.T) {
|
||||
for _, stale := range []bool{false, true} {
|
||||
t.Run(map[bool]string{false: "parked", true: "stale"}[stale], func(t *testing.T) {
|
||||
var err error
|
||||
if stale {
|
||||
err = storecontract.ErrStaleTransition
|
||||
}
|
||||
bus := events.NewBus()
|
||||
defer bus.Close()
|
||||
sub := bus.Subscribe(1)
|
||||
defer sub.Close()
|
||||
d := &Daemon{Store: parkStore{err: err}, Bus: bus, Log: slog.New(slog.DiscardHandler)}
|
||||
task := &workflow.Task{ID: 7, Attempt: 3, Owner: "owner", Repo: "repo", Workflow: "implement"}
|
||||
d.parkRunningTask(t.Context(), task, "clone authentication failed", taskstate.ParkNeedsHuman)
|
||||
select {
|
||||
case event := <-sub.C:
|
||||
if stale {
|
||||
t.Fatal("stale park emitted an event")
|
||||
}
|
||||
if event.Attempt != 3 || event.Kind != events.KindParked || event.Detail != "clone authentication failed" {
|
||||
t.Fatalf("park event = %+v", event)
|
||||
}
|
||||
default:
|
||||
if !stale {
|
||||
t.Fatal("early park did not record the attempt")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -22,29 +22,29 @@ import (
|
||||
func (d *Daemon) adoptWorkflowIdentity(ctx context.Context, task *workflow.Task) bool {
|
||||
if err := d.pinWorkflowDefinition(ctx, task); err != nil {
|
||||
d.Log.Error("pin workflow definition failed", "task", task.ID, "err", err)
|
||||
d.parkRunningTask(ctx, task.ID, "pin workflow definition: "+err.Error(), pinParkClass(err))
|
||||
d.parkRunningTask(ctx, task, "pin workflow definition: "+err.Error(), pinParkClass(err))
|
||||
return false
|
||||
}
|
||||
iface, err := workflowtask.ParseWorkflowInterface(task.WorkflowDefinitionYAML)
|
||||
if err != nil {
|
||||
d.parkRunningTask(ctx, task.ID, "workflow "+task.Workflow+": "+err.Error(), taskstate.ParkNeedsHuman)
|
||||
d.parkRunningTask(ctx, task, "workflow "+task.Workflow+": "+err.Error(), taskstate.ParkNeedsHuman)
|
||||
return false
|
||||
}
|
||||
if iface.Identity == "" {
|
||||
d.parkRunningTask(ctx, task.ID, "workflow "+task.Workflow+" declares no identity to run as; set one in its settings", taskstate.ParkNeedsHuman)
|
||||
d.parkRunningTask(ctx, task, "workflow "+task.Workflow+" declares no identity to run as; set one in its settings", taskstate.ParkNeedsHuman)
|
||||
return false
|
||||
}
|
||||
runsAs, runnerName, ok := d.declaredIdentity(iface.Identity)
|
||||
if !ok {
|
||||
d.parkRunningTask(ctx, task.ID, "workflow "+task.Workflow+" runs as identity "+iface.Identity+", which is not configured", taskstate.ParkNeedsHuman)
|
||||
d.parkRunningTask(ctx, task, "workflow "+task.Workflow+" runs as identity "+iface.Identity+", which is not configured", taskstate.ParkNeedsHuman)
|
||||
return false
|
||||
}
|
||||
if !d.mayRunWorkflow(ctx, task, d.publisherIdentity(task.Identity)) {
|
||||
d.parkRunningTask(ctx, task.ID, "the identity that started it may not run workflow "+task.Workflow, taskstate.ParkNeedsHuman)
|
||||
d.parkRunningTask(ctx, task, "the identity that started it may not run workflow "+task.Workflow, taskstate.ParkNeedsHuman)
|
||||
return false
|
||||
}
|
||||
if !d.mayRunWorkflow(ctx, task, runsAs) {
|
||||
d.parkRunningTask(ctx, task.ID, "identity "+iface.Identity+" may not run workflow "+task.Workflow, taskstate.ParkNeedsHuman)
|
||||
d.parkRunningTask(ctx, task, "identity "+iface.Identity+" may not run workflow "+task.Workflow, taskstate.ParkNeedsHuman)
|
||||
return false
|
||||
}
|
||||
// In memory only: the stored identity stays the starter's, so every
|
||||
|
||||
@@ -34,7 +34,7 @@ type JobSpec struct {
|
||||
Pool string `json:"pool,omitempty"`
|
||||
|
||||
// Detail is a human-readable label rendered on events.
|
||||
Detail string `json:"detail,omitempty"`
|
||||
Detail string `json:"detail,omitempty" title:"Schedule name"`
|
||||
|
||||
// Kind selects the delivery runner. Empty means KindChat.
|
||||
Kind string `json:"kind,omitempty"`
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/identity"
|
||||
)
|
||||
|
||||
// actorNames resolves each actor once per response; stable IDs stay in the wire record.
|
||||
func (s *Server) actorNames(ctx context.Context) func(string) string {
|
||||
names := map[string]string{}
|
||||
return func(id string) string {
|
||||
if label, ok := names[id]; ok {
|
||||
return label
|
||||
}
|
||||
label := id
|
||||
if strings.Count(id, "-") == 4 {
|
||||
label = "Unavailable identity"
|
||||
}
|
||||
if s.Identities != nil {
|
||||
if actor, err := s.Identities.Get(ctx, identity.IdentityID(id)); err == nil && actor.DisplayName != "" {
|
||||
label = actor.DisplayName
|
||||
}
|
||||
}
|
||||
names[id] = label
|
||||
return label
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/identity"
|
||||
)
|
||||
|
||||
type namedActors struct{ identity.Repository }
|
||||
|
||||
func (namedActors) Get(_ context.Context, id identity.IdentityID) (identity.Identity, error) {
|
||||
if id == "11111111-1111-4111-8111-111111111111" || id == "d898c8c8-47f4-57d6c-945a-2e7dc98ca1c1" {
|
||||
return identity.Identity{ID: id, DisplayName: "Sam"}, nil
|
||||
}
|
||||
return identity.Identity{}, identity.ErrNotFound
|
||||
}
|
||||
|
||||
func TestAuditActorNames(t *testing.T) {
|
||||
name := (&Server{Identities: namedActors{}}).actorNames(t.Context())
|
||||
for _, tc := range []struct{ id, want string }{
|
||||
{"11111111-1111-4111-8111-111111111111", "Sam"},
|
||||
{"d898c8c8-47f4-57d6c-945a-2e7dc98ca1c1", "Sam"},
|
||||
{"22222222-2222-4222-8222-222222222222", "Unavailable identity"},
|
||||
{"system:migration", "system:migration"},
|
||||
} {
|
||||
if got := name(tc.id); got != tc.want {
|
||||
t.Errorf("actor %s = %s, want %s", tc.id, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ type auditEntryView struct {
|
||||
NewValue json.RawMessage `json:"new_value"`
|
||||
Version int64 `json:"version"`
|
||||
Actor string `json:"actor"`
|
||||
ActorName string `json:"actor_name"`
|
||||
Source string `json:"source"`
|
||||
At *time.Time `json:"at,omitempty"`
|
||||
}
|
||||
@@ -39,11 +40,12 @@ func (s *Server) handleAudit(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
entries := make([]auditEntryView, 0, len(response.Entries))
|
||||
actorName := s.actorNames(r.Context())
|
||||
for _, entry := range response.Entries {
|
||||
view := auditEntryView{
|
||||
ID: entry.Id, Table: entry.Table, RecordKey: entry.RecordKey, Field: entry.Field,
|
||||
OldValue: jsonOrNull(entry.OldValueJson), NewValue: jsonOrNull(entry.NewValueJson),
|
||||
Version: entry.Version, Actor: entry.Actor, Source: entry.Source,
|
||||
Version: entry.Version, Actor: entry.Actor, ActorName: actorName(entry.Actor), Source: entry.Source,
|
||||
}
|
||||
if entry.At != nil {
|
||||
at := entry.At.AsTime()
|
||||
|
||||
@@ -36,6 +36,7 @@ type controlPlaneRevision struct {
|
||||
Version int64 `json:"version"`
|
||||
Value json.RawMessage `json:"value"`
|
||||
Actor string `json:"actor"`
|
||||
ActorName string `json:"actor_name"`
|
||||
Source string `json:"source"`
|
||||
RequestID string `json:"request_id"`
|
||||
At *time.Time `json:"at,omitempty"`
|
||||
@@ -82,9 +83,10 @@ func (s *Server) handleControlPlaneHistory(w http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
revisions := make([]controlPlaneRevision, 0, len(response.Revisions))
|
||||
actorName := s.actorNames(r.Context())
|
||||
for _, revision := range response.Revisions {
|
||||
view := controlPlaneRevision{
|
||||
Version: revision.Version, Value: revision.ValueJson, Actor: revision.Actor,
|
||||
Version: revision.Version, Value: revision.ValueJson, Actor: revision.Actor, ActorName: actorName(revision.Actor),
|
||||
Source: revision.Source, RequestID: revision.RequestId,
|
||||
}
|
||||
if revision.At != nil {
|
||||
|
||||
@@ -50,6 +50,7 @@ type taskAttemptView struct {
|
||||
FinishedAt *time.Time `json:"finished_at,omitempty"`
|
||||
DurationMS *int64 `json:"duration_ms,omitempty"`
|
||||
EventCount int `json:"event_count"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Stages []taskStageView `json:"stages"`
|
||||
}
|
||||
|
||||
@@ -101,6 +102,11 @@ func (s *Server) handleTaskAttempts(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
attempts := attemptsFromEvents(evs, steps, t.Status, t.Attempt)
|
||||
for i := range attempts {
|
||||
if attempts[i].Attempt == t.Attempt && t.Status == task.StatusParked {
|
||||
attempts[i].Error = t.ParkReason
|
||||
}
|
||||
}
|
||||
writeJSON(w, taskAttemptsView{
|
||||
TaskID: t.ID,
|
||||
CurrentAttempt: t.Attempt,
|
||||
@@ -170,6 +176,19 @@ func attemptsFromEvents(evs []events.Event, steps []task.StepExecution, taskStat
|
||||
}
|
||||
grouped[e.Attempt] = append(grouped[e.Attempt], e)
|
||||
}
|
||||
// A claimed attempt exists even if preparation failed before its first step.
|
||||
if currentAttempt > 0 {
|
||||
if _, seen := grouped[currentAttempt]; !seen {
|
||||
grouped[currentAttempt] = nil
|
||||
numbers = append(numbers, currentAttempt)
|
||||
}
|
||||
}
|
||||
for _, step := range steps {
|
||||
if _, seen := grouped[step.Attempt]; !seen && step.Attempt > 0 {
|
||||
grouped[step.Attempt] = nil
|
||||
numbers = append(numbers, step.Attempt)
|
||||
}
|
||||
}
|
||||
sort.Ints(numbers)
|
||||
|
||||
attempts := make([]taskAttemptView, 0, len(numbers))
|
||||
@@ -208,6 +227,9 @@ func attemptRail(number int, evs []events.Event, steps []task.StepExecution, tas
|
||||
EventCount: len(evs),
|
||||
Stages: stages,
|
||||
}
|
||||
if attempt.Status == attemptStatusUnknown {
|
||||
attempt.Status, attempt.Error = earlyAttemptOutcome(evs, number, taskStatus, currentAttempt)
|
||||
}
|
||||
if !first.IsZero() {
|
||||
attempt.StartedAt = &first
|
||||
}
|
||||
@@ -223,6 +245,28 @@ func attemptRail(number int, evs []events.Event, steps []task.StepExecution, tas
|
||||
return attempt
|
||||
}
|
||||
|
||||
// earlyAttemptOutcome uses explicit park evidence when no stage ran.
|
||||
func earlyAttemptOutcome(evs []events.Event, number int, taskStatus string, currentAttempt int) (string, string) {
|
||||
status, detail := attemptStatusUnknown, ""
|
||||
for _, event := range evs {
|
||||
switch event.Kind {
|
||||
case events.KindParked:
|
||||
status, detail = task.StatusParked, event.Detail
|
||||
case events.KindTaskRetried:
|
||||
if reason, ok := event.Data["previous_reason"].(string); ok && reason != "" {
|
||||
status, detail = task.StatusParked, reason
|
||||
}
|
||||
}
|
||||
}
|
||||
if number == currentAttempt {
|
||||
switch taskStatus {
|
||||
case task.StatusParked, task.StatusDead, task.StatusWaitingHuman:
|
||||
status = taskStatus
|
||||
}
|
||||
}
|
||||
return status, detail
|
||||
}
|
||||
|
||||
// attemptBounds is the span of an attempt's own recorded events: the earliest
|
||||
// and latest timestamp any of them carries. A zero time contributes nothing -- a
|
||||
// record whose timestamp did not parse is not evidence of when it happened.
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||
"github.com/samcharles93/archie-core/internal/events"
|
||||
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||
)
|
||||
|
||||
func TestEarlyAttemptHistory(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
events []events.Event
|
||||
steps []task.StepExecution
|
||||
status string
|
||||
current int
|
||||
want string
|
||||
}{
|
||||
{name: "current parked attempt without stage events", status: task.StatusParked, current: 3, want: "parked"},
|
||||
{name: "retry preserves the previous park reason", events: []events.Event{{Attempt: 1, Kind: events.KindTaskRetried, Data: map[string]any{"previous_reason": "clone authentication failed"}}}, status: task.StatusRunning, current: 2, want: "parked"},
|
||||
{name: "historical early failure", events: []events.Event{{Attempt: 1, Kind: events.KindParked, Detail: "clone failed"}}, status: task.StatusRunning, current: 2, want: "parked"},
|
||||
{name: "step execution without events", steps: []task.StepExecution{{Attempt: 1, Kind: task.StepKindStage, Name: "prepare", Status: taskstate.StepFailed}}, status: task.StatusParked, current: 2, want: "failed"},
|
||||
{name: "historical state has no recorded outcome", events: []events.Event{{Attempt: 1, Kind: events.KindTaskRetried}}, status: task.StatusRunning, current: 2, want: "unknown"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
attempts := attemptsFromEvents(tc.events, tc.steps, tc.status, tc.current)
|
||||
if len(attempts) == 0 {
|
||||
t.Fatal("current attempt missing")
|
||||
}
|
||||
if attempts[0].Status != tc.want {
|
||||
t.Fatalf("status = %s, want %s", attempts[0].Status, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user