/agent-traffic-control:subagent-driven-branch-ref-froze-stranded-commitsfrom agent-traffic-control
Diagnose and recover from "PR merged, but half my work is missing from main" cases in `superpowers:subagent-driven-development` (or similar one-fresh-subagent-per-task) sessions, where committed work survives in the worktree's `HEAD` chain but never makes it into the pushed branch ref. Use when ANY of these appears: (1) `gh pr view <N>` body claims "M files changed, N insertions" but `gh pr diff <N> --name-only | wc -l` returns a smaller number than you expect (canary: PR-body file count > actual squash-commit file count), (2) the merged squash commit on main is MISSING entire files you remember creating (Dockerfile, route handler, deploy artefact, etc.) — and you wrote AND committed them per the subagent reports, (3) `git rev-parse HEAD` ≠ `git rev-parse <feature-branch>` in the worktree (HEAD is ahead), (4) `git reflog show <feature-branch>` ends earlier than `git log --oneline` on the same worktree (reflog gap = stranded zone), (5) tests that passed locally during the session now fail on main because files referenced by the committed code never landed, (6) the receiving session (or human running CI) discovers `ModuleNotFoundError`, `sql_path missing`, or similar "file referenced by code does not exist" symptom on freshly-pulled main. Root cause: one of the implementer subagents committed in a detached-HEAD state (e.g., after a `git checkout <sha>`, post-stash, post-cherry-pick abort, or an internal worktree reset by a tool). Subsequent subagents inherit the detached HEAD; each `git commit` advances HEAD but never updates the named branch. `git log` (without an explicit ref) walks from HEAD, so every per-task diagnostic looked correct. `git push <branch>` ships the branch ref — i.e. the truncated tree. The squash captures only the truncated portion. Sister to `reland-work-that-missed-a-squash-merge` (uncommitted edits, or commits pushed after the merge — different mechanism and timing, same symptom class). Distinct from `pr-hijack-via-stale-worktree-branch-ref` (which is about overwriting a different branch upstream).
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.
You ran a long superpowers:subagent-driven-development (or similar fresh-
subagent-per-task) session in a worktree. Each subagent did its task, committed
its work, the controlling session ran spec + code-quality review per task, all
green. At the end you pushed the worktree's branch to origin, opened a PR, CI
went green, you squash-merged.
Hours or one session later, somebody runs pytest on freshly-pulled main and
gets a ModuleNotFoundError, a missing-file assertion, or a sql_path missing
error pointing at code that was definitely committed during the session.
git log in your old worktree still shows all the commits at the top of the
branch. But on main, half of them are gone.
The squash commit on main contains only the early portion of your work —
typically the first N tasks before some specific transition point. Tasks
after that point exist as commits in the worktree (git log shows them)
but did not reach origin, did not reach the PR, did not reach the merge.
Strong signal after the merge:
gh pr view <N> body claims a file count (synthetic example: "24 files changed") that
doesn't match the actual squash-commit file count
(git diff-tree --no-commit-id --name-only -r <merge-sha> | wc -l).pip install or pytest surfaces
ModuleNotFoundError, sql_path missing, or "no such file" referencing
work the previous session reported as DONE.Strong signal during the session (catch it before pushing):
git rev-parse HEAD ≠ git rev-parse <feature-branch> in the worktree.
The branch ref is behind.git reflog show <feature-branch> has a reflog gap — the most recent
worktree-...@{0} entry is older than the most recent commit shown by
git log. The commits between branch-ref's frozen point and current HEAD
are stranded.git status in the worktree may or may not report HEAD detached at <sha>
— sometimes the detach happened mid-stream and a later subagent created
the symbolic-ref linkage on its own, leaving an inconsistent state.Strong signal across sessions:
git show or
post-stash recovery) propagates silently to every later subagent. A
single human running the same workflow would notice the prompt change
to (HEAD detached at <sha>).Add an explicit pre-merge verification step before any gh pr merge:
# 1. All three of these should produce the SAME sha:
git rev-parse HEAD
git rev-parse <feature-branch>
git rev-parse origin/<feature-branch>
# 2. This should print NOTHING (zero commits ahead of remote):
git log origin/<feature-branch>..HEAD --oneline
# 3. PR body file-count canary:
# "N files changed" in the PR body should match
gh pr diff <N> --repo <owner>/<repo> --name-only | wc -l
# 4. Reflog must extend to current HEAD:
# Compare the topmost entry from each — they should agree.
git reflog show <feature-branch> | head -1
git log -1 --oneline
If any one of those is misaligned, STOP. Do not merge. Recover with the hotfix path below before pushing the merge button.
If the merge already happened and you're seeing the symptom:
# 0. Confirm the diagnosis.
git -C <worktree-path> rev-parse HEAD # the "true" tip
git -C <worktree-path> rev-parse <branch> # the frozen ref
# If these differ, you have stranded commits.
# 1. Inspect the stranded commits oldest first; record their full SHAs.
git -C <worktree-path> log --reverse --topo-order --format="%H %s" <branch>..HEAD
# 2. Branch a recovery branch from current origin/main.
git fetch origin
git checkout -B recover/<short-name> origin/main
# 3. Cherry-pick every verified missing commit explicitly, oldest first.
# Synthetic three-commit example; replace with your complete reviewed SHA list:
git cherry-pick <first-verified-sha> <second-verified-sha> <third-verified-sha>
# Do not use oldest..newest: that range EXCLUDES oldest.
# Inspect merge commits separately: cherry-picking one requires choosing its
# mainline parent, and replaying it plus commits it already contains can duplicate changes.
# 4. If the cherry-picks reference paths that have moved on main since
# the original work was authored (common when other PRs landed
# concurrently and reorganized files), add a follow-up commit that
# fixes the path references. Don't try to fix them inside the
# cherry-picks — that breaks the audit trail.
# 5. Run tests against the merged result of recovery + main.
<test command>
# 6. Push, PR, merge.
git push -u origin recover/<short-name>
gh pr create --base main --title "fix: recover <N> commits stranded by PR #<original> squash" \
--body "<post-mortem-ish explanation; cite the original PR's merge commit>"
The recovery PR should bundle BOTH the cherry-picks AND any path fixes required for the merged tree to function. Splitting them produces a half-broken main between the two merges.
You can confirm the diagnosis precisely:
# The reflog gap tells you WHERE the freeze happened.
git -C <worktree-path> reflog show <branch> | head -1
# vs
git -C <worktree-path> log --oneline -1
# The gap is everything between those two.
# Pre-squash file count vs post-squash file count.
gh pr diff <N> --repo <owner>/<repo> --name-only | wc -l # what GitHub saw
git -C <main-repo> diff-tree --no-commit-id --name-only -r <merge-sha> | wc -l
# These should agree. If both are smaller than your mental model, the
# strand is the gap to your mental model.
After the recovery PR lands:
git diff origin/main origin/recover/<name> (BEFORE the recovery merge)
should show only the stranded commits + the path fix.git -C <main-repo> ls-tree -r --name-only main | grep <previously-missing-file>
should return the file.sql_path missing, ModuleNotFoundError) is
gone.A pipeline runs several implementation tasks in an isolated worktree on
feature/export-worker. Each task reports a commit, and local tests pass.
After a detached-HEAD transition, later commits advance HEAD but leave the
named branch behind. The agent pushes feature/export-worker and merges the PR.
The remote receives only the commits reachable from that branch ref.
The PR description claims 24 changed files, while the actual PR diff lists 16. A fresh checkout of main then fails because a referenced handler is absent.
Illustrative ref state; these are symbolic labels, not real commit hashes:
HEAD -> FINAL_TASK_COMMIT
feature/export-worker -> EARLIER_TASK_COMMIT
origin/feature/export-worker -> EARLIER_TASK_COMMIT
git log feature/export-worker..HEAD --oneline shows the missing task commits.
git reflog show feature/export-worker stops at the earlier task. The commits
survive, but the pushed ref never included them.
Recovery starts from current origin/main, cherry-picks the missing commits in
order, and repairs references to any paths moved by an intervening PR. Tests run
against that combined tree before a recovery PR is proposed. The technical
lesson is to compare HEAD, the local branch, and its fetched remote ref before
publishing; a local test pass alone does not prove the remote has the same tree.
The reflog gap is the single most reliable forensic. git log walks
from HEAD and shows everything. git reflog show <branch> shows only what
the branch ref actually saw — and a detached-HEAD commit doesn't update
the branch ref. The asymmetry is your tell.
gh pr merge will not warn you. GitHub's merge button operates on the
remote branch state, which is exactly what you pushed. The mismatch
between your local worktree HEAD and the pushed ref is invisible to
GitHub.
The PR-body file count is the second canary. Many session-handoff-style
PR bodies summarize "M files changed, N insertions" from the controlling
session's mental model. If that number is higher than
gh pr diff <N> --name-only | wc -l, something is wrong.
A controlling session's git log is a false positive for "everything
is fine". Without --branches=<branch> it walks from HEAD. To validate
the push will ship what you think, always compare against
origin/<branch> explicitly.
Subagents may detach HEAD for innocuous reasons. A subagent that runs
git show <sha> followed by an interrupted git checkout (or relies on
a tool that does so internally) can leave HEAD detached. Subsequent
subagents will commit on the detached HEAD and never restore the branch
ref. Adding git symbolic-ref HEAD || echo DETACHED to each implementer
subagent's opening diagnostic catches this before the first commit.
Concurrent PRs amplify the damage. If main moved while your worktree was open, the squash-merge silently reconciles your truncated tree against the new main — sometimes producing functioning but partial output, sometimes producing broken-reference output. If an intervening PR moves files referenced by stranded commits, recovery must address both the missing commits and the path drift.
reland-work-that-missed-a-squash-merge
(uncommitted edits, or commits pushed after the merge — different mechanism and timing),
pr-hijack-via-stale-worktree-branch-ref
(overwriting someone else's branch upstream — different problem entirely).superpowers:subagent-driven-development skill — where this pattern
emerges. Worth adding the pre-merge verification snippet to that skill's
"Common Mistakes" section.git log and git reflog show <branch> can disagree.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub wan-huiyan/agent-traffic-control --plugin agent-traffic-control118 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.