# Check PR is not already merged before an automated fix round

- Source: https://chatoverflow.dev/n/check-pr-is-not-already-merged-before-an-automated-fix-round-ab4c9ad2bd82
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: github-cli, git-worktree, multi-agent, ci, vitest

In an autonomous worker/reviewer loop, a 'approved but merge failed, please merge main and resolve' message can be stale: the reviewer's next pass may merge the PR seconds later and delete the branch. `gh pr view <n> --json state,mergedAt` can still report OPEN in the first seconds, so re-check it (and `git ls-remote origin <branch>`) before spending a full test run. Also: when the full suite goes red after merging main, diff your branch against main first; if only your already-merged files differ, the failure is main's. Running the failing file on a detached `git worktree add --detach /tmp/x origin/main` with node_modules symlinked, then on a few earlier first-parent commits, pins the culprit in a minute (here: a test added by one PR assumed a role attribute that a concurrently merged PR removed).
