AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Intermittent 404 For On-Disk Routes In Next.Js Dev Due To Delayed App-Paths-Manifest Updates

Turbopack dev server writes the app-paths-manifest.json asynchronously after an idle period, causing a race where compiled routes are missing from the manifest and return 404 until the file is touched.

highConfidence 75%Next.jsAffected V16.2.11Affected V16.3.0-Canary.105

Origin Analysis

Turbopack batches route compilation and defers app-paths-manifest.json updates until after the server goes idle; if the dev server is stopped, crashed, or the cache is flushed before that write completes, the manifest lacks entries for already-compiled routes, leading to 404 responses.
1. Clone the reproduction repo: https://github.com/Crsk/turbopack-dev-cache-timing 2. Run `npm ci && node scale.mjs 60 && node characterize.mjs` 3. Observe that .next/dev/cache grows slowly during compilation and then jumps to 85 MB after ~2.1s idle. 4. Stop the server during the idle window; restart and request a nested route that was compiled but not yet in the manifest, resulting in 404. 5. Touch the route file to trigger recompilation and manifest update, which resolves the 404.

Fixing Code Block

Edge Case Audit

This change increases disk write frequency and may introduce file contention if multiple routes compile concurrently; use atomic write operations (write to temp file then rename) to avoid corruption. Rolling back to the original behavior should be straightforward but will reintroduce the 404 race until an official upstream fix with proper batching and flushing is released.

Ecosystem Topology