Skip to content

fix(ci): retry gh-pages push in cleanup-previews to survive deploy races - #3810

Merged
cixzhang merged 1 commit into
meta:mainfrom
sangwook-dev:fix/cleanup-previews-push-race
Jul 12, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
sangwook-dev:fix/cleanup-previews-push-race

Conversation

@sangwook-dev

Copy link
Copy Markdown
Contributor

Summary

The Cleanup Preview Deployments workflow intermittently fails when a PR merges — two failures today alone (example run):

To https://github.com/facebook/astryx
 ! [rejected]        gh-pages -> gh-pages (fetch first)
error: failed to push some refs

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's deploy-preview and redeploy-preview.yml already carry a retry loop for exactly this reason — cleanup-previews was the only gh-pages writer without one.

Changes

  • Record every deleted path during detection, then push with retry (5 attempts): on rejection, fetch the fresh remote tip, reset --hard to 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 preserves pr/ and reports/ across deploys, so the stale paths still exist on the new tip.
  • If the refresh shows the paths already gone (another writer cleaned them first), exit 0 with nothing to push.
  • Dedicated cleanup-previews concurrency group so simultaneous PR closes don't race each other. Deliberately not the pages-deploy group: 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:

  • Race path: first push rejected with the exact production error → retry resets to the rewritten history, replays the deletion, pushes successfully. Open-PR previews and the deployer's new content both survive; the closed PR's preview is gone.
  • Already-cleaned path: competitor removed the same paths first → Stale paths already removed upstream and exit 0 (no empty commit, no failure).
  • No-race path: first push succeeds unchanged.
  • bash -n on the embedded script; YAML parses with the expected concurrency group.

@vercel

vercel Bot commented Jul 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 11, 2026 12:31pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 11, 2026
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
sangwook-dev force-pushed the fix/cleanup-previews-push-race branch from d752d3a to de1c41b Compare July 11, 2026 12:28
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Jul 11, 2026

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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 preserves pr//reports/ so the stale paths still exist to re-delete.
  • Already-cleaned path exits 0 cleanly (git diff --cached --quiet guard, no empty commit); no-race path pushes first try.
  • Dedicated cleanup-previews concurrency group, deliberately not pages-deploy (avoids cancelling a pending main deploy) — matches the existing retry pattern in deploy-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.

@cixzhang cixzhang removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Jul 12, 2026
@cixzhang
cixzhang merged commit fdc6f63 into meta:main Jul 12, 2026
20 checks passed
@sangwook-dev
sangwook-dev deleted the fix/cleanup-previews-push-race branch July 12, 2026 07:00

This branch was successfully deployed

1 active deployment
Preview — de1c41b3 Deployed Jul 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants