From 24dd288df910904d025a0c84fe0bd442dcab368f Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Mon, 26 Oct 2026 18:27:06 +1100 Subject: [PATCH] fix(workflow): report a parked run's outcome as the task's status A run that parked left tc.Outcome empty, so the taskrun response carried an empty status and the daemon logged 'taskrun run recorded no outcome' for a run that had recorded one, then retried the park it could not apply. Record the outcome once the parked transition lands, so a budget stop and every other park surface with the reason the run parked. --- internal/domain/workflow/park_outcome_test.go | 33 +++++++++++++++++++ internal/domain/workflow/workflow.go | 5 +++ 2 files changed, 38 insertions(+) create mode 100644 internal/domain/workflow/park_outcome_test.go diff --git a/internal/domain/workflow/park_outcome_test.go b/internal/domain/workflow/park_outcome_test.go new file mode 100644 index 000000000..230624339 --- /dev/null +++ b/internal/domain/workflow/park_outcome_test.go @@ -0,0 +1,33 @@ +package workflow + +import ( + "context" + "errors" + "log/slog" + "strings" + "testing" + + "github.com/samcharles93/archie-core/internal/domain/workflow/task" +) + +// TestRunReportsTheParkedOutcome pins the status a parked run hands back to +// whoever dispatched it: archie-agent returns tc.Outcome in its taskrun +// response, so a park that leaves the outcome empty reads there as a run that +// recorded nothing. +func TestRunReportsTheParkedOutcome(t *testing.T) { + reason := "agent parked (budget_exhausted): stopped after 60/60 steps" + wf := Workflow{Name: "implement", Stages: []Stage{{ + Name: "plan", + Run: func(context.Context, *TaskContext) error { return errors.New(reason) }, + }}} + tc := &TaskContext{Task: &task.Task{ID: 1, Attempt: 1}, Store: &fakeStepStore{}, Log: slog.Default()} + + Run(context.Background(), wf, tc) + + if tc.Outcome.Status != StatusParked { + t.Fatalf("outcome status = %q, want %q", tc.Outcome.Status, StatusParked) + } + if !strings.Contains(tc.Outcome.Detail, reason) { + t.Fatalf("outcome detail = %q, want it to carry %q", tc.Outcome.Detail, reason) + } +} diff --git a/internal/domain/workflow/workflow.go b/internal/domain/workflow/workflow.go index 59b88e7bd..8fa55f430 100644 --- a/internal/domain/workflow/workflow.go +++ b/internal/domain/workflow/workflow.go @@ -520,6 +520,11 @@ func park(ctx context.Context, tc *TaskContext, reason string) { tc.Log.ErrorContext(ctx, "task park transition failed", "err", err) return } + // The applied transition is the run's outcome: the taskrun response reports + // it, and an empty one there reads as a run that recorded nothing. Recorded + // only past the transition, so a park that did not land still leaves the + // caller to record one. + tc.Outcome = Outcome{Status: StatusParked, Detail: reason} tc.Emit(ctx, 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