From dbd4f4ccedf1d4ab5a5bf6c48edf90288c0f9088 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 15:51:19 +0000 Subject: [PATCH] fix(pr-assistant): make pipeline auto-fix learn from failed attempts and keep timed-out edits Attempts 1-3 on shorts-generator#411 failed for three unrelated reasons that each retry repeated blind: a timeout that threw away a finished edit, a new CSS file the review rejected, and a rewrite of .env.example. Retries now receive the earlier rejection reasons, the prompt states the rules the validators enforce (coverage gates, no whole-file rewrites, no new files, stop early), and a timed-out edit goes through the full gate instead of being discarded. Timeouts are reported as such. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Cn6JQLtmA8NV75CtdV373W --- .../agents/pr_assistant/pipeline-fix-flow.ts | 4 +-- ts/src/agents/pr_assistant/pipeline-fixer.ts | 35 ++++++++++++++++--- ts/tests/pr-assistant.test.ts | 14 +++++++- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/ts/src/agents/pr_assistant/pipeline-fix-flow.ts b/ts/src/agents/pr_assistant/pipeline-fix-flow.ts index bb4291d3..8ea1608a 100644 --- a/ts/src/agents/pr_assistant/pipeline-fix-flow.ts +++ b/ts/src/agents/pr_assistant/pipeline-fix-flow.ts @@ -3,7 +3,7 @@ import type { GithubClient, PR } from "../../github/client.ts"; import { commitsBehind } from "./branch-staleness.ts"; import { getPipelineErrorLogs } from "./logs.ts"; import { checkPipelineStatus } from "./pipeline.ts"; -import { MANUAL_PIPELINE_LABEL, buildMarker, fixPipelineAutonomously, maxAttempts, pipelineFixEnabled, readAttemptState } from "./pipeline-fixer.ts"; +import { MANUAL_PIPELINE_LABEL, buildMarker, fixPipelineAutonomously, maxAttempts, pipelineFixEnabled, previousAttemptFailures, readAttemptState } from "./pipeline-fixer.ts"; type Log = (m: string, level?: string) => void; @@ -53,7 +53,7 @@ export async function attemptPipelineFix(pr: PR, gh: GithubClient, log: Log): Pr if (!data.logs.trim()) { log(`No actionable pipeline logs for PR #${pr.number}`, "WARNING"); return false; } const attempt = last + 1; log(`PR #${pr.number}: pipeline failing — fix attempt ${attempt}/${mx}`); - const [success, msg, sha] = await fixPipelineAutonomously(gh, pr, data.logs, data.failed_checks, attempt, mx); + const [success, msg, sha] = await fixPipelineAutonomously(gh, pr, data.logs, data.failed_checks, attempt, mx, previousAttemptFailures(comments)); await commentAttempt(pr, gh, log, msg, attempt, mx, sha || pr.head.sha, success); if (success) return true; if (attempt >= mx) await markManual(pr, gh, log, msg); diff --git a/ts/src/agents/pr_assistant/pipeline-fixer.ts b/ts/src/agents/pr_assistant/pipeline-fixer.ts index e1213bce..032925b8 100644 --- a/ts/src/agents/pr_assistant/pipeline-fixer.ts +++ b/ts/src/agents/pr_assistant/pipeline-fixer.ts @@ -44,7 +44,18 @@ export function readAttemptState(comments: { body?: string | null }[]): [number, for (const c of comments) { const m = MARKER_RE.exec(c.body ?? ""); if (m) { attempt = parseInt(m[1]!, 10); sha = m[2]!; } } return [attempt, sha]; } -export function buildPrompt(errorLogs: string, failedChecks: string[]): string { +/** Reasons of the earlier failed attempts (newest last), read back from the attempt comments so a retry does not repeat them. */ +export function previousAttemptFailures(comments: { body?: string | null }[], limit = 3): string[] { + const out: string[] = []; + for (const c of comments) { + const body = c.body ?? ""; + if (!MARKER_RE.test(body) || !body.includes("a tentativa falhou")) continue; + const m = /\*\*Detalhes:\*\*\s*([\s\S]*?)\s*