Repository navigation
ci(preview): stop a Turbopack cache panic killing previews - #936
Conversation
…ilds Two Railway preview builds of #879 died in six days inside `turbo-persistence`, Turbopack's on-disk cache store — once on `AMQF data out of bounds`, once on SIGBUS, both right after `✓ Compiled successfully`. Neither commit is implicated: the same branch built green at `1de5fae`, `main` stayed green throughout, and `pnpm build` at the failing commit exits 0 locally. The store lives in `.next/cache/turbopack`, inside the one directory Railpack restores between builds of a service, so a store corrupted by a build killed mid-write rides onto every later build of that branch and a PR loses its preview indefinitely. Nothing in the loop can recover it — clearing a builder's cache is a write to the vendor account, and no upstream fix exists to wait for (vercel/next.js#87283 has no maintainer answer on discarding a bad store instead of panicking). `turbopackFileSystemCacheForBuild: false` is what stops the panic: no store is opened, so the restored copy is inert. The `rm` at the head of the build script does a second, smaller job — it stops the cache mount saving and restoring a directory nothing reads, and it is the only way to clear the copy Railpack has already restored, the build being the only way onto a builder. Both go in `package.json` and `next.config.mjs` unconditionally rather than behind a Railway or CI gate, so a local `pnpm build` stays the build the builder runs; `railway.toml` declares no build command and there is no Railpack config, so the script is the only shared entry point either way. Verified by seeding `.next/cache/turbopack` and building: the directory is gone afterwards and nothing rewrites it, `.next/cache/.tsbuildinfo` survives, `.next/standalone` still carries `.next/static` and `public/`, and its `server.js` answers `/api/health` with 200. The spec's two cases were each watched failing against the real defects — flag absent, flag true, `rm` dropped, `rm` moved after the build. Every preview build now compiles cold. No warm-build measurement exists for this app, so the saving given up is unknown rather than small; two previews lost in six days is what it buys. `turbopackFileSystemCacheForDev` is left alone — the dev store lives at `.next/dev/cache/turbopack` and never reaches a builder. Closes #932 Co-authored-by: Claude <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019aWmw2LLpDPgcvLsGz5Jbv
The Build & Start list enumerated what `pnpm build` runs, and the deletion of `.next/cache/turbopack` is now its first step. The paragraph below it already explains one thing `next.config.mjs` does to the build output, so the reason a preview build compiles cold goes there too — a reader who finds every build slower should not have to reach #932 to learn it is deliberate. Co-authored-by: Claude <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_019aWmw2LLpDPgcvLsGz5Jbv
|
🚅 Deployed to the SahajCloud-pr-936 environment in sahajcloud
1 service not affected by this PR
|
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff is the ticket, at the ticket's size: two levers, one spec, one doc paragraph, nothing smuggled in. No contract surface is touched — no collection, field, endpoint or generated type — so there is no consumer side to follow. The preview is live and healthy, which settles the one acceptance criterion no local gate could answer.
Two things to settle, neither a blocker. The rm half prevents nothing the flag does not, and it turns into a trap if the flag is ever flipped back. And one rationale is written out four times across three files.
Findings
should-fix— one story told four times:next.config.mjs:122(7 lines), the spec docblock (9), its inline note (3),DEPLOYMENT.md:63(6). Thread onnext.config.mjs:122.consider— the flag and thermare coupled, but pinned independently. Thread onpackage.json:8.
What was checked
- Ticket #932 against the diff: all three numbered steps present,
turbopackFileSystemCacheForDevuntouched, the comment names the ticket. next.config.mjswhole:experimentalis new here, so no duplicate key —maincarried none.pnpm-lock.yaml:[email protected], so the flag exists (16.3.0+).node_modulesis absent in a routine clone, sowithPayload'sexperimentalspread stays the author's measurement, not re-verified here.- Spec conventions against
tests/unit/csp-frame-src.spec.tsand the five otherresolve(__dirname, '../..')specs: both match. - Preview, both links:
/api/health→ 200{"status":"ok"}, uptime 334 s;/admin/login→ 200,<title>Login - Sahaj Cloud</title>, 51 KB. Manual-verification step 1 is done. Step 2, a second green build, is still open. - Docs sweep:
.next/cache,turbopackandstandalone-postbuildacross every*.mdhit onlyDEPLOYMENT.md, and both lines are updated.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
The Railpack-restores-`.next/cache` narrative was written out four times: the `experimental` comment, the spec's docblock, its inline note, and `DEPLOYMENT.md`. The doc is the home for it, so the two code comments now carry only what a reader cannot get from the code — the constraint and the `#932` breadcrumb in `next.config.mjs`, and why each lever is pinned in the spec. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MFVxANxEM8LZVB43MZUy8K
The spec asserts the flag and the `rm` separately, which reads as two independent requirements. Flipping the flag back after an upstream fix would turn only the first assertion red, leaving a build script that deletes the store it just re-enabled. The docblock now says the `rm` goes when the flag does. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MFVxANxEM8LZVB43MZUy8K
|
Both review threads adopted and resolved. Pushed
Both commits are comment-only. Lean gate green on Anomaly: 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
#936 landed a second `experimental` literal on main while this branch carried its own. Both merged cleanly — neither hunk touches the other — and the later literal replaced the earlier one wholesale, so `proxyClientMaxBodySize` was gone from the config Next receives. `tests/unit/next-config-body-limit.spec.ts` read `undefined` and failed on the merge commit CI tests, though the branch alone stayed green. Lint sees nothing: `no-dupe-keys` does not fire on this file. The two keys are now one literal, and the ⚠ above it says why a second is never safe here: both flags fail open. An unset cap truncates every /api write at 10 MB. An unset Turbopack flag restores the corrupt store. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VgKpwYjNuqhVdCS4zby42F
Summary
Change outline
Flow — what a Railway build does with
.next/cacheRailpack restores
.next/cachebefore the build and saves it after. The store Turbopackpanicked on was inside it, so the fix is at both ends: nothing opens a store, and the restored
copy is removed rather than carried on.
Behaviour — what each half is for
The two are not interchangeable, and neither is a second guard for the other.
Preview
A preview carries no content and
previewUrl.seedis unset for this repo, so both links open onwhat the deploy itself produces rather than on seeded records. For this change that is the point:
the claim under test is that the build completes and boots at all.
/api/health— the deploy's own health JSON, no sign-in. Astatus: okbody is the build having produced a working.next/standalone./admin/login— the sign-in view, which renders without content. Proves the admin bundle shipped. Signing in needs a link asPREVIEW_ADMIN_EMAIL.Test results
pnpm lint,pnpm typecheck,pnpm typecheck:tests,pnpm test:unit(2340 passed, 179 files)tests/unit/turbopack-build-cache.spec.tspnpm buildexit 0,[standalone-postbuild] doneVerified end to end rather than inferred:
.next/cache/turbopackwas seeded with a sentinel filebefore the build and did not exist afterwards, so the
rmfires and nothing rewrites a store..next/cache/.tsbuildinfosurvived..next/standalonecarried.next/staticandpublic/, andnode .next/standalone/server.jsansweredGET /api/healthwith 200.Each new assertion was watched failing against the real defect before being kept — flag absent,
flag
true, thermdropped, thermmoved after the build, andnext builddropped.Manual verification
SUCCESS— the one acceptance criterion no local gatecan answer, and the failure this ticket exists for.
evidence than two.
this app, so the saving given up is unknown rather than known-small.
Notes for reviewer
#903interacts. If preview builds move onto GitHub Actions, the same store becomes anActions cache question, and this flag keeps the answer "do not carry it".
said the flag and the
rmwere two independent requirements, each sufficient to restore thefailure if dropped. They are not: the flag alone stops the panic. The docblock now says what each
is actually for, matching the ticket.
stopped before they reported, so I covered both myself and the findings are above: only the
turbopacksubdirectory is discarded (.tsbuildinfosurvives, measured), andrailway.tomldeclares no build command with no Railpack config present, so
package.json'sbuildis theonly shared entry point — putting the change behind a Railway or CI gate would diverge the
preview bundler from local
pnpm build, which is what rejected option B on the ticket.tests/unit/turbopack-build-cache.spec.tsdisappeared from the worktree between two
git statusreads while review subagents wererunning. It was restored from the commit, and the committed content is what the lean gate and
the defect re-verification both ran against.
Detail
Why the flag is not gated on Railway or CI. Option B on the ticket — building with
--webpackon Railway — was rejected because it diverges the preview bundler from localpnpm build, so a Turbopack-only failure would reach a preview unseen. Aprocess.env.RAILWAY_*gate on this flag has the same shape, so both halves are unconditional.
check.sh --fullandscripts/standalone-postbuild.mjsare the only other callers ofpnpm build, and both wantexactly the build the builder runs.
Spec cost. The new file runs in 644 ms alone, almost all of it importing
next.config.mjs(476 ms) past
withPayloadandwithSentryConfig.tests/unit/csp-frame-src.spec.tsalreadypays the same import (539 ms), and Vitest gives each spec file its own module registry, so the
lane pays it twice — about +0.5 s on a 45 s lane.
Why the spec reads the default export rather than the
nextConfigliteral:withPayloadspreads
experimentalrather than replacing it, which is the behaviour the assertion depends on.A future wrapper that dropped the key would leave the store on while the source still named the
flag, and only the default-export read catches that.
Fixture pre-mortem. The spec's one assumption is that
next.config.mjs's default export is aplain object, not a function — checked by importing it and printing
typeofbefore writing theassertion. It is an object, and its
experimentalkeys after both wrappers areturbopackFileSystemCacheForBuild,turbopackServerFastRefresh(added bywithPayload) andclientTraceMetadata(added by Sentry). The second assertion readspackage.jsondirectly, whichhas no configuration to drift from.
No migration and no contract impact. The diff touches no collection, field, endpoint or
generated type, so
contractStepdid not apply. The security-review trigger pattern did not matcheither — no path in the diff is under
src/.Closes #932