S SEOMONEY SEO · Công nghệ · Tài chính cá nhân 26.06.2026

Merge Conflict Preflight: Phát Hiện Lỗi Trước Khi Quá Muộn

Tại sao phát hiện conflict trước khi merge lại quan trọng hơn giải quyết sau? Và làm sao Preflight catch 94% conflicts?

2Phút đọc
392Từ
10Mục lục
26.062026
2 phút đọc

The Problem with Late Detection

Trước khi có Preflight, conflict được phát hiện sau khi merge:

14:32 — PR #945 merge vào main (CI pass, QA pass)
14:35 — Main branch now has conflict from next PR
14:40 — Developer of PR #946 cố merge
        ❌ Git: "cannot merge, conflicts exist"
14:45 — Developer start resolving manually
15:30 — After 45 min, finally merged

Problem:

  1. Delay feedback — Developer không biết issue cho tới sau merge attempt
  2. CI queue blocked — Nếu có 5 PR, 4 cái phải chờ
  3. Manual intervention — Con người phải babysit
  4. No early warning system

Preflight: Detect Before Merge

Với Preflight, detection xảy ra trước merge:

14:00 — PR #945 tạo
        Preflight runs: simulate merge → ✅ clean
        
14:32 — PR #945 merge vào main
        
14:33 — Preflight check runs on open PRs
        PR #946: test merge with new main
        ⚠️ CONFLICT detected
        Post comment: "Add auto-resolve label"
        
14:34 — Developer see notification
        Add label immediately
        
14:40 — Auto-resolve workflow complete
        ✅ PR ready for merge

Benefits:

  1. Immediate feedback
  2. Specific conflict report
  3. Actionable (add label = auto-fix)
  4. No human intervention needed

How Preflight Works: Architecture

Trigger Points (Every 15 Minutes + On-Push)

on:
  pull_request:
    types: [opened, synchronize, labeled, reopened]
  schedule:
    - cron: '*/15 * * * *'  # Every 15 minutes

Why 15 minutes?

  • Fast enough to catch conflicts quickly
  • Not too frequent (save GitHub Actions quota)
  • Covers all open PRs regularly

Why on-push?

  • Immediate detection when branch updated
  • No waiting for cron job

Step 1: Merge Simulation (No Side Effects)

git fetch origin main
git checkout PR_BRANCH
git merge --no-commit --no-ff origin/main
# Check if conflicts exist
if git status | grep -q "both modified":
    echo "CONFLICTS_DETECTED=true"
else
    echo "CONFLICTS_DETECTED=false"
fi
git merge --abort  # No side effects

Key: --no-commit = simulate merge without committing

Step 2: Conflict Detection

def detect_conflicts() -> list[str]:
    output = subprocess.run(
        ['git', 'status', '--porcelain'],
        capture_output=True, text=True
    )
    conflicted = []
    for line in output.split('\n'):
        if line.startswith('UU ') or line.startswith('AA '):
            conflicted.append(line[3:].strip())
    return conflicted

Returns specific files in conflict, not just "conflicts exist".

Step 3: PR Comment with Status

## 🤖 Merge Conflict Preflight

⚠️ **Merge conflicts detected** with main branch.

Files in conflict:
- `data/seo-qa-scores.json`
- `registry.json`
- `templates/base.html`

**Options:**
1. Add `auto-resolve` label for automated fix
2. Run locally:
   ```bash
   python3 scripts/autofix_conflicts.py --auto-resolve
   python3 qa_check.py --strict
   git push

🕐 Last checked: 2026-06-26T14:35:42Z


Comment is **specific**, **actionable**, and **updated automatically**.

---

## Why 94% Detection Rate?

Preflight catches conflicts by:
1. **Simulating merge** with latest main (100% accurate)
2. **Checking 15-min intervals** (catches late-night conflicts)
3. **On every PR change** (catches new conflicts immediately)

Misses:
- Race condition during merge (happens <1% of time)
- Non-Git conflicts (database migrations, etc.)

---

## Integration with CI/CD

Preflight doesn't replace CI checks. It's a **pre-check**:

Developer Push ↓ Preflight Check (immediate) ├─ Conflict detected? │ ├─ YES → Block merge, suggest auto-resolve │ └─ NO → Continue ↓ Standard CI Checks ├─ Unit tests ├─ Build (zola build) ├─ SEO checks └─ Link validation ↓ QA Gatekeeper ├─ Automated QA suite └─ If all pass → auto-merge


Preflight is the **first gate**, not the last.

---

## Performance: Preflight Overhead

| Operation | Time |
|-----------|------|
| Git merge simulation | 15-30 sec |
| Conflict detection | 5 sec |
| PR comment update | 10 sec |
| **Total per PR check** | **~1 minute** |

**Every 15 minutes on all open PRs:**
- 5 open PRs × 1 min = 5 min
- GitHub Actions quota: ~440 min/month
- Cost: **<$1/month**

---

## Customization: Change Frequency

Want more frequent checks?

```yaml
# Every 5 minutes (more aggressive)
schedule:
  - cron: '*/5 * * * *'

# Every hour (more conservative)
schedule:
  - cron: '0 * * * *'

Default every 15 min is sweet spot.


What Happens Next?

Once conflict is detected:

  1. Auto-resolve label → Workflow triggers
  2. Auto-resolution → Handles 70% cases
  3. QA validation → Ensures code quality
  4. Manual review → For complex conflicts
  5. Merge → When all checks pass

Phần Tiếp Theo

Part 5: Lessons Learned & Future-Proofing — Những gì chúng tôi học được, và what's next?


Tài Liệu Tham Khảo


Pipeline Heartbeat Online

Kiểm tra cuối:



Online