fix(workflow): record a parked run's reason in its own log

The agent-side half of the same gap. A stage failure already logged
"stage failed -- parking" before parking, but a run whose OUTCOME was parked
(a review that could not run, a workflow that ended with no outcome) reached
the timeline as a KindParked event and the store as park_reason and never
the log an operator downloads.

park is the one place a park's reason is final, so it is now the one place
that logs it; the stage-failure branch no longer logs its own near-copy, and
the stage names itself inside the reason. The entry carries the stage as a
field so nothing is lost by dropping the duplicate line.

observability.md's "Implemented design" section documented the container's
system-log path as though it were the only source of task-log content; it
now records the daemon's and the workflow's own park writers, including why
the entry follows the transition rather than preceding it.
This commit is contained in:
sam committed 2026-09-18 01:49:56 +10:00
1 parent e869261109
commit 2e1e1549ec
3 files changed
+60 -1

No files matched your search

+9
View File
@@ -95,6 +95,15 @@ appears on the dashboard exactly like daemon output. The approved target is
for this composition to move to `internal/app/archied`; that package does not
yet exist, so this document does not claim the migration is complete.
The daemon is also a writer in its own right for the decisions only it makes.
Every park records its reason into that attempt's sink (`daemon.recordPark`),
on the daemon side after the guarded transition lands and in
`workflow.park` on the agent side, because "why did this park?" is the question
the log exists to answer and the container path cannot answer a run that never
reached a container. The entry is written only once the park actually
happened, so a transition another actor won does not leave a log claiming an
outcome the task board contradicts.
### Gate output: stop discarding it
`StageBaselineGate` and the equivalent TDD-stage gate runs write full
@@ -1,9 +1,11 @@
package workflow_test
import (
"bytes"
"context"
"log/slog"
"path/filepath"
"strings"
"testing"
"github.com/samcharles93/archie-core/internal/agentexec"
@@ -35,6 +37,50 @@ func (r *storeIntegrationRunner) Run(
return res, nil
}
// TestRunRecordsAParkReasonInTheRunsOwnLog pins the agent-side half of the
// same contract: a run's own log is what an operator downloads to answer "why
// did this park?", and a parked OUTCOME (a review that could not run, a stage
// that ended parked rather than failing) used to reach the timeline as an event
// and the store as park_reason, but never the log. A workflow that ends without
// an outcome is the smallest way to reach that path.
func TestRunRecordsAParkReasonInTheRunsOwnLog(t *testing.T) {
st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "archie.db"))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
if err := st.Close(); err != nil {
t.Errorf("close store: %v", err)
}
})
ctx := context.Background()
if _, err := st.EnqueueIssue(ctx, "owner", "repo", 3, "title", "body", "", ""); err != nil {
t.Fatal(err)
}
task, err := st.ClaimNext(ctx)
if err != nil {
t.Fatal(err)
}
var logs bytes.Buffer
workflow.Run(ctx, workflow.Workflow{Name: "empty"}, &workflow.TaskContext{
Task: task, Store: st, Repo: config.Repo{Owner: "owner", Name: "repo"},
Log: slog.New(slog.NewJSONHandler(&logs, nil)),
})
const reason = "workflow ended without an outcome (definition bug)"
if !strings.Contains(logs.String(), reason) {
t.Errorf("run log = %s, want the park reason %q recorded in it", logs.String(), reason)
}
got, err := st.TaskByIssue(ctx, "owner", "repo", 3)
if err != nil {
t.Fatal(err)
}
if got.Status != workflow.StatusParked || got.ParkReason != reason {
t.Fatalf("task status/park_reason = (%q, %q), want parked with the same reason the log carries", got.Status, got.ParkReason)
}
}
func TestAgentStagePersistsReturnedNotes(t *testing.T) {
st, err := store.Open(t.Context(), filepath.Join(t.TempDir(), "archie.db"))
if err != nil {
+5 -1
View File
@@ -316,7 +316,6 @@ func Run(ctx context.Context, wf Workflow, tc *TaskContext) {
return
}
t.ParkReason = fmt.Sprintf("stage %s: %v", stage.Name, err)
log.Warn("stage failed -- parking", "stage", stage.Name, "err", err)
park(ctx, tc, t.ParkReason)
return
}
@@ -348,6 +347,11 @@ func park(ctx context.Context, tc *TaskContext, reason string) {
_ = tc.Store.Update(ctx, t)
_ = tc.Store.Transition(ctx, t.ID, StatusRunning, StatusParked, reason)
tc.Emit(events.KindParked, t.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)
}
func clip(s string, n int) string {