Repository navigation
fix(ci): retry gh-pages push in cleanup-previews to survive deploy races - #3810
Merged
Merged
Conversation
sangwook-dev
requested review from
cixzhang,
ejhammond,
imdreamrunner,
josephfarina,
marie-lucas,
nynexman4464 and
thedjpetersen
as code owners
July 11, 2026 10:01
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
When a PR merges, two writers hit gh-pages at once: the merge closes the PR (firing this cleanup) and pushes main (firing deploy.yml's force-orphan deploy). The cleanup's plain 'git push' loses that race with '[rejected] (fetch first)' — two failures today alone. ci.yml's deploy-preview and redeploy-preview.yml already retry for exactly this reason; cleanup-previews was the only gh-pages writer without a retry. Because deploy.yml force-orphans the branch, the histories are unrelated after a lost race and a rebase can't recover. Instead, record every deleted path during detection; on a rejected push, fetch the fresh tip, reset to it, replay the recorded deletions (--ignore-unmatch), and push again — up to 5 attempts. If the refresh shows the paths already gone (another writer cleaned them), exit successfully with nothing to push. Also serialize cleanup runs against each other with a dedicated concurrency group. Deliberately NOT the pages-deploy group: a cleanup run joining it could cancel a PENDING main deploy (GitHub keeps only the newest pending run per group), leaving the site stale. Verified with a local three-clone simulation (bare remote + deployer force-orphan racing the cleanup): reproduces the exact production rejection, retry replays the deletion on the rewritten history, open-PR previews and the deployer's new content survive; also covers the already-cleaned (exit 0) and no-race paths.
sangwook-dev
force-pushed
the
fix/cleanup-previews-push-race
branch
from
July 11, 2026 12:28
d752d3a to
de1c41b
Compare
cixzhang
approved these changes
Jul 12, 2026
cixzhang
left a comment
Contributor
There was a problem hiding this comment.
🟢 No review blockers found — CI-only change, verified clean within what I can check.
Initial review pass (community contributor) — findings are a triage map for maintainers, not a verdict.
Adds a push-retry loop to the cleanup-previews workflow so it survives the structural race against deploy.yml's force-orphan gh-pages push when a PR merges.
Verified:
- Records every deleted path, then on a rejected push does
fetch --depth=1+reset --hard FETCH_HEAD+ replays the deletions with--ignore-unmatch— correct given deploy.yml rewrites history (rebase would be wrong here) and preservespr//reports/so the stale paths still exist to re-delete. - Already-cleaned path exits 0 cleanly (
git diff --cached --quietguard, no empty commit); no-race path pushes first try. - Dedicated
cleanup-previewsconcurrency group, deliberately notpages-deploy(avoids cancelling a pending main deploy) — matches the existing retry pattern indeploy-preview/redeploy-preview.
Recap — #3810 · fix(ci): retry gh-pages push in cleanup-previews to survive deploy races · @Han5991
What it does: makes the preview-cleanup workflow retry its gh-pages push instead of failing when a concurrent main deploy wins the race.
Recommendation: Approve.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Cleanup Preview Deployments workflow intermittently fails when a PR merges — two failures today alone (example run):
The race is structural: merging a PR simultaneously fires this cleanup (
pull_request: closed) and a main push that makes deploy.yml force-orphan push gh-pages. Both write the same branch within seconds. ci.yml'sdeploy-previewand redeploy-preview.yml already carry a retry loop for exactly this reason — cleanup-previews was the only gh-pages writer without one.Changes
reset --hardto it, replay the recorded deletions with--ignore-unmatch, and push again. A rebase can't be used here — deploy.yml force-orphans the branch, so after a lost race the histories are unrelated. deploy.yml preservespr/andreports/across deploys, so the stale paths still exist on the new tip.cleanup-previewsconcurrency group so simultaneous PR closes don't race each other. Deliberately not thepages-deploygroup: joining it could cancel a pending main deploy (GitHub keeps only the newest pending run per group), leaving the site stale.Test plan
Verified with a local three-clone git simulation (bare remote + a deployer force-orphan pushing between the cleanup's checkout and push), running the workflow's script verbatim:
Stale paths already removed upstreamand exit 0 (no empty commit, no failure).bash -non the embedded script; YAML parses with the expected concurrency group.