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.
This commit is contained in:
sam committed 2026-10-26 18:28:32 +11:00
1 parent c4c50ea70d
commit c00a90c9ca
2 files changed
+38

No files matched your search

@@ -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)
}
}
+5
View File
@@ -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