From f9e97b561f34324767b1067f7895ea34e8a00350 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Wed, 30 Sep 2026 07:40:26 +1000 Subject: [PATCH] fix(workflow): the own-PR flow no longer parks on the operator-approval gate --- internal/domain/workflow/implement_test.go | 7 ++ internal/domain/workflow/prreview_headless.go | 4 +- internal/domain/workflow/prreview_own_pr.go | 14 +-- .../domain/workflow/prreview_own_pr_test.go | 88 +++++++++++++++++++ internal/domain/workflow/prreview_stages.go | 21 +++-- 5 files changed, 123 insertions(+), 11 deletions(-) diff --git a/internal/domain/workflow/implement_test.go b/internal/domain/workflow/implement_test.go index c6ec770de..a4ee7f10a 100644 --- a/internal/domain/workflow/implement_test.go +++ b/internal/domain/workflow/implement_test.go @@ -363,6 +363,10 @@ func (f *fakeForge) VerifyPush(ctx context.Context, owner, repo string) error { // TestStageCommitPushClosesIssueWhenBuildNoChanges verifies that // StageCommitPush closes the issue with a comment when BuildNoChanges // is true, instead of trying to commit and failing. +// +// This is also the terminal half of the hazard archie-core-7nst describes: a +// run re-entered against a worktree that already carries the change reaches +// this path, and it must close the issue without ever opening a pull request. func TestStageCommitPushClosesIssueWhenBuildNoChanges(t *testing.T) { f := &fakeForge{} @@ -389,6 +393,9 @@ func TestStageCommitPushClosesIssueWhenBuildNoChanges(t *testing.T) { } else { t.Log("CloseIssue called (no changes needed)") } + if len(f.calls) != 0 { + t.Errorf("forge calls = %v, want none: a no-changes run closes the issue and opens no pull request", f.calls) + } if tc.Outcome.Status != StatusCompleted { t.Errorf("expected Outcome=Completed, got %s", tc.Outcome.Status) } else { diff --git a/internal/domain/workflow/prreview_headless.go b/internal/domain/workflow/prreview_headless.go index 2e82f1b2f..8cf2a139d 100644 --- a/internal/domain/workflow/prreview_headless.go +++ b/internal/domain/workflow/prreview_headless.go @@ -16,6 +16,8 @@ type PRReviewDecision struct { SkippedPhases []string } +// ReviewPullRequest refuses operator approval outright, so the gate is left +// out of the stage list rather than reached and skipped. func ReviewPullRequest(ctx context.Context, tc *TaskContext) (PRReviewDecision, error) { if tc.Cfg.Review.ApproveBeforePost { return PRReviewDecision{}, fmt.Errorf("headless review cannot wait for operator approval") @@ -27,7 +29,7 @@ func ReviewPullRequest(ctx context.Context, tc *TaskContext) (PRReviewDecision, _ = os.RemoveAll(tc.prReview.snapshotDir) } }() - for _, stage := range prReviewDecisionStages() { + for _, stage := range prReviewDecisionStages(false) { if err := ctx.Err(); err != nil { return PRReviewDecision{}, err } diff --git a/internal/domain/workflow/prreview_own_pr.go b/internal/domain/workflow/prreview_own_pr.go index 58cfac479..2aba55dcb 100644 --- a/internal/domain/workflow/prreview_own_pr.go +++ b/internal/domain/workflow/prreview_own_pr.go @@ -104,6 +104,12 @@ func renderBlockingFindingsDetail(findings []prreview.ScoredFinding) string { // the outcome the PR's existence already earned -- the same best-effort // convention the deleted StagePostReviewComments followed. // +// The operator-approval gate is deliberately not spliced in here: it belongs +// to the standalone pr-review workflow, where an operator's response +// re-reviews a pull request that already exists to post to. This trigger +// reviews a change with no PR and no place to post yet, so a wait here would +// end the implement run before its PR was opened (archie-core-7nst). +// // This must run every decision stage from inside one Stage.Run body rather // than as separate Stage entries in the workflow's list: the engine ends a // run the instant any stage sets tc.Outcome (workflow.go's Run loop), so a @@ -111,7 +117,7 @@ func renderBlockingFindingsDetail(findings []prreview.ScoredFinding) string { // spliced in as their own preceding stages -- OpenPR's own doc comment names // this exact pattern ("call this and then do so in the same stage"). func StagePRReviewAndOpenPR(body func(*TaskContext) string) Stage { - return stagePRReviewAndOpenPR(prReviewDecisionStages(), body) + return stagePRReviewAndOpenPR(prReviewDecisionStages(false), body) } // stagePRReviewAndOpenPR is StagePRReviewAndOpenPR's implementation, taking @@ -127,10 +133,8 @@ func stagePRReviewAndOpenPR(decisionStages []Stage, body func(*TaskContext) stri return fmt.Errorf("pr-review (%s): %w", stage.Name, err) } if tc.Outcome.Status != "" { - // A decision stage ended the run itself (operator-approval's - // waiting_human, or a decision stage's own park). Honor it - // rather than proceed to open a PR the operator has not - // cleared yet. + // A decision stage ended the run itself. Honor it rather than + // proceed to open a PR the run has already decided against. return nil } } diff --git a/internal/domain/workflow/prreview_own_pr_test.go b/internal/domain/workflow/prreview_own_pr_test.go index 8f563e661..ee8a40b60 100644 --- a/internal/domain/workflow/prreview_own_pr_test.go +++ b/internal/domain/workflow/prreview_own_pr_test.go @@ -4,8 +4,10 @@ import ( "context" "errors" "log/slog" + "strings" "testing" + "github.com/samcharles93/archie-core/internal/agentexec" "github.com/samcharles93/archie-core/internal/config" "github.com/samcharles93/archie-core/internal/domain/workflow/prreview" ) @@ -168,6 +170,92 @@ func TestLocalPRSourceReadsFromTheTasksOwnWorktree(t *testing.T) { } } +// scriptedPRReviewPipeline answers every agent call the full decision +// pipeline makes with the minimum its decoder accepts, ending with one +// advisory (non-blocking) finding: enough for the pipeline to reach the point +// of opening a PR, and nothing that parks on its own. +func scriptedPRReviewPipeline() *concurrentAgentRunner { + return &concurrentAgentRunner{byStage: func(stage string) (agentexec.Result, error) { + switch { + case stage == "intake-ai-score": + return captureResult("score_ai_generated", map[string]any{"confidence": 0.1}), nil + case strings.HasPrefix(stage, "lens-"): + return captureResult("propose_dimensions", map[string]any{"dimensions": []map[string]any{{ + "name": "defect", "prompt": "review main.go", "target_files": []string{"main.go"}, "priority": 1.0, + }}}), nil + case strings.HasPrefix(stage, "reviewer-"): + return captureResult("report_findings", map[string]any{"findings": []map[string]any{{ + "file": "main.go", "line_start": 1, "severity": "important", "title": "defect", + "body": "broken", "evidence": "package main", "confidence": 0.9, + }}}), nil + case stage == "evidence-verifier": + return captureResult("verify_findings", map[string]any{"verdicts": []map[string]any{{"index": 0, "supported": true}}}), nil + case stage == "adversary": + return captureResult("adversary_verdicts", map[string]any{"verdicts": []map[string]any{{"index": 0, "verdict": "confirmed"}}}), nil + case stage == "consistency": + return captureResult("report_findings", map[string]any{"findings": []any{}}), nil + case stage == "merge-gate": + return captureResult("classify_blocking", map[string]any{"blocking": false}), nil + case stage == "polish": + return captureResult("polish", map[string]any{"body": "tightened"}), nil + default: + return passedResult("phase complete"), nil + } + }} +} + +// TestStagePRReviewAndOpenPRDoesNotParkOnOperatorApproval is the regression +// test for archie-core-7nst. The own-PR trigger splices the pr-review +// decision stages into the implement workflow before it opens its PR, and +// with review.approve_before_post set the operator-approval gate used to end +// that run in waiting_human with no PR in existence. Approving such a park +// re-runs the whole implement workflow against a worktree that already +// carries the change; a builder that then finds nothing to do makes +// StageCommitPush close the issue, so the run completes and the PR is never +// opened. The gate belongs to the standalone pipeline only. +func TestStagePRReviewAndOpenPRDoesNotParkOnOperatorApproval(t *testing.T) { + tc, forge := ownPRTaskContext(t) + tc.Task.Workflow = "implement" + tc.Cfg.Review.ApproveBeforePost = true + tc.Cfg.Models = map[string]string{"review": "provider/review", "classification": "provider/classification"} + tc.Agent = scriptedPRReviewPipeline() + + if err := StagePRReviewAndOpenPR(implementPRBody).Run(context.Background(), tc); err != nil { + t.Fatalf("stage: %v", err) + } + if tc.Outcome.Status == StatusWaitingHuman { + t.Fatalf("outcome = %q: the own-PR splice must not park on the operator-approval gate, there is no PR to post to yet", tc.Outcome.Status) + } + if tc.Outcome.Status != StatusPROpen { + t.Fatalf("outcome = %q, want %q", tc.Outcome.Status, StatusPROpen) + } + if forge.prNumber == 0 { + t.Fatal("no PR was opened") + } +} + +// TestPRReviewWorkflowStillParksOnOperatorApproval is the other half of the +// archie-core-7nst fix: the gate is dropped from the own-PR splice, not from +// the pipeline. The standalone pr-review workflow still waits for the +// operator before it posts and before its merge gate runs. +func TestPRReviewWorkflowStillParksOnOperatorApproval(t *testing.T) { + tc := baseTaskContext(t) + tc.Cfg.Review.ApproveBeforePost = true + tc.PRSource = &fakePRSource{diff: smallDiff, files: map[string]string{"main.go": "package main\n"}} + tc.Agent = scriptedPRReviewPipeline() + forge := &fakeForge{} + tc.Forge = forge + + Run(context.Background(), PRReview(), tc) + + if tc.Outcome.Status != StatusWaitingHuman { + t.Fatalf("outcome = %q, want %q: the standalone pipeline must still wait for the operator", tc.Outcome.Status, StatusWaitingHuman) + } + if len(forge.calls) != 0 || forge.reviewCalls != 0 { + t.Errorf("forge calls = %v (reviews %d), want none: nothing posts before the operator responds", forge.calls, forge.reviewCalls) + } +} + // configRepoWithBase builds a minimal config.Repo whose BaseBranch() // resolves without a live git call. func configRepoWithBase(t *testing.T) config.Repo { diff --git a/internal/domain/workflow/prreview_stages.go b/internal/domain/workflow/prreview_stages.go index 273b85fbb..f26af44fd 100644 --- a/internal/domain/workflow/prreview_stages.go +++ b/internal/domain/workflow/prreview_stages.go @@ -163,7 +163,7 @@ func PRReview() Workflow { "depth": {Type: "string"}, }, }, - Stages: append(prReviewDecisionStages(), stagePROutput()), + Stages: append(prReviewDecisionStages(true), stagePROutput()), } } @@ -174,8 +174,17 @@ func PRReview() Workflow { // trigger): the decision of whether an unchallenged blocking finding parks // the task must happen before a PR exists to post to, while phase 9's // posting must happen after, once a PR number exists to anchor comments to. -func prReviewDecisionStages() []Stage { - return []Stage{ +// +// withOperatorApproval splices the operator-approval gate in between +// synthesis and the merge gate. Only the standalone pr-review workflow passes +// true: there the operator's response re-reviews the pull request, and the +// run is re-entered from the start anyway, which is safe because that +// pipeline has no write-then-close stage. Archie's own PRs has no PR to give +// the operator a posting decision about yet, and a park there would end the +// implement run before it opened one (archie-core-7nst), so the splice drops +// the gate instead. +func prReviewDecisionStages(withOperatorApproval bool) []Stage { + stages := []Stage{ stagePRIntake(), stagePRAnatomy(), stagePRLenses(), @@ -184,9 +193,11 @@ func prReviewDecisionStages() []Stage { stagePRVerification(), stagePRCoverageConsistency(), stagePRSynthesis(), - stagePROperatorApproval(), - stagePRMergeGate(), } + if withOperatorApproval { + stages = append(stages, stagePROperatorApproval()) + } + return append(stages, stagePRMergeGate()) } // stagePRIntake is pipeline phase 1: PR metadata and diff statistics, the