/agent-traffic-control:gha-pr-merge-ref-shows-upstream-changesfrom agent-traffic-control
Diagnose "my CI failed on a file I didn't change — the test passes locally but CI insists there's a duplicate / conflict / lint violation that isn't in my branch." Caused by GitHub Actions checking out `refs/pull/N/merge` (the auto-computed merge of PR head + base) on `pull_request` events. Use when: (1) CI fails on a `git`/lint/whole-tree check (duplicate IDs, schema drift, file-content audit) that PASSES on the same SHA locally, (2) you're working in a dense parallel-PR window where main is moving faster than your CI runs, (3) `gh run view N --json headSha` matches your latest force-push but `git fetch origin main && git rev-list --left-right --count origin/main...HEAD` shows main is ahead by N commits, (4) the failure references symbols / IDs / values that are present in MAIN but absent from your branch. Root cause: GitHub re-computes the merge ref every time the base moves, so CI on `pull_request` sees `main-at-CI-start + your-branch`, NOT just `your-branch`. Sister concept to `gha-billing-failure-fast-fail-pattern` (different GHA gotcha). Recurs during a dense parallel-PR window, when the base keeps moving under you.
Trending skills
7-day visitors to each skill page
Ships in agent-traffic-control. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
pull_request Event Uses Merge-Ref, Not Head-RefYou push a commit to a PR branch at T0. CI starts running at T0+10s. A sibling PR merges to main at T0+5s. Your CI run sees the sibling's changes mixed into your branch and fails on something neither side introduced alone.
Most confusingly: locally on the exact same commit SHA, every check
passes. gh run view <N> --json headSha reports your SHA correctly.
git show <SHA>:<file> shows your file is clean. But CI failed on that
SHA citing duplicates / conflicts / violations that aren't there.
pull_request event (NOT push)gh run view <N> --json headSha matches your local HEADgit fetch origin main && git rev-list --left-right --count origin/main...HEAD
shows main is ahead by 1+ commits since your pushX" where X was added
to main by a PR that merged seconds before your CI ran)GitHub Actions, when triggered by pull_request: [opened, synchronize, reopened, ...], checks out a SYNTHETIC ref called refs/pull/<N>/merge.
This ref is the **3-way merge of refs/pull/<N>/head + refs/heads/main
Concretely:
Local view: your-branch-HEAD (clean)
CI view: merge(your-branch-HEAD, main-HEAD-at-CI-start) (may have collisions)
GitHub regenerates the merge ref whenever:
If main moves between your push and your CI's checkout step, the merge ref includes main's NEW state plus your branch.
The headSha field in gh run view reflects your branch's commit,
which makes the failure look like "my branch broke this" rather than
"main + my branch combined broke this."
The actions/checkout@v4 default behavior:
pull_request event → ref: refs/pull/N/merge (the merge ref)push event → ref: <pushed-sha> (your actual commit)ref: ${{ github.event.pull_request.head.sha }} →
force checkout of branch head only (no merge preview)Default is "merge preview" because it tests what would happen post-merge, which is genuinely useful for catching integration conflicts. The downside is that base-side breakage can fail YOUR CI without anything in your branch causing it.
# 1. Confirm CI ran on your SHA
gh run view <run-id> --json headSha
git rev-parse HEAD # should match
# 2. Check whether main moved since your push
git fetch origin --quiet
git log --oneline origin/main ^HEAD | head -5
# Any output = main moved. Empty = main is at or behind your branch.
# 3. Inspect the failure's specific accusation
# If it cites symbols/IDs/strings, search for them on main vs your branch:
git show origin/main:<path> | grep <accused-symbol>
git show HEAD:<path> | grep <accused-symbol>
# If they BOTH show different occurrences = merge preview surfaced
# a collision your branch alone doesn't have.
The standard fix. Bring your branch onto current main, resolve any real conflicts, force-push. CI's next merge-ref will be a clean fast-forward, and the spurious failure goes away.
git fetch origin main
git rebase origin/main
# Resolve any conflicts that arise (these are the REAL ones — the CI was
# previewing them via the merge ref).
git push --force-with-lease
If main is moving because other PRs are actively sweeping the same file you're touching (e.g. tracker collision fixes, schema migrations), sometimes waiting 10-15 minutes lets the dust settle. Then rebase once and merge. Each force-push you do during the wave triggers a fresh CI cycle that's likely to re-surface the moving target.
Only if you're SURE the base-side check is wrong and you want to bypass the merge preview:
# In .github/workflows/your.yml
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
This makes CI test your branch in isolation. Don't use as a default — you'll lose the integration-conflict catch. Use only for specific checks (e.g. linting your branch's diff) where the merge preview is the wrong question.
After rebase + force-push, the next CI run on your branch should:
headSha matching your new HEADIf CI still fails after rebase with the same accusation, it's a real issue in your branch — the merge-ref theory was a red herring. Inspect the file at HEAD directly.
Observed 2026-05-11 in the project repo during a dense parallel-PR
window. My PR #708 (UI tweaks + new tracker entry) pushed at T0. The
test_tracker_no_id_collision CI lint failed citing duplicate IDs
cat7-7ho and cat7-7hp that weren't in my branch's tracker file.
Locally: pytest <analytics_pkg>/tests/test_tracker_no_id_collision.py -v → 2/2 PASSED.
CI: gh run view 25665633945 --json headSha → my exact SHA.
Investigation:
git fetch origin main --quiet
git log --oneline origin/main ^HEAD | head -3
# ab9deb13 docs(s170): handoff for magic-link soft-launch ... (#706)
# d18ec4e6 docs(s169): handoff + review report for /actions polish PR #696 (#704)
Main had absorbed 2 PRs in the 5 minutes between my push and CI's
checkout. Each of those PRs added new tracker entries with IDs
overlapping mine in the merge preview. CI's refs/pull/708/merge =
my branch + main's new state = duplicate IDs.
Resolution: git rebase origin/main (resolved 2 real tracker conflicts),
git push --force-with-lease. Next CI run: green.
The same trap recurred 2 more times in the same session as PRs #706
and #707 landed during subsequent rebases. In a dense parallel-PR window
that is expected behaviour — the lint is doing its job, just on a sliding
target. (The cadence question — how often to rebase while the base keeps
moving — was written up in a project-specific skill dropped in v1.2.0 and
has no home here since. The gh pr merge --auto behaviour that travels
with it does: see gh-pr-merge-unstable-state-needs-auto-and-watch-branch-deletes
and solo-repo-branch-protection-stable-gate-and-self-merge Trap 2, which
covers the zero-required-checks case that makes --auto merge instantly.)
gh pr view <N> --json mergeStateStatus reports DIRTY when there
are content conflicts — that's a stronger signal than just CI failure.
Always check this before assuming your branch is broken.pull_request_target event uses the BASE branch's workflow file
but checks out the PR's HEAD — different semantics entirely, used for
permissioned workflows on forks. Don't confuse with pull_request.gh-pr-merge-worktree-checkout-trap (different gh subcommand
failure mode)What SKILL.md sets; muted values are Claude Code's defaults
118 skills in this plugin
/agent-refusal-with-evidence-beats-literal-complianceA dispatched agent that does exactly what you asked can ship a defect you would
have stopped yourself, because it can see something at the worksite that you
could not see when you wrote the brief. Use when: (1) you are writing a brief
that prescribes a specific fix, threshold, wording or value rather than the
outcome you want; (2) an agent reports that it did not do what you asked and
you are deciding whether that is insubordination or judgement; (3) an agent
asserts "this is fine" or "not needed" with no measurement behind it; (4) you
are reviewing overnight output and want to know which decisions were checked
and which were assumed. Two halves, and both are needed: give the agent
explicit permission to satisfy the INTENT of an instruction while refusing its
letter, and REQUIRE the evidence with the refusal — what it built or measured,
what that showed, what it did instead. Evidence is the whole difference between
a refusal you can bank and one you have to re-litigate. Four agents correctly
declined an instruction in a single run; one built the suggested fix, measured
that it turned a silent safe refusal into a permanently red pipeline, and
reverted it unpushed.
/auto-merge-rearms-while-agent-live-kill-then-disarm-verifyDisarming auto-merge on a PR whose agent is still running does not hold it —
the agent re-arms within minutes and the PR merges, because arming is a step in
the agent's brief and disarming is not an instruction to the agent at all. Use
when: (1) you want to STOP a pull request from merging that an agent opened and
armed, for review, for a rethink, or because it is landing into a queue you are
trying to drain; (2) a PR you disarmed merged anyway; (3) you are telling agents
which PRs are on hold and want the hold to be enforced rather than announced;
(4) you are about to run `gh pr merge --disable-auto` and have not decided what
to do about the agent. The order is KILL THE AGENT FIRST, THEN DISARM, THEN
VERIFY the disarm by reading `autoMergeRequest` back — a disarm you did not read
back is not a hold. The stronger form needs no ordering at all: convert the PR
to a draft with `gh pr ready --undo`. A draft cannot merge whatever any agent
does to it, so the hold survives an agent you missed, an agent that restarts,
and an agent you did not know about.
/batch-member-cites-a-path-only-a-non-member-addsYou wrote something correct that the default reader cannot reach: a batch member citing a
path only a NON-member adds, or a rule, ruling or ledger sitting on an unlanded branch.
/batch-merge-subject-is-not-evidence-a-member-landedYou are about to close, delete the branch of, or mark as landed a pull
request because a batch, roll-up or merge-train commit on the target branch
names it in the subject line, and because the member's own commits all
predate that merge by wall clock. Neither of those is evidence. A batch
branch is assembled at some moment BEFORE it merges, so anything the member
pushed after assembly is outside it, and the subject records INTENT at
assembly time rather than CONTENT at merge time. Use before closing a
member, when an ancestry check against a squashed batch says no, or when a
member's branch still shows commits ahead of the target. Compare file
content against the target branch instead, expecting exactly one legitimate
difference: the shared aggregate file every member appends to.
/check-a-stale-branch-is-not-undoing-newer-main-workA branch built on an out-of-date main is about to merge, or has merged, and may undo work
that landed since. Use when a green, conflict-free PR deletes files you never touched,
newer values or a whole redesign vanish after a sibling PR merged, rows of a shared ledger
(tracker, registry, CHANGELOG) disappear or revert, or when `git diff main...HEAD` or a
reviewer says your small PR touches dozens of files you did not change.
/ci-leg-skipping-moves-minutes-it-does-not-remove-themYou are about to propose, price or approve a CI cost saving that works by
making a job or matrix leg SKIP on pull requests — a path filter, a safe
list, a changed-files gate, an exemption list. Check first whether the
pipeline runs a complement or backstop on merge, on push, or nightly:
many do, and then the legs a pull request skipped are exactly the legs some
later run executes, so a branch that goes green once and merges bills the
same total either way and the wall clock does not move at all. Use when
pricing a filter change, when a percentage saving is quoted with no basis,
or when choosing between filtering legs and batching pull requests. The
question that separates money from bookkeeping is whether the change
removes RUNS or merely moves LEGS.
npx claudepluginhub wan-huiyan/agent-traffic-control --plugin agent-traffic-control