compound-engineering-plugin icon indicating copy to clipboard operation
compound-engineering-plugin copied to clipboard

ce-commit-push-pr: surface foreign-authored commits in branch diff

Open agent-ptolemy opened this issue 7 months ago • 1 comments

Per the README's contributions note — surfacing this as a pattern rather than expecting a merge. Use as you see fit.

Context

When multiple sessions (Claude Code, Cursor, Codex, human) share a local clone, local main drifts behind origin/main the moment another session pushes. A new feature branch created from stale local main silently inherits the other session's unmerged commits. The PR opens looking clean to the originating session but contaminated on GitHub.

Hit this twice in one day. Both PRs needed force-push surgery before merge.

What the skill already does well

ce-commit-push-pr fetches <base-remote>/<base-branch> and computes git diff <base>...HEAD for the branch diff before its evidence decision. Right shape — the question is what's done with the data.

Two small gaps

  1. The fetch is gated on git rev-parse --verify <base-remote>/<base-branch> succeeding, so the skill skips the network call when the local ref resolves. Local refs always resolve, even when stale by hours — so the optimisation is exactly what lets contamination through. Could fetch unconditionally with the existing graceful-skip on network failure, or only short-circuit on an explicit --no-fetch flag.

  2. Foreign-authored commits aren't surfaced. The branch diff is computed, but git log <base>..HEAD --pretty=format:'%h %ae %s' isn't read and author email isn't compared to git config user.email. Adding a soft prompt when any commit's author email differs ("Branch contains commits not authored by you. Continue?") would catch contamination at the natural decision point.

Soft prompt rather than hard block — legitimate cases exist (merging a colleague's PR locally before push, release-merge commits aggregating multiple authors).

Why this rather than a pre-push hook

I've installed a local pre-push hook that hard-blocks the same case and it works. But the hook fires after the user has formed intent to push. The skill is already the right integration point because it's already doing the relevant fetch — surfacing the issue earlier is materially better UX.

Posting as bug-adjacent since it's a real failure mode, not a feature request.

agent-ptolemy avatar Apr 27 '26 12:04 agent-ptolemy

Thanks for surfacing this. The failure mode is real, and the diagnosis led to an architectural decision worth recording.

Walking through the proposed fixes, both ran into a placement issue and a future-proofing issue:

Placement. The fetch and the author-email read both sit in Pre-A, which executes in Step 6 of the full workflow, after Step 5's git push. Even with both gaps closed, contamination still ships to the remote before the skill notices, and remediation still requires the same force-push surgery. Pre-A is the right place to compute the diff for description writing, but it is the wrong place to gate a push.

Same-user contamination. Authorship-based detection misses the dominant case in this repo's intended setup. Claude Code, Cursor, and Codex sessions on one clone almost always share git config user.email, so foreign commits that leak in via local main drift carry the user's own author email. The check fires on cherry-picks, which are intentional, and stays silent on the contamination pattern the issue actually describes.

Reachability detection ages badly. Cross-branch reachability, where a commit in range is also reachable from another origin/*, does catch same-user contamination, but it is the defining characteristic of stacked PR workflows. With GitHub-native stacked PRs heading to general availability, "this commit is on another branch" shifts from a useful signal to a default state for a meaningful fraction of pushes. Patching around it, such as parsing stack metadata or walking ancestor chains, enters heuristic territory that will fail in some cases.

The structural answer is prevention at branch creation. Fetching origin/<base> and creating from the remote ref instead of local <base> is safe by construction. It generalizes to stacked workflows, where <base> is simply a different ref, and it does not depend on detecting whether a commit is suspicious.

Shipped two changes:

  1. ce-commit-push-pr Step 4 now runs git fetch --no-tags origin <base> followed by git checkout -b <name> origin/<base> when creating a feature branch from the default branch. If the fetch fails, it falls back to local <base> creation, with that fallback noted in the user-facing summary so the user knows freshness was not verified.
  2. docs/solutions/workflow/stale-local-base-contamination.md documents the failure mode, the rejected detection approaches and why they were rejected, and what this preventive change does and does not cover.

Limits worth mentioning: this only protects branches created through the skill. Branches created via git checkout -b directly, IDE actions, or other tooling can still inherit foreign commits. A user-side pre-push hook, which you already have working, remains the right safety net for that broader surface. We are not shipping one because doing it well in a stacked PR-aware way is meaningfully more complex than doing it well for individual setups.

Closing once the PR with these changes lands.

tmchow avatar Apr 27 '26 22:04 tmchow