Skip to content

fix(#1323): skip pre-push replay when origin/branch is an ancestor - #1793

Merged
waynesun09 merged 1 commit into
mainfrom
agent/1323-skip-replay-when-ancestor
Oct 26, 2026
Merged

waynesun09 merged 1 commit into
mainfrom
agent/1323-skip-replay-when-ancestor

Conversation

@fullsend-ai-coder

Copy link
Copy Markdown
Contributor

Summary

scripts/post-fix.src.sh (and the regenerated bundle scripts/post-fix.sh) now skips the pre-push git rebase origin/<branch> replay whenever the freshly fetched origin/<branch> is already an ancestor of local HEAD. In that state the plain push is a fast-forward and there is nothing to reconcile.

Why

The replay was only skipped through narrow arms tied to the agent's rebased_onto_target/merged_target flags, the human instruction wording, or a forge-reported conflict. When the agent reconciled a stale base with an ordinary merge of the target, origin/<branch> was already an ancestor of HEAD, but the default git rebase still ran. That rebase drops the merge commit and replays target-side history onto the old PR tip, with two outcomes:

Approach

A new arm just before the replay, active only when nothing else has already set SKIP_REMOTE_REBASE:

git merge-base --is-ancestor "origin/${BRANCH}" HEAD
  • It uses only ancestry the runner computes itself, so no flag written inside the sandbox is trusted.
  • For linear histories it changes nothing (the rebase was already a no-op there).
  • GitLab reconstructions have diverged SHAs, so they never pass the check and still go through the existing replay.
  • If the remote gained a commit that HEAD doesn't have, the replay still runs (covered by push-rebase-conflict-fails-closed).
  • Merge commits in the range are still secret-scanned by the existing step earlier in the script.

Testing

  • New push-preserves-unflagged-target-merge tests in scripts/post-fix-test.sh:
    • clean: the replay would apply cleanly
    • conflict: the replay would conflict
    • a signed-commits-off variant of clean
  • Each test checks that no replay happens, the merge commit is kept, the target tip is an ancestor of what was pushed, and the pushed tree matches the agent's tree. All three fail on the old script and pass with the fix.
  • push-history-rewrite-ordinary-append now checks only that the "to preserve" skip arms don't fire, because a linear append now takes the fast-forward skip.
  • post-fix-test.sh passes against both the source and the bundled script. The exception is 3 harness-config checks that fail the same way on main because yq isn't installed in the sandbox.
  • The bundle is up to date with post-fix.src.sh. skillsaw --strict passes, and shellcheck plus the pre-commit-hooks checks pass when run directly. pre-commit itself couldn't fetch its hook repos because of a sandbox TLS error.

Not included

The issue's optional richer push-rejected comment, which would mention that the agent had already recorded a verified resolution. With this skip in place, the replay only fails when the remote really did gain commits the agent never saw, and the existing message is accurate for that case.

🤖 Generated with Claude Code


Closes #1323

Post-script verification

  • Branch is not main/master (agent/1323-skip-replay-when-ancestor)
  • Secret scan passed (gitleaks — f589f2e719ba9bdda0a5915b8d4a86c45e7694e7..HEAD)
  • PR body secret scan passed (gitleaks — no-git)
  • Final PR description secret scan passed (gitleaks — no-git)

post-fix replayed local commits onto the freshly fetched
origin/<branch> unless one of the narrow, flag- or instruction-gated
skip arms fired. When the agent reconciled a stale base by merging
the target (no rebased_onto_target / merged_target flag, or a forge
state that was not CONFLICTING), origin/<branch> was already an
ancestor of HEAD, yet the default `git rebase` still ran. It drops
the merge commit and replays target-side history onto the old PR
tip: it either re-hits the conflict the agent already resolved
(push-rejected, as on fullsend#7308) or applies cleanly and pushes
a silently inflated PR (as on fullsend#8755).

Add a general skip arm just before the replay: when nothing else
has skipped it and `git merge-base --is-ancestor origin/<branch>
HEAD` holds, skip the replay and push directly (a fast-forward).
The check uses runner-computed ancestry only, so it does not widen
trust in sandbox-written flags; it is a no-op for linear histories;
and GitLab reconstructions (diverged SHAs) never satisfy it, so
they keep falling through to the existing replay.

Tests: add push-preserves-unflagged-target-merge (clean and
conflicting replay, plus a signed-commits-off variant), which fail
on the old script. Narrow push-history-rewrite-ordinary-append to
assert only that the preservation skips do not fire, since a linear
append now takes the fast-forward skip. The optional richer
push-rejected comment from the issue is not included.

Note: pre-commit could not fetch hook repos (TLS failure in the
sandbox); the configured hooks were run directly instead (shellcheck,
pre-commit-hooks fixers/checks, lint-release-cases) and passed, and
gitleaks ran via scan-secrets. Three post-fix-test.sh checks fail
identically on main because yq is not installed in the sandbox.

Closes #1323

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fullsend-ai-coder
fullsend-ai-coder Bot requested a review from a team as a code owner October 26, 2026 15:16
@fullsend-ai-coder fullsend-ai-coder Bot added the ready-for-review Triggers review agent dispatch label Oct 26, 2026
@fullsend-ai-review

fullsend-ai-review Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 3:18 PM UTC · Completed 3:27 PM UTC

Commit: a72dadd · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5-5 · Effort: high · Cost: $1.70

@fullsend-ai-review fullsend-ai-review Bot added the risk/moderate PR risk: moderate label Oct 26, 2026
@fullsend-ai-review

Copy link
Copy Markdown

<!-- fullsend:risk-assessment -->
Risk Assessment: moderate (2/5)

Details

Small, well-tested bug fix precisely matching linked issue scope, tempered by protected script modifications and historical churn without a rollback toggle.

@fullsend-ai-review

Copy link
Copy Markdown

Review

Findings

Medium


Labels: PR fixes a defect in the fix-agent post-script push logic.

@ravelley

Copy link
Copy Markdown

This should cover most cases. If a concurrent update causes the post-script to rebase, though, it can still drop the agent’s merge and inflate the PR diff. I’ve tracked that edge case separately in #1797.

@waynesun09 waynesun09 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Checked at a72dadd:

  • post-fix-test.sh passes against the source and the bundled script (195 tests), and make check-bundle is clean.
  • The three new push-preserves-unflagged-target-merge tests fail against main's script, so they catch #1323.
  • origin/<branch> is force-fetched right before the ancestry check. The plain push, its lease fallback and the signed path all reject a remote that moved, so nothing is overwritten.

Non-blocking test and comment nits for a follow-up:

  • No bot-triggered variant, and no case where the remote moved while HEAD has a merge.
  • The negative greps at post-fix-test.sh:2525/2620/2796 still match the shared "skipping rebase onto" prefix.
  • The header comment at post-fix-test.sh:3395 and the merged_target wording in skills/fix-result-contract/SKILL.md are now stale.

@waynesun09
waynesun09 added this pull request to the merge queue Oct 26, 2026
Merged via the queue into main with commit 161d19b Oct 26, 2026
117 of 126 checks passed
@waynesun09
waynesun09 deleted the agent/1323-skip-replay-when-ancestor branch October 26, 2026 20:04

This branch was successfully deployed

1 active deployment
dev — a72dadd8 Deployed Oct 26, 2026 by fullsend-ai-coder[bot] via behaviour #1318
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fix-agent ready-for-review Triggers review agent dispatch requires-manual-review Review requires human judgment risk/moderate PR risk: moderate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

post-fix.sh: skip the pre-push rebase-replay when origin/<branch> is already an ancestor of HEAD, not just after an explicit agent rebase

2 participants