Skip to content

ci(preview): stop a Turbopack cache panic killing previews - #936

Merged
sydevs-bot merged 4 commits into
mainfrom
claude/ci-932-turbopack-cache
Oct 14, 2026
Merged

sydevs-bot merged 4 commits into
mainfrom
claude/ci-932-turbopack-cache

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • A Railway build no longer carries a Turbopack cache store, so a corrupt one cannot kill a preview.
  • Cost, accepted on the ticket: every preview build now compiles cold.

Change outline

Flow — what a Railway build does with .next/cache

Railpack restores .next/cache before the build and saves it after. The store Turbopack
panicked 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.

 Railpack restores .next/cache                 (one mount per Next.js app)
 pnpm build                                    package.json:8
+  rm -rf .next/cache/turbopack                # the copy Railpack just restored
   next build
-    opens .next/cache/turbopack
-      corrupt store → turbo-persistence panics, after "✓ Compiled successfully"
-        AMQF data out of bounds, or SIGBUS on an mmap of a truncated file
+    turbopackFileSystemCacheForBuild: false   next.config.mjs — no store opened
   node scripts/standalone-postbuild.mjs
 Railpack saves .next/cache                    # .tsbuildinfo still rides; no turbopack/ to save

Behaviour — what each half is for

The two are not interchangeable, and neither is a second guard for the other.

flag false   → no store is read or written, so the panic cannot happen
rm -rf       → clears the copy Railpack already restored, and stops the mount
               saving a directory nothing reads. The build is the only way onto
               a builder, so it is the only place this can run.
ForDev flag  → untouched. That store is .next/dev/cache/turbopack, never on a builder.

Preview

A preview carries no content and previewUrl.seed is unset for this repo, so both links open on
what 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. A status: ok body 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 as PREVIEW_ADMIN_EMAIL.
  • Data: not seeded — neither link needs any.

Test results

  • Lean gate: ✓ pnpm lint, pnpm typecheck, pnpm typecheck:tests, pnpm test:unit (2340 passed, 179 files)
  • Targeted specs: 2 passed — tests/unit/turbopack-build-cache.spec.ts
  • Build: ✓ pnpm build exit 0, [standalone-postbuild] done

Verified end to end rather than inferred: .next/cache/turbopack was seeded with a sentinel file
before the build and did not exist afterwards, so the rm fires and nothing rewrites a store.
.next/cache/.tsbuildinfo survived. .next/standalone carried .next/static and public/, and
node .next/standalone/server.js answered GET /api/health with 200.

Each new assertion was watched failing against the real defect before being kept — flag absent,
flag true, the rm dropped, the rm moved after the build, and next build dropped.

Manual verification

  1. Confirm this PR's Railway preview reaches SUCCESS — the one acceptance criterion no local gate
    can answer, and the failure this ticket exists for.
  2. Watch a second build of this branch. The failure was intermittent, so one green build is weaker
    evidence than two.
  3. Decide whether the cold-compile build time is acceptable. No warm-build measurement exists for
    this app, so the saving given up is unknown rather than known-small.

Notes for reviewer

  • #903 interacts. If preview builds move onto GitHub Actions, the same store becomes an
    Actions cache question, and this flag keeps the answer "do not carry it".
  • One review claim was wrong and is fixed in the diff. An earlier draft of the spec's docblock
    said the flag and the rm were two independent requirements, each sufficient to restore the
    failure if dropped. They are not: the flag alone stops the panic. The docblock now says what each
    is actually for, matching the ticket.
  • Two review lenses were run by hand, not by an agent. The efficiency and altitude agents were
    stopped before they reported, so I covered both myself and the findings are above: only the
    turbopack subdirectory is discarded (.tsbuildinfo survives, measured), and railway.toml
    declares no build command with no Railpack config present, so package.json's build is the
    only 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.
  • Anomaly, reported not explained. Mid-run, tests/unit/turbopack-build-cache.spec.ts
    disappeared from the worktree between two git status reads while review subagents were
    running. 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
--webpack on Railway — was rejected because it diverges the preview bundler from local
pnpm build, so a Turbopack-only failure would reach a preview unseen. A process.env.RAILWAY_*
gate on this flag has the same shape, so both halves are unconditional. check.sh --full and
scripts/standalone-postbuild.mjs are the only other callers of pnpm build, and both want
exactly 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 withPayload and withSentryConfig. tests/unit/csp-frame-src.spec.ts already
pays 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 nextConfig literal: withPayload
spreads experimental rather 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 a
plain object, not a function — checked by importing it and printing typeof before writing the
assertion. It is an object, and its experimental keys after both wrappers are
turbopackFileSystemCacheForBuild, turbopackServerFastRefresh (added by withPayload) and
clientTraceMetadata (added by Sentry). The second assertion reads package.json directly, which
has no configuration to drift from.

No migration and no contract impact. The diff touches no collection, field, endpoint or
generated type, so contractStep did not apply. The security-review trigger pattern did not match
either — no path in the diff is under src/.

Closes #932

…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
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-936 October 13, 2026 15:46 Destroyed
@railway-app

railway-app Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-936 environment in sahajcloud

Service Status Web Updated
SahajCloud ✅ Success (View Logs) Web Oct 13, 2026 at 4:22 pm UTC
1 service not affected by this PR
  • mailpit

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 13, 2026
@sydevs-bot

sydevs-bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 16:03Z address-review · attempt 1 · session · done
  • 16:03Z address-review · attempt 1 · session
  • 15:55Z review-pr · attempt 1 · session · done
  • 15:55Z review-pr · attempt 1 · session

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🧐 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 on next.config.mjs:122.
  • consider — the flag and the rm are coupled, but pinned independently. Thread on package.json:8.

What was checked

  • Ticket #932 against the diff: all three numbered steps present, turbopackFileSystemCacheForDev untouched, the comment names the ticket.
  • next.config.mjs whole: experimental is new here, so no duplicate key — main carried none.
  • pnpm-lock.yaml: [email protected], so the flag exists (16.3.0+). node_modules is absent in a routine clone, so withPayload's experimental spread stays the author's measurement, not re-verified here.
  • Spec conventions against tests/unit/csp-frame-src.spec.ts and the five other resolve(__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, turbopack and standalone-postbuild across every *.md hit only DEPLOYMENT.md, and both lines are updated.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread next.config.mjs Resolved
Comment thread package.json Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Oct 13, 2026
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
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-936 October 13, 2026 16:10 Destroyed
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Both review threads adopted and resolved. Pushed a7dd9e2.

  • Adopted — one story told four times → 651ef98. The experimental comment is the suggested two lines. The spec's docblock and inline note lost the same narrative; DEPLOYMENT.md:60 keeps it. Three code blocks, 19 lines to 7.
  • Adopted — the flag and the rm are coupled → a7dd9e2. The docblock now says the rm goes when the flag does, so flipping the flag back cannot leave a build deleting the store it re-enabled. The rm stays.

Both commits are comment-only. Lean gate green on a7dd9e2: lint, typecheck, typecheck:tests, test:unit (2340 passed, 179 files). Docs checked, nothing stale. Nothing in the PR body is now false, so it stands.

Anomaly: issue_read method:get_labels answered "Could not resolve to an Issue with the number of 936", while method:get returned the PR with the lock intact.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Oct 13, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review October 13, 2026 16:23
@sydevs-bot
sydevs-bot requested a review from Ardnived October 13, 2026 16:23
@sydevs-bot
sydevs-bot enabled auto-merge October 13, 2026 16:23
@sydevs-bot sydevs-bot moved this from Revising to Approved in SYDevelopers Technical Roadmap Oct 14, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Oct 14, 2026
Merged via the queue into main with commit ed039aa Oct 14, 2026
50 of 52 checks passed
@sydevs-bot
sydevs-bot deleted the claude/ci-932-turbopack-cache branch October 14, 2026 16:15
@sydevs-bot sydevs-bot moved this from Approved to Done in SYDevelopers Technical Roadmap Oct 14, 2026
sydevs-bot pushed a commit that referenced this pull request Oct 14, 2026
#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

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-936 — a7dd9e20 Deployed Oct 13, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

ci(preview): stop a Turbopack cache panic killing previews

3 participants