feat: auto-resolve merge conflicts with escalating strategy (t302)#1203
feat: auto-resolve merge conflicts with escalating strategy (t302)#1203marcusquinn merged 1 commit intomainfrom
Conversation
Add escalating conflict resolution to rebase_sibling_pr(): 1. Plain rebase (no conflicts) 2. Rebase with -Xtheirs (feature branch wins on conflicts) 3. AI CLI resolution for complex cases (Strategy 3 fallback) Also adds: - resolve_rebase_conflicts() for AI-assisted per-file resolution - Stale worktree cleanup (abort stuck rebases, fix detached HEAD) - Temp worktree creation when no worktree exists (avoids dirty tree) - CONFLICTING added to t298 handler (was only BEHIND/DIRTY) - Phase 7b: periodic retry of merge-conflict-blocked tasks (30min) Tested: resolved 4 blocked PRs (#1171, #1187, #1188, #1191) that were stuck with merge conflicts — all resolved with -Xtheirs.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
WalkthroughThis change introduces AI-assisted git rebase conflict resolution to the supervisor helper script. A new Changes
Sequence DiagramsequenceDiagram
participant Supervisor as Supervisor Script
participant Git as Git Operations
participant AI as AI CLI
participant Worktree as Worktree Manager
Supervisor->>Git: Attempt rebase (plain)
Git-->>Supervisor: Conflicts detected
Supervisor->>Git: Attempt rebase with -Xtheirs
Git-->>Supervisor: Conflicts persist
Supervisor->>Git: Abort rebase, reset to origin/main
Supervisor->>Worktree: Prepare worktree (cleanup/create)
Supervisor->>Git: Detect conflicting files
Git-->>Supervisor: Return conflict file list
Supervisor->>Git: Read conflicting file content
Git-->>Supervisor: File with conflict markers
Supervisor->>AI: Send file + conflict resolution rules
AI-->>Supervisor: Resolved file content
Supervisor->>Git: Validate marker removal
Supervisor->>Git: Stage resolved file
Supervisor->>Git: Rebase --continue
Git-->>Supervisor: Rebase complete
Supervisor->>Supervisor: Log outcome, update task state
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🔍 Code Quality Report�[0;35m[MONITOR]�[0m Code Review Monitoring Report �[0;34m[INFO]�[0m Latest Quality Status: �[0;34m[INFO]�[0m Recent monitoring activity: 📈 Current Quality Metrics
Generated on: Thu Feb 12 02:46:08 UTC 2026 Generated by AI DevOps Framework Code Review Monitoring |
|
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
.agents/scripts/supervisor-helper.sh (2)
9059-9063:⚠️ Potential issue | 🟠 MajorAlign merge-conflict error token with Phase 7b filter
Phase 7b retries only
error LIKE '%merge_conflict%', but this path writes"Merge conflict — auto-rebase failed", so those tasks won’t be picked up for retry. Standardize the error token (or broaden the Phase 7b filter).🔧 Suggested fix
- cmd_transition "$task_id" "blocked" --error "Merge conflict — auto-rebase failed" 2>>"$SUPERVISOR_LOG" || true + cmd_transition "$task_id" "blocked" --error "merge_conflict:auto_rebase_failed" 2>>"$SUPERVISOR_LOG" || true
10821-10827:⚠️ Potential issue | 🟠 MajorTODO.md conflict auto‑resolve (Issue
#1176) is still missing
commit_and_push_todo()aborts on rebase conflicts and retries, but the required behavior is to detect TODO.md conflict markers, keep the longer line, stage, andrebase --continue(single attempt, then abort on failure). Without this, concurrent TODO.md edits still block the pipeline.🛠️ Minimal implementation sketch
commit_and_push_todo() { local repo_path="$1" local commit_msg="$2" local max_retries="${3:-3}" + local auto_resolve_attempted=false @@ - if ! git -C "$repo_path" pull --rebase --autostash 2>>"$SUPERVISOR_LOG"; then + if ! git -C "$repo_path" pull --rebase --autostash 2>>"$SUPERVISOR_LOG"; then log_warn "Pull-rebase failed (attempt $attempt/$max_retries)" - # Abort rebase if in progress and retry - git -C "$repo_path" rebase --abort 2>>"$SUPERVISOR_LOG" || true + # Single auto-resolve attempt for TODO.md conflicts (t302/t1176) + if [[ "$auto_resolve_attempted" == "false" ]] && _auto_resolve_todo_conflict "$repo_path/TODO.md" "$repo_path"; then + auto_resolve_attempted=true + if ! git -C "$repo_path" rebase --continue 2>>"$SUPERVISOR_LOG"; then + git -C "$repo_path" rebase --abort 2>>"$SUPERVISOR_LOG" || true + fi + else + git -C "$repo_path" rebase --abort 2>>"$SUPERVISOR_LOG" || true + fi sleep "$attempt" continue fi# helper sketch (place near commit_and_push_todo) _auto_resolve_todo_conflict() { local todo_file="$1" local repo_path="$2" [[ -f "$todo_file" ]] || return 1 grep -q '<<<<<<<' "$todo_file" || return 1 local tmp_file tmp_file=$(mktemp) local state=0 head="" other="" while IFS= read -r line || [[ -n "$line" ]]; do case "$line" in "<<<<<<<"*) state=1; head=""; other=""; continue ;; "=======") state=2; continue ;; ">>>>>>>") if [[ ${`#head`} -ge ${`#other`} ]]; then echo "$head" >> "$tmp_file"; else echo "$other" >> "$tmp_file"; fi state=0; continue ;; esac if [[ "$state" -eq 1 ]]; then head="$line"; elif [[ "$state" -eq 2 ]]; then other="$line"; else echo "$line" >> "$tmp_file"; fi done < "$todo_file" mv "$tmp_file" "$todo_file" git -C "$repo_path" add "$todo_file" 2>>"$SUPERVISOR_LOG" || true return 0 }
🤖 Fix all issues with AI agents
In @.agents/scripts/supervisor-helper.sh:
- Around line 8169-8178: The branch that handles successful git -C "$git_dir"
diff --check -- "$conflict_file" should explicitly stage the file before
counting it resolved: run git -C "$git_dir" add "$conflict_file" (redirect
errors to "$SUPERVISOR_LOG" or || true as in the other branch), only increment
resolved_count and call log_info "Resolved: $conflict_file" after the add
succeeds (or still increment but ensure add is attempted), mirroring the
fallback branch that already stages files with git -C "$git_dir" add
"$conflict_file" 2>>"$SUPERVISOR_LOG" || true.
| # Check if the file was resolved (no more conflict markers) | ||
| if git -C "$git_dir" diff --check -- "$conflict_file" 2>/dev/null; then | ||
| # diff --check returns 0 if no conflict markers remain | ||
| resolved_count=$((resolved_count + 1)) | ||
| log_info " Resolved: $conflict_file" | ||
| elif ! grep -q '<<<<<<<' "$full_path" 2>/dev/null; then | ||
| # Fallback check: no conflict markers in file | ||
| # Ensure it is staged | ||
| git -C "$git_dir" add "$conflict_file" 2>>"$SUPERVISOR_LOG" || true | ||
| resolved_count=$((resolved_count + 1)) |
There was a problem hiding this comment.
Stage AI-resolved files before continuing the rebase
git diff --check can pass even when the file is still unmerged/unstaged (if the AI didn’t run git add), which makes rebase --continue fail and abort the escalation. Stage explicitly after the clean check to keep the automation deterministic.
🔧 Suggested fix
- if git -C "$git_dir" diff --check -- "$conflict_file" 2>/dev/null; then
- # diff --check returns 0 if no conflict markers remain
- resolved_count=$((resolved_count + 1))
- log_info " Resolved: $conflict_file"
+ if git -C "$git_dir" diff --check -- "$conflict_file" 2>/dev/null; then
+ # diff --check returns 0 if no conflict markers remain
+ git -C "$git_dir" add "$conflict_file" 2>>"$SUPERVISOR_LOG" || true
+ resolved_count=$((resolved_count + 1))
+ log_info " Resolved: $conflict_file"🤖 Prompt for AI Agents
In @.agents/scripts/supervisor-helper.sh around lines 8169 - 8178, The branch
that handles successful git -C "$git_dir" diff --check -- "$conflict_file"
should explicitly stage the file before counting it resolved: run git -C
"$git_dir" add "$conflict_file" (redirect errors to "$SUPERVISOR_LOG" or || true
as in the other branch), only increment resolved_count and call log_info
"Resolved: $conflict_file" after the add succeeds (or still increment but ensure
add is attempted), mirroring the fallback branch that already stages files with
git -C "$git_dir" add "$conflict_file" 2>>"$SUPERVISOR_LOG" || true.



Summary
rebase_sibling_pr(): plain rebase →-Xtheirs→ AI CLI fallbackresolve_rebase_conflicts()for AI-assisted per-file conflict resolution (Strategy 3)CONFLICTINGto the t298 handler (previously only handledBEHIND/DIRTY)Testing
Tested live against 4 blocked PRs (#1171, #1187, #1188, #1191) — all resolved successfully with
-Xtheirs(Strategy 2). The AI CLI fallback (Strategy 3) was not needed for these cases but is available for more complex conflicts.Closes
Closes #1176
Summary by CodeRabbit
Release Notes