Skip to content

Commit 20e41e0

Browse files
fantapopclaude
andcommitted
autosolve: Exit non-zero when implementation fails
Previously the implement binary exited 0 even on failure (all retries exhausted, security check failed, PR creation failed), making the step appear green. Now it writes outputs first so subsequent workflow steps can still read them, then returns an error so the step is correctly marked as failed. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9efd0ef commit 20e41e0

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

autosolve/internal/implement/implement.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ func Run(
158158
for _, v := range violations {
159159
action.LogWarning(v)
160160
}
161-
action.LogWarning("Security check failed: violations found in staged changes")
162-
return writeOutputs("FAILED", "", "", resultText, &tracker)
161+
_ = writeOutputs("FAILED", "", "", resultText, &tracker)
162+
return fmt.Errorf("security check failed: violations found in staged changes")
163163
}
164164
action.LogNotice("Security check passed")
165165
}
@@ -170,8 +170,10 @@ func Run(
170170
var err error
171171
prURL, branchName, err = pushAndPR(ctx, cfg, runner, ghClient, gitClient, tmpDir, resultText, &tracker)
172172
if err != nil {
173-
action.LogWarning(fmt.Sprintf("PR creation failed: %v", err))
174-
return writeOutputs("FAILED", "", "", resultText, &tracker)
173+
// Write outputs before returning the error so status/summary are
174+
// available to subsequent workflow steps.
175+
_ = writeOutputs("FAILED", "", "", resultText, &tracker)
176+
return fmt.Errorf("PR creation failed: %w", err)
175177
}
176178
}
177179

@@ -186,7 +188,13 @@ func Run(
186188
}
187189
}
188190

189-
return writeOutputs(status, prURL, branchName, resultText, &tracker)
191+
if err := writeOutputs(status, prURL, branchName, resultText, &tracker); err != nil {
192+
return err
193+
}
194+
if status != "SUCCESS" {
195+
return fmt.Errorf("implementation failed")
196+
}
197+
return nil
190198
}
191199

192200
func pushAndPR(

autosolve/internal/implement/implement_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ func TestRun_AllRetriesFail(t *testing.T) {
181181
results: []string{"IMPLEMENTATION_RESULT - FAILED", "IMPLEMENTATION_RESULT - FAILED"},
182182
}
183183

184-
// Should not return error — just sets status to FAILED
184+
// Should return an error so the step exits non-zero.
185185
err := Run(context.Background(), cfg, runner, &mockGHClient{}, &mockGitClient{}, tmpDir)
186-
if err != nil {
187-
t.Fatal(err)
186+
if err == nil {
187+
t.Fatal("expected error when all retries fail")
188188
}
189189
if runner.calls != 2 {
190190
t.Errorf("expected 2 calls, got %d", runner.calls)

0 commit comments

Comments
 (0)