diff --git a/.opencode/agents/ca-continuous-pr-reviewer.md b/.opencode/agents/ca-continuous-pr-reviewer.md index 1c1589de3..b0e22faa9 100644 --- a/.opencode/agents/ca-continuous-pr-reviewer.md +++ b/.opencode/agents/ca-continuous-pr-reviewer.md @@ -416,15 +416,32 @@ LOOP FOREVER: last_status: result.merge_status } elif result.merge_status == "conflict": - post comment on PR #pr_number: - "Merge conflict detected. The implementing agent - needs to rebase this branch onto latest master. + # Merge conflict — attempt rebase before giving up. + # The implementing agent has already exited, so nobody + # else will rebase this branch. + rebase_success = attempt_rebase(pr_number) + if rebase_success: + pending_merge[pr_number] = { + attempts: pending_merge.get(pr_number, {}).get(attempts, 0) + 1, + last_status: "rebased_retrying" + } + post comment on PR #pr_number: + "Merge conflict detected. Reviewer pool rebased + the branch onto latest master. Re-attempting merge. - --- - **Automated by CleverAgents Bot** - Supervisor: PR Review | Agent: ca-continuous-pr-reviewer" - reviewed_prs.add(pr_number) - pending_merge.pop(pr_number, None) + --- + **Automated by CleverAgents Bot** + Supervisor: PR Review | Agent: ca-continuous-pr-reviewer" + else: + post comment on PR #pr_number: + "Merge conflict detected. Automatic rebase failed + (conflicts too complex). Manual rebase required. + + --- + **Automated by CleverAgents Bot** + Supervisor: PR Review | Agent: ca-continuous-pr-reviewer" + reviewed_prs.add(pr_number) + pending_merge.pop(pr_number, None) elif result.decision == "changes_requested": reviewed_prs.add(pr_number) pending_merge.pop(pr_number, None) @@ -549,7 +566,7 @@ The pool supervisor tracks PRs across their full merge lifecycle: | `ci_pending` | CI still running, merge not yet attempted | Retry next cycle. | | `ci_failing` | CI failed, fix attempted | Retry next cycle (ca-pr-checker may fix it). | | `merge_failed` | Merge API call failed | Retry next cycle indefinitely. Post diagnostic every 10 attempts. | -| `conflict` | Merge conflicts exist | Post comment, stop retrying. Implementor must rebase. | +| `conflict` | Merge conflicts exist | Attempt auto-rebase; if it fails, post comment and stop. | | `changes_requested` | Code review found issues | Wait for implementor to push fixes. Re-review on SHA change. | | `awaiting_human` | `needs feedback` label | Stop. Human must merge. | @@ -559,6 +576,49 @@ they choose, but the system never gives up autonomously. --- +## Auto-Rebase on Conflict + +When a reviewer reports `merge_status: "conflict"`, the pool supervisor +attempts to rebase the PR branch onto the latest master before giving up. +The implementing agent has already exited after PR creation, so nobody else +will perform this rebase. + +``` +def attempt_rebase(pr_number): + pr = fetch PR #pr_number via Forgejo API + branch = pr.head.ref + + cd "$CLONE_DIR" + git fetch origin + git checkout + git rebase origin/master + + if rebase succeeds (exit code 0): + git push origin --force-with-lease + if push succeeds: + return True + else: + git rebase --abort # safety + return False + else: + git rebase --abort + return False +``` + +**Key rules for auto-rebase:** +- Use `--force-with-lease` (not `--force`) to avoid overwriting concurrent + pushes from other agents. +- If the rebase produces conflicts that cannot be auto-resolved, abort + immediately — do not attempt manual conflict resolution. +- After a successful rebase + push, the PR's head SHA changes. Add the PR + back to `pending_merge` so the next cycle re-dispatches a reviewer to + attempt the merge. +- Limit rebase attempts to **3 per PR**. If three consecutive rebases fail, + post a comment and stop retrying (the conflicts are too complex for + auto-resolution). + +--- + ## Bot Signature (Required on ALL Forgejo Content) Every comment, issue body, PR description, and review you post to Forgejo