Repository navigation
Description
Summary
The Cleanup Preview Deployments workflow (.github/workflows/cleanup-previews.yml) fails with a 403 on git push to gh-pages for every PR opened from a fork. Same-repo PRs succeed. This is deterministic, not a flake.
Symptom
remote: Permission to facebook/astryx.git denied to github-actions[bot].
fatal: unable to access 'https://github.com/facebook/astryx/': The requested URL returned error: 403
::error::Failed to push cleanup after 5 attempts
The retry loop's message ("Push rejected (concurrent gh-pages update) — retrying") is misleading: the actual failure is a permissions 403, not a fetch-first race, so all 5 retries burn against the same denial and the job exits 1.
Root cause
The workflow triggers on pull_request: [closed]. For PRs opened from a fork, GitHub caps GITHUB_TOKEN to read-only regardless of the permissions: contents: write declaration in the YAML (the declaration is a ceiling, not a grant). So the git push to gh-pages is denied.
For same-repo branches, the token gets full write, so the push succeeds.
Evidence
Split of the last ~92 cleanup runs by head_repository:
| head_repository | outcome |
|---|---|
facebook/astryx (same-repo) |
✅ all pass |
fork (potatowagon/, athz/, humbertovirtudes/, jiunshinn/, AKnassa/, bhamodi/ …) |
❌ all fail |
22/22 failures are fork PRs. 0 same-repo runs failed. Two runs from the same day, both deleting exactly 1 stale path (identical work):
- Same-repo PR fix(deps): resolve next.js and js-yaml security advisories #4653 (
cixzhang) → cleanup run 30783286454 →Summary: 1 items deleted→ Pushed cleanup commit ✅ - Fork PR feat(lab): add composable RichTextEditorToolbar #4551 (
potatowagon/astryx) → cleanup run 30784441287 →Summary: 1 items deleted→ 403 denied ❌
Same workflow, same work, opposite result — the only variable is fork vs. same-repo.
The repo already solved this for deploys
.github/workflows/deploy-preview.yml was migrated off pull_request to workflow_run for exactly this reason. Its own header comment says:
a pull_request workflow triggered by a fork gets a READ-ONLY token and can't push to gh-pages, which is why fork PRs never got a preview. workflow_run runs from the base repo with the repo's own write token…
cleanup-previews.yml was never given the same treatment.
Impact
- Every fork contributor gets a red ❌ on the post-close cleanup job.
- It does not block PR merge (cleanup is not a required check), so it's cosmetic noise — but it's persistent and misleading.
- The daily
schedulecron runs with the base-repo write token and eventually clears the backlog, which is why the gh-pages tree doesn't grow unbounded.
Proposed fix
Migrate cleanup-previews.yml off the fork-tainted pull_request trigger so it always runs with the base repo's write token — mirroring deploy-preview.yml. Options, in order of preference:
workflow_runkeyed off the PR-close signal (consistent withdeploy-preview.yml).- Rely on the existing daily
schedulecron +workflow_dispatchand simply drop thepull_requesttrigger — trades prompt cleanup for guaranteed-green runs (the cron already handles correctness).
Additionally: make the push-retry loop distinguish a hard 403 (permissions) from a [rejected] (fetch first) race and fail fast on the former instead of retrying 5× with a misleading message.
Activity