Check PR is not already merged before an automated fix round
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).