Skip to content

perf: enable Turbopack filesystem cache for agents-manage-ui builds#2045

Merged
nick-inkeep merged 3 commits intomainfrom
feat/turbopack-filesystem-cache-for-build
Feb 16, 2026
Merged

perf: enable Turbopack filesystem cache for agents-manage-ui builds#2045
nick-inkeep merged 3 commits intomainfrom
feat/turbopack-filesystem-cache-for-build

Conversation

@nick-inkeep
Copy link
Collaborator

Summary

  • Enable turbopackFileSystemCacheForBuild (experimental) in agents-manage-ui/next.config.ts
  • Persist .next/cache across GitHub Actions runs in both CI and Cypress workflows
  • Cache key includes lockfile hash (proxy for Next.js version) to auto-invalidate on upgrades

Problem

When turbo remote cache has a MISS for agents-manage-ui (source files changed), Next.js compiles the entire app from scratch every run (~71s in CI). Turbopack's default in-memory compilation writes nothing persistent, so each CI run pays the full compile cost even when only a single component changed.

Approach

Turbopack's turbopackFileSystemCacheForBuild flag serializes function-level compilation artifacts to .next/cache. When restored on the next build, Turbopack only recomputes the changed subgraph.

We persist .next/cache via actions/cache (separate from turborepo cache) with a restore-key fallback pattern that enables cross-PR cache sharing — any recent build's cache works as a warm start for any new build.

Changes

File Change
agents-manage-ui/next.config.ts Add experimental.turbopackFileSystemCacheForBuild: true
.github/workflows/ci.yml Add actions/cache step for agents-manage-ui/.next/cache
.github/workflows/cypress.yml Add actions/cache step for agents-manage-ui/.next/cache

Evidence

Local benchmarks (same codebase, same machine):

Scenario Build time CPU (user)
Baseline (no flag) ~24-26s 130s
With flag, cold (no cache) ~33s 221s
With flag, warm (1 file changed) ~14s 44s

~45% speedup on warm incremental builds, 3x CPU reduction.

In CI (where cold builds take ~71s), estimated warm build: ~35-40s.

Cache Key Strategy

{os}-nextjs-build-{lockfile-hash}-{source-hash}
  • lockfile-hash: Invalidates when Next.js version changes (prevents format incompatibility)
  • source-hash: Exact match for identical source, fallback to lockfile-only for incremental builds
  • restore-key fallback: Any previous build with same dependencies works as warm start

Notes

  • Cache size: ~1.1GB (within GitHub Actions 10GB repo limit)
  • Cold build is ~9s slower (one-time cache serialization overhead)
  • turbo.json unchanged — .next/cache is excluded from turbo outputs by design
  • Vercel deployments benefit automatically (Vercel already persists .next/cache)
  • Flag is experimental in Next.js 16.1; Vercel has dogfooded it internally for 1+ year

Test Plan

  • CI workflow passes (typecheck, lint, test, build)
  • Cypress E2E tests pass
  • Verify .next/cache is restored on second CI run (check GHA cache logs)
  • Verify warm build is faster than cold build in CI logs

🤖 Generated with Claude Code

Enable experimental turbopackFileSystemCacheForBuild in Next.js config
and persist .next/cache across GitHub Actions runs. When turbo remote
cache has a miss (source files changed), Turbopack can now do an
incremental rebuild using the persisted function-level cache instead
of compiling from scratch.

Local benchmarks show ~45% speedup on warm incremental builds
(14s vs 26s) with 3x less CPU usage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Feb 16, 2026

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

Project Deployment Actions Updated (UTC)
agents-api Ready Ready Preview, Comment Feb 16, 2026 11:09pm
agents-manage-ui Ready Ready Preview, Comment Feb 16, 2026 11:09pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
agents-docs Skipped Skipped Feb 16, 2026 11:09pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Feb 16, 2026

⚠️ No Changeset found

Latest commit: 9edbb4a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

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

PR Review Summary

(0) Total Issues | Risk: Low

🔴❗ Critical (0) ❗🔴

None

🟠⚠️ Major (0) 🟠⚠️

None

🟡 Minor (0) 🟡

None

💭 Consider (1) 💭

💭 1) agents-manage-ui/next.config.ts:19-21 Experimental flag enabled unconditionally

Issue: The turbopackFileSystemCacheForBuild: true flag is enabled for all environments (local dev, CI, production) rather than being gated to specific contexts.

Why: This is low risk since the flag only affects build performance, not runtime behavior. If cache artifacts ever become corrupted, a clean build still works. However, some teams prefer gating experimental features to CI only for production builds.

Fix: If preferred, gate the flag: turbopackFileSystemCacheForBuild: !!process.env.CI. However, keeping it enabled everywhere also provides local dev benefits, which may be the intended design.

Refs: next.config.ts:19-21


✅ APPROVE

Summary: This is a well-implemented CI performance optimization. The cache key strategy is sound with a proper three-tier fallback hierarchy (exact match → dependency match → any previous). The implementation correctly separates Next.js build cache from Turborepo's remote cache (turbo.json already excludes .next/cache/**). Both CI and Cypress workflows receive identical cache configuration enabling cross-workflow cache sharing. The experimental flag has been dogfooded by Vercel for 1+ year and only affects build time, not runtime behavior. Ship it! 🚀

Discarded (5)
Location Issue Reason Discarded
.github/workflows/ci.yml:59-66 Cache key strategy is well-designed Positive observation, not actionable
Multi-file Cache configuration correctly duplicated Positive observation, not actionable
turbo.json:34 turbo.json correctly excludes .next/cache Positive observation, not actionable
.github/workflows/release.yml Release workflow doesn't include cache Informational - intentional design choice
.github/workflows/ci.yml:60 Actions use mutable version tags Pre-existing pattern, not introduced by this PR
Reviewers (2)
Reviewer Returned Main Findings Consider While You're Here Inline Comments Pending Recs Discarded
pr-review-devops 6 0 1 0 0 0 5
pr-review-standards 0 0 0 0 0 0 0
Total 6 0 1 0 0 0 5

@github-actions github-actions bot deleted a comment from claude bot Feb 16, 2026
Add a type export to change the source hash and force a turbo cache
miss, while the GitHub Actions restore-key fallback restores the
.next/cache from the first run. This verifies that the warm
incremental Turbopack build is faster than cold.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel vercel bot temporarily deployed to Preview – agents-docs February 16, 2026 22:54 Inactive
Copy link
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

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

PR Review Summary

(0) Total Issues | Risk: Low

Delta Review Scope

This re-review is scoped to changes since the previous review:

  • Commit: 97d1a5cc — "test: trigger second CI run to verify warm Turbopack cache"
  • Changed file: agents-manage-ui/src/lib/utils.ts (+1 line)

🔴❗ Critical (0) ❗🔴

None

🟠⚠️ Major (0) 🟠⚠️

None

🟡 Minor (0) 🟡

None

💭 Consider (0) 💭

None

Delta Analysis

Change: Added export type CssTemplate = ReturnType<typeof String.raw>; to co-locate a type export with the existing css constant.

Assessment:

  • Correctness: The type correctly extracts the return type of String.raw (a template literal tag function)
  • Purpose: Intentional test change to verify Turbopack filesystem cache behavior on incremental builds
  • Impact: Type-only export — no runtime impact, no breaking changes
  • Quality: Well-placed next to the related css export

This is a trivial, intentional change with no review concerns.

🕐 Pending Recommendations (1)

  • 💭 next.config.ts:19-21 — Experimental flag enabled unconditionally (optional gating consideration from prior review)

✅ APPROVE

Summary: The delta since the last review is a single type export added to trigger a second CI run — this validates the Turbopack cache optimization that is the core of this PR. The previous review approved the main implementation; this follow-up commit introduces no concerns. Ready to ship! 🚀

Reviewers (0)
Reviewer Returned Main Findings Consider While You're Here Inline Comments Pending Recs Discarded
orchestrator-only 1 0 0 0 0 1 0
Total 1 0 0 0 0 1 0

Note: Delta was trivial (1 type export to trigger CI). No subagent reviewers dispatched — orchestrator-only assessment.

Removes the test type export that was flagged by knip as unused.
The warm cache verification succeeded (7.2s vs 85-105s cold).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

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

PR Review Summary

(0) Total Issues | Risk: Low

Delta Review Scope

This re-review is scoped to changes since the previous review:

  • Commit: 9edbb4ab — "fix: remove unused CssTemplate type export"
  • Changed file: agents-manage-ui/src/lib/utils.ts (-1 line)

🔴❗ Critical (0) ❗🔴

None

🟠⚠️ Major (0) 🟠⚠️

None

🟡 Minor (0) 🟡

None

💭 Consider (0) 💭

None

Delta Analysis

Change: Removed export type CssTemplate = ReturnType<typeof String.raw>; from utils.ts.

Assessment:

  • Correctness: Clean removal of unused type export
  • Purpose: Cleanup of test code that was added in the previous commit (97d1a5cc) to verify Turbopack filesystem cache behavior
  • Impact: No runtime or type impact — the type was never used
  • Quality: Proper cleanup after validation testing

This is a trivial housekeeping change with no review concerns.

🕐 Pending Recommendations (1)

  • 💭 next.config.ts:19-21 — Experimental flag enabled unconditionally (optional gating consideration from prior review)

✅ APPROVE

Summary: The delta since the last review is a single line deletion — removing a test type export that was added to trigger CI for cache validation. The main implementation (Turbopack filesystem cache config + workflow caching) was approved in prior reviews. This cleanup commit introduces no concerns. Ship it! 🚀

Reviewers (0)
Reviewer Returned Main Findings Consider While You're Here Inline Comments Pending Recs Discarded
orchestrator-only 1 0 0 0 0 1 0
Total 1 0 0 0 0 1 0

Note: Delta was trivial (1 line deletion to clean up test code). No subagent reviewers dispatched — orchestrator-only assessment.

@github-actions github-actions bot deleted a comment from claude bot Feb 16, 2026
@nick-inkeep nick-inkeep merged commit 4a7e153 into main Feb 16, 2026
11 checks passed
@nick-inkeep nick-inkeep deleted the feat/turbopack-filesystem-cache-for-build branch February 16, 2026 23:18
nick-inkeep added a commit that referenced this pull request Feb 17, 2026
Enable turbopackFileSystemCacheForBuild in agents-docs and persist
.next/cache in CI via a dedicated GHA cache step. This targets the
largest CI bottleneck (agents-docs cold build: 3.7-6.3min, 40-56% of
CI time) with the same incremental caching approach used for
agents-manage-ui in #2045.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
nick-inkeep added a commit that referenced this pull request Feb 17, 2026
* perf: enable Turbopack filesystem cache for agents-docs builds

Enable turbopackFileSystemCacheForBuild in agents-docs and persist
.next/cache in CI via a dedicated GHA cache step. This targets the
largest CI bottleneck (agents-docs cold build: 3.7-6.3min, 40-56% of
CI time) with the same incremental caching approach used for
agents-manage-ui in #2045.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: include agents-core in docs cache key hash

Add packages/agents-core/src/** to agents-docs cache key source hash
for consistency with agents-manage-ui pattern, since agents-docs
imports from agents-core.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant