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.
This commit is contained in:
sam committed 2026-10-26 18:07:01 +11:00
1 parent 46477b8e26
commit a40ff52bd4
2 files changed
+34 -1

No files matched your search

+4 -1
View File
@@ -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
}
@@ -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")
}
}