Skip to content

perf(ci): key sandbox next cache by PR to stop cross-basepath invalidation - #3864

Merged
cixzhang merged 1 commit into
meta:mainfrom
sangwook-dev:perf/pr-sandbox-cache-key
Jul 12, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
sangwook-dev:perf/pr-sandbox-cache-key

Conversation

@sangwook-dev

Copy link
Copy Markdown
Contributor

Summary

The PR build job (ci.yml) and the main Deploy build (deploy.yml) share one Next.js sandbox cache key — nextjs-sandbox-<lock hash>-<core dist hash> — but they build with different basePaths: PRs set SANDBOX_BASE_PATH=/<repo>/pr/<n>/sandbox, main sets /<repo>/sandbox. Next.js invalidates its webpack cache whenever the resolved config changes, so the main-built cache that PRs restore is always dead on arrival: the PR pays to download it, then compiles cold anyway.

Worse, because the shared key registers as a hit, actions/cache logs Cache hit occurred on the primary key, not saving — so a PR can never save a cache for its own basePath. Every PR push recompiles the sandbox from scratch, forever.

Measured evidence

run context cache sandbox compile
29181246330 PR build hit on shared key (67MB restored) 4.0min
29181173652 main Deploy hit on the same key 64s
29180552092 control, cache miss miss (cold) 3.9min

Same key, same hit — 4.0min on the PR vs 64s on main, and the PR's "hit" is indistinguishable from the cold-cache control. The restored cache is pure download weight on the PR path.

Changes

  • ci.yml: scope the sandbox cache key by PR number — nextjs-sandbox-pr<n>-<lock hash>-<core dist hash>. Each PR now warms its own cache on the first push and gets real warm rebuilds (~64s-class instead of ~4min) on every subsequent push that doesn't change packages/core/dist. PR-to-PR sharing is also (correctly) excluded, since every PR has a distinct basePath too.
  • deploy.yml: key unchanged. Added a comment cross-referencing why ci.yml's key is PR-scoped.
  • The no-restore-keys policy is preserved in both files — the feat: XDS un-prefix migration — bare names canonical, XDS* compat aliases #2941 rationale (module cache bakes in core's resolved export graph; a loose fallback can restore a poisoned cache) still stands, and this change doesn't touch it. A changed key still means a cold, safe rebuild.
  • No merge_group fallback is needed in the key: the cache step (and the sandbox build itself) is gated on github.event_name == 'pull_request', so github.event.pull_request.number is always set when the key is evaluated.

Test plan

  • Both workflows parse (yaml.parse via node); ci key resolves to nextjs-sandbox-pr<n>-<hashes>, deploy key byte-identical to before
  • No key collision possible between the two: hashFiles() emits hex, so main's nextjs-sandbox-<hex>… can never equal a PR's nextjs-sandbox-pr<n>…
  • Re-pushes within one PR keep the same key (PR number is stable across pushes), so the cache saved by push 1 warms push 2+
  • On this PR: first push is expected to be a cache miss (that's the fix working — it finally saves a PR-scoped cache). Push a trivial follow-up commit and confirm the second run restores nextjs-sandbox-pr<n>-… and the sandbox compile drops from ~240s to the ~64s class seen on main

Expected effect: for re-pushes that don't touch core, sandbox compile ~240s → ~64s, cutting ~3min off the PR critical path (stacked with #3811's parallelization, PR CI lands in the ~4min range).

@vercel

vercel Bot commented Jul 12, 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 12, 2026 6:38am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 12, 2026
@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 12, 2026
@github-actions

github-actions Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.6KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | View full report

…ation

PR builds and main deploys shared one Next.js sandbox cache key, but they
build with different basePaths (/<repo>/pr/<n>/sandbox vs /<repo>/sandbox),
so Next.js invalidated the restored webpack cache on every PR build: a
primary-key hit still compiled for ~4min (run 29181246330) versus 64s for
the same key on main (run 29181173652) — the restore was pure download
cost. And because the shared key registered as a hit, PRs could never save
a cache for their own basePath.

Scope the ci.yml key by PR number so each PR warms and reuses its own
cache across re-pushes. deploy.yml's key is unchanged, and the
no-restore-keys policy (meta#2941) is preserved in both files.
@github-actions github-actions Bot 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 52d7c5f into meta:main Jul 12, 2026
21 checks passed
@sangwook-dev
sangwook-dev deleted the perf/pr-sandbox-cache-key branch July 12, 2026 07:00

This branch was successfully deployed

1 active deployment
Preview — eec0888e Deployed Jul 12, 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