Skip to content

Commit 7a902fc

Browse files
authored
improvement(ci): drop the e2e build's persistent compiler cache (#10281)
* improvement(ci): drop the e2e build's persistent compiler cache * fix(ci): turn the build filesystem cache off explicitly, since Next enables it by default * chore(ci): drop the dead build-cache prune mode and document the compiler cache removal
1 parent 534c8ba commit 7a902fc

7 files changed

Lines changed: 30 additions & 180 deletions

File tree

‎.github/CI.md‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ Database integration uses 4-vCPU Blacksmith runners with sticky dependency disks
3636

3737
GitHub runners install dependencies directly rather than transferring Bun and `node_modules` archives. In a same-source paired comparison, those restores took 26.2 seconds before an 82-millisecond install, while a clean install took 12.42 seconds. This is one paired observation; retain the policy only while repeated CI timings support it. Blacksmith keeps its sticky dependency disks. GitHub Turbo output caches remain enabled for jobs that request them, with a commit-specific key and a task/event/fork-scoped restore prefix, so a rerun can reuse an exact entry without creating another archive. Push jobs never restore pull-request entries.
3838

39-
Trusted Blacksmith E2E builders can reuse Next's incremental compiler state when a complete Turbo build is not already cached. The compiler cache has its own mode, event, OS/architecture, resolved toolchain, lockfile and build-recipe namespace; fork PRs and GitHub fallback keep the compiler cache off. The build command always runs, and an uncertain cache probe restores state rather than skipping compilation.
40-
41-
Compiler maintenance enforces a 20 GiB regular-file working-state limit before and after compilation, preserves the mounted root, and fails closed on access or ownership errors. Dev maintenance remains separate and nonblocking. Sticky disks are optional last-good compiler snapshots, not cross-job artifact handoff or validation receipts; no freshest-snapshot or physical-storage eviction guarantee is assumed. Hosted/deployment builds remain cache-off until separately qualified. A cold E2E qualification job took 259 seconds versus 225 uncached; fresh-runner warm and changed-source jobs took 148 and 159 seconds versus 227 and 229 uncached. These paired observations do not establish a universal CI speedup or justify smaller runners. Compilation and all existing acceptance coverage remain required.
39+
E2E builds compile without Next's persistent compiler cache (`turbopackFileSystemCacheForBuild: false`; Next enables it by default). Its earlier qualification showed warm, identical-source builds at 148 seconds, but real PR compiles restoring a shared cache took 2.9-4.6 minutes plus 15-37 seconds writing the cache back, while the same builds without it compiled in 2.5 minutes with no write. A complete Turbo build output is still reused when nothing it depends on changed. `scripts/prune-turbopack-cache.mts` caps only the dev cache.
4240

4341
Closing a same-repository pull request deletes only its GitHub merge-ref caches after verifying that it remains closed or merged. The regular `pull_request` workflow skips forks and Dependabot because their tokens cannot delete caches; those entries retain GitHub's normal cache eviction. Cleanup checks out no code and never selects a branch-wide or default-branch cache. Blacksmith sticky disks retain their separate lifecycle.
4442

‎.github/workflows/checks.yml‎

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ jobs:
10141014
TOTAL_GB=$(awk '/MemTotal/ {printf "%d", $2/1048576}' /proc/meminfo)
10151015
echo "Runner memory: ${TOTAL_GB} GB"
10161016
if [ "$TOTAL_GB" -lt 40 ]; then
1017-
echo "::warning::Runner has ${TOTAL_GB} GB. A cold-cache build peaks ~51 GB, so this run may be OOM-killed (reported only as 'the runner has received a shutdown signal'). Warm/partial builds should still fit."
1017+
echo "::warning::Runner has ${TOTAL_GB} GB. A build peaks ~51 GB, so this run may be OOM-killed (reported only as 'the runner has received a shutdown signal')."
10181018
fi
10191019
10201020
- name: Build application
@@ -1043,9 +1043,6 @@ jobs:
10431043
if: needs.changes.outputs.e2e_build == 'true'
10441044
runs-on: ${{ (vars.CI_PROVIDER == '' || vars.CI_PROVIDER == 'blacksmith') && 'blacksmith-16vcpu-ubuntu-2404' || 'linux-x64-8-core' }}
10451045
timeout-minutes: 25
1046-
env:
1047-
NEXT_BUILD_PERSISTENT_CACHE: ${{ (vars.CI_PROVIDER == '' || vars.CI_PROVIDER == 'blacksmith') && (github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork) && 'true' || 'false' }}
1048-
10491046
steps:
10501047
- *checkout-mirror
10511048
- *checkout-plain
@@ -1064,10 +1061,8 @@ jobs:
10641061
echo "::warning::Runner has ${TOTAL_GB} GB. A cold-cache build peaks ~51 GB, so this run may be OOM-killed (reported only as 'the runner has received a shutdown signal'). Warm/partial builds should still fit."
10651062
fi
10661063
1067-
- name: Plan incremental compiler state
1068-
id: compiler-cache-plan
1069-
if: env.NEXT_BUILD_PERSISTENT_CACHE == 'true'
1070-
env: &e2e-build-env
1064+
- name: Build application
1065+
env:
10711066
NODE_OPTIONS: '--no-warnings --max-old-space-size=8192'
10721067
NEXT_PUBLIC_APP_URL: 'http://localhost:3000'
10731068
DATABASE_URL: 'postgresql://postgres:postgres@localhost:5432/simstudio'
@@ -1082,38 +1077,8 @@ jobs:
10821077
# already enforce.
10831078
NEXT_BUILD_SKIP_TYPE_CHECK: 'true'
10841079
NEXT_BUILD_SKIP_SOURCE_MAPS: 'true'
1085-
run: |
1086-
echo "toolchain=bun$(bun --version)-node$(node --version)" >> "$GITHUB_OUTPUT"
1087-
if bunx turbo run build --filter=@sim/app --dry=json > "$RUNNER_TEMP/e2e-build-plan.json" &&
1088-
jq -e 'type == "object" and (.tasks | type) == "array" and ([.tasks[] | select(.taskId == "@sim/app#build")] | length == 1 and .[0].cache.status == "HIT")' "$RUNNER_TEMP/e2e-build-plan.json" > /dev/null; then
1089-
echo 'restore=false' >> "$GITHUB_OUTPUT"
1090-
else
1091-
echo 'restore=true' >> "$GITHUB_OUTPUT"
1092-
fi
1093-
1094-
- name: Mount incremental compiler state
1095-
id: compiler-cache
1096-
if: steps.compiler-cache-plan.outputs.restore == 'true'
1097-
uses: ./.github/actions/cache
1098-
with:
1099-
provider: ${{ vars.CI_PROVIDER }}
1100-
key: ${{ github.repository }}-next-build-e2e-v1-${{ runner.os }}-${{ runner.arch }}-${{ github.event_name }}-${{ steps.compiler-cache-plan.outputs.toolchain }}-${{ hashFiles('bun.lock', 'package.json', 'patches/**', 'apps/sim/package.json', 'apps/sim/next.config.ts', 'apps/sim/lib/core/config/env.ts', '.github/workflows/checks.yml', '.github/actions/setup/action.yml') }}
1101-
path: ./apps/sim/.next/cache
1102-
1103-
- name: Bound restored compiler state
1104-
if: steps.compiler-cache.outcome == 'success'
1105-
working-directory: apps/sim
1106-
run: node ../../scripts/prune-turbopack-cache.mts --build
1107-
1108-
- name: Build application
1109-
env: *e2e-build-env
11101080
run: bunx turbo run build --filter=@sim/app
11111081

1112-
- name: Bound compiler state before persistence
1113-
if: always() && !cancelled() && steps.compiler-cache.outcome == 'success'
1114-
working-directory: apps/sim
1115-
run: node ../../scripts/prune-turbopack-cache.mts --build
1116-
11171082
# Everything `next start` reads, including the spreadsheet parse worker it spawns (named, so a
11181083
# missing bundle fails packaging as it fails docker/app.Dockerfile); node_modules and the source
11191084
# tree come from e2e-production's own checkout and setup, at the same workspace path and

‎apps/sim/lib/core/config/env.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ export const env = createEnv({
349349
// Infrastructure & Deployment
350350
NEXT_RUNTIME: z.string().optional(), // Next.js runtime environment
351351
DOCKER_BUILD: z.boolean().optional(), // Flag indicating Docker build environment
352-
NEXT_BUILD_PERSISTENT_CACHE: z.boolean().optional(), // Enables incremental compiler state for qualified CI builds
353352
NEXT_BUILD_SKIP_SOURCE_MAPS: z.boolean().optional(), // Omits unused browser source maps in acceptance builds
354353
NEXT_BUILD_SKIP_TYPE_CHECK: z.boolean().optional(), // Skips `next build`'s TypeScript pass where another CI job type-checks
355354

‎apps/sim/next.config.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,10 @@ const nextConfig: NextConfig = {
166166
*/
167167
turbopackFileSystemCacheForDev: true,
168168
/**
169-
* Only qualified CI builds opt into persistent compiler state. Other builds
170-
* remain cache-off until their own memory, invalidation and restore costs are
171-
* qualified. CI keeps this state separate from complete build-output caches.
169+
* Off, explicitly: Next enables it by default, and a CI build compiles code its cache has
170+
* never seen, so it only pays for writing the cache back (15-37s) on a disk that is discarded.
172171
*/
173-
turbopackFileSystemCacheForBuild: isTruthy(env.NEXT_BUILD_PERSISTENT_CACHE),
172+
turbopackFileSystemCacheForBuild: false,
174173
/**
175174
* TypeScript 7 ships no JavaScript compiler API until 7.1, so Next's default
176175
* checker cannot load it — this shells out to the project-local `tsc` instead.

‎apps/sim/turbo.json‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,7 @@
220220
]
221221
},
222222
"build": {
223-
"env": [
224-
"NEXT_BUILD_PERSISTENT_CACHE",
225-
"NEXT_BUILD_SKIP_SOURCE_MAPS",
226-
"NEXT_BUILD_SKIP_TYPE_CHECK"
227-
],
223+
"env": ["NEXT_BUILD_SKIP_SOURCE_MAPS", "NEXT_BUILD_SKIP_TYPE_CHECK"],
228224
"inputs": [
229225
"$TURBO_DEFAULT$",
230226
".env*",

‎scripts/prune-turbopack-cache.mts‎

Lines changed: 16 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
#!/usr/bin/env node
22
/**
3-
* Caps each app's Turbopack cache from its working directory.
3+
* Caps an app's Turbopack dev cache (`.next/dev/cache/turbopack`) from its working directory.
44
*
5-
* Dev maintenance is best effort and never blocks startup. `--build` selects
6-
* `.next/cache`, preserves its mounted root, and fails on maintenance errors;
7-
* run it only between compiler processes. Oversized state is discarded so the
8-
* next compiler starts cold. Child symlinks are neither counted nor followed.
5+
* Best effort: it never blocks `next dev` startup. Oversized state is discarded so the next start
6+
* compiles cold. Child symlinks are neither counted nor followed; a symlinked cache root is unlinked
7+
* without touching its target.
98
*
10-
* Build maintenance uses Node's bounded directory iterator and stops counting
11-
* above the cap. Dev commands keep Bun and its existing best-effort behavior.
12-
*
13-
* CI build maintenance runs with Node 24: `node scripts/prune-turbopack-cache.mts [--build] [--force] [--dry-run]`.
9+
* Usage: `bun run scripts/prune-turbopack-cache.mts [--force] [--dry-run]`.
1410
* `SIM_TURBOPACK_CACHE_MAX_GB` overrides the default 20 GiB cap.
1511
*/
1612
import { existsSync, lstatSync, statSync } from 'node:fs'
@@ -19,43 +15,26 @@ import path from 'node:path'
1915

2016
const DEFAULT_MAX_GB = 20
2117
const BYTES_PER_GB = 1024 ** 3
22-
const BUILD_CACHE = process.argv.includes('--build')
2318

24-
/**
25-
* Each app owns its cache under its working directory. Build maintenance selects
26-
* a separate root, so it cannot prune a live dev server's state.
27-
*/
28-
const CACHE_DIR = path.resolve(
29-
process.cwd(),
30-
BUILD_CACHE ? '.next/cache' : '.next/dev/cache/turbopack'
31-
)
19+
/** Each app owns its dev cache under its working directory. */
20+
const CACHE_DIR = path.resolve(process.cwd(), '.next/dev/cache/turbopack')
3221

3322
function isMissingPath(error: unknown): boolean {
3423
return error instanceof Error && 'code' in error && error.code === 'ENOENT'
3524
}
3625

3726
/** Counts regular files without following symlinks or retaining the tree in memory. */
38-
async function directorySize(dir: string, limit: number): Promise<number> {
27+
async function directorySize(dir: string): Promise<number> {
3928
let total = 0
40-
let entries: Awaited<ReturnType<typeof opendir>>
41-
try {
42-
entries = await opendir(dir, { bufferSize: 32 })
43-
} catch (error) {
44-
if (BUILD_CACHE && isMissingPath(error)) return 0
45-
throw error
46-
}
47-
for await (const entry of entries) {
29+
for await (const entry of await opendir(dir, { bufferSize: 32 })) {
4830
const entryPath = path.join(dir, entry.name)
4931
if (entry.isDirectory()) {
50-
total += await directorySize(entryPath, limit - total)
32+
total += await directorySize(entryPath)
5133
} else if (entry.isFile()) {
5234
try {
5335
total += (await stat(entryPath)).size
54-
} catch (error) {
55-
if (BUILD_CACHE && !isMissingPath(error)) throw error
56-
}
36+
} catch {}
5737
}
58-
if (total > limit) break
5938
}
6039
return total
6140
}
@@ -92,28 +71,11 @@ function parseMaxGb(): number {
9271
async function main() {
9372
const force = process.argv.includes('--force')
9473
const dryRun = process.argv.includes('--dry-run')
95-
96-
if (BUILD_CACHE) {
97-
let root: ReturnType<typeof lstatSync>
98-
try {
99-
root = lstatSync(CACHE_DIR)
100-
} catch (error) {
101-
if (isMissingPath(error)) return
102-
throw error
103-
}
104-
if (root.isSymbolicLink() || !root.isDirectory())
105-
throw new Error('Build cache root must be a directory without symlinks')
106-
} else if (!existsSync(CACHE_DIR) || !statSync(CACHE_DIR).isDirectory()) {
107-
return
108-
}
74+
if (!existsSync(CACHE_DIR) || !statSync(CACHE_DIR).isDirectory()) return
10975

11076
const maxGb = parseMaxGb()
111-
const limit = BUILD_CACHE ? maxGb * BYTES_PER_GB : Number.POSITIVE_INFINITY
112-
const bytes = force ? 0 : await directorySize(CACHE_DIR, limit)
113-
const gb = bytes / BYTES_PER_GB
114-
const sizeLabel = force
115-
? 'cache'
116-
: `${BUILD_CACHE && bytes > limit ? 'at least ' : ''}${gb.toFixed(1)} GB`
77+
const gb = force ? 0 : (await directorySize(CACHE_DIR)) / BYTES_PER_GB
78+
const sizeLabel = force ? 'cache' : `${gb.toFixed(1)} GB`
11779

11880
if (!force && gb <= maxGb) {
11981
if (dryRun) console.log(`[turbopack-cache] ${sizeLabel} (cap ${maxGb} GB) — keeping`)
@@ -127,15 +89,14 @@ async function main() {
12789
}
12890

12991
console.log(`[turbopack-cache] ${sizeLabel} is ${reason} — pruning; next start recompiles cold`)
130-
if (!BUILD_CACHE && lstatSync(CACHE_DIR).isSymbolicLink()) {
92+
if (lstatSync(CACHE_DIR).isSymbolicLink()) {
13193
await rm(CACHE_DIR, { force: true })
13294
return
13395
}
13496
await clearDirectory(CACHE_DIR)
135-
if (!BUILD_CACHE) await rmdir(CACHE_DIR)
97+
await rmdir(CACHE_DIR)
13698
}
13799

138100
main().catch((error) => {
139101
console.warn('[turbopack-cache] prune skipped:', error)
140-
if (BUILD_CACHE) process.exitCode = 1
141102
})
Lines changed: 6 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { spawnSync } from 'node:child_process'
22
import {
33
existsSync,
4-
lstatSync,
54
mkdirSync,
65
mkdtempSync,
7-
readdirSync,
86
readFileSync,
97
rmSync,
10-
statSync,
118
symlinkSync,
129
writeFileSync,
1310
} from 'node:fs'
@@ -36,7 +33,7 @@ function fixture() {
3633
}
3734

3835
function run(root: string, args: string[], maximum = '0.000001') {
39-
return spawnSync(args.includes('--build') ? 'node' : 'bun', [script, ...args], {
36+
return spawnSync('bun', [script, ...args], {
4037
cwd: root,
4138
encoding: 'utf8',
4239
timeout: 10_000,
@@ -48,58 +45,8 @@ afterEach(() => {
4845
for (const root of fixtures.splice(0)) rmSync(root, { recursive: true, force: true })
4946
})
5047

51-
describe('compiler cache maintenance through the real CLI', () => {
52-
it.each(['size', 'force'])(
53-
'clears only build contents by %s while preserving its mount',
54-
(mode) => {
55-
const { root, build, dev, outside } = fixture()
56-
const inode = statSync(build).ino
57-
const result = run(
58-
root,
59-
mode === 'force' ? ['--build', '--force'] : ['--build'],
60-
mode === 'force' ? '1' : undefined
61-
)
62-
expect(result.status, result.stderr).toBe(0)
63-
expect(existsSync(build)).toBe(true)
64-
expect(statSync(build).ino).toBe(inode)
65-
expect(readdirSync(build)).toEqual([])
66-
expect(existsSync(join(dev, 'state'))).toBe(true)
67-
expect(existsSync(join(outside, 'state'))).toBe(true)
68-
}
69-
)
70-
71-
it('retains useful build state without counting external symlink targets', () => {
72-
const { root, build, dev, outside } = fixture()
73-
const inode = statSync(build).ino
74-
const buildBytes = readFileSync(join(build, 'state'))
75-
const devBytes = readFileSync(join(dev, 'state'))
76-
const outsideBytes = readFileSync(join(outside, 'state'))
77-
expect(run(root, ['--build'], '0.000006').status).toBe(0)
78-
expect(statSync(build).ino).toBe(inode)
79-
expect(readFileSync(join(build, 'state'))).toEqual(buildBytes)
80-
expect(readFileSync(join(dev, 'state'))).toEqual(devBytes)
81-
expect(readFileSync(join(outside, 'state'))).toEqual(outsideBytes)
82-
})
83-
84-
it('does not substitute dev state when the build cache is absent', () => {
85-
const { root, build, dev } = fixture()
86-
rmSync(build, { recursive: true })
87-
expect(run(root, ['--build']).status).toBe(0)
88-
expect(existsSync(join(dev, 'state'))).toBe(true)
89-
})
90-
91-
it('rejects a non-directory ancestor instead of treating it as an absent build cache', () => {
92-
const { root, outside } = fixture()
93-
const parent = join(root, '.next')
94-
rmSync(parent, { recursive: true })
95-
writeFileSync(parent, 'unrelated parent file')
96-
const result = run(root, ['--build'])
97-
expect(result.status, result.stderr).not.toBe(0)
98-
expect(readFileSync(parent, 'utf8')).toBe('unrelated parent file')
99-
expect(existsSync(join(outside, 'state'))).toBe(true)
100-
})
101-
102-
it('keeps the existing dev command scoped to dev state', () => {
48+
describe('dev cache maintenance through the real CLI', () => {
49+
it('prunes only dev state, never the build cache or other directories', () => {
10350
const { root, build, dev, outside } = fixture()
10451
expect(run(root, []).status).toBe(0)
10552
expect(existsSync(dev)).toBe(false)
@@ -126,25 +73,10 @@ describe('compiler cache maintenance through the real CLI', () => {
12673
}
12774
)
12875

129-
it('leaves both caches intact for a build dry run', () => {
76+
it('keeps dev state on a dry run over the cap', () => {
13077
const { root, build, dev } = fixture()
131-
expect(run(root, ['--build', '--dry-run']).status).toBe(0)
132-
expect(existsSync(join(build, 'state'))).toBe(true)
78+
expect(run(root, ['--dry-run']).status).toBe(0)
13379
expect(existsSync(join(dev, 'state'))).toBe(true)
80+
expect(existsSync(join(build, 'state'))).toBe(true)
13481
})
135-
136-
it.each([true, false])(
137-
'refuses a symlink build root when target existence is %s',
138-
(targetExists) => {
139-
const { root, build, dev, outside } = fixture()
140-
rmSync(build, { recursive: true })
141-
symlinkSync(outside, build, process.platform === 'win32' ? 'junction' : 'dir')
142-
if (!targetExists) rmSync(outside, { recursive: true })
143-
const result = run(root, ['--build', '--force'])
144-
expect(result.status, result.stderr).not.toBe(0)
145-
expect(lstatSync(build).isSymbolicLink()).toBe(true)
146-
expect(existsSync(join(outside, 'state'))).toBe(targetExists)
147-
expect(existsSync(join(dev, 'state'))).toBe(true)
148-
}
149-
)
15082
})

0 commit comments

Comments
 (0)