fix: strengthen validation in conflict resolver to prevent bad merge commits (#26754)

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Keith Williams
2026-01-12 15:10:18 +00:00
committed by GitHub
co-authored by Devin AI
parent 1e295827c7
commit 92f13cdb56
+30 -8
View File
@@ -316,6 +316,8 @@ jobs:
Base Branch: ${pr.base_ref}
${pr.is_fork ? `Fork Repository: ${pr.head_repo_owner}/${pr.head_repo_name}` : ''}
IMPORTANT WARNING: If your merge commit shows more than 50 files changed, DO NOT PUSH. This indicates the merge was done incorrectly. Abort and leave a comment instead.
Your tasks:
${forkInstructions}
@@ -327,13 +329,32 @@ jobs:
- If unsure about a conflict, prefer keeping both changes where possible
2. Test that the code still works after resolving conflicts (run lint/type checks).
3. Commit the merge resolution with a clear commit message.
4. CRITICAL VALIDATION BEFORE PUSHING: You MUST validate your merge commit before pushing:
- Run: git diff --stat HEAD^1...HEAD (shows changes relative to PR branch parent)
- Run: git diff --stat HEAD^2...HEAD (shows changes relative to base branch parent)
- The changes relative to the base branch parent (HEAD^2) should be SIMILAR to the original PR changes, NOT include all the new commits from ${pr.base_ref}
- If your merge commit shows hundreds of files changed or includes changes that were already in ${pr.base_ref}, STOP IMMEDIATELY
- A proper merge commit only contains conflict resolutions, not reproduced changes from the target branch
- If validation fails: DO NOT PUSH. Log the error, explain what went wrong, and abort the task.
4. CRITICAL VALIDATION BEFORE PUSHING - YOU MUST RUN THESE EXACT COMMANDS:
Step A: Count files changed in your merge commit:
\`\`\`
FILE_COUNT=$(git diff --name-only HEAD^1...HEAD | wc -l)
echo "Files changed in merge commit: $FILE_COUNT"
\`\`\`
Step B: If FILE_COUNT > 50, STOP IMMEDIATELY. DO NOT PUSH.
- A proper merge commit should only contain conflict resolutions
- If you see 50+ files changed, the merge was done INCORRECTLY
- This usually means you accidentally reproduced changes from ${pr.base_ref} instead of just resolving conflicts
Step C: Compare your merge to the original PR:
\`\`\`
git diff --stat HEAD^1...HEAD
\`\`\`
- This should show ONLY the files that had conflicts, plus any files from ${pr.base_ref} that were merged in
- If you see hundreds of files or files unrelated to the original PR conflicts, STOP
Step D: If validation fails:
- DO NOT PUSH under any circumstances
- DO NOT attempt to fix it
- Leave a comment on the PR explaining that the merge validation failed
- ABORT THE TASK IMMEDIATELY
- It is better to leave the PR with conflicts than to push a broken merge commit that pollutes git history
5. Push the resolved changes to the PR branch only after validation passes.
6. After successfully pushing the resolved changes, remove the \`devin-conflict-resolution\` label from the PR using the GitHub API.
@@ -345,7 +366,8 @@ jobs:
4. If a conflict seems too complex or risky to resolve automatically, explain the situation in a PR comment instead.
5. Never ask for user confirmation. Never wait for user messages.
6. CRITICAL: If this is a fork PR and you encounter ANY error when pushing (permission denied, authentication failure, etc.), you MUST fail the task immediately. Do NOT attempt to push to a new branch in the main ${owner}/${repo} repository as a workaround. Simply report the error and stop.
7. CRITICAL: Never reproduce or recreate changes from the target branch. Your merge commit should ONLY contain conflict resolutions. If you find yourself manually copying file contents from ${pr.base_ref} or creating changes that mirror what's already in ${pr.base_ref}, you are doing it wrong. Use git's merge functionality properly - it handles bringing in changes automatically.`;
7. CRITICAL: Never reproduce or recreate changes from the target branch. Your merge commit should ONLY contain conflict resolutions. If you find yourself manually copying file contents from ${pr.base_ref} or creating changes that mirror what's already in ${pr.base_ref}, you are doing it wrong. Use git's merge functionality properly - it handles bringing in changes automatically.
8. CRITICAL: If your merge commit shows a large number of files changed (more than 50), DO NOT PUSH UNDER ANY CIRCUMSTANCES. This is a sign that the merge was done incorrectly. Abort the task and leave a comment explaining the issue. A bad merge commit in the git history is worse than leaving the PR with conflicts.`;
try {
let sessionUrl;