Auto fix conflicts

Resolved 💬 3 comments Opened Mar 31, 2026 by DisabledAbel Closed May 10, 2026
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

What variant of Codex are you using?

Web

What feature would you like to see?

It seems that codex falls into conflicts a lot for example branch has conflicts that must be resolved
Use the web editor or the command line to resolve conflicts before continuing.
README.md
index.html

This happens all the time and I don't understand why because I didn't edit any files

Additional information

_No response_

View original on GitHub ↗

3 Comments

github-actions[bot] contributor · 5 months ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #16290

Powered by Codex Action

DisabledAbel · 4 months ago

Why this happens

Codex creates its branch from a snapshot of main at task start. If main moves forward before Codex finishes (even a README edit or an auto-generated commit), the PR lands with conflicts — even though you never touched those files. It's a race condition between Codex's branch base and the current main.

Workaround that worked for me

I created a GitHub Actions workflow that auto-resolves conflicts by merging main into the Codex branch with -X theirs (keeping Codex's changes):

name: Auto Fix Conflicts

on:
  pull_request:
    types: [opened, synchronize, reopened]
  workflow_dispatch:
    inputs:
      branch:
        description: "Branch to fix"
        required: false
        default: ""

jobs:
  auto-fix:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write

    steps:
      - name: Checkout repo
        uses: actions/checkout@v5
        with:
          ref: ${{ github.event.inputs.branch || github.head_ref }}
          token: ${{ secrets.GITHUB_TOKEN }}
          fetch-depth: 0

      - name: Configure git identity
        run: |
          git config user.name "conflict-bot"
          git config user.email "bot@example.com"

      - name: Fetch base branch
        run: git fetch origin main

      - name: Try auto-merge (prefer incoming changes)
        run: git merge -X theirs origin/main || true

      - name: Detect conflicts
        id: conflicts
        run: |
          files=$(git diff --name-only --diff-filter=U)
          echo "files=$files" >> $GITHUB_OUTPUT

      - name: Auto resolve conflicts (fallback)
        if: steps.conflicts.outputs.files != ''
        run: |
          for file in ${{ steps.conflicts.outputs.files }}; do
            echo "Resolving $file"
            git checkout --theirs $file
            git add $file
          done

      - name: Commit & push changes
        run: |
          git add .
          git commit -m "🤖 Auto-resolved merge conflicts" || echo "No changes"
          git push

Key things that tripped me up:

  • permissions: contents: write is required or the push silently fails with 403
  • git config must come before the merge step, not just before the commit
  • Use actions/checkout@v5 to avoid the Node 20 deprecation warning

Would love to see Codex handle this natively — maybe by rebasing its branch on main right before opening the PR.

etraut-openai contributor · 3 months ago

This feature request hasn't received enough upvotes, so I'm going to close it.