From a40ff52bd4d47e0d63d6a52bb386558f148ad3ea Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Mon, 26 Oct 2026 18:07:01 +1100 Subject: [PATCH] fix(workflow): record the own-PR flag after the review stages that allocate it StagePRReviewAndOpenPR set tc.prReview.ownPR before the decision stages ran, but intake allocates tc.prReview, so every implement run dereferenced a nil state at repo.open-pr and the agent container panicked with exit code 2 before opening the pull request. --- internal/domain/workflow/prreview_own_pr.go | 5 +++- .../domain/workflow/prreview_own_pr_test.go | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 internal/domain/workflow/prreview_own_pr_test.go diff --git a/internal/domain/workflow/prreview_own_pr.go b/internal/domain/workflow/prreview_own_pr.go index 7b03ecbf4..5e739e03a 100644 --- a/internal/domain/workflow/prreview_own_pr.go +++ b/internal/domain/workflow/prreview_own_pr.go @@ -92,7 +92,6 @@ func stagePRReviewAndOpenPR(decisionStages []Stage, body func(*TaskContext) stri if tc.PRSource == nil { tc.PRSource = &localPRSource{tc: tc} } - tc.prReview.ownPR = true defer removePRSnapshot(tc) for _, stage := range decisionStages { if err := stage.Run(ctx, tc); err != nil { @@ -110,6 +109,10 @@ func stagePRReviewAndOpenPR(decisionStages []Stage, body func(*TaskContext) stri return nil } + // Intake allocates the review state on every entry, so this flag is set + // on the state the decision stages built, not before them. + tc.prReview.ownPR = true + if err := OpenPR(ctx, tc, body(tc)); err != nil { return err } diff --git a/internal/domain/workflow/prreview_own_pr_test.go b/internal/domain/workflow/prreview_own_pr_test.go new file mode 100644 index 000000000..714a07380 --- /dev/null +++ b/internal/domain/workflow/prreview_own_pr_test.go @@ -0,0 +1,30 @@ +package workflow + +import ( + "context" + "log/slog" + "testing" + + "github.com/samcharles93/archie-core/internal/domain/workflow/task" +) + +// Intake allocates tc.prReview on every entry, so the own-PR flag is recorded +// after the decision stages, on the state they built. Recording it before them +// dereferenced a nil state and panicked the agent container at the end of every +// implement run, before the pull request was opened. +func TestOwnPRReviewRecordsOwnPRAfterTheDecisionStages(t *testing.T) { + tc := &TaskContext{Task: &task.Task{ID: 7, Source: task.SourceTest, Owner: "o", Repo: "r"}, Log: slog.Default()} + RecordDeliveries(tc) + intake := Stage{Name: "intake", Run: func(_ context.Context, tc *TaskContext) error { + tc.prReview = &prReviewState{} + return nil + }} + + stage := stagePRReviewAndOpenPR([]Stage{intake}, func(*TaskContext) string { return "" }) + if err := stage.Run(context.Background(), tc); err != nil { + t.Fatalf("own-PR review: %v", err) + } + if !tc.prReview.ownPR { + t.Fatal("the pull request this run opened is not marked as its own") + } +}