Skip to content

fix(deploy): stop copying PR previews forward; publish via cheap orphan commit - #4718

Merged
cixzhang merged 1 commit into
mainfrom
fix/deploy-gh-pages-timeout
Aug 5, 2026
Merged

cixzhang merged 1 commit into
mainfrom
fix/deploy-gh-pages-timeout

Conversation

@cixzhang

@cixzhang cixzhang commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Problem

Every push to main has had its Deploy job cancelled for ~a day — it hits the 15-minute job timeout in the preview-preservation logic and never reaches the publish step. The gh-pages site (Storybook/Sandbox) has been stale since the last success.

Timeline from a representative failed run (deploy job):

Step Duration
Download artifacts ~10s
Preserve PR previews and reports from gh-pages ~8m 20s
Prepare deployment killed at 15m mid-cp (Terminate orphan process: pid … (cp))
Deploy to GitHub Pages never runs

Root cause

The job cloned all of gh-pages and cp -r'd the entire /pr/ tree forward on every push. Measured today: /pr/ is >1 GB across ~52 live previews and 38,986+ files (the tree API response is truncated — actual is larger). That's a ~1.2 GB clone plus two full copies of ~40k files per deploy — an O(all live previews) cost that crossed the 15-min budget (durations had been climbing: 8m → 27m → 44m → 50m → 1h59m before the hard failures).

The copy existed because peaceiris force_orphan:true publishes whatever is in publish_dir, so the full tree had to be materialized locally.

Fix

Build the single orphan commit ourselves and reuse /pr/ & /reports/ by SHA instead of copying them:

  • --filter=blob:none + sparse-checkout materializes only the stable paths (storybook/ sandbox/ assets/ + root files). /pr/ & /reports/ blobs are never fetched or written — they stay in the index as skip-worktree entries.
  • Clean-replace the stable paths so superseded content-hashed assets don't accumulate (preserves what keep_files:false originally fixed in fix(deploy): clean deploys, PR previews at /pr/<number>/, stable sandbox URL #916).
  • git write-tree rebuilds the full tree from the index (/pr/ & /reports/ reused by SHA); git commit-tree with no parent yields a single orphan commit — the same clean-slate history force_orphan gave us ([codex] Compact gh-pages history #2239 / Trim gh-pages artifact history from default clones #2238), now without a full local copy of gh-pages.
  • Push with --force-with-lease + retry to stay safe against concurrent gh-pages writers (other main deploys, PR-preview pushes).

Three constraints, all preserved

Constraint Source This PR
A Deploy time independent of preview count ← the bug ✅ now O(1)
B No stale-asset accumulation in the live tree #916 ✅ stable paths clean-replaced
C No gh-pages history / clone bloat #2238 / #2239 ✅ still a single orphan commit

Validation

Verified the load-bearing mechanism (sparse-checkout + write-tree preserving excluded paths as an orphan commit) in a self-contained local git repo:

  • after sparse checkout, pr/ & reports/ are absent from the worktree;
  • their tree SHAs are preserved byte-for-byte in the pushed commit;
  • resulting history is exactly 1 commit (== force_orphan);
  • stable paths are cleanly replaced (old content-hashed files gone);
  • all 50 preview files under a pr/<n>/ survived.

Also: bash -n clean on both run: scripts; YAML parses.

Follow-up (not in this PR)

deploy-preview.yml still full-clones gh-pages on every PR-preview push (same root pattern, just not at the timeout yet). Worth the same --filter=blob:none/sparse treatment.

cc @thedjpetersen — this reworks the force_orphan path you added in #2239; the single-orphan-commit history behavior is intentionally preserved, just produced via plumbing so it no longer requires copying the whole preview tree.

…an commit

Every push to main has had its Deploy job cancelled for ~a day (15-min job
timeout). The deploy job cloned all of gh-pages and `cp -r`'d the entire
/pr/ tree forward on every push. With ~52 live previews (>1GB, ~40k files)
the clone + two copies blew the 15-min budget before the publish step ever ran.

The cost was O(all live previews) per deploy — a full local copy of the tree
was required because peaceiris `force_orphan:true` publishes whatever is in
publish_dir.

Fix: build the single orphan commit ourselves and reuse /pr/ & /reports/ by
SHA instead of copying them:
  - --filter=blob:none + sparse-checkout materializes ONLY the stable paths
    (storybook/ sandbox/ assets/ + root files). /pr/ & /reports/ (the >1GB of
    preview blobs) are never fetched or written — they stay in the index as
    skip-worktree entries.
  - clean-replace the stable paths so superseded content-hashed assets don't
    accumulate (keeps what keep_files:false originally fixed, #916).
  - git write-tree rebuilds the full tree from the index (pr/ & reports/ reused
    by SHA); git commit-tree with no parent produces a single orphan commit —
    the same clean-slate history force_orphan gave us (#2239/#2238), now without
    a full local copy of gh-pages.
  - push with --force-with-lease + retry to stay safe against concurrent
    gh-pages writers (other main deploys, PR-preview pushes).

Deploy time is now O(1) in preview count. compact-gh-pages.yml stays as the
weekly history backstop.

Note: deploy-preview.yml still full-clones gh-pages per preview push (same
root pattern, not yet at the timeout) — worth the same treatment as a follow-up.
@vercel

vercel Bot commented Aug 5, 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 Aug 5, 2026 3:55am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 5, 2026
@cixzhang
cixzhang requested a review from thedjpetersen August 5, 2026 03:53
@cixzhang
cixzhang enabled auto-merge (squash) August 5, 2026 03:59
@cixzhang
cixzhang merged commit e5c0c51 into main Aug 5, 2026
18 checks passed
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

github-actions Bot added a commit that referenced this pull request Aug 5, 2026
@github-actions
github-actions Bot deleted the fix/deploy-gh-pages-timeout branch August 5, 2026 06:59

This branch was successfully deployed

1 active deployment
Preview — 20206c3f Deployed Aug 5, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant