Wrapping the data response in a Buffer misclassifies it as dynamic, dropping Content-Length and ETag
Tier 2 hard typescript · cross-file · real merged PR from vercel/next.js #80189
Ground-truth defects
The response-handling refactor builds the /_next/data JSON page response as Buffer.from(JSON.stringify(result.value.pageData)). RenderResult.isDynamic decides static-vs-dynamic via `typeof this.response !== 'string'`, so a Buffer is misclassified as a dynamic stream; sendRenderResult then skips Content-Length and ETag and falls back to Transfer-Encoding: chunked, breaking CDN-side compression for self-hosted Pages Router deploys. The fix deletes the Buffer.from wrapper. (Large-diff stress case: ~3k lines, 22 files.)
In app-page.ts the resume-render branch calls getFallbackRouteParams(pathname) where pathname (parsedUrl.pathname, interpolated in prepare()) is the resolved concrete path with no [param] segments, so getRouteRegex finds no dynamic keys and returns null; it should use normalizedSrcPage (the route pattern) as the sibling PPR-fallback call and the original base-server pathname (match.definition.pathname) did, breaking PPR fallback-shell param postponement for dynamic routes when renderFallbackShell is set in production.
In the app-route template's on-demand-revalidate path, responseGenerator correctly writes a real 404 response (res.statusCode = 404; res.end(...)) and returns null when isOnDemandRevalidate && revalidateOnlyGenerated && !previousCacheEntry. Back in handleResponse, because this route is ISR-eligible (isIsr is true -- it's determined solely by prerender-manifest membership, independent of the on-demand-revalidate flags, and on-demand revalidation is inherently an ISR-only feature), the `if (!isIsr) return null` short-circuit is skipped, and cacheEntry?.value?.kind !== CachedRouteKind.APP_ROUTE (true, since cacheEntry is null) throws an "Invariant: app-route received invalid cache entry" error -- even though a valid 404 HTTP response was already sent to the client. Because isIsr is true, the surrounding catch re-throws this spurious error rather than swallowing it, propagating it up through base-server onto an already-ended response.
With `trailingSlash: true`, the new handler templates (app-page.ts, app-route.ts, pages.ts) take `resolvedPathname` from the request URL, which base-server now rebuilds from the raw `initURL` and which still ends in a slash. None of them calls `removeTrailingSlash`, which base-server applied before its cache-key and prerender lookups. The build writes prerender-manifest keys without the slash, so every lookup misses. For app-page, a prerendered page on a `dynamicParams = false` route is taken to be unlisted and throws NoFallbackError (404), and the ISR cache key becomes `/blog/a/`, so the prebuilt output is never served.
The pages template sets `isIsrFallback` for an ungenerated path of a `fallback: true` route and clears it only for bots, minimal mode or an existing cache entry, never for on-demand revalidation. Base-server forced a blocking render when `isOnDemandRevalidate` was set. So `res.revalidate('/posts/new')` for a path not yet generated now returns the build-time fallback shell with its cache control deleted: nothing is stored, yet the response carries `x-nextjs-cache: REVALIDATED`, so the revalidate call reports success without generating the page.
The app-route template's outer catch now calls `routeModule.onRequestError(req, err, {...})` without the fourth `routerServerContext` argument that every other call site in this diff passes. `RouteModule.onRequestError` therefore falls back to a bare `console.error(err)` instead of `routerServerContext.logErrorWithOriginalStack`, so a server started with `quiet: true` now prints route-handler errors, a normal server loses the standard error prefix, and in dev the original-stack logger is skipped.
The dev server's `getStaticPaths` now copies each dynamic route's static paths and fallback mode into `<distDir>/prerender-manifest.json` with an unsynchronised readFile, JSON.parse, mutate, writeFile. Calls are coalesced only per pathname, so two different dynamic routes can resolve together. The second writer drops the first route's entries, and two overlapping truncating writes can leave the file as invalid JSON, after which every dev request that loads manifests throws until the dev server restarts.
The app-page template adds an early `if (isSSG && prerenderInfo?.fallback === false && !isPrerendered) throw new NoFallbackError()` that runs before draft mode or minimal mode is considered. The base-server check it replaces skipped preview/draft mode and minimal mode, and the sibling pages and app-route templates keep a `!isDraftMode` guard. A draft-mode request for a path of a `dynamicParams = false` app page that was not prerendered now returns 404 instead of rendering on demand, which breaks CMS preview of unpublished pages.
The app-page template's responseGenerator copies base-server's static-shell-debugging short-circuit, which returns a cache entry of `kind: CachedRouteKind.PAGES`. The template's own handleResponse then throws "Invariant app-page handler received invalid cache entry PAGES" for any kind other than APP_PAGE. Base-server served that entry through its generic branch as an empty HTML response, so a static-shell debugging request now fails with the invariant error.
The change under review
diff (truncated — full diff)
@@ -693,10 +693,18 @@ "692": "Expected clientReferenceManifest to be defined.", "693": "%s must not be used within a client component. Next.js should be preventing %s from being included in client components statically, but did not in this case.", "694": "createPrerenderPathname was called inside a client component scope.", - "695": "Expected workUnitAsyncStorage to have a store.", - "696": "Next DevTools: Can't dispatch %s in this environment. This is a bug in Next.js", + "695": "Invariant: received non-pages cache entry in pages handler", + "696": "Expected workUnitAsyncStorage to have a store.", "697": "Next DevTools: Can't render in this environment. This is a bug in Next.js", - "698": "Next DevTools: App Dev Overlay is already mounted. This is a bug in Next.js", - "699": "Next DevTools: Pages Dev Overlay is already mounted. This is a bug in Next.js", - "700": "Failed to persist Chrome DevTools workspace UUID. The Chrome DevTools Workspace needs to be reconnected after the next page reload." + "698": "Next DevTools: Can't dispatch %s in this environment. This is a bug in Next.js", + "699": "Next DevTools: App Dev Overlay is already mounted. This is a bug in Next.js", + "700": "Next DevTools: Pages Dev Overlay is already mounted. This is a bug in Next.js", + "701": "Invariant: app-route received invalid cache entry %s", + "702": "Invariant: unexpected APP_ROUTE cache data", + "703": "Route is configured with dynamic = error which cannot be statically generated.", + "704": "Route is configured with dynamic = error be statically generated.", + "705": "Route is configured with dynamic = error that cannot be statically generated.", + "706": "Invariant: static responses cannot be streamed %s", + "707": "Invariant app-page handler received invalid cache entry %s", + "708": "Failed to persist Chrome DevTools workspace UUID. The Chrome DevTools Workspace needs to be reconnected after the next page reload." } @@ -1,5 +1,4 @@ import type { LoaderTree } from '../../server/lib/app-dir-module' -import type { ServerOnInstrumentationRequestError } from '../../server/app-render/types' import type { IncomingMessage, ServerResponse } from 'node:http' import { @@ -16,7 +15,10 @@ import { BaseServerSpan } from '../../server/lib/trace/constants' import { interopDefault } from '../../server/app-render/interop-default' import { NodeNextRequest, NodeNextResponse } from '../../server/base-http/node' import { checkIsAppPPREnabled } from '../../server/lib/experimental/ppr' -import { getFallbackRouteParams } from '../../server/request/fallback-params' +import { + getFallbackRouteParams, + type FallbackRouteParams, +} from '../../server/request/fallback-params' import { setReferenceManifestsSingleton } from '../../server/app-render/encryption-utils' import { isHtmlBotRequest, @@ -26,13 +28,27 @@ import { createServerModuleMap } from '../../server/app-render/action-utils' import { normalizeAppPath } from '../../shared/lib/router/utils/app-paths' import { getIsPossibleServerAction } from '../../server/lib/server-action-request-meta' import { - RouterServerContextSymbol, - routerServerGlobal, -} from '../../server/lib/router-utils/router-server-context' -import { - NEXT_ROUTER_PREFETCH_HEADER, RSC_HEADER, + NEXT_ROUTER_PREFETCH_HEADER, + NEXT_IS_PRERENDER_HEADER, + NEXT_DID_POSTPONE_HEADER, } from '../../client/components/app-router-headers' +import { getBotType, isBot } from '../../shared/lib/router/utils/is-bot' +import { + CachedRouteKind, + type CachedAppPageValue, + type CachedPageValue, + type ResponseCacheEntry, + type ResponseGenerator, +} from '../../server/response-cache' +import { decodePathParams } from '../../server/lib/router-utils/decode-path-params' +import { FallbackMode, parseFallbackField } from '../../lib/fallback' +import RenderResult from '../../server/render-result' +import { CACHE_ONE_YEAR, NEXT_CACHE_TAGS_HEADER } from '../../lib/constants' +import type { CacheControl } from '../../server/lib/cache-control' +import { ENCODED_TAGS } from '../../server/stream-utils/encoded-tags' +import { sendRenderResult } from '../../server/send-payload' +import { NoFallbackError } from '../../shared/lib/no-fallback-error.external' // These are injected by the loader afterwards. @@ -67,7 +83,6 @@ export const __next_app__ = { } import * as entryBase from '../../server/app-render/entry-base' with { 'turbopack-transition': 'next-server-utility' } -import { getBotType } from '../../shared/lib/router/utils/is-bot' export * from '../../server/app-render/entry-base' with { 'turbopack-transition': 'next-server-utility' } @@ -110,7 +125,9 @@ export async function handler( const multiZoneDraftMode = process.env .__NEXT_MULTI_ZONE_DRAFT_MODE as any as boolean - const postponed = getRequestMeta(req, 'postponed') + const initialPostponed = getRequestMeta(req, 'postponed') + // TODO: replace with more specific flags + const minimalMode = getRequestMeta(req, 'minimalMode') const prepareResult = await routeModule.prepare(req, res, { srcPage, @@ -132,57 +149,71 @@ export async function handler( pageIsDynamic, buildManifest, nextFontManifest, - serverFilesManifest, reactLoadableManifest, serverActionsManifest, clientReferenceManifest, subresourceIntegrityManifest, prerenderManifest, isDraftMode, - isOnDemandRevalidate, + + revalidateOnlyGenerated, + routerServerContext, + nextConfig, } = prepareResult - const routerServerContext = - routerServerGlobal[RouterServerContextSymbol]?.[ - process.env.__NEXT_RELATIVE_PROJECT_DIR || '' - ] - - const onInstrumentationRequestError = - routeModule.instrumentationOnRequestError.bind(routeModule) - - const onError: ServerOnInstrumentationRequestError = ( - err, - _, - errorContext - ) => { - if (routerServerContext?.logErrorWithOriginalStack) { - routerServerContext.logErrorWithOriginalStack(err, 'app-dir') - } else { - console.error(err) - } - return onInstrumentationRequestError( - req, - err, - { - path: req.url || '/', - headers: req.headers, - method: req.method || 'GET', - }, - errorContext - ) + const pathname = parsedUrl.pathname || '/' + const normalizedSrcPage = normalizeAppPath(srcPage) + + let { isOnDemandRevalidate } = prepareResult + + // TODO: rework this to not be necessary as a middleware + // rewrite should not need to pass this context like this + // maybe we rely on rewrite header instead + let resolvedPathname = getRequestMeta(req, 'rewroteURL') || pathname + + if (resolvedPathname === '/index') { + resolvedPathname = '/' } + resolvedPathname = decodePathParams(resolvedPathname) - const nextConfig = - routerServerContext?.nextConfig || serverFilesManifest.config + const prerenderInfo = prerenderManifest.dynamicRoutes[normalizedSrcPage] + const isPrerendered = prerenderManifest.routes[resolvedPathname] - const pathname = parsedUrl.pathname || '/' - const normalizedSrcPage = normalizeAppPath(srcPage) - let isIsr = Boolean( - prerenderManifest.dynamicRoutes[normalizedSrcPage] || - prerenderManifest.routes[normalizedSrcPage] || - prerenderManifest.routes[pathname] + let isSSG = Boolean( + prerenderInfo || + isPrerendered || + prerenderManifest.routes[normalizedSrcPage] ) + // if the page is dynamicParams: false and this pathname wasn't prerender + // trigger the no fallback handling + if (isSSG && prerenderInfo?.fallback === false && !isPrerendered) { + throw new NoFallbackError() + } + + const userAgent = req.headers['user-agent'] || '' + const botType = getBotType(userAgent) + const isHtmlBot = isHtmlBotRequest(req) + + /** + * If true, this indicates that the request being made is for an app + * prefetch request. + */ + const isPrefetchRSCRequest = + getRequestMeta(req, 'isPrefetchRSCRequest') ?? + Boolean(req.headers[NEXT_ROUTER_PREFETCH_HEADER]) + + // NOTE: Don't delete headers[RSC] yet, it still needs to be used in renderToHTML later + + const isRSCRequest = + getRequestMeta(req, 'isRSCRequest') ?? Boolean(req.headers[RSC_HEADER]) + + const isPossibleServerAction = getIsPossibleServerAction(req) + + /** + * If the route being rendered is an app page, and the ppr feature has been + * enabled, then the given route _could_ support PPR. + */ const couldSupportPPR: boolean = checkIsAppPPREnabled( nextConfig.experimental.ppr ) @@ -201,22 +232,19 @@ export async function handler( // This page supports PPR if it is marked as being `PARTIALLY_STATIC` in the // prerender manifest and this is an app page. - const isRoutePPREnabled = Boolean( + const isRoutePPREnabled: boolean = couldSupportPPR && - (( - prerenderManifest.routes[normalizedSrcPage] ?? - prerenderManifest.routes[pathname] ?? - prerenderManifest.dynamicRoutes[normalizedSrcPage] - )?.renderingMode === 'PARTIALLY_STATIC' || - // Ideally we'd want to check the appConfig to see if this page has PPR - // enabled or not, but that would require plumbing the appConfig through - // to the server during development. We assume that the page supports it - // but only during development. - (hasDebugStaticShellQuery && - (routeModule.isDev || routerServerContext?.experimentalTestProxy))) - ) - - const isDebugFallbackShell = hasDebugFallbackShellQuery && isRoutePPREnabled + (( + prerenderManifest.routes[normalizedSrcPage] ?? + prerenderManifest.dynamicRoutes[normalizedSrcPage] + )?.renderingMode === 'PARTIALLY_STATIC' || + // Ideally we'd want to check the appConfig to see if this page has PPR + // enabled or not, but that would require plumbing the appConfig through + // to the server during development. We assume that the page supports it + // but only during development. + (hasDebugStaticShellQuery && + (routeModule.isDev === true || + routerServerContext?.experimentalTestProxy === true))) const isDebugStaticShell: boolean = hasDebugStaticShellQuery && isRoutePPREnabled @@ -226,23 +254,67 @@ export async function handler( const isDebugDynamicAccesses = isDebugStaticShell && routeModule.isDev === true - const isRSCRequest = - getRequestMeta(req, 'isRSCRequest') || Boolean(req.headers[RSC_HEADER]) + const isDebugFallbackShell = hasDebugFallbackShellQuery && isRoutePPREnabled - const userAgent = req.headers['user-agent'] || '' - const botType = getBotType(userAgent) - const isHtmlBot = isHtmlBotRequest(req) + // If we're in minimal mode, then try to get the postponed information from + // the request metadata. If available, use it for resuming the postponed + // render. + const minimalPostponed = isRoutePPREnabled ? initialPostponed : undefined + + // If PPR is enabled, and this is a RSC request (but not a prefetch), then + // we can use this fact to only generate the flight data for the request + // because we can't cache the HTML (as it's also dynamic). + const isDynamicRSCRequest = + isRoutePPREnabled && isRSCRequest && !isPrefetchRSCRequest + + // Need to read this before it's stripped by stripFlightHeaders. We don't + // need to transfer it to the request meta because it's only read + // within this function; the static segment data should have already been + // generated, so we will always either return a static response or a 404. + const segmentPrefetchHeader = getRequestMeta(req, 'segmentPrefetchRSCRequest') + + // TODO: investigate existing bug with shouldServeStreamingMetadata always + // being true for a revalidate due to modifying the base-server this.renderOpts + // when fixing this to correct logic it causes hydration issue since we set + // serveStreamingMetadata to true during export + let serveStreamingMetadata = !userAgent + ? true + : shouldServeStreamingMetadata(userAgent, nextConfig.htmlLimitedBots) + + if (isHtmlBot && isRoutePPREnabled) { + isSSG = false + serveStreamingMetadata = false + } + + // In development, we always want to generate dynamic HTML. + let supportsDynamicResponse: boolean = + // If we're in development, we always support dynamic HTML, unless it's + // a data request, in which case we only produce static HTML. + routeModule.isDev === true || + // If this is not SSG or does not have static paths, then it supports + // dynamic HTML. + !isSSG || + // If this request has provided postponed data, it supports dynamic + // HTML. + typeof initialPostponed === 'string' || + // If this is a dynamic RSC request, then this render supports dynamic + // HTML (it's dynamic). + isDynamicRSCRequest + + // When html bots request PPR page, perform the full dynamic rendering. const shouldWaitOnAllReady = isHtmlBot && isRoutePPREnabled - // If this is a dynamic route with PPR enabled and the default route - // matches were set, then we should pass the fallback route params to - // the renderer as this is a fallback revalidation request. - const fallbackRouteParams = - pageIsDynamic && - isRoutePPREnabled && - (getRequestMeta(req, 'renderFallbackShell') || isDebugFallbackShell) - ? getFallbackRouteParams(normalizedSrcPage) - : null + let ssgCacheKey: string | null = null + if ( + !isDraftMode && + isSSG && + !supportsDynamicResponse && + !isPossibleServerAction && + !minimalPostponed && + !isDynamicRSCRequest + ) { + ssgCacheKey = resolvedPathname + } const ComponentMod = { ...entryBase, @@ -268,66 +340,97 @@ export async function handler( }) } - const isPossibleServerAction = getIsPossibleServerAction(req) + const method = req.method || 'GET' + const tracer = getTracer() + const activeSpan = tracer.getActiveScopeSpan() - /** - * If true, this indicates that the request being made is for an app - * prefetch request. - */ - const isPrefetchRSCRequest = - getRequestMeta(req, 'isPrefetchRSCRequest') ?? - Boolean(isRSCRequest && req.headers[NEXT_ROUTER_PREFETCH_HEADER]) + try { + const invokeRouteModule = async ( + span: Span | undefined, + context: AppPageRouteHandlerContext + ) => { + const nextReq = new NodeNextRequest(req) + const nextRes = new NodeNextResponse(res) - // If PPR is enabled, and this is a RSC request (but not a prefetch), then - // we can use this fact to only generate the flight data for the request - // because we can't cache the HTML (as it's also dynamic). - const isDynamicRSCRequest = - isRoutePPREnabled && isRSCRequest && !isPrefetchRSCRequest + // TODO: adapt for putting the RDC inside the postponed data + // If we're in dev, and this isn't a prefetch or a server action, + // we should seed the resume data cache. + if (process.env.NODE_ENV === 'development') { + if ( + nextConfig.experimental.dynamicIO && + !isPrefetchRSCRequest && + !context.renderOpts.isPossibleServerAction + ) { + const warmup = await routeModule.warmup(nextReq, nextRes, context) - let supportsDynamicResponse: boolean = - // If we're in development, we always support dynamic HTML - routeModule.isDev === true || - // If this is not SSG or does not have static paths, then it supports - // dynamic HTML. - !isIsr || - // If this request has provided postponed data, it supports dynamic - // HTML. - typeof postponed === 'string' || - // If this is a dynamic RSC request, then this render supports dynamic - // HTML (it's dynamic). - isDynamicRSCRequest + // If the warmup is successful, we should use the resume data + // cache from the warmup. + if (warmup.metadata.devRenderResumeDataCache) { + context.renderOpts.devRenderResumeDataCache = + warmup.metadata.devRenderResumeDataCache + } + } + } - // This is a revalidation request if the request is for a static - // page and it is not being resumed from a postponed render and - // it is not a dynamic RSC request then it is a revalidation - // request. - const isRevalidate = - isIsr && !supportsDynamicResponse && !postponed && !isDynamicRSCRequest - - let serveStreamingMetadata = - // During the export phase of `next build` we're hard-coding - // `serveStreamingMetadata` to `true`, so we need to do the same during - // revalidation. - isRevalidate || - // Otherwise we're checking the user agent to decide if we should - // serve streaming metadata. - shouldServeStreamingMetadata( - userAgent, - // @ts-expect-error update for readonly - nextConfig.htmlLimitedBots - ) + return routeModule.render(nextReq, nextRes, context).finally(() => { + if (!span) return - if (isHtmlBot && isRoutePPREnabled) { - isIsr = false - serveStreamingMetadata = false - } + span.setAttributes({ + 'http.status_code': res.statusCode, + 'next.rsc': false, + }) - const method = req.method || 'GET' - const tracer = getTracer() - const activeSpan = tracer.getActiveScopeSpan() + const rootSpanAttributes = tracer.getRootSpanAttributes() + // We were unable to get attributes, probably OTEL is not enabled + if (!rootSpanAttributes) { + return + } - try { - const invokeRouteModule = async (span?: Span) => { + if ( + rootSpanAttributes.get('next.span_type') !== + BaseServerSpan.handleRequest + ) { + console.warn( + `Unexpected root span type '${rootSpanAttributes.get( + 'next.span_type' + )}'. Please report this Next.js issue https://github.com/vercel/next.js` + ) + return + } + + const route = rootSpanAttributes.get('next.route') + if (route) { + const name = `${method} ${route}` + + span.setAttributes({ + 'next.route': route, + 'http.route': route, + 'next.span_name': name, + }) + span.updateName(name) + } else { + span.updateName(`${method} ${req.url}`) + } + }) + } + + const doRender = async ({ + span, + postponed, + fallbackRouteParams, + }: { + span?: Span + /** + * The postponed data for this render. This is only provided when resuming + * a render that has been postponed. + */ + postponed: string | undefined + + /** + * The unknown route params for this render. + */ + fallbackRouteParams: FallbackRouteParams | null + }): Promise<ResponseCacheEntry> => { const context: AppPageRouteHandlerContext = { query, params, @@ -353,21 +456,22 @@ export async function handler( postponed, shouldWaitOnAllReady, serveStreamingMetadata, - supportsDynamicResponse, + supportsDynamicResponse: + typeof postponed === 'string' || supportsDynamicResponse, buildManifest, nextFontManifest, reactLoadableManifest, subresourceIntegrityManifest, serverActionsManifest, clientReferenceManifest, - isPossibleServerAction, - isOnDemandRevalidate, setIsrStatus: routerServerContext?.setIsrStatus, dir: routeModule.projectDir, isDraftMode, - isRevalidate,
Leaderboard for this case
hard · 0 of 9 bots fully caught it (0% solve rate) · 31% avg coverage.
| # | Bot | Result | Caught | Coverage | Findings | False alarms |
|---|---|---|---|---|---|---|
| 1 | Drape (Deep Review) | partial | 6/9 | 60.9% | 17 | 0 |
| 2 | Claude Code (Opus 5.5) | partial | 4/9 | 43.5% | 6 | 0 |
| 3 | Drape (Review) | partial | 4/9 | 43.5% | 11 | 0 |
| 4 | cursor | partial | 3/9 | 39.1% | 7 | 2 |
| 5 | Mjolnir (Opus 5.5) | partial | 2/9 | 34.8% | 10 | 0 |
| 6 | qodo | partial | 2/9 | 21.7% | 7 | 2 |
| 7 | greptile | partial | 2/9 | 8.7% | 4 | 0 |
| 8 | Mjolnir (Sonnet 5.5) | partial | 1/9 | 4.3% | 6 | 0 |
| 9 | Cubic | partial | 1/9 | 4.3% | 7 | 3 |
Bot results
Claude Code (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
| d2 | high | ✓ | exact |
| d3 | high | ✓ | off by one |
| d5 | high | ✗ | — |
| d6 | medium | ✗ | — |
| d7 | low | ✗ | — |
| d8 | low | ✓ | exact |
| d9 | medium | ✗ | — |
| d10 | low | ✓ | exact |
In app-page, `routeModule.handleResponse` is called without `revalidateOnlyGenerated`, so the route-module guard `!(isOnDemandRevalidate && revalidateOnlyGenerated)` is true and the call throws. The handler's own local `if (!cacheEntry) { if (ssgCacheKey) throw }` check would also throw, even though `responseGenerator` has already sent the 404. The base-server code before this change exempted this case. [grounded: tree packages/next/src/build/templates/app-page.ts] [consensus 3/3: valid=3]
In pages.ts, the activeSpan branch now calls `handleResponse()` with no span; the old code called `invokeRouteModule(activeSpan)`. Because the span is undefined, the `.finally` block returns early (`if (!span) return`), so the span attributes and span name are never set. [grounded: diff] [consensus 3/3: valid=3]
raw comments (6)
The fallback route params for a fallback-shell revalidation are now built with `getFallbackRouteParams(pathname)`. `pathname` is the concrete request URL (e.g. `/blog/foo`), not the route pattern. `getFallbackRouteParams` looks for dynamic segments like `[slug]`, so on a concrete URL it finds none and returns null. Every other call site, and the old code, passes `normalizedSrcPage`. Result: requests flagged `renderFallbackShell`, and the `__nextppronly=fallback` debug path, render the concrete params into what should be a generic fallback shell. That shell is then cached and served for other paths.
This path can throw after a 404 has already been sent. On an on-demand revalidate with `revalidateOnlyGenerated` and no existing cache entry, `responseGenerator` writes the 404 and returns null. But `routeModule.handleResponse` is called here without `revalidateOnlyGenerated`, so it throws 'invariant: cache entry required but not generated' because `ssgCacheKey` is set. If it didn't, the local `if (!cacheEntry && ssgCacheKey)` check would throw the same error. The client gets the 404, but an error is logged, sent to `onRequestError`, and rethrown for a valid request.
Same problem for ISR route handlers. When the revalidate-only-generated branch sends the 404 and returns null, `handleResponse` returns null. Because `isIsr` is true, the code goes straight to `cacheEntry?.value?.kind !== APP_ROUTE` and throws 'Invariant: app-route received invalid cache entry undefined' after the response has ended. That turns a normal on-demand revalidation miss into a reported server error.
The minimal-mode debug static shell branch (`__nextppronly` together with postponed data) returns a cache entry of kind `CachedRouteKind.PAGES`. `handleResponse` now rejects anything that isn't `APP_PAGE` with 'Invariant app-page handler received invalid cache entry PAGES', so this debug path always fails with a 500.
When the handler runs inside an existing span (the `activeSpan` path), it now calls `handleResponse()` without that span. The old code passed `invokeRouteModule(activeSpan)`. The `.finally` block that sets `http.status_code`, `next.route`, `http.route` and the span name returns early when there is no span, so Pages Router tracing under next-server loses these attributes.
`getStaticPaths` in dev now does an unsynchronized read-modify-write of `prerender-manifest.json` for each dynamic pathname. If two routes resolve static paths at the same time, both read the same original file and one write overwrites the other's `routes`/`dynamicRoutes` entries. The handlers then read the manifest without caching in dev and can see stale or missing `fallback` info. For example, a `dynamicParams: false` / `fallback: false` route may not raise `NoFallbackError` as expected.
Cubic · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
| d2 | high | ✗ | — |
| d3 | high | ✗ | — |
| d5 | high | ✗ | — |
| d6 | medium | ✗ | — |
| d7 | low | ✗ | — |
| d8 | low | ✓ | off by one |
| d9 | medium | ✗ | — |
| d10 | low | ✗ | — |
Batcher.batch returns the pending promise for a deduplicated key without calling the work fn (`if (pending) return pending` in batcher.ts), so only the first caller's waitUntil gets the background promise. The claim is accurate, but the impact is small because the first caller still registers it. [grounded: tree packages/next/src/server/response-cache/index.ts] [consensus 5/5: valid=5]
logErrorWithOriginalStack treats 'app-dir' as plain Log.error(err) with no label, so Pages Router errors are not attributed to the wrong router. The allowed type union also has no 'pages-dir' value. [invalid: contradiction] [consensus 4/5: invalid=4, valid=1]
matches a claim this case records as not a defect (d4)
The diff reassigns existing codes 695-700 to different messages instead of adding new codes after the current maximum, which breaks stable error codes. [grounded: diff] [consensus 5/5: valid=5]
This new throw sits in the 'force-dynamic' case but its message says dynamic = error, which misleads users. [grounded: diff] [consensus 5/5: valid=5]
The throw site in render-result already matches entry 151 exactly. Entry 706 is an unused leftover entry, so the thrown error still maps to a valid code and nothing breaks. [invalid: contradiction] [consensus 3/5: invalid=3, valid=2]
raw comments (8)
<!-- cubic:v=24a82281-d348-49e1-8fb0-a1d6d39f9bf6 -->
<!-- cubic:review-run=f40cad7d-35ba-53f6-9060-b2a0cab3d67e -->
<!-- metadata:{"confidence":8} -->
P2: When a request joins an existing stale revalidation, `Batcher.batch` returns the pending promise without invoking this callback, so its `waitUntil` never receives the background revalidation. Register each caller's `waitUntil` with the shared revalidation promise, including deduplicated callers.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/next/src/server/response-cache/index.ts, line 206:
<comment>When a request joins an existing stale revalidation, `Batcher.batch` returns the pending promise without invoking this callback, so its `waitUntil` never receives the background revalidation. Register each caller's `waitUntil` with the shared revalidation promise, including deduplicated callers.</comment>
<file context>
@@ -71,130 +72,140 @@ export default class ResponseCache implements ResponseCacheBase {
+ // we need to ensure background revalidates are
+ // passed to waitUntil
+ if (waitUntil) {
+ waitUntil(prom)
}
+ return prom
</file context>
```
</details>
<!-- cubic:v=9d387575-79cb-445f-83c1-21ba16283910 -->
<!-- cubic:review-run=f40cad7d-35ba-53f6-9060-b2a0cab3d67e -->
<!-- metadata:{"confidence":9} -->
P2: When different dynamic routes resolve `getStaticPaths` concurrently, each invocation can read the same manifest and overwrite the other route's update. Serialize these manifest updates and write the result atomically so fallback metadata is not lost and request handlers cannot parse a partial file.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/next/src/server/dev/next-dev-server.ts, line 880:
<comment>When different dynamic routes resolve `getStaticPaths` concurrently, each invocation can read the same manifest and overwrite the other route's update. Serialize these manifest updates and write the result atomically so fallback metadata is not lost and request handlers cannot parse a partial file.</comment>
<file context>
@@ -870,6 +873,32 @@ export default class DevServer extends Server {
+ if (res.value?.fallbackMode !== undefined) {
+ // we write the static paths to partial manifest for
+ // fallback handling inside of entry handler's
+ const rawExistingManifest = await fs.promises.readFile(
+ pathJoin(this.distDir, PRERENDER_MANIFEST),
+ 'utf8'
</file context>
```
</details>
<!-- cubic:v=31a7a8b3-997b-41ad-a756-bb2557103fb3 -->
<!-- cubic:review-run=f40cad7d-35ba-53f6-9060-b2a0cab3d67e -->
<!-- metadata:{"confidence":8} -->
P2: When a Pages Router request reports an error, this labels it `app-dir`, producing incorrect route attribution in development logs. Derive the label from `errorContext.routerKind` before calling `logErrorWithOriginalStack`.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/next/src/server/route-modules/route-module.ts, line 365:
<comment>When a Pages Router request reports an error, this labels it `app-dir`, producing incorrect route attribution in development logs. Derive the label from `errorContext.routerKind` before calling `logErrorWithOriginalStack`.</comment>
<file context>
@@ -239,6 +267,117 @@ export abstract class RouteModule<
+ routerServerContext?: RouterServerContext[string]
+ ) {
+ if (routerServerContext?.logErrorWithOriginalStack) {
+ routerServerContext.logErrorWithOriginalStack(err, 'app-dir')
+ } else {
+ console.error(err)
</file context>
```
</details>
```suggestion
routerServerContext.logErrorWithOriginalStack(
err,
errorContext.routerKind === 'App Router' ? 'app-dir' : 'pages-dir'
)
```
<!-- cubic:v=68c5ef07-27ed-4175-982b-e268c9054733 -->
<!-- cubic:review-run=f40cad7d-35ba-53f6-9060-b2a0cab3d67e -->
<!-- metadata:{"confidence":9} -->
P2: When minimal mode is enabled, this still enables ISR disk flushing, unlike the regular server path. Disable flushing in minimal mode to avoid writing cache files in deployments that explicitly use the in-memory/minimal cache path.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/next/src/server/route-modules/route-module.ts, line 351:
<comment>When minimal mode is enabled, this still enables ISR disk flushing, unlike the regular server path. Disable flushing in minimal mode to avoid writing cache files in deployments that explicitly use the in-memory/minimal cache path.</comment>
<file context>
@@ -239,6 +267,117 @@ export abstract class RouteModule<
+ serverDistDir: `${projectDir}/${this.distDir}/server`,
+ fetchCacheKeyPrefix: nextConfig.experimental.fetchCacheKeyPrefix,
+ maxMemoryCacheSize: nextConfig.cacheMaxMemorySize,
+ flushToDisk: nextConfig.experimental.isrFlushToDisk,
+ getPrerenderManifest: () => prerenderManifest,
+ CurCacheHandler: CacheHandler,
</file context>
```
</details>
```suggestion
flushToDisk:
!getRequestMeta(req, 'minimalMode') &&
nextConfig.experimental.isrFlushToDisk,
```
<!-- cubic:v=05150ec3-9f47-453d-ad6e-c9ba2439b6ef -->
<!-- cubic:review-run=f40cad7d-35ba-53f6-9060-b2a0cab3d67e -->
<!-- metadata:{"confidence":9} -->
P2: Adding this entry at code 695 renumbers every existing error code from 695 through 700. Append new messages after the existing maximum so established `E695`–`E700` identifiers remain stable.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/next/errors.json, line 696:
<comment>Adding this entry at code 695 renumbers every existing error code from 695 through 700. Append new messages after the existing maximum so established `E695`–`E700` identifiers remain stable.</comment>
<file context>
@@ -693,10 +693,18 @@
"694": "createPrerenderPathname was called inside a client component scope.",
- "695": "Expected workUnitAsyncStorage to have a store.",
- "696": "Next DevTools: Can't dispatch %s in this environment. This is a bug in Next.js",
+ "695": "Invariant: received non-pages cache entry in pages handler",
+ "696": "Expected workUnitAsyncStorage to have a store.",
"697": "Next DevTools: Can't render in this environment. This is a bug in Next.js",
</file context>
```
</details>
<!-- cubic:v=cebcdb5f-b9d5-4a9e-8fc9-2b0ed7cf6fd8 -->
<!-- cubic:review-run=f40cad7d-35ba-53f6-9060-b2a0cab3d67e -->
<!-- metadata:{"confidence":9} -->
P3: The error message in the `force-dynamic` branch says `dynamic = error`, but this is the `force-dynamic` case (the `error` case is a separate switch branch below). A user who hits this static-generation failure is told the wrong export value caused it. Change the message to reference `force-dynamic`, e.g. `Route is configured with dynamic = force-dynamic which cannot be statically generated.`
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/next/src/server/route-modules/app-route/module.ts, line 729:
<comment>The error message in the `force-dynamic` branch says `dynamic = error`, but this is the `force-dynamic` case (the `error` case is a separate switch branch below). A user who hits this static-generation failure is told the wrong export value caused it. Change the message to reference `force-dynamic`, e.g. `Route is configured with dynamic = force-dynamic which cannot be statically generated.`</comment>
<file context>
@@ -724,6 +724,14 @@ export class AppRouteRouteModule extends RouteModule<
workStore.forceDynamic = true
+ if (workStore.isStaticGeneration) {
+ const err = new DynamicServerError(
+ 'Route is configured with dynamic = error which cannot be statically generated.'
+ )
+ workStore.dynamicUsageDescription = err.message
</file context>
```
</details>
<!-- cubic:v=07fe6edd-cd3d-43cb-a640-7c27c3dd3696 -->
<!-- cubic:review-run=f40cad7d-35ba-53f6-9060-b2a0cab3d67e -->
<!-- metadata:{"confidence":6} -->
P3: Entry 706 declares a %s placeholder, but the only throw site (render-result.ts) throws 'Invariant: static responses cannot be streamed' with no argument, so the %s is never substituted and the code won't match this error. Drop the %s from the entry or format the message at the throw site.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At packages/next/errors.json, line 707:
<comment>Entry 706 declares a %s placeholder, but the only throw site (render-result.ts) throws 'Invariant: static responses cannot be streamed' with no argument, so the %s is never substituted and the code won't match this error. Drop the %s from the entry or format the message at the throw site.</comment>
<file context>
@@ -693,10 +693,18 @@
+ "703": "Route is configured with dynamic = error which cannot be statically generated.",
+ "704": "Route is configured with dynamic = error be statically generated.",
+ "705": "Route is configured with dynamic = error that cannot be statically generated.",
+ "706": "Invariant: static responses cannot be streamed %s",
+ "707": "Invariant app-page handler received invalid cache entry %s",
+ "708": "Failed to persist Chrome DevTools workspace UUID. The Chrome DevTools Workspace needs to be reconnected after the next page reload."
</file context>
```
</details>
<!-- cubic:review-summary:start -->
**7 issues found** across 22 files
<!-- cubic:review-summary:end -->
<details>
<summary>Prompt for AI agents (unresolved issues)</summary>
```text
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/next/src/server/route-modules/app-route/module.ts">
<violation number="1" location="packages/next/src/server/route-modules/app-route/module.ts:729">
P3: The error message in the `force-dynamic` branch says `dynamic = error`, but this is the `force-dynamic` case (the `error` case is a separate switch branch below). A user who hits this static-generation failure is told the wrong export value caused it. Change the message to reference `force-dynamic`, e.g. `Route is configured with dynamic = force-dynamic which cannot be statically generated.`</violation>
</file>
<file name="packages/next/src/server/response-cache/index.ts">
<violation number="1" location="packages/next/src/server/response-cache/index.ts:206">
P2: When a request joins an existing stale revalidation, `Batcher.batch` returns the pending promise without invoking this callback, so its `waitUntil` never receives the background revalidation. Register each caller's `waitUntil` with the shared revalidation promise, including deduplicated callers.</violation>
</file>
<file name="packages/next/src/server/dev/next-dev-server.ts">
<violation number="1" location="packages/next/src/server/dev/next-dev-server.ts:880">
P2: When different dynamic routes resolve `getStaticPaths` concurrently, each invocation can read the same manifest and overwrite the other route's update. Serialize these manifest updates and write the result atomically so fallback metadata is not lost and request handlers cannot parse a partial file.</violation>
</file>
<file name="packages/next/src/server/route-modules/route-module.ts">
<violation number="1" location="packages/next/src/server/route-modules/route-module.ts:351">
P2: When minimal mode is enabled, this still enables ISR disk flushing, unlike the regular server path. Disable flushing in minimal mode to avoid writing cache files in deployments that explicitly use the in-memory/minimal cache path.</violation>
<violation number="2" location="packages/next/src/server/route-modules/route-module.ts:365">
P2: When a Pages Router request reports an error, this labels it `app-dir`, producing incorrect route attribution in development logs. Derive the label from `errorContext.routerKind` before calling `logErrorWithOriginalStack`.</violation>
</file>
<file name="packages/next/errors.json">
<violation number="1" location="packages/next/errors.json:696">
P2: Adding this entry at code 695 renumbers every existing error code from 695 through 700. Append new messages after the existing maximum so established `E695`–`E700` identifiers remain stable.</violation>
<violation number="2" location="packages/next/errors.json:707">
P3: Entry 706 declares a %s placeholder, but the only throw site (render-result.ts) throws 'Invariant: static responses cannot be streamed' with no argument, so the %s is never substituted and the code won't match this error. Drop the %s from the entry or format the message at the throw site.</violation>
</file>
```
</details>
<sub>**Tip**: cubic can generate docs of your entire codebase and keep them up to date. Try it [here](https://docs.cubic.dev/wiki/ai-wiki?utm_source=github).<br /><br />[Re-trigger cubic](https://www.cubic.dev/action/re-review/pr/drape-io/crbench-cubic-2026-09/63/ai_pr_review_github_delivery_177d3d72e38ec921a86126dccc0fc0f3877f8b24f069e9255ec2d710bf6052c2?returnTo=https%3A%2F%2Fgithub.com%2Fdrape-io%2Fcrbench-cubic-2026-09%2Fpull%2F63)</sub>
<!-- cubic:review-post:ai_pr_review_github_delivery_177d3d72e38ec921a86126dccc0fc0f3877f8b24f069e9255ec2d710bf6052c2:d50418da74ebca8c19802e823906a7edb5e7a2b7:f40cad7d-35ba-53f6-9060-b2a0cab3d67e -->
cursor · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
| d2 | high | ✓ | exact |
| d3 | high | ✓ | exact |
| d5 | high | ✗ | — |
| d6 | medium | ✗ | — |
| d7 | low | ✓ | off by one |
| d8 | low | ✗ | — |
| d9 | medium | ✗ | — |
| d10 | low | ✗ | — |
The new throw sits inside the `case 'force-dynamic'` branch, but its message says the route is configured with `dynamic = error`. That is a misleading diagnostic added by this change. [grounded: diff] [consensus 5/5: valid=5]
matches a claim this case records as not a defect (d4)
The app-page `handleResponse` call passes `isOnDemandRevalidate` but not `revalidateOnlyGenerated`, so the guard in `route-module.handleResponse` has no effect. The handler then throws anyway whenever `ssgCacheKey` is set and the cache entry is null. The old base-server path skipped the throw for `isOnDemandRevalidate && revalidateOnlyGenerated`. [grounded: tree packages/next/src/build/templates/app-page.ts] [consensus 5/5: valid=5]
In the dev bundler, `logErrorWithOriginalStack` with type `'app-dir'` just calls `Log.error(err)`. That is the same as the untyped default, so there is no wrong overlay or stack filtering. The classification has no observable effect. [invalid: contradiction] [consensus 5/5: invalid=5]
raw comments (8)
### Wrong error for force-dynamic routes
**Medium Severity**
<!-- DESCRIPTION START -->
The new static-generation bailout in the `force-dynamic` branch throws a `DynamicServerError` whose message says the route is configured with `dynamic = error`. Builds and dynamic-usage logs for `force-dynamic` app routes then blame the wrong `dynamic` setting.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 0d485940-f9cf-4c41-8328-92debd6ce19f -->
<!-- LOCATIONS START
packages/next/src/server/route-modules/app-route/module.ts#L726-L733
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmU5NGMzODE3LTkzMDEtNDJkZS1iOGRmLTBkM2Y0OWE1MTBkNCIsImVuY3J5cHRpb25LZXkiOiJfdzZHdmZCTndRRkxvQTllaWExb1doRzhkOVAtSGI1TUx3OHhYbGlzRnNNIiwiYnJhbmNoIjoidDItbmV4dGpzLTgwMTg5IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmU5NGMzODE3LTkzMDEtNDJkZS1iOGRmLTBkM2Y0OWE1MTBkNCIsImVuY3J5cHRpb25LZXkiOiJfdzZHdmZCTndRRkxvQTllaWExb1doRzhkOVAtSGI1TUx3OHhYbGlzRnNNIiwiYnJhbmNoIjoidDItbmV4dGpzLTgwMTg5IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwck51bWJlciI6NjUsImNvbW1pdFNoYSI6IjlhZmU0NmU0NGE5NWM0YTQ0OTI5ZWQwNzQ5ZmRhZDM1NzZjMjgxYzYiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 9afe46e44a95c4a44929ed0749fdad3576c281c6. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Fallback params use resolved pathname
**High Severity**
<!-- DESCRIPTION START -->
PPR fallback revalidation now calls `getFallbackRouteParams` with `pathname` (`parsedUrl.pathname`) instead of `normalizedSrcPage`. That value is the interpolated request path, so dynamic param keys are not found and fallback shells omit postpone placeholders.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 20fc6a27-d174-42c6-8dd6-843ed3e449a3 -->
<!-- LOCATIONS START
packages/next/src/build/templates/app-page.ts#L728-L734
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmQxNDViODE4LWYxYTItNDVhMC1iNmM5LTk2MzcxMTQxZGFjYyIsImVuY3J5cHRpb25LZXkiOiIxa3hfM01hTkk0UkZ4T3JNanV2RDBuSGdTbHVMbWkzd0ZITVJxU1ItaV8wIiwiYnJhbmNoIjoidDItbmV4dGpzLTgwMTg5IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmQxNDViODE4LWYxYTItNDVhMC1iNmM5LTk2MzcxMTQxZGFjYyIsImVuY3J5cHRpb25LZXkiOiIxa3hfM01hTkk0UkZ4T3JNanV2RDBuSGdTbHVMbWkzd0ZITVJxU1ItaV8wIiwiYnJhbmNoIjoidDItbmV4dGpzLTgwMTg5IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwck51bWJlciI6NjUsImNvbW1pdFNoYSI6IjlhZmU0NmU0NGE5NWM0YTQ0OTI5ZWQwNzQ5ZmRhZDM1NzZjMjgxYzYiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 9afe46e44a95c4a44929ed0749fdad3576c281c6. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### ISR flushes to disk in minimal mode
**Medium Severity**
<!-- DESCRIPTION START -->
`RouteModule.getIncrementalCache` sets `flushToDisk` from `isrFlushToDisk` alone. Unlike `next-server`, it does not gate on `minimalMode`, so serverless/minimal runtimes can write ISR entries to the ephemeral filesystem.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 4c772747-9878-4ab4-92e6-2b258ea96b8d -->
<!-- LOCATIONS START
packages/next/src/server/route-modules/route-module.ts#L350-L351
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjE3MDRiNjFhLWYwMDYtNDBhMi1hZmI4LWEzNWEyYWIxODE4MCIsImVuY3J5cHRpb25LZXkiOiJlNklGbXc4QnhmbzFOaFVwbTZNNGNWY2Y3TFdpejhRTXQ4ci1xX0h3THAwIiwiYnJhbmNoIjoidDItbmV4dGpzLTgwMTg5IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjE3MDRiNjFhLWYwMDYtNDBhMi1hZmI4LWEzNWEyYWIxODE4MCIsImVuY3J5cHRpb25LZXkiOiJlNklGbXc4QnhmbzFOaFVwbTZNNGNWY2Y3TFdpejhRTXQ4ci1xX0h3THAwIiwiYnJhbmNoIjoidDItbmV4dGpzLTgwMTg5IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwck51bWJlciI6NjUsImNvbW1pdFNoYSI6IjlhZmU0NmU0NGE5NWM0YTQ0OTI5ZWQwNzQ5ZmRhZDM1NzZjMjgxYzYiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 9afe46e44a95c4a44929ed0749fdad3576c281c6. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### App page revalidate-only-generated throws
**High Severity**
<!-- DESCRIPTION START -->
On-demand revalidate with `revalidateOnlyGenerated` can correctly 404 and return `null`, but `handleResponse` never forwards `revalidateOnlyGenerated`, and the app-page handler still throws `invariant: cache entry required but not generated` when `ssgCacheKey` is set.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 5b7b5d9c-4cda-4aa0-9807-1252e0b314ef -->
<!-- LOCATIONS START
packages/next/src/build/templates/app-page.ts#L744-L780
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjYyZjBjODFmLWRhZmItNDQwYS1iMTM1LTE4ZDlkNTUxM2JjZCIsImVuY3J5cHRpb25LZXkiOiJxV29DNlViWW40R1BjbUloYTk3MktZNzNRVnA4elVGWmpjTnU1U2xpTS1vIiwiYnJhbmNoIjoidDItbmV4dGpzLTgwMTg5IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjYyZjBjODFmLWRhZmItNDQwYS1iMTM1LTE4ZDlkNTUxM2JjZCIsImVuY3J5cHRpb25LZXkiOiJxV29DNlViWW40R1BjbUloYTk3MktZNzNRVnA4elVGWmpjTnU1U2xpTS1vIiwiYnJhbmNoIjoidDItbmV4dGpzLTgwMTg5IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwck51bWJlciI6NjUsImNvbW1pdFNoYSI6IjlhZmU0NmU0NGE5NWM0YTQ0OTI5ZWQwNzQ5ZmRhZDM1NzZjMjgxYzYiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 9afe46e44a95c4a44929ed0749fdad3576c281c6. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### App route revalidate-only-generated throws
**High Severity**
<!-- DESCRIPTION START -->
After a `revalidateOnlyGenerated` miss, the app-route handler 404s and returns `null`, then treats a missing cache entry as an invalid `APP_ROUTE` kind and throws an invariant.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 892443fc-7166-4cb6-8e71-dcf5a488f2d4 -->
<!-- LOCATIONS START
packages/next/src/build/templates/app-route.ts#L386-L390
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjE2NTc4MzkwLTI5MDAtNGFmNS1hNTNkLWFmOGQ4YzBmODM4MiIsImVuY3J5cHRpb25LZXkiOiJYR245UkR4ZkJON3pENmZkdjRQdi1ya2hqX3g5VTFPV0NGMU51dnY3czd3IiwiYnJhbmNoIjoidDItbmV4dGpzLTgwMTg5IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjE2NTc4MzkwLTI5MDAtNGFmNS1hNTNkLWFmOGQ4YzBmODM4MiIsImVuY3J5cHRpb25LZXkiOiJYR245UkR4ZkJON3pENmZkdjRQdi1ya2hqX3g5VTFPV0NGMU51dnY3czd3IiwiYnJhbmNoIjoidDItbmV4dGpzLTgwMTg5IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwck51bWJlciI6NjUsImNvbW1pdFNoYSI6IjlhZmU0NmU0NGE5NWM0YTQ0OTI5ZWQwNzQ5ZmRhZDM1NzZjMjgxYzYiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 9afe46e44a95c4a44929ed0749fdad3576c281c6. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### App route errors skip original stack
**Medium Severity**
<!-- DESCRIPTION START -->
The outer `catch` calls `routeModule.onRequestError` without `routerServerContext`. App-route failures then `console.error` instead of `logErrorWithOriginalStack`, so dev and custom servers lose source-mapped stacks.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 02ea8045-e3d5-4ca6-8932-42586eeb4148 -->
<!-- LOCATIONS START
packages/next/src/build/templates/app-route.ts#L466-L475
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmI2NzgxYzU3LTI0ZjctNDRlYS04MDQ0LTQ3NzFkZWQwYTJiOSIsImVuY3J5cHRpb25LZXkiOiIzNHBpVUJ6SWV2UEZqMVNVUWlneVM0ZmlYcTRuWHZ1Yks0RXRiSFhoaWx3IiwiYnJhbmNoIjoidDItbmV4dGpzLTgwMTg5IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmI2NzgxYzU3LTI0ZjctNDRlYS04MDQ0LTQ3NzFkZWQwYTJiOSIsImVuY3J5cHRpb25LZXkiOiIzNHBpVUJ6SWV2UEZqMVNVUWlneVM0ZmlYcTRuWHZ1Yks0RXRiSFhoaWx3IiwiYnJhbmNoIjoidDItbmV4dGpzLTgwMTg5IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwck51bWJlciI6NjUsImNvbW1pdFNoYSI6IjlhZmU0NmU0NGE5NWM0YTQ0OTI5ZWQwNzQ5ZmRhZDM1NzZjMjgxYzYiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 9afe46e44a95c4a44929ed0749fdad3576c281c6. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Pages errors logged as app-dir
**Low Severity**
<!-- DESCRIPTION START -->
Shared `onRequestError` always calls `logErrorWithOriginalStack` with `'app-dir'`. Pages-router handler errors are therefore classified as App Router errors, which can use the wrong overlay and stack filtering in development.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 7d58f2b0-bb6d-4cee-aa60-368032e00473 -->
<!-- LOCATIONS START
packages/next/src/server/route-modules/route-module.ts#L363-L365
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmRlOTBmYzIzLWVlYTUtNDcyOC04OGRkLTkwNTRlOGIyYmVjMiIsImVuY3J5cHRpb25LZXkiOiJ3aUpuNUFnd1NuQTRjVWJkRWR2SmlwQWVVZGhmN25Na29UTzY1Q0dmcTBJIiwiYnJhbmNoIjoidDItbmV4dGpzLTgwMTg5IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmRlOTBmYzIzLWVlYTUtNDcyOC04OGRkLTkwNTRlOGIyYmVjMiIsImVuY3J5cHRpb25LZXkiOiJ3aUpuNUFnd1NuQTRjVWJkRWR2SmlwQWVVZGhmN25Na29UTzY1Q0dmcTBJIiwiYnJhbmNoIjoidDItbmV4dGpzLTgwMTg5IiwicmVwb093bmVyIjoiZHJhcGUtaW8iLCJyZXBvTmFtZSI6ImNyYmVuY2gtY3Vyc29yLTIwMjYtMDkiLCJwck51bWJlciI6NjUsImNvbW1pdFNoYSI6IjlhZmU0NmU0NGE5NWM0YTQ0OTI5ZWQwNzQ5ZmRhZDM1NzZjMjgxYzYiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 9afe46e44a95c4a44929ed0749fdad3576c281c6. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- BUGBOT_REVIEW -->
Cursor Bugbot has reviewed your changes using high effort and found 7 potential issues.
<!-- BUGBOT_FIX_ALL -->
<a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aToyMGU1YWE5OC01YTRiLTRkZTQtOTBiMS1hMDZlYjQ0ZWQ5NzciLCJlbmNyeXB0aW9uS2V5IjoiUVpCWmZMTDhlNjZ4SEJqSnZJbmJQOGM2ek0zWEp2cG5SY2RZbGtLdEpvOCIsImJyYW5jaCI6InQyLW5leHRqcy04MDE4OSIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix All in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a>
<!-- /BUGBOT_FIX_ALL -->
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_BEGIN -->
<sup>❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_END -->
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 9afe46e44a95c4a44929ed0749fdad3576c281c6. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
Drape (Deep Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
| d2 | high | ✓ | exact |
| d3 | high | ✓ | off by one |
| d5 | high | ✗ | — |
| d6 | medium | ✓ | off by one |
| d7 | low | ✓ | exact |
| d8 | low | ✓ | off by one |
| d9 | medium | ✓ | exact |
| d10 | low | ✗ | — |
this.distDir is the relative dist dir and the server-files cacheHandler is relative to distDir. That makes the joined path relative, so it resolves against the cwd. The sibling loadCustomCacheHandlers prefixes absoluteProjectDir instead. [grounded: tree packages/next/src/server/route-modules/route-module.ts] [consensus 3/3: valid=3]
base-server now returns null for handler-based modules before it reaches its onCacheEntry call. The pages and app-route templates never read onCacheEntry, while app-page does. [grounded: tree packages/next/src/server/base-server.ts] [consensus 3/3: valid=3]
The span is not passed, so doRender's finally block returns early and never sets the span attributes or name. Before this change, invokeRouteModule(activeSpan) did that work. [grounded: diff] [consensus 3/3: valid=3]
A promise that rejects is handed to waitUntil, whose awaiter logs errors with console.error, and the same error is also rethrown to the handler. The result is duplicate logging. [grounded: tree packages/next/src/server/response-cache/index.ts] [consensus 3/3: valid=3]
In draft mode, cacheControl comes from the getStaticProps revalidate value and is written before the notFound and redirect early returns. The draft no-cache header is only set later, so those responses never get it. The old base-server forced revalidate 0 for preview mode. [grounded: tree packages/next/src/build/templates/pages.ts] [consensus 3/3: valid=3]
handleResponse always builds a new IncrementalCache, even when the cache key is null and base-server already put one on the request meta. That is a second instance on every request. [grounded: tree packages/next/src/server/route-modules/route-module.ts] [consensus 3/3: valid=3]
The removed code forced serveStreamingMetadata to true for revalidations. Now it depends only on the user agent, so a revalidation triggered by an HTML-limited bot can cache blocking-metadata HTML for everyone. [grounded: diff] [consensus 3/3: valid=3]
app-page's handleResponse call omits revalidateOnlyGenerated, and its own check throws whenever ssgCacheKey is set. So after the generator sends a 404 and returns null, the invariant still throws. [grounded: tree packages/next/src/build/templates/app-page.ts] [consensus 3/3: valid=3]
The old code required isRSCRequest as well. Now the prefetch header alone is enough whenever the request meta is unset. [grounded: diff] [consensus 3/3: valid=3]
The old onError in pages only called instrumentation. The new onRequestError also logs, and it runs even when wrapped by base-server, which logs again. [grounded: diff] [consensus 3/3: valid=3]
In dev, the dev server writes fallback:false with no routes to the manifest when generateStaticParams is empty, so the template throws NoFallbackError for every path. The old base-server let dev fall through to a render when there were no static paths. [grounded: diff] [consensus 3/3: valid=3]
raw comments (17)
**Custom `cacheHandler` path resolved against the cwd**
`formatDynamicImportPath(this.distDir, cacheHandler)` uses the relative `distDir` (e.g. `.next`). A relative handler path from the server-files config is then resolved against the cwd, not the project dir. `loadCustomCacheHandlers` right above prefixes `absoluteProjectDir`. Join `projectDir` (as computed below) with `this.distDir` before resolving the handler path.
```
packages/next/src/server/route-modules/route-module.ts:316 let CacheHandler: any
packages/next/src/server/route-modules/route-module.ts:317 const { cacheHandler } = nextConfig
packages/next/src/server/route-modules/route-module.ts:319 if (cacheHandler) {
packages/next/src/server/route-modules/route-module.ts:320 const { formatDynamicImportPath } =
packages/next/src/build/index.ts:2262 cacheHandler: cacheHandler
packages/next/src/build/index.ts:2263 ? path.relative(distDir, cacheHandler)
packages/next/src/build/index.ts:2264 : config.cacheHandler,
packages/next/src/lib/format-dynamic-import-path.ts:12 export const formatDynamicImportPath = (dir: string, filePath: string) => {
packages/next/src/lib/format-dynamic-import-path.ts:13 const absoluteFilePath = path.isAbsolute(filePath)
packages/next/src/lib/format-dynamic-import-path.ts:14 ? filePath
```
**Pages router no longer calls `onCacheEntry`**
base-server now returns early for handler-based modules, before its `onCacheEntry` call. The pages handler never reads that request meta, so callers relying on it never get pages entries. app-page.ts still calls it. Invoke `onCacheEntry` after `handleResponse` like app-page.ts does.
The same mistake is at `packages/next/src/build/templates/app-route.ts:368`.
```
packages/next/src/build/templates/pages.ts:577 const result = await routeModule.handleResponse({
packages/next/src/build/templates/pages.ts:578 cacheKey,
packages/next/src/build/templates/pages.ts:579 req,
packages/next/src/build/templates/pages.ts:580 nextConfig,
packages/next/src/server/base-server.ts:3378 // If there's a callback for `onCacheEntry`, call it with the cache entry
packages/next/src/server/base-server.ts:3379 // and the revalidate options.
packages/next/src/server/base-server.ts:3380 const onCacheEntry = getRequestMeta(req, 'onCacheEntry')
packages/next/src/server/base-server.ts:3381 if (onCacheEntry) {
packages/next/src/server/base-server.ts:3382 const finished = await onCacheEntry(
packages/next/src/server/base-server.ts:3383 {
```
**Pages spans lose route name under next-server**
When there is an active span, `handleResponse()` is called without it, so `doRender` skips setting `http.status_code`/`next.route` and renaming the span. Before, `invokeRouteModule(activeSpan)` did this; app-route and app-page still pass the span. Call `handleResponse(activeSpan)`.
```
packages/next/src/build/templates/pages.ts:774 if (activeSpan) {
packages/next/src/build/templates/pages.ts:775 await handleResponse()
packages/next/src/build/templates/pages.ts:776 } else {
packages/next/src/build/templates/pages.ts:484 isRevalidate: hasStaticProps,
packages/next/src/build/templates/pages.ts:485 isOnDemandRevalidate,
packages/next/src/build/templates/pages.ts:486 }),
packages/next/src/build/templates/pages.ts:487 },
packages/next/src/build/templates/pages.ts:488 routerServerContext
packages/next/src/build/templates/pages.ts:489 )
packages/next/src/build/templates/pages.ts:490 }
```
**Failed renders logged twice via waitUntil**
`prom` goes to `waitUntil` even when it rejects for the current request (a cache miss that throws before resolving). The server's waitUntil awaiter logs the rejection with console.error, and the same error is also thrown to the handler, which reports it again. Pass `prom.catch(() => {})` to `waitUntil`.
```
packages/next/src/server/response-cache/index.ts:203 // we need to ensure background revalidates are
packages/next/src/server/response-cache/index.ts:204 // passed to waitUntil
packages/next/src/server/response-cache/index.ts:205 if (waitUntil) {
packages/next/src/server/response-cache/index.ts:206 waitUntil(prom)
packages/next/src/server/next-server.ts:2106 const awaiter = new AwaiterOnce({ onError: console.error })
packages/next/src/build/templates/app-route.ts:464 } catch (err) {
packages/next/src/build/templates/app-route.ts:465 // if we aren't wrapped by base-server handle here
packages/next/src/build/templates/app-route.ts:466 if (!activeSpan) {
packages/next/src/build/templates/app-route.ts:467 await routeModule.onRequestError(req, err, {
packages/next/src/build/templates/app-route.ts:468 routerKind: 'App Router',
```
**Draft mode 404s for non-prerendered dynamicParams=false pages**
The no-fallback check runs for every request, including draft mode and minimal mode. The old base-server only threw NoFallbackError when neither preview/draft mode nor minimal mode was active. Only throw when `!isDraftMode && !minimalMode`, as the pages template and the old base-server do.
```
packages/next/src/build/templates/app-page.ts:188 // if the page is dynamicParams: false and this pathname wasn't prerender
packages/next/src/build/templates/app-page.ts:189 // trigger the no fallback handling
packages/next/src/build/templates/app-page.ts:190 if (isSSG && prerenderInfo?.fallback === false && !isPrerendered) {
packages/next/src/build/templates/app-page.ts:191 throw new NoFallbackError()
packages/next/src/build/templates/app-page.ts:192 }
packages/next/src/server/base-server.ts:2995 if (
packages/next/src/server/base-server.ts:2996 process.env.NEXT_RUNTIME !== 'edge' &&
packages/next/src/server/base-server.ts:2997 !this.minimalMode &&
packages/next/src/server/base-server.ts:2998 fallbackMode !== FallbackMode.BLOCKING_STATIC_RENDER &&
packages/next/src/server/base-server.ts:2999 staticPathKey &&
```
**Concurrent dev requests corrupt prerender-manifest.json**
Each dynamic-route request reads the manifest, edits it and rewrites it with a plain non-atomic `writeFile`. Concurrent getStaticPaths for different routes overwrite each other, and route modules can read the file while it is half-written. Serialize the read-modify-write behind one promise chain and write atomically (temp file plus rename).
```
packages/next/src/server/dev/next-dev-server.ts:877 if (res.value?.fallbackMode !== undefined) {
packages/next/src/server/dev/next-dev-server.ts:878 // we write the static paths to partial manifest for
packages/next/src/server/dev/next-dev-server.ts:879 // fallback handling inside of entry handler's
packages/next/src/server/dev/next-dev-server.ts:880 const rawExistingManifest = await fs.promises.readFile(
packages/next/src/server/route-modules/route-module.ts:183 loadManifestFromRelativePath<PrerenderManifest>({
packages/next/src/server/route-modules/route-module.ts:184 projectDir,
packages/next/src/server/route-modules/route-module.ts:185 distDir: this.distDir,
packages/next/src/server/route-modules/route-module.ts:186 manifest: PRERENDER_MANIFEST,
packages/next/src/server/route-modules/route-module.ts:187 shouldCache: !this.isDev,
packages/next/src/server/route-modules/route-module.ts:188 }),
```
**Draft-mode 404/redirect responses get public cache headers**
In draft mode, `cacheControl` comes from the getStaticProps result and is written before the notFound and redirect early returns. The draft-mode 'private, no-cache' override only runs further down, so those responses never get it. Set `cacheControl` to revalidate 0 when `isDraftMode`, before writing the header.
```
packages/next/src/build/templates/pages.ts:633 cacheControl = {
packages/next/src/build/templates/pages.ts:634 revalidate: result.cacheControl.revalidate,
packages/next/src/build/templates/pages.ts:635 expire: result.cacheControl?.expire ?? nextConfig.expireTime,
packages/next/src/build/templates/pages.ts:636 }
packages/next/src/server/render.tsx:1036 } else if (
packages/next/src/server/render.tsx:1037 data.revalidate === false ||
packages/next/src/server/render.tsx:1038 typeof data.revalidate === 'undefined'
packages/next/src/server/render.tsx:1039 ) {
packages/next/src/server/render.tsx:1040 // By default, we never revalidate.
packages/next/src/server/render.tsx:1041 revalidate = false
```
**Second IncrementalCache built on every request**
`handleResponse` always calls `getIncrementalCache`, even for uncached (null key) routes and even though base-server already put one on the request meta. That means a new IncrementalCache and cache-handler instance on every request. Reuse `getRequestMeta(req, 'incrementalCache')` when present, and build it only when `cacheKey` is set.
```
packages/next/src/server/route-modules/route-module.ts:726 routeKind,
packages/next/src/server/route-modules/route-module.ts:727 isFallback,
packages/next/src/server/route-modules/route-module.ts:728 isRoutePPREnabled,
packages/next/src/server/route-modules/route-module.ts:729 isOnDemandRevalidate,
packages/next/src/server/response-cache/index.ts:66 if (!key) {
packages/next/src/server/response-cache/index.ts:67 return responseGenerator({ hasResolved: false, previousCacheEntry: null })
packages/next/src/server/response-cache/index.ts:68 }
packages/next/src/server/base-server.ts:1445 // cache can be leveraged locally
packages/next/src/server/base-server.ts:1446 if (
packages/next/src/server/base-server.ts:1447 !(this.serverOptions as any).webServerConfig &&
```
**Route handler errors lose source-mapped dev logging**
The outer catch calls `routeModule.onRequestError` without `routerServerContext`, so it falls back to `console.error` instead of `logErrorWithOriginalStack`. The old `onError` and every other call site pass the context. Pass `routerServerContext` as the fourth argument.
```
packages/next/src/build/templates/app-route.ts:467 await routeModule.onRequestError(req, err, {
packages/next/src/build/templates/app-route.ts:468 routerKind: 'App Router',
packages/next/src/build/templates/app-route.ts:469 routePath: normalizedSrcPage,
packages/next/src/build/templates/app-route.ts:470 routeType: 'route',
packages/next/src/server/route-modules/route-module.ts:364 if (routerServerContext?.logErrorWithOriginalStack) {
packages/next/src/server/route-modules/route-module.ts:365 routerServerContext.logErrorWithOriginalStack(err, 'app-dir')
packages/next/src/server/route-modules/route-module.ts:366 } else {
packages/next/src/server/route-modules/route-module.ts:367 console.error(err)
packages/next/src/server/route-modules/route-module.ts:368 }
packages/next/src/server/lib/router-server.ts:690 experimentalTestProxy: renderServerOpts.experimentalTestProxy,
```
**Fallback shell renders with real params**
The fallback-shell render (minimal-mode `renderFallbackShell` or the `__nextppronly=fallback` debug query) calls `getFallbackRouteParams(pathname)`, but `pathname` is the request URL (e.g. `/blog/hello`), not the route pattern. A concrete URL has no dynamic segments, so it returns null and nothing gets postponed. Pass `normalizedSrcPage` to `getFallbackRouteParams`, as the old template did.
```
packages/next/src/build/templates/app-page.ts:728 // the renderer as this is a fallback revalidation request.
packages/next/src/build/templates/app-page.ts:729 const fallbackRouteParams =
packages/next/src/build/templates/app-page.ts:730 pageIsDynamic &&
packages/next/src/build/templates/app-page.ts:731 isRoutePPREnabled &&
packages/next/src/server/request/fallback-params.ts:6 function getParamKeys(page: string) {
packages/next/src/server/request/fallback-params.ts:7 const pattern = getRouteRegex(page)
packages/next/src/server/request/fallback-params.ts:8 const matcher = getRouteMatcher(pattern)
packages/next/src/server/request/fallback-params.ts:10 // Get the default list of allowed params.
packages/next/src/server/request/fallback-params.ts:11 return Object.keys(matcher(page))
packages/next/src/server/request/fallback-params.ts:12 }
```
**ISR pages cache bot-specific metadata HTML**
`serveStreamingMetadata` used to be forced true for revalidations (as at build). Now it depends only on the user agent. An HTML-limited bot that triggers an ISR regeneration stores blocking-metadata HTML in the shared cache, which is then served to all visitors. Keep forcing `serveStreamingMetadata` to true when `isSSG && !supportsDynamicResponse`.
```
packages/next/src/build/templates/app-page.ts:280 let serveStreamingMetadata = !userAgent
packages/next/src/build/templates/app-page.ts:281 ? true
packages/next/src/build/templates/app-page.ts:282 : shouldServeStreamingMetadata(userAgent, nextConfig.htmlLimitedBots)
packages/next/src/build/templates/app-page.ts:300 (base) // This is a revalidation request if the request is for a static
packages/next/src/build/templates/app-page.ts:301 (base) // page and it is not being resumed from a postponed render and
packages/next/src/build/templates/app-page.ts:302 (base) // it is not a dynamic RSC request then it is a revalidation
packages/next/src/build/templates/app-page.ts:303 (base) // request.
packages/next/src/build/templates/app-page.ts:304 (base) const isRevalidate =
packages/next/src/build/templates/app-page.ts:305 (base) isIsr && !supportsDynamicResponse && !postponed && !isDynamicRSCRequest
packages/next/src/build/templates/app-page.ts:307 (base) let serveStreamingMetadata =
```
**Revalidate-if-generated on ungenerated app page throws**
When an only-generated on-demand revalidate hits a path that was never generated, the generator sends a 404 and returns null. `routeModule.handleResponse` is never given `revalidateOnlyGenerated`, so it throws the invariant anyway. Pass `revalidateOnlyGenerated` through and skip the local invariant in that case.
```
packages/next/src/build/templates/app-page.ts:605 // skip on-demand revalidate if cache is not present and
packages/next/src/build/templates/app-page.ts:606 // revalidate-if-generated is set
packages/next/src/build/templates/app-page.ts:607 if (
packages/next/src/build/templates/app-page.ts:608 isOnDemandRevalidate &&
packages/next/src/server/route-modules/route-module.ts:740 if (
packages/next/src/server/route-modules/route-module.ts:741 cacheKey &&
packages/next/src/server/route-modules/route-module.ts:742 // revalidate only generated can bail even if cacheKey is provided
packages/next/src/server/route-modules/route-module.ts:743 !(isOnDemandRevalidate && revalidateOnlyGenerated)
packages/next/src/server/route-modules/route-module.ts:744 ) {
packages/next/src/server/route-modules/route-module.ts:745 // A cache entry might not be generated if a response is written
```
**Revalidate-if-generated on route handler throws invariant**
The only-generated on-demand revalidate path sends a 404 and returns null. Because `isIsr` is true, the cache-entry kind check runs next and throws on the missing entry. Return early when `cacheEntry` is null, before the kind check.
```
packages/next/src/build/templates/app-route.ts:267 if (
packages/next/src/build/templates/app-route.ts:268 !getRequestMeta(req, 'minimalMode') &&
packages/next/src/build/templates/app-route.ts:269 isOnDemandRevalidate &&
packages/next/src/build/templates/app-route.ts:270 revalidateOnlyGenerated &&
packages/next/src/build/templates/app-route.ts:387 if (cacheEntry?.value?.kind !== CachedRouteKind.APP_ROUTE) {
packages/next/src/build/templates/app-route.ts:388 throw new Error(
packages/next/src/build/templates/app-route.ts:389 `Invariant: app-route received invalid cache entry ${cacheEntry?.value?.kind}`
packages/next/src/build/templates/app-route.ts:390 )
packages/next/src/build/templates/app-route.ts:391 }
packages/next/src/build/templates/app-route.ts:481 if (isIsr) throw err
```
**On-demand revalidate serves fallback shell instead of generating**
For an ungenerated `fallback: true` path, an on-demand revalidate still takes the `isIsrFallback` branch, because base-server's switch to a blocking render was dropped. The fallback shell is returned without cache control, so nothing gets cached. Clear `isIsrFallback` on on-demand revalidate, and run the only-generated 404 check before the fallback branch.
```
packages/next/src/build/templates/pages.ts:213 }
packages/next/src/build/templates/pages.ts:215 if (hasStaticPaths && !isDraftMode) {
packages/next/src/build/templates/pages.ts:216 const decodedPathname = removeTrailingSlash(
packages/next/src/build/templates/pages.ts:217 decodePathParams(
packages/next/src/build/templates/pages.ts:527 }
packages/next/src/build/templates/pages.ts:528 )
packages/next/src/build/templates/pages.ts:529 if (fallbackResponse) {
packages/next/src/build/templates/pages.ts:530 // Remove the cache control from the response to prevent it from being
packages/next/src/build/templates/pages.ts:531 // used in the surrounding cache.
packages/next/src/build/templates/pages.ts:532 delete fallbackResponse.cacheControl
```
**HTML requests with prefetch header treated as prefetch**
`isPrefetchRSCRequest` now falls back to the raw `next-router-prefetch` header without requiring an RSC request. A plain HTML request carrying that header counts as a prefetch: it gets the prerender headers on postponed PPR responses and skips the dev warmup. Require `isRSCRequest` too, as before.
```
packages/next/src/build/templates/app-page.ts:202 const isPrefetchRSCRequest =
packages/next/src/build/templates/app-page.ts:203 getRequestMeta(req, 'isPrefetchRSCRequest') ??
packages/next/src/build/templates/app-page.ts:204 Boolean(req.headers[NEXT_ROUTER_PREFETCH_HEADER])
packages/next/src/build/templates/app-page.ts:278 (base) getRequestMeta(req, 'isPrefetchRSCRequest') ??
packages/next/src/build/templates/app-page.ts:279 (base) Boolean(isRSCRequest && req.headers[NEXT_ROUTER_PREFETCH_HEADER])
packages/next/src/server/base-server.ts:2172 const isPrefetchRSCRequest =
packages/next/src/server/base-server.ts:2173 getRequestMeta(req, 'isPrefetchRSCRequest') ?? false
```
**Pages render errors are logged twice**
The catch now calls `routeModule.onRequestError`, which logs, even when wrapped by the base server, and the base server logs the error again. Previously only instrumentation was notified; app-page gates this on `!activeSpan`. Only log when `!activeSpan`.
```
packages/next/src/build/templates/pages.ts:792 } catch (err) {
packages/next/src/build/templates/pages.ts:793 await routeModule.onRequestError(
packages/next/src/build/templates/pages.ts:794 req,
packages/next/src/build/templates/pages.ts:795 err,
packages/next/src/server/base-server.ts:3840 const isWrappedError = err instanceof WrappedBuildError
packages/next/src/server/base-server.ts:3842 if (!isWrappedError) {
packages/next/src/server/base-server.ts:3843 if (
packages/next/src/server/base-server.ts:3844 (this.minimalMode && process.env.NEXT_RUNTIME !== 'edge') ||
packages/next/src/server/base-server.ts:3845 this.renderOpts.dev
packages/next/src/server/base-server.ts:3846 ) {
```
**Dev 404s when generateStaticParams returns no paths**
In dev, the base server only threw NoFallbackError when static paths weren't empty, and otherwise rendered. The template throws whenever `fallback === false` and the path isn't prerendered, so an empty `generateStaticParams` now 404s every path in dev. In dev, skip the throw when the route has no static paths.
```
packages/next/src/build/templates/app-page.ts:188 // if the page is dynamicParams: false and this pathname wasn't prerender
packages/next/src/build/templates/app-page.ts:189 // trigger the no fallback handling
packages/next/src/build/templates/app-page.ts:190 if (isSSG && prerenderInfo?.fallback === false && !isPrerendered) {
packages/next/src/build/templates/app-page.ts:191 throw new NoFallbackError()
packages/next/src/server/base-server.ts:3005 if (
packages/next/src/server/base-server.ts:3006 // In development, fall through to render to handle missing
packages/next/src/server/base-server.ts:3007 // getStaticPaths.
packages/next/src/server/base-server.ts:3008 (isProduction || (staticPaths && staticPaths?.length > 0)) &&
packages/next/src/server/base-server.ts:3009 // When fallback isn't present, abort this render so we 404
packages/next/src/server/base-server.ts:3010 fallbackMode === FallbackMode.NOT_FOUND
```
Drape (Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
| d2 | high | ✓ | exact |
| d3 | high | ✓ | off by one |
| d5 | high | ✗ | — |
| d6 | medium | ✗ | — |
| d7 | low | ✓ | exact |
| d8 | low | ✓ | off by one |
| d9 | medium | ✗ | — |
| d10 | low | ✗ | — |
NextNodeServer gates flushToDisk with `!this.minimalMode && ...`; the new route-module getIncrementalCache drops that guard, so minimal-mode requests will flush ISR to disk. [grounded: diff] [consensus 3/3: valid=3]
Existing codes 695-700 get reassigned to different messages, which breaks the stable error-code mapping. Unused near-duplicate messages are also added. [grounded: diff] [consensus 3/3: valid=3]
The new throw sits in the 'force-dynamic' case but its message names 'dynamic = error', so the bail-out reason is wrong. [grounded: diff] [consensus 3/3: valid=3]
The old code passed activeSpan to invokeRouteModule. Now handleResponse gets no span, so the `if (!span) return` in the finally block skips setting the status code and route name. [grounded: diff] [consensus 3/3: valid=3]
The generator returns null after writing a 404 for revalidateOnlyGenerated. app-page's check throws the invariant without excluding that case, and it also doesn't pass revalidateOnlyGenerated to routeModule.handleResponse. The old base-server excluded it. [grounded: diff] [consensus 3/3: valid=3]
In route modules distDir is relative (from __NEXT_RELATIVE_DIST_DIR), whereas NextNodeServer's distDir was absolute. A relative cacheHandler therefore resolves against cwd, not the project dist dir. loadCustomCacheHandlers in the same file already uses the absolute dir. [grounded: diff] [consensus 3/3: valid=3]
The finally block was removed. ctx.waitUntil is now passed to the response cache, but it is only called when a cache key exists. Whether losing the empty-resolve signal causes any observable failure isn't shown. [uncertain: no evidence quoted] [consensus 3/3: uncertain=3]
raw comments (11)
**Fallback shell uses URL instead of route pattern**
In `responseGenerator`, `getFallbackRouteParams(pathname)` is called with the concrete request URL. The original code and the PPR fallback branch above pass `normalizedSrcPage`, the route pattern. Call `getFallbackRouteParams(normalizedSrcPage)`.
```
packages/next/src/build/templates/app-page.ts:728 // the renderer as this is a fallback revalidation request.
packages/next/src/build/templates/app-page.ts:729 const fallbackRouteParams =
packages/next/src/build/templates/app-page.ts:730 pageIsDynamic &&
packages/next/src/build/templates/app-page.ts:731 isRoutePPREnabled &&
```
**ISR flush-to-disk enabled in minimal mode**
`getIncrementalCache` passes `flushToDisk: nextConfig.experimental.isrFlushToDisk`. The server's version was `!this.minimalMode && isrFlushToDisk`. Use `!getRequestMeta(req, 'minimalMode') && nextConfig.experimental.isrFlushToDisk`.
```
packages/next/src/server/route-modules/route-module.ts:344 requestHeaders: req.headers,
packages/next/src/server/route-modules/route-module.ts:345 allowedRevalidateHeaderKeys:
```
**Route errors skip the original-stack logger**
The catch-block call `routeModule.onRequestError(req, err, {...})` omits the fourth `routerServerContext` argument that the other five callers pass. Pass `routerServerContext` as the fourth argument.
```
packages/next/src/build/templates/app-route.ts:467 await routeModule.onRequestError(req, err, {
packages/next/src/build/templates/app-route.ts:468 routerKind: 'App Router',
packages/next/src/build/templates/app-route.ts:469 routePath: normalizedSrcPage,
packages/next/src/build/templates/app-route.ts:470 routeType: 'route',
```
**Existing error codes renumbered in errors.json**
The change inserts a new message at 695 and shifts the existing 695-700 entries to 696-708, and also adds three near-identical `dynamic = error` messages (703-705) of which only one is used. Keep existing codes unchanged, append new messages at the end, and drop the unused duplicates.
```
packages/next/errors.json:695 "694": "createPrerenderPathname was called inside a client component scope.",
packages/next/errors.json:696 "695": "Invariant: received non-pages cache entry in pages handler",
packages/next/errors.json:697 "696": "Expected workUnitAsyncStorage to have a store.",
packages/next/errors.json:698 "697": "Next DevTools: Can't render in this environment. This is a bug in Next.js",
```
**force-dynamic bail-out says dynamic = error**
When a `force-dynamic` route handler runs during static generation, the new DynamicServerError and `dynamicUsageDescription` say the route uses "dynamic = error". Anyone reading the bail-out reason is pointed at the wrong config. Change the message to name force-dynamic, as the page-side message does.
```
packages/next/src/server/route-modules/app-route/module.ts:727 if (workStore.isStaticGeneration) {
packages/next/src/server/route-modules/app-route/module.ts:728 const err = new DynamicServerError(
packages/next/src/server/route-modules/app-route/module.ts:729 'Route is configured with dynamic = error which cannot be statically generated.'
packages/next/src/server/route-modules/app-route/module.ts:730 )
packages/next/src/server/route-modules/app-route/module.ts:745 case 'error':
packages/next/src/server/route-modules/app-route/module.ts:746 // The dynamic property is set to error, so we should throw an
packages/next/src/server/route-modules/app-route/module.ts:747 // error if the page is being statically generated.
packages/next/src/server/route-modules/app-route/module.ts:748 workStore.dynamicShouldError = true
packages/next/src/server/route-modules/app-route/module.ts:749 if (workStore.isStaticGeneration)
packages/next/src/server/route-modules/app-route/module.ts:750 request = new Proxy(req, requireStaticRequestHandlers)
```
**Invariant error thrown after 404 already sent**
When on-demand revalidate with revalidate-only-generated finds no previous entry, the generator writes the 404 and returns null. For an ISR route, `handleResponse` then sees `isIsr` true and a null entry and throws the invariant. Return early when the response is already finished or the entry is null.
```
packages/next/src/build/templates/app-route.ts:268 !getRequestMeta(req, 'minimalMode') &&
packages/next/src/build/templates/app-route.ts:269 isOnDemandRevalidate &&
packages/next/src/build/templates/app-route.ts:270 revalidateOnlyGenerated &&
packages/next/src/build/templates/app-route.ts:271 !previousCacheEntry
packages/next/src/server/route-modules/route-module.ts:735 ),
packages/next/src/server/route-modules/route-module.ts:736 waitUntil,
packages/next/src/server/route-modules/route-module.ts:737 })
packages/next/src/server/route-modules/route-module.ts:739 if (!cacheEntry) {
packages/next/src/server/route-modules/route-module.ts:740 if (
packages/next/src/server/route-modules/route-module.ts:741 cacheKey &&
```
**Active span not passed to pages handler**
`handleResponse()` is called without `activeSpan`, although it takes `span` and uses it to set the status code and route name. The old code passed `activeSpan`. Call `handleResponse(activeSpan)`.
```
packages/next/src/build/templates/pages.ts:773 // next-server can be removed when this is no longer used
packages/next/src/build/templates/pages.ts:774 if (activeSpan) {
packages/next/src/build/templates/pages.ts:775 await handleResponse()
packages/next/src/build/templates/pages.ts:776 } else {
```
**Dev getStaticPaths rewrites prerender manifest unsafely**
On each first-time getStaticPaths result, dev reads, edits and rewrites the shared prerender-manifest.json with no lock or atomic write. Requests for different dynamic routes can run this at once. Serialize manifest updates and write via a temp file plus rename.
```
packages/next/src/server/dev/next-dev-server.ts:877 if (res.value?.fallbackMode !== undefined) {
packages/next/src/server/dev/next-dev-server.ts:878 // we write the static paths to partial manifest for
packages/next/src/server/dev/next-dev-server.ts:879 // fallback handling inside of entry handler's
packages/next/src/server/dev/next-dev-server.ts:880 const rawExistingManifest = await fs.promises.readFile(
packages/next/src/server/route-modules/route-module.ts:180 manifest: ROUTES_MANIFEST,
packages/next/src/server/route-modules/route-module.ts:181 shouldCache: !this.isDev,
packages/next/src/server/route-modules/route-module.ts:182 }),
packages/next/src/server/route-modules/route-module.ts:183 loadManifestFromRelativePath<PrerenderManifest>({
packages/next/src/server/route-modules/route-module.ts:184 projectDir,
packages/next/src/server/route-modules/route-module.ts:185 distDir: this.distDir,
```
**404 for revalidate-only-generated then throws invariant**
When `revalidateOnlyGenerated` with on-demand revalidate and no previous entry, the generator writes a 404 and returns null. The `!cacheEntry` check then throws "cache entry required but not generated" because it doesn't exclude this case. Skip the invariant when `isOnDemandRevalidate && revalidateOnlyGenerated`, as the old base-server check did.
```
packages/next/src/build/templates/app-page.ts:773 if (!cacheEntry) {
packages/next/src/build/templates/app-page.ts:774 if (ssgCacheKey) {
packages/next/src/build/templates/app-page.ts:775 // A cache entry might not be generated if a response is written
packages/next/src/build/templates/app-page.ts:776 // in `getInitialProps` or `getServerSideProps`, but those shouldn't
```
**Custom cacheHandler path resolved against relative distDir**
`getIncrementalCache` calls `formatDynamicImportPath(this.distDir, cacheHandler)`. In a route module `this.distDir` is relative (e.g. `.next`), whereas NextNodeServer passed an absolute dist dir. `loadCustomCacheHandlers` in the same file already prefixes the absolute project dir. Use `${projectDir}/${this.distDir}` as the base, as loadCustomCacheHandlers does.
```
packages/next/src/server/route-modules/route-module.ts:319 if (cacheHandler) {
packages/next/src/server/route-modules/route-module.ts:320 const { formatDynamicImportPath } =
packages/next/src/server/route-modules/route-module.ts:321 require('../../lib/format-dynamic-import-path') as typeof import('../../lib/format-dynamic-import-path')
packages/next/src/server/route-modules/route-module.ts:323 CacheHandler = interopDefault(
```
**Pages handler no longer signals waitUntil completion**
The `finally` that called `ctx.waitUntil?.(Promise.resolve())` was removed. It now runs only in the bad-request early return. Restore the finally block, or call waitUntil with a promise that resolves once all work is done.
```
packages/next/src/build/templates/pages.ts:366 (base) // We don't allow any waitUntil work in pages API routes currently
packages/next/src/build/templates/pages.ts:367 (base) // so if callback is present return with resolved promise since no
packages/next/src/build/templates/pages.ts:368 (base) // pending work
packages/next/src/build/templates/pages.ts:369 (base) ctx.waitUntil?.(Promise.resolve())
packages/next/src/build/templates/pages.ts:128 ctx.waitUntil?.(Promise.resolve())
```
greptile · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
| d2 | high | ✗ | — |
| d3 | high | ✗ | — |
| d5 | high | ✗ | — |
| d6 | medium | ✗ | — |
| d7 | low | ✗ | — |
| d8 | low | ✓ | wrong severity |
| d9 | medium | ✗ | — |
| d10 | low | ✓ | wrong severity |
The new error is thrown inside `case 'force-dynamic'`, but its message says the route uses `dynamic = error`. Users get a misleading build diagnostic that names the wrong config. [grounded: diff] [consensus 3/3: valid=3]
Before this change the code passed the span with `invokeRouteModule(activeSpan)`. It now calls `handleResponse()` with no span, so the `.finally` block exits at `if (!span) return` and never sets the route or status span attributes. [grounded: diff] [consensus 3/3: valid=3]
raw comments (5)
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Debug Resume Uses Wrong Kind**
For a minimal-mode PPR resume request with static-shell or dynamic-access debugging enabled, this branch returns a `PAGES` cache entry. The consumer immediately requires an `APP_PAGE` entry, so the request throws the “invalid cache entry” invariant instead of returning the intended empty debug response.
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Concurrent Manifest Updates Are Lost**
Development requests for different dynamic routes are coalesced separately, so they can execute this read-modify-write sequence at the same time. Both can read the same manifest and write independent snapshots, allowing the later write to erase the other route’s new `routes` or `dynamicRoutes` entries. This causes incorrect fallback handling until the affected route is recomputed.
<a href="#"><img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top"></a> **Force Dynamic Error Is Misidentified**
This is the `force-dynamic` branch, but its new static-generation error says the route uses `dynamic = error`, which is a separate configuration below. This can replace the actionable export diagnostic with a misleading message and make the build failure harder to resolve.
```suggestion
const err = new DynamicServerError(
'Route is configured with dynamic = force-dynamic which cannot be statically generated.'
)
```
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
<a href="#"><img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top"></a> **Active Span Is Dropped**
When the base server already provides an active span, this branch calls `handleResponse` without passing it. The Pages request therefore skips the route and status attributes applied inside `handleResponse`, reducing the usefulness of its trace.
```suggestion
if (activeSpan) {
await handleResponse(activeSpan)
```
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
<h3>Greptile Summary</h3>
This PR moves Pages, App Page, and App Route response-cache and fallback handling into generated route handlers, adds route-module-owned cache initialization, and adjusts development prerender metadata.
- Adds handler-local ISR, PPR, fallback, redirect, and response serialization logic.
- Moves cache and manifest initialization into route modules.
- Adds development prerender-manifest updates and new instrumentation/error paths.
- Contains two blocking correctness defects in PPR debug handling and concurrent development manifest updates.
<h3>Confidence Score: 3/5</h3>
The PR is not safe to merge until the invalid App Page debug cache entry and concurrent development prerender-manifest updates are corrected.
Minimal-mode PPR debug requests deterministically produce a cache entry rejected by their own consumer, while concurrent static-path generation can lose route metadata through competing manifest rewrites; the remaining findings affect diagnostics and tracing.
**Files Needing Attention:** packages/next/src/build/templates/app-page.ts, packages/next/src/server/dev/next-dev-server.ts, packages/next/src/server/route-modules/app-route/module.ts, packages/next/src/build/templates/pages.ts
<details><summary><h3>Important Files Changed</h3></summary>
| Filename | Overview |
|----------|----------|
| packages/next/src/build/templates/app-page.ts | Moves App Page caching and PPR response handling into the template, but returns an incompatible cache kind for minimal-mode debug resumes. |
| packages/next/src/server/dev/next-dev-server.ts | Writes generated static paths into the development prerender manifest using an unsynchronized read-modify-write sequence. |
| packages/next/src/server/route-modules/app-route/module.ts | Adds a static-generation failure for force-dynamic route handlers with an incorrect configuration diagnostic. |
| packages/next/src/build/templates/pages.ts | Moves Pages response handling into the template but drops the active span on the already-instrumented path. |
| packages/next/src/server/route-modules/route-module.ts | Centralizes manifest loading, incremental-cache creation, response-cache access, and request-error reporting. |
| packages/next/src/server/response-cache/index.ts | Adds lifecycle tracking for cache generation and renames the dynamically configured minimal-mode field. |
</details>
<details open><summary><h3>Flowchart</h3></summary>
```mermaid
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Incoming request] --> B[Generated route handler]
B --> C[RouteModule.prepare]
C --> D[Resolve pathname, locale, fallback state]
D --> E[RouteModule.handleResponse]
E --> F[ResponseCache]
F -->|hit| G[Cached route entry]
F -->|miss or stale| H[Handler response generator]
H --> I[Render route module]
I --> J[Persist through IncrementalCache]
G --> K[Serialize HTML, RSC, JSON, redirect, or route response]
J --> K
K --> L[HTTP response]
```
</details>
<!-- greptile_other_comments_section -->
<sub>Reviews (1): Last reviewed commit: ["Update packages/next/errors.json and 21 ..."](https://github.com/drape-io/crbench-greptile-2026-09/commit/8a15c280c2671c3134e5cb0f1dfc6d4ad874646b) | [Re-trigger Greptile](https://app.greptile.com/api/retrigger?id=64284722)</sub>
Mjolnir (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
| d2 | high | ✓ | off by one |
| d3 | high | ✓ | exact |
| d5 | high | ✗ | — |
| d6 | medium | ✗ | — |
| d7 | low | ✗ | — |
| d8 | low | ✗ | — |
| d9 | medium | ✗ | — |
| d10 | low | ✗ | — |
The app-page handleResponse call passes isOnDemandRevalidate but not revalidateOnlyGenerated. So when responseGenerator returns null after rendering the 404, route-module.handleResponse throws, and so does the template's own ssgCacheKey check. Base-server used to exempt this case. [grounded: tree packages/next/src/build/templates/app-page.ts] [consensus 3/3: valid=3]
onRequestError logs through logErrorWithOriginalStack or console.error, and the pages catch has no !activeSpan guard. It then rethrows into base-server, whose renderToResponseImpl calls this.logError in production. The old code only called the instrumentation hook, which doesn't log. [grounded: tree packages/next/src/build/templates/pages.ts] [consensus 3/3: valid=3]
prom is handed to waitUntil even when the error is rethrown because nothing has resolved yet. next-server's internal waitUntil uses AwaiterOnce({ onError: console.error }), so the same error is logged again. [grounded: diff-section packages/next/src/server/response-cache/index.ts] [consensus 3/3: valid=3]
The dev server only adds entries to the prerender manifest and skips the write when fallbackMode is undefined. Entry handlers now read this manifest to decide NoFallbackError and prerendered status, so stale entries persist until restart. prerender-manifest.json is a runtime file, but the code that writes it via PRERENDER_MANIFEST is in the diff. [grounded: diff-section packages/next/src/server/dev/next-dev-server.ts] [consensus 3/3: valid=3]
Same issue as finding 0: revalidateOnlyGenerated isn't passed to routeModule.handleResponse, and the template's own check lacks the exemption, so the invariant is thrown after the 404 has been sent. [grounded: tree packages/next/src/build/templates/app-page.ts] [consensus 3/3: valid=3]
Base-server now returns before reaching the onCacheEntry call for handler-based modules. Only the app-page template calls onCacheEntry; the pages and app-route templates don't, so the hook no longer fires for those entries. [grounded: diff-section packages/next/src/server/base-server.ts] [consensus 3/3: valid=3]
The build stores cacheHandler as path.relative(distDir, cacheHandler). formatDynamicImportPath joins it with the relative distDir and pathToFileURL resolves the result against cwd, so the import fails when cwd isn't the project dir. The sibling loadCustomCacheHandlers uses the absolute project dir. ../handler.js is only the finding's example path. [grounded: diff-section packages/next/src/server/route-modules/route-module.ts] [consensus 3/3: valid=3]
Duplicate of finding 1: the pages catch has no !activeSpan guard, logs through onRequestError and rethrows, so base-server logs the error again. [grounded: tree packages/next/src/build/templates/pages.ts] [consensus 3/3: valid=3]
raw comments (10)
[P2] On-demand revalidate of a not-yet-generated app page now throws the cache-entry invariant
When `isOnDemandRevalidate && revalidateOnlyGenerated` and there is no previous cache entry, `responseGenerator` renders the 404 and returns `null`. This happens, for example, with `res.revalidate(path, { unstable_onlyGenerated: true })` against a dynamic app page that hasn't been generated yet. `ssgCacheKey` is set in this case. However, the `routeModule.handleResponse(...)` call doesn't pass `revalidateOnlyGenerated`, so its `!(isOnDemandRevalidate && revalidateOnlyGenerated)` exemption never applies, and it throws `invariant: cache entry required but not generated`. The handler's own `if (!cacheEntry) { if (ssgCacheKey) throw ... }` check right after it has the same gap. The old base-server code and the new pages/app-route handlers all exempt this case. Here, a 404 that has already been sent is followed by an invariant error that gets logged and bubbles to base-server's error rendering.
[P2] Pages render errors are logged twice in production
The pages handler's outer `catch` now calls `routeModule.onRequestError` unconditionally. That function logs the error itself, through `routerServerContext.logErrorWithOriginalStack`, which is `Log.error` under `next start`, or through `console.error` otherwise. The handler then rethrows. The rethrown error reaches base-server's `renderToResponseImpl` catch, which calls `this.logError(...)` again in non-dev, non-minimal mode, so every pages render error (for example, a throwing `getServerSideProps`) is printed twice. Before this change, the pages handler only called `instrumentationOnRequestError`, which doesn't log. The app-page and app-route handlers in this same diff avoid the double log by only calling `onRequestError` when `!activeSpan`, meaning when they aren't wrapped by base-server.
[P3] Foreground cache-generation errors are also handed to `waitUntil` and logged again
`prom` is always passed to `waitUntil`, including when the cache entry hasn't resolved yet and the generator throws, for example on a first-hit ISR render error. In that case `prom` rejects and the same error is rethrown to the caller. Under `next start`, `waitUntil` is next-server's `AwaiterOnce({ onError: console.error })`, so the rejection is logged once more on top of the normal error handling. In minimal mode, the platform's `waitUntil` receives a rejected promise. The comment says the intent is only to keep background revalidations alive, so the promise passed to `waitUntil` should not surface errors that are already being propagated.
[P3] Dev prerender-manifest entries are only ever added, never removed
The dev server merges `routes[staticPath] = {}` and `dynamicRoutes[pathname]` into `prerender-manifest.json` but never removes anything. The entry handlers now read this file on every request in dev to decide `NoFallbackError`, `isSSG` and `isPrerendered`. Two cases go wrong until the dev server restarts. First, a path removed from `getStaticPaths`/`generateStaticParams` with `fallback: false`/`dynamicParams = false` stays "prerendered" and keeps rendering instead of returning 404. Second, if a change makes `fallbackMode` `undefined`, the write is skipped entirely, so a stale `fallback: false` entry stays and every unlisted param keeps returning 404. An example of the second case is removing both `generateStaticParams` and `dynamicParams = false` from an app page.
[P1] App-page on-demand revalidation with "only generated" now throws after sending a 404
This happens when an on-demand revalidation has `revalidateOnlyGenerated` set (the `x-prerender-revalidate-if-generated` header / `unstable_onlyGenerated`) and targets an app page that has not been generated yet. In that case `responseGenerator` writes a 404 and returns `null`. The `routeModule.handleResponse(...)` call does not pass `revalidateOnlyGenerated`, so its `!(isOnDemandRevalidate && revalidateOnlyGenerated)` guard is true and it throws `invariant: cache entry required but not generated`. The template's own `if (!cacheEntry) { if (ssgCacheKey) throw ... }` check would throw too, because it also lacks that exclusion. Before this change, base-server excluded this case explicitly, so the revalidation returned a clean 404. Now the request errors after the response has already ended, the error gets logged and reported, and the revalidate call fails.
[P1] App-route on-demand revalidation with "only generated" now hits an invariant
This is the same scenario for ISR route handlers: an on-demand revalidation with `revalidateOnlyGenerated` for a path that is not in the cache yet. `responseGenerator` ends the response with a 404 and returns `null`, and `handleResponse` passes this through because the flag is forwarded. Because `isIsr` is true, the code then reaches `cacheEntry?.value?.kind !== CachedRouteKind.APP_ROUTE` and throws `Invariant: app-route received invalid cache entry undefined`. A null entry needs an early return when `isOnDemandRevalidate && revalidateOnlyGenerated`.
[P2] Fallback route params are built from the request URL instead of the route pattern
`getFallbackRouteParams(pathname)` reads dynamic segment keys from the string it is given. In base-server, `pathname` was the page pattern (e.g. `/blog/[slug]`). Here it is `parsedUrl.pathname`, the concrete URL such as `/blog/hello`, so no keys are found and it returns `null`. As a result, with PPR the `?__nextppronly=fallback` fallback-shell debugging (`isDebugFallbackShell`) renders the full page instead of the fallback shell. This path is always taken in dev because `ssgCacheKey` is null there. The renderFallbackShell revalidation path depends on the same lookup. The earlier fallback block already uses `normalizedSrcPage`, which is the correct input here too.
[P2] `onCacheEntry` request-meta hook is no longer called for pages and app routes
Base-server used to call `getRequestMeta(req, 'onCacheEntry')` for every cache entry (pages, app-route and app-page). After this change, pages and app routes return early from base-server into their handlers, and only the app-page template calls `onCacheEntry`. The pages template (and the app-route template) never calls it. Deployment adapters that use this hook to capture or short-circuit ISR cache entries for Pages Router and route-handler responses will silently stop receiving them.
[P2] Custom `cacheHandler` path is resolved against a relative distDir
`this.distDir` is the relative `__NEXT_RELATIVE_DIST_DIR` (e.g. `.next`). When `routerServerContext.nextConfig` isn't available, `nextConfig` comes from `serverFilesManifest.config`. This is the case in minimal mode, where next-server only registers `render404`. In that config, `cacheHandler` is stored relative to distDir (`path.relative(distDir, cacheHandler)`). `formatDynamicImportPath('.next', '../handler.js')` then builds a file URL relative to `process.cwd()`. So whenever cwd differs from the project directory, as in monorepo or adapter deployments, the custom cache handler fails to import. `loadCustomCacheHandlers` right above already uses `${absoluteProjectDir}/${this.distDir}`, and this call should do the same.
[P3] Pages Router render errors are now logged twice
The pages handler's catch block previously only called the instrumentation hook. It now calls `routeModule.onRequestError`, which also logs: through `routerServerContext.logErrorWithOriginalStack` (labelled `'app-dir'`), or `console.error`. Unlike the app-page and app-route templates, the call is not guarded by `!activeSpan`. The error is then rethrown into base-server, whose catch calls `this.logError` again in production, so every `getServerSideProps`/render error is printed twice.
Mjolnir (Sonnet 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
| d2 | high | ✗ | — |
| d3 | high | ✗ | — |
| d5 | high | ✗ | — |
| d6 | medium | ✗ | — |
| d7 | low | ✗ | — |
| d8 | low | ✓ | off by one |
| d9 | medium | ✗ | — |
| d10 | low | ✗ | — |
The app-page call to routeModule.handleResponse passes isOnDemandRevalidate but not revalidateOnlyGenerated. When the responseGenerator returns null after writing a 404 with ssgCacheKey set, the shared handleResponse throws the invariant. The old base-server code exempted this case, and the pages and app-route templates both forward the flag. [grounded: tree packages/next/src/build/templates/app-page.ts] [consensus 3/3: valid=3]
The diff reassigns existing codes 695–700 to different messages instead of appending new ones, which breaks stable error-code ids. Codes 704 and 705 are near-duplicate variants of 703 that no source uses. [grounded: diff] [consensus 3/3: valid=3]
This is the same issue as finding 0: revalidateOnlyGenerated is never forwarded, so RouteModule.handleResponse throws after the 404 has already been written. [grounded: tree packages/next/src/build/templates/app-page.ts] [consensus 3/3: valid=3]
Existing codes are renumbered (for example, workUnitAsyncStorage moves from 695 to 696), and only the 703 text is used in source. [grounded: diff] [consensus 3/3: valid=3]
The error is thrown in the force-dynamic case but says the route is configured with 'dynamic = error', so it misreports the configuration. The same text is also stored in dynamicUsageDescription. [grounded: diff] [consensus 3/3: valid=3]
raw comments (6)
[P2] On-demand revalidate with revalidate-if-generated throws after responding 404
(the `routeModule.handleResponse` call inside `handleResponse`) The app-page `handleResponse` calls `routeModule.handleResponse(...)` without passing `revalidateOnlyGenerated`. It is destructured from `prepareResult` and used in `responseGenerator`, but never forwarded. When an on-demand revalidate request sets `revalidateOnlyGenerated`, the page was not previously generated, and `!minimalMode`, the generator renders the 404 and returns `null`. Because `ssgCacheKey` is set, the shared `handleResponse` then sees no cache entry. It evaluates `!(isOnDemandRevalidate && revalidateOnlyGenerated)` as true and throws `invariant: cache entry required but not generated`. The 404 has already been written, so the request ends in an error and `onRequestError` is called. The pages and app-route templates both pass `revalidateOnlyGenerated`. The old base-server code skipped the invariant in this case.
[P3] errors.json renumbers existing error codes and adds unused or mismatched entries
Existing codes 695–700 are shifted: "Expected workUnitAsyncStorage…" moves from 695 to 696, the DevTools messages move up by one, and the Chrome DevTools message moves from 700 to 708. Error ids are meant to be stable, so any build or log that already carries the old ids will now decode to the wrong messages. New ids should be appended instead. - 704 and 705 are near-duplicate variants of 703 and are not referenced by any source I found. - 706 (`static responses cannot be streamed %s`) doesn't match the source string in `render-result.ts`, which has no `%s`.
[P2] app-page handler drops `revalidateOnlyGenerated` when calling `handleResponse` — packages/next/src/build/templates/app-page.ts (the `routeModule.handleResponse({ cacheKey: ssgCacheKey, ..., isOnDemandRevalidate, isRoutePPREnabled, ... })` call in `handleResponse`; `revalidateOnlyGenerated` is destructured from `prepareResult` but not forwarded). The app-page `responseGenerator` handles on-demand revalidate with `revalidateOnlyGenerated` and no previous entry (non-minimal mode) by rendering a 404 and returning `null`. `RouteModule.handleResponse` throws `invariant: cache entry required but not generated` when `cacheKey && !cacheEntry && !(isOnDemandRevalidate && revalidateOnlyGenerated)`. Because the flag is not passed, that exemption never applies. This affects a production, non-dynamic (ISR) app page with an on-demand revalidate request that sets the revalidate-if-generated header for a path that was never generated. The 404 is already written, and then the handler throws, so the error path tries to serve a 500 and logs a spurious invariant error. `app-route.ts` and `pages.ts` both pass `revalidateOnlyGenerated`; this call site does not.
[P2] Dev prerender-manifest read-modify-write is unsynchronized
(the new `readFile` / `JSON.parse` / `writeFile` block in the `getStaticPaths` `.then`). `withCoalescedInvoke` only coalesces calls with the same `pathname`. Concurrent dev requests for two different dynamic routes (for example a page and its sibling, or parallel navigations) each read the whole `prerender-manifest.json`, mutate it, and rewrite it. Overlapping calls can lose each other's `dynamicRoutes` and `routes` entries. A reader can also hit a partially written file, and `JSON.parse` then throws and rejects `getStaticPaths` for that request. A lost entry means a route's `fallback: false` / prerendered state is not applied until its `staticPathsCache` entry is refreshed. `writeFile` is also not atomic, and the file is read concurrently by `RouteModule.loadManifests` in dev (`shouldCache: false`)
[P3] Existing error codes were renumbered and dead near-duplicate codes were added
Codes 695-700 previously mapped to specific messages (e.g. 695 "Expected workUnitAsyncStorage…", 696 "Next DevTools: Can't dispatch…", 700 "Failed to persist Chrome DevTools…"). They are now shifted (695 is a new pages invariant, 696 is the workUnitAsyncStorage message, and so on, with the DevTools persist message moved to 708). Error codes are append-only identifiers, so reassigning them breaks the mapping for already-published code numbers. In addition, 703, 704 and 705 are three near-identical "dynamic = error" messages (704 is ungrammatical), and only the 703 text is used in source. 706 duplicates the already-existing `render-result.ts` message and is not referenced via this code
[P3] force-dynamic branch throws a message about `dynamic = error`
The new `DynamicServerError` is thrown inside `case 'force-dynamic'` during static generation, but its text says "Route is configured with dynamic = error which cannot be statically generated." A route configured with `dynamic = 'force-dynamic'` will therefore report a misleading configuration value, and this error is also stored in `workStore.dynamicUsageDescription
qodo · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | high | ✗ | — |
| d2 | high | ✓ | exact |
| d3 | high | ✗ | — |
| d5 | high | ✗ | — |
| d6 | medium | ✗ | — |
| d7 | low | ✗ | — |
| d8 | low | ✓ | off by one |
| d9 | medium | ✗ | — |
| d10 | low | ✗ | — |
base-server still runs the 405/Allow check in renderToResponseWithComponentsImpl before it reaches doRender, which is what invokes the handler. So a non-GET request to an SSG page is still rejected on that path. The handler never ran this check itself before this change either. [invalid: contradiction] [consensus 3/3: invalid=3]
The old base-server fallback lookup also keyed on pathname, which is the route definition pattern (match.definition.pathname). The fallback shell is a single per-route entry by design, so using srcPage matches the earlier behavior. [invalid: contradiction] [consensus 3/3: invalid=3]
The new per-request loadCustomCacheHandlers sets the initialized flag before it awaits the handler imports. Concurrent requests therefore return early while the handler map is still incomplete, and a failed import is never retried. next-server uses the same pattern but runs it once during prepare. [grounded: tree packages/next/src/server/route-modules/route-module.ts] [consensus 3/3: valid=3]
Before this change the code called invokeRouteModule(activeSpan). Now handleResponse() is called without the span, so the `if (!span) return` in finally exits early and the route span attributes are never set. app-page and app-route both pass activeSpan. [grounded: diff] [consensus 3/3: valid=3]
The error is thrown in the 'force-dynamic' case, but its message says the route is configured with 'dynamic = error', which names the wrong setting. [grounded: diff] [consensus 3/3: valid=3]
raw comments (9)
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
1\. Static pages accept ordinary posts <code>🐞 Bug</code> <code>≡ Correctness</code>
<pre>
The app-page handler assigns <b><i>ssgCacheKey</i></b> to non-action requests without rejecting unsupported HTTP
methods. An ordinary POST to a statically generated app page therefore reaches the response cache
and can return cached HTML instead of the established 405 response with an <b><i>Allow</i></b> header.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
The app-page template no longer rejects non-GET/HEAD requests to static pages, allowing ordinary POST requests to return page content instead of 405.
## Fix Focus Areas
- packages/next/src/build/templates/app-page.ts[307-317]
- packages/next/src/server/base-server.ts[2314-2329]
## Recommended Fix
Restore the existing unsupported-method guard before cache lookup or rendering. Exempt Server Actions, resume requests, and status/error pages as before, and return 405 with `Allow: GET, HEAD` for all other non-GET/HEAD requests to static pages.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
2\. Fallback shells lose dynamic parameters <code>🐞 Bug</code> <code>≡ Correctness</code>
<pre>
The fallback revalidation branch calls <b><i>getFallbackRouteParams(pathname)</i></b> after <b><i>prepare</i></b> has
interpolated <b><i>parsedUrl.pathname</i></b> into the concrete request path. For a route such as
<b><i>/blog/[slug]</i></b>, the resulting <b><i>/blog/post</i></b> contains no parameter keys, so PPR fallback rendering
receives <b><i>null</i></b> instead of placeholder parameters and cannot postpone dynamic parameter access
correctly.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
PPR fallback revalidation derives fallback parameters from the concrete pathname rather than the dynamic route pattern, producing no placeholder parameters.
## Fix Focus Areas
- packages/next/src/build/templates/app-page.ts[726-734]
- packages/next/src/server/request/fallback-params.ts[6-25]
## Recommended Fix
Pass `normalizedSrcPage` to `getFallbackRouteParams`, matching the other fallback-shell branch and ensuring dynamic segment names are extracted from the route pattern.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
3\. Dynamic fallbacks share one cache entry <code>🐞 Bug</code> <code>≡ Correctness</code>
<pre>
The pages fallback lookup uses <b><i>srcPage</i></b>, the dynamic route definition, instead of the concrete
resolved pathname as its response-cache key. Requests for different values of the same dynamic route
consequently collide under one fallback entry and no longer use the key expected by the existing
fallback cache path.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
Pages fallback requests use the route pattern as their cache key, causing different concrete paths to share one fallback entry.
## Fix Focus Areas
- packages/next/src/build/templates/pages.ts[501-515]
- packages/next/src/server/base-server.ts[3017-3033]
## Recommended Fix
Use the concrete resolved request pathname for the fallback response-cache key, including the locale prefix where applicable, matching the established base-server fallback lookup.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
4\. Concurrent requests lose cache handlers <code>🐞 Bug</code> <code>☼ Reliability</code>
<pre>
<b><i>loadCustomCacheHandlers</i></b> marks the global handler map initialized before awaiting imports of the
configured handlers, causing concurrent callers to return immediately with an incomplete map. A
request using a custom cache kind during that interval fails with <b><i>Unknown cache handler</i></b>, and a
failed initial import also prevents subsequent requests from retrying initialization.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
Global custom cache-handler initialization becomes visible before asynchronous imports complete, allowing concurrent requests to observe missing handlers.
## Fix Focus Areas
- packages/next/src/server/route-modules/route-module.ts[270-304]
- packages/next/src/server/use-cache/handlers.ts[28-75]
## Recommended Fix
Store and await a shared initialization promise that resolves only after every configured handler is installed. Clear the promise or reset initialization state after a failed import so later requests can retry.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
5\. Wrapped page requests lose route spans <code>🐞 Bug</code> <code>◔ Observability</code>
<pre>
The active-span branch invokes <b><i>handleResponse()</i></b> without passing the available <b><i>activeSpan</i></b>, unlike
the previous invocation path. Because the render finalizer exits when its <b><i>span</i></b> argument is absent,
requests wrapped by the base server no longer receive status, route, name, or server-component
tracing attributes.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
Pages requests with an existing active span invoke response handling without that span, preventing route-specific tracing attributes from being recorded.
## Fix Focus Areas
- packages/next/src/build/templates/pages.ts[432-470]
- packages/next/src/build/templates/pages.ts[772-789]
## Recommended Fix
Call `handleResponse(activeSpan)` in the active-span branch, matching the app-page and app-route handlers and the prior pages invocation behavior.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
6\. Dynamic routes report the wrong setting <code>🐞 Bug</code> <code>≡ Correctness</code>
<pre>
The <b><i>force-dynamic</i></b> static-generation bailout constructs a <b><i>DynamicServerError</i></b> claiming that the
route uses <b><i>dynamic = error</i></b>. Users whose route correctly specifies <b><i>force-dynamic</i></b> therefore
receive diagnostics naming the opposite configuration when static generation encounters the route.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
The static-generation bailout for `force-dynamic` routes incorrectly reports that `dynamic = error` was configured.
## Fix Focus Areas
- packages/next/src/server/route-modules/app-route/module.ts[724-734]
- packages/next/errors.json[703-706]
## Recommended Fix
Change the error text to identify `dynamic = force-dynamic` and describe that the route cannot be statically generated. Regenerate the errors catalog so its message matches the corrected source.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
7\. Development requests lose fallback paths <code>🐞 Bug</code> <code>☼ Reliability</code>
<pre>
<b><i>DevServer.getStaticPaths</i></b> performs an unsynchronized read-modify-write of the shared development
prerender manifest with <b><i>fs.promises.writeFile</i></b>. Because static-path generation is coalesced only
per pathname, concurrent requests for different dynamic routes can read the same old manifest and
overwrite one another’s static-path or fallback updates, leaving handlers to make fallback decisions
from incomplete metadata.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
`DevServer.getStaticPaths` updates a shared development prerender manifest through an unsynchronized read-modify-write cycle. Concurrent static-path generation for different routes can overwrite each other’s additions, causing route handlers to observe missing static-path or fallback metadata.
## Fix Focus Areas
- packages/next/src/server/dev/next-dev-server.ts[847-853]
- packages/next/src/server/dev/next-dev-server.ts[877-900]
## Recommended Fix
Serialize all development prerender-manifest mutations through a server-level shared lock, mutex, or coalesced operation independent of pathname. Perform the read, merge, and write inside that critical section so every update reads the latest manifest state before merging its route entries, then replace the manifest file atomically.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<h3>PR Summary by Qodo</h3>
Move route response caching into generated entry handlers
<code>✨ Enhancement</code> <code>🐞 Bug fix</code> <code>🧪 Tests</code> <code>🕐 40+ Minutes</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<details>
<summary>AI Description</summary>
<dl>
<dd>
<br/>
><pre>
>• Moves response caching and delivery into generated handlers across all router types.
>• Adds fallback, revalidation, PPR streaming, redirects, and cache-header handling at entry
> boundaries.
>• Centralizes route-module cache setup, request errors, manifests, and server context.
></pre>
</dd>
</dl>
</details>
<details>
<summary>Diagram</summary>
<dl>
<dd>
<br/>
```mermaid
sequenceDiagram
actor Client
participant Handler as Entry Handler
participant Module as Route Module
participant Cache as Response Cache
participant Store as Incremental Cache
participant Renderer
Client->>Handler: Route request
Handler->>Module: Prepare context
Handler->>Module: Handle response
Module->>Cache: Resolve cache entry
Cache->>Store: Read entry
alt Cache miss or stale
Cache->>Handler: Generate response
Handler->>Renderer: Render route
Renderer-->>Handler: Render result
Handler-->>Cache: Typed cache entry
Cache->>Store: Persist entry
end
Cache-->>Module: Resolved entry
Module-->>Handler: Cached response
Handler-->>Client: HTML RSC or API
```
</dd>
</dl>
</details>
<details>
<summary>High-Level Assessment</summary>
<dl>
<dd>
<br/>
>The following are alternative approaches to this PR:
<details>
<summary><b>1. Keep orchestration in BaseServer</b></summary>
<dl>
<dd>
- ➕ Avoids duplicating response semantics across generated handlers.
- ➕ Retains one established cache and rendering control path.
- ➖ Keeps entry handlers dependent on BaseServer execution.
- ➖ Prevents route modules from fully handling standalone responses.
- ➖ Continues passing substantial state through mutable render options.
</dd>
</dl>
</details>
<details>
<summary><b>2. Introduce a shared response coordinator</b></summary>
<dl>
<dd>
- ➕ Could consolidate cache headers, revalidation, redirects, and response sending.
- ➕ Would reduce behavioral drift between Pages, App Page, and App Route handlers.
- ➖ Router-specific fallback and PPR behavior makes a common abstraction complex.
- ➖ Adds another orchestration layer during an already broad ownership migration.
</dd>
</dl>
</details>
>**Recommendation:** Moving response ownership into generated handlers is appropriate because each router has distinct output and fallback semantics, while RouteModule supplies shared cache construction and error handling. Retaining BaseServer orchestration would undermine that goal. Follow-up extraction of narrowly shared response primitives is preferable to a single generalized coordinator, especially for cache-status headers, cache-control validation, and on-demand revalidation behavior.
</dd>
</dl>
</details>
<details>
<summary> Files changed (22) <code> +2255 / -724 </code> </summary>
<dl>
<dd>
<br/>
<details>
<summary>Enhancement (11) <code> +2127 / -618 </code></summary>
<dl>
<dd>
<details>
<summary>app-page.ts<code>Move App Page caching and response delivery into the handler</code> <code>+852/-193</code></summary>
<br/>
>Move App Page caching and response delivery into the handler
>
><pre>
>• Expands the generated App Page handler to own ISR cache lookup, fallback generation, PPR postpone/resume streaming, segment prefetches, cache headers, and HTML/RSC delivery. It also handles rewritten cache keys, bot behavior, on-demand revalidation, and route-level error reporting.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-bc87cb622b355cd3ead736f9eddee557676ff9520362113061cedcbc78166cbf'>packages/next/src/build/templates/app-page.ts</a>
</details>
<details>
<summary>app-route.ts<code>Handle App Route ISR responses within the entry handler</code> <code>+239/-114</code></summary>
<br/>
>Handle App Route ISR responses within the entry handler
>
><pre>
>• Routes App Route responses through RouteModule response-cache orchestration, including cache serialization, revalidation, cache headers, and cached response reconstruction. It also validates fallback paths and reports background regeneration errors.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-9efec33ed2d8c93637c6e69a517513e4c8864b7d85294939122136c562698f62'>packages/next/src/build/templates/app-route.ts</a>
</details>
<details>
<summary>pages.ts<code>Move Pages rendering and ISR response handling into the entry</code> <code>+624/-184</code></summary>
<br/>
>Move Pages rendering and ISR response handling into the entry
>
><pre>
>• Makes the generated Pages handler responsible for cache keys, static-path fallbacks, redirects, not-found responses, data responses, cache-control headers, and final payload delivery. It preserves tracing and adds background revalidation error reporting.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-56c00e6d9d226078e70bcb2117a5a3ad8b3f2ab8d611f72cc1bd9bc88e5f012a'>packages/next/src/build/templates/pages.ts</a>
</details>
<details>
<summary>types.ts<code>Expose revalidation and server-action render flags</code> <code>+2/-0</code></summary>
<br/>
>Expose revalidation and server-action render flags
>
><pre>
>• Adds optional on-demand revalidation and possible-server-action flags to shared render options so generated handlers can pass request state into App rendering.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-99e640c5ba03d5acdad955a1bda55121a3a44ac5f77104c0473f03385e73664a'>packages/next/src/server/app-render/types.ts</a>
</details>
<details>
<summary>next-dev-server.ts<code>Persist development static paths into the prerender manifest</code> <code>+31/-2</code></summary>
<br/>
>Persist development static paths into the prerender manifest
>
><pre>
>• Writes discovered static paths and fallback configuration into the development prerender manifest. Generated handlers can then apply production-like fallback decisions during development.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-2f6fd5a9538abfaf3d5b76a82a8d1ffa029f84a36f0cdae5460520c5cfc2db6b'>packages/next/src/server/dev/next-dev-server.ts</a>
</details>
<details>
<summary>router-server.ts<code>Expose 404 rendering through router server context</code> <code>+3/-2</code></summary>
<br/>
>Expose 404 rendering through router server context
>
><pre>
>• Adds the server's render404 function to shared router context for generated handlers. Production error logging now respects quiet mode.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-37243d614f1f5d3f7ea50bbf2af263f6b1a9a4f70e84427977781e07b02f57f1'>packages/next/src/server/lib/router-server.ts</a>
</details>
<details>
<summary>router-server-context.ts<code>Type shared router-context 404 rendering</code> <code>+9/-0</code></summary>
<br/>
>Type shared router-context 404 rendering
>
><pre>
>• Extends RouterServerContext with an optional render404 callback accepting Node requests, responses, parsed URLs, and header behavior.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-0322662562abbafca8a44b769b260b2428a461a8e206f905990590527170dd05'>packages/next/src/server/lib/router-utils/router-server-context.ts</a>
</details>
<details>
<summary>request-meta.ts<code>Add minimal-mode request metadata</code> <code>+6/-0</code></summary>
<br/>
>Add minimal-mode request metadata
>
><pre>
>• Introduces a typed minimalMode request metadata flag used by entry handlers to select cache, resume, and response behavior.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-2e275fed0edd26f5ec8f13dda59234880c7bc5d4d2ea629b2f80e5bc641718c9'>packages/next/src/server/request-meta.ts</a>
</details>
<details>
<summary>index.ts<code>Track background cache regeneration with waitUntil</code> <code>+119/-108</code></summary>
<br/>
>Track background cache regeneration with waitUntil
>
><pre>
>• Allows response-cache regeneration promises to be registered with waitUntil while preserving stale-while-revalidate behavior and retry backoff. It also renames internal minimal-mode state to avoid build-time replacement.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-57e079476fe821acb43fd2600a52dd1ade532b071f6355dbc4d56fcfcc63f318'>packages/next/src/server/response-cache/index.ts</a>
</details>
<details>
<summary>types.ts<code>Allow tracing context in response generators</code> <code>+1/-0</code></summary>
<br/>
>Allow tracing context in response generators
>
><pre>
>• Adds an optional span field to response generator state for handler-owned rendering and trace attribution.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-cdee3ad3788ca17ac8dbaa342fe7e7ac4b1362cbc10b7bf22f7568302c995584'>packages/next/src/server/response-cache/types.ts</a>
</details>
<details>
<summary>route-module.ts<code>Add shared cache orchestration to RouteModule</code> <code>+241/-15</code></summary>
<br/>
>Add shared cache orchestration to RouteModule
>
><pre>
>• Adds manifest preparation, custom cache-handler loading, request-scoped IncrementalCache construction, ResponseCache ownership, and unified request-error reporting. Generated handlers can now resolve cached responses without BaseServer orchestration.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-85e921520df42ad21a6d90f68d5a65a6e31816d745f9582340472219387fe8f0'>packages/next/src/server/route-modules/route-module.ts</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Bug fix (3) <code> +17 / -8 </code></summary>
<dl>
<dd>
<details>
<summary>action-handler.ts<code>Derive forwarded action protocol from request metadata</code> <code>+7/-6</code></summary>
<br/>
>Derive forwarded action protocol from request metadata
>
><pre>
>• Uses the request's initial protocol when forwarding actions and redirect renders instead of reading protocol state from IncrementalCache. This decouples action forwarding from cache construction.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-c809d50461027cdba7c092e564818b1172133d337abc5c513f829c94c8483dc6'>packages/next/src/server/app-render/action-handler.ts</a>
</details>
<details>
<summary>resolve-routes.ts<code>Normalize missing route pathnames to root</code> <code>+2/-2</code></summary>
<br/>
>Normalize missing route pathnames to root
>
><pre>
>• Uses '/' instead of an empty string when parsed route pathnames are absent, ensuring consistent root-route matching.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-ac95049c6d4d7e5ec087ba8f7c32f056e4ba4cadfa649c52ce6dd1fadb81b68a'>packages/next/src/server/lib/router-utils/resolve-routes.ts</a>
</details>
<details>
<summary>module.ts<code>Reject force-dynamic routes during static generation</code> <code>+8/-0</code></summary>
<br/>
>Reject force-dynamic routes during static generation
>
><pre>
>• Throws a DynamicServerError when a force-dynamic App Route is encountered during static generation and records diagnostic details on the work store.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-84203f2db6b1c868f5147e60de960aa02f525fb939356cb0aa33d7d55a043831'>packages/next/src/server/route-modules/app-route/module.ts</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Refactor (6) <code> +96 / -93 </code></summary>
<dl>
<dd>
<details>
<summary>base-server.ts<code>Delegate entry-route response ownership to generated handlers</code> <code>+68/-81</code></summary>
<br/>
>Delegate entry-route response ownership to generated handlers
>
><pre>
>• Removes duplicate cache and response processing for handler-backed Pages, App Page, and App Route modules. It now supplies request metadata, invokes handlers directly, proxies development fetch metrics, and leaves legacy response-cache behavior for other paths.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-6f4291cc2bfc5073fdca12a014011769e840ee68583db1468acef075f037015a'>packages/next/src/server/base-server.ts</a>
</details>
<details>
<summary>index.ts<code>Remove request protocol from IncrementalCache state</code> <code>+0/-4</code></summary>
<br/>
>Remove request protocol from IncrementalCache state
>
><pre>
>• Eliminates the requestProtocol property and constructor option because request forwarding now reads protocol directly from request metadata.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-c990316f5df4319261936cd61b07566c5e12cd7e68c9e92f6da38a190a639154'>packages/next/src/server/lib/incremental-cache/index.ts</a>
</details>
<details>
<summary>next-server.ts<code>Initialize handler context and simplify incremental cache setup</code> <code>+20/-5</code></summary>
<br/>
>Initialize handler context and simplify incremental cache setup
>
><pre>
>• Registers a project-scoped 404 renderer for generated handlers and removes protocol plumbing from incremental-cache creation. No-fallback handling now imports the shared external error type.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-c49c4767e6ed8627e6e1b8f96b141ee13246153f5e9142e1da03450c8e81e96f'>packages/next/src/server/next-server.ts</a>
</details>
<details>
<summary>web-server.ts<code>Use shared no-fallback error and remove protocol plumbing</code> <code>+2/-2</code></summary>
<br/>
>Use shared no-fallback error and remove protocol plumbing
>
><pre>
>• Imports NoFallbackError from its runtime-neutral module and stops passing a fixed protocol into IncrementalCache.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-38e5e1dc8dbda298cbdc42c49c8d9ddcc10ccc3a58d1b122506c578fc1b09caa'>packages/next/src/server/web-server.ts</a>
</details>
<details>
<summary>adapter.ts<code>Remove obsolete edge cache protocol option</code> <code>+0/-1</code></summary>
<br/>
>Remove obsolete edge cache protocol option
>
><pre>
>• Stops supplying requestProtocol when constructing the edge adapter's IncrementalCache.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-dce9407414c80361939535961e30238fc36c549e0465bbe5c969a2dfebd00c07'>packages/next/src/server/web/adapter.ts</a>
</details>
<details>
<summary>no-fallback-error.external.ts<code>Extract a runtime-neutral no-fallback error</code> <code>+6/-0</code></summary>
<br/>
>Extract a runtime-neutral no-fallback error
>
><pre>
>• Defines NoFallbackError in a shared external module so server implementations and generated route entries can use the same fallback signal without importing BaseServer.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-02854d9f548a0ac849fbb6f33779d9a2c376a3fcf4cbbc42281abaebc399a679'>packages/next/src/shared/lib/no-fallback-error.external.ts</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Tests (1) <code> +2 / -0 </code></summary>
<dl>
<dd>
<details>
<summary>index.test.js<code>Normalize new handler frames in development error snapshots</code> <code>+2/-0</code></summary>
<br/>
>Normalize new handler frames in development error snapshots
>
><pre>
>• Strips handleResponse and doRender stack frames introduced by the new entry-handler orchestration, preserving stable user-facing error assertions.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-1f2cb866290399753cccb9a69ec9b42a6442632c088828a5df077452c5c48a7c'>test/integration/server-side-dev-errors/test/index.test.js</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Other (1) <code> +13 / -5 </code></summary>
<dl>
<dd>
<details>
<summary>errors.json<code>Register new route-cache and static-generation errors</code> <code>+13/-5</code></summary>
<br/>
>Register new route-cache and static-generation errors
>
><pre>
>• Adds invariant messages for invalid cached route kinds, unsupported streamed static responses, and dynamic route generation failures. Existing generated error identifiers are renumbered accordingly.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-58a77e62796608e78f8ef4373ddafad4dc329d2fb96df8aa0b820318cea68946'>packages/next/errors.json</a>
</details>
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<h3>Code Review by Qodo</h3>
<code>🐞 Bugs (7)</code> <code>📘 Rule violations (0)</code> <code>📜 Skill insights (0)</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<br/>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
<details>
<summary> 1. Static pages accept ordinary posts <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
>The app-page handler assigns <b><i>ssgCacheKey</i></b> to non-action requests without rejecting unsupported HTTP
>methods. An ordinary POST to a statically generated app page therefore reaches the response cache
>and can return cached HTML instead of the established 405 response with an <b><i>Allow</i></b> header.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[packages/next/src/build/templates/app-page.ts[R310-313]](https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-bc87cb622b355cd3ead736f9eddee557676ff9520362113061cedcbc78166cbfR310-R313)</code>
>
>```diff
>+ isSSG &&
>+ !supportsDynamicResponse &&
>+ !isPossibleServerAction &&
>+ !minimalPostponed &&
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The new cache-key condition excludes Server Actions but contains no HTTP method validation, while
>the former base-server path explicitly rejects these requests. Invalid or ordinary POSTs are not
>consumed by Server Action handling, so they continue into rendering.
></pre>
>
> <code>[packages/next/src/build/templates/app-page.ts[307-317]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/build/templates/app-page.ts/#L307-L317)</code>
> <code>[packages/next/src/server/base-server.ts[2314-2329]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/server/base-server.ts/#L2314-L2329)</code>
> <code>[packages/next/src/server/app-render/action-handler.ts[493-499]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/server/app-render/action-handler.ts/#L493-L499)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>The app-page template no longer rejects non-GET/HEAD requests to static pages, allowing ordinary POST requests to return page content instead of 405.
>
>## Fix Focus Areas
>- packages/next/src/build/templates/app-page.ts[307-317]
>- packages/next/src/server/base-server.ts[2314-2329]
>
>## Recommended Fix
>Restore the existing unsupported-method guard before cache lookup or rendering. Exempt Server Actions, resume requests, and status/error pages as before, and return 405 with `Allow: GET, HEAD` for all other non-GET/HEAD requests to static pages.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 2. Fallback shells lose dynamic parameters <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
>The fallback revalidation branch calls <b><i>getFallbackRouteParams(pathname)</i></b> after <b><i>prepare</i></b> has
>interpolated <b><i>parsedUrl.pathname</i></b> into the concrete request path. For a route such as
><b><i>/blog/[slug]</i></b>, the resulting <b><i>/blog/post</i></b> contains no parameter keys, so PPR fallback rendering
>receives <b><i>null</i></b> instead of placeholder parameters and cannot postpone dynamic parameter access
>correctly.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[packages/next/src/build/templates/app-page.ts[R730-733]](https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-bc87cb622b355cd3ead736f9eddee557676ff9520362113061cedcbc78166cbfR730-R733)</code>
>
>```diff
>+ pageIsDynamic &&
>+ isRoutePPREnabled &&
>+ (getRequestMeta(req, 'renderFallbackShell') || isDebugFallbackShell)
>+ ? getFallbackRouteParams(pathname)
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
><b><i>getFallbackRouteParams</i></b> extracts keys by running a route regex against its argument and returns
>null when there are no dynamic keys. The preparation path interpolates <b><i>parsedUrl.pathname</i></b>, while
>the sibling fallback-shell branch correctly passes <b><i>normalizedSrcPage</i></b>.
></pre>
>
> <code>[packages/next/src/build/templates/app-page.ts[726-734]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/build/templates/app-page.ts/#L726-L734)</code>
> <code>[packages/next/src/build/templates/app-page.ts[677-684]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/build/templates/app-page.ts/#L677-L684)</code>
> <code>[packages/next/src/server/request/fallback-params.ts[6-25]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/server/request/fallback-params.ts/#L6-L25)</code>
> <code>[packages/next/src/server/route-modules/route-module.ts[596-607]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/server/route-modules/route-module.ts/#L596-L607)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>PPR fallback revalidation derives fallback parameters from the concrete pathname rather than the dynamic route pattern, producing no placeholder parameters.
>
>## Fix Focus Areas
>- packages/next/src/build/templates/app-page.ts[726-734]
>- packages/next/src/server/request/fallback-params.ts[6-25]
>
>## Recommended Fix
>Pass `normalizedSrcPage` to `getFallbackRouteParams`, matching the other fallback-shell branch and ensuring dynamic segment names are extracted from the route pattern.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 3. Dynamic fallbacks share one cache entry <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
>The pages fallback lookup uses <b><i>srcPage</i></b>, the dynamic route definition, instead of the concrete
>resolved pathname as its response-cache key. Requests for different values of the same dynamic route
>consequently collide under one fallback entry and no longer use the key expected by the existing
>fallback cache path.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[packages/next/src/build/templates/pages.ts[R503-507]](https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-56c00e6d9d226078e70bcb2117a5a3ad8b3f2ab8d611f72cc1bd9bc88e5f012aR503-R507)</code>
>
>```diff
>+ routeModule.isDev
>+ ? null
>+ : locale
>+ ? `/${locale}${srcPage}`
>+ : srcPage,
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The template marks non-prerendered dynamic requests as fallbacks and then keys their cache lookup
>with <b><i>srcPage</i></b>. The equivalent base-server implementation uses the concrete <b><i>pathname</i></b>, and
>response-cache retrieval and persistence both depend directly on the supplied key.
></pre>
>
> <code>[packages/next/src/build/templates/pages.ts[227-240]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/build/templates/pages.ts/#L227-L240)</code>
> <code>[packages/next/src/build/templates/pages.ts[501-515]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/build/templates/pages.ts/#L501-L515)</code>
> <code>[packages/next/src/server/base-server.ts[3017-3033]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/server/base-server.ts/#L3017-L3033)</code>
> <code>[packages/next/src/server/response-cache/index.ts[95-119]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/server/response-cache/index.ts/#L95-L119)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>Pages fallback requests use the route pattern as their cache key, causing different concrete paths to share one fallback entry.
>
>## Fix Focus Areas
>- packages/next/src/build/templates/pages.ts[501-515]
>- packages/next/src/server/base-server.ts[3017-3033]
>
>## Recommended Fix
>Use the concrete resolved request pathname for the fallback response-cache key, including the locale prefix where applicable, matching the established base-server fallback lookup.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details><summary><ins><strong>View high (1)</strong></ins></summary><br/>
<details>
<summary> 4. Concurrent requests lose cache handlers <code>🐞 Bug</code> <code>☼ Reliability</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>loadCustomCacheHandlers</i></b> marks the global handler map initialized before awaiting imports of the
>configured handlers, causing concurrent callers to return immediately with an incomplete map. A
>request using a custom cache kind during that interval fails with <b><i>Unknown cache handler</i></b>, and a
>failed initial import also prevents subsequent requests from retrying initialization.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[packages/next/src/server/route-modules/route-module.ts[R278-280]](https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-85e921520df42ad21a6d90f68d5a65a6e31816d745f9582340472219387fe8f0R278-R280)</code>
>
>```diff
>+ // If we've already initialized the cache handlers interface, don't do it
>+ // again.
>+ if (!initializeCacheHandlers()) return
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
><b><i>initializeCacheHandlers</i></b> creates the global map synchronously, after which later callers return
>false. The new route-module loader then awaits dynamic imports before installing custom entries,
>while cache use throws when the requested entry is still absent.
></pre>
>
> <code>[packages/next/src/server/route-modules/route-module.ts[270-304]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/server/route-modules/route-module.ts/#L270-L304)</code>
> <code>[packages/next/src/server/use-cache/handlers.ts[32-40]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/server/use-cache/handlers.ts/#L32-L40)</code>
> <code>[packages/next/src/server/use-cache/handlers.ts[84-90]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/server/use-cache/handlers.ts/#L84-L90)</code>
> <code>[packages/next/src/server/use-cache/use-cache-wrapper.ts[598-607]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/server/use-cache/use-cache-wrapper.ts/#L598-L607)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>Global custom cache-handler initialization becomes visible before asynchronous imports complete, allowing concurrent requests to observe missing handlers.
>
>## Fix Focus Areas
>- packages/next/src/server/route-modules/route-module.ts[270-304]
>- packages/next/src/server/use-cache/handlers.ts[28-75]
>
>## Recommended Fix
>Store and await a shared initialization promise that resolves only after every configured handler is installed. Clear the promise or reset initialization state after a failed import so later requests can retry.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
</details>
<br/>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
<details>
<summary> 5. Wrapped page requests lose route spans <code>🐞 Bug</code> <code>◔ Observability</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
>The active-span branch invokes <b><i>handleResponse()</i></b> without passing the available <b><i>activeSpan</i></b>, unlike
>the previous invocation path. Because the render finalizer exits when its <b><i>span</i></b> argument is absent,
>requests wrapped by the base server no longer receive status, route, name, or server-component
>tracing attributes.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[packages/next/src/build/templates/pages.ts[R774-775]](https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-56c00e6d9d226078e70bcb2117a5a3ad8b3f2ab8d611f72cc1bd9bc88e5f012aR774-R775)</code>
>
>```diff
> if (activeSpan) {
>- return await invokeRouteModule(activeSpan)
>+ await handleResponse()
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The handler obtains <b><i>activeSpan</i></b> and enters the active branch but drops it at the call. The render
>finalizer checks <b><i>if (!span) return</i></b>, so all subsequent span attribute and name updates are skipped.
></pre>
>
> <code>[packages/next/src/build/templates/pages.ts[254-255]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/build/templates/pages.ts/#L254-L255)</code>
> <code>[packages/next/src/build/templates/pages.ts[432-470]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/build/templates/pages.ts/#L432-L470)</code>
> <code>[packages/next/src/build/templates/pages.ts[772-789]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/build/templates/pages.ts/#L772-L789)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>Pages requests with an existing active span invoke response handling without that span, preventing route-specific tracing attributes from being recorded.
>
>## Fix Focus Areas
>- packages/next/src/build/templates/pages.ts[432-470]
>- packages/next/src/build/templates/pages.ts[772-789]
>
>## Recommended Fix
>Call `handleResponse(activeSpan)` in the active-span branch, matching the app-page and app-route handlers and the prior pages invocation behavior.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 6. Dynamic routes report the wrong setting <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
>The <b><i>force-dynamic</i></b> static-generation bailout constructs a <b><i>DynamicServerError</i></b> claiming that the
>route uses <b><i>dynamic = error</i></b>. Users whose route correctly specifies <b><i>force-dynamic</i></b> therefore
>receive diagnostics naming the opposite configuration when static generation encounters the route.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[packages/next/src/server/route-modules/app-route/module.ts[R727-730]](https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-84203f2db6b1c868f5147e60de960aa02f525fb939356cb0aa33d7d55a043831R727-R730)</code>
>
>```diff
>+ if (workStore.isStaticGeneration) {
>+ const err = new DynamicServerError(
>+ 'Route is configured with dynamic = error which cannot be statically generated.'
>+ )
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The message is emitted inside the <b><i>force-dynamic</i></b> switch branch immediately after setting
><b><i>workStore.forceDynamic</i></b>. The separate <b><i>error</i></b> branch uses <b><i>dynamicShouldError</i></b>, demonstrating that
>the two settings have distinct and opposite semantics.
></pre>
>
> <code>[packages/next/src/server/route-modules/app-route/module.ts[724-734]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/server/route-modules/app-route/module.ts/#L724-L734)</code>
> <code>[packages/next/src/server/route-modules/app-route/module.ts[745-751]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/server/route-modules/app-route/module.ts/#L745-L751)</code>
> <code>[packages/next/src/server/app-render/dynamic-rendering.ts[138-146]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/server/app-render/dynamic-rendering.ts/#L138-L146)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>The static-generation bailout for `force-dynamic` routes incorrectly reports that `dynamic = error` was configured.
>
>## Fix Focus Areas
>- packages/next/src/server/route-modules/app-route/module.ts[724-734]
>- packages/next/errors.json[703-706]
>
>## Recommended Fix
>Change the error text to identify `dynamic = force-dynamic` and describe that the route cannot be statically generated. Regenerate the errors catalog so its message matches the corrected source.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 7. Development requests lose fallback paths <code>🐞 Bug</code> <code>☼ Reliability</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>DevServer.getStaticPaths</i></b> performs an unsynchronized read-modify-write of the shared development
>prerender manifest with <b><i>fs.promises.writeFile</i></b>. Because static-path generation is coalesced only
>per pathname, concurrent requests for different dynamic routes can read the same old manifest and
>overwrite one another’s static-path or fallback updates, leaving handlers to make fallback decisions
>from incomplete metadata.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[packages/next/src/server/dev/next-dev-server.ts[R895-898]](https://github.com/drape-io/crbench-qodo-2026-09/pull/60/files#diff-2f6fd5a9538abfaf3d5b76a82a8d1ffa029f84a36f0cdae5460520c5cfc2db6bR895-R898)</code>
>
>```diff
>+ if (updatedManifest !== rawExistingManifest) {
>+ await fs.promises.writeFile(
>+ pathJoin(this.distDir, PRERENDER_MANIFEST),
>+ updatedManifest
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>Static-path computation is coalesced using <b><i>staticPaths-${pathname}</i></b>, which shares work only for
>identical pathnames and allows different dynamic routes to execute concurrently. Each execution
>reads the entire shared prerender manifest and later rewrites the same file without synchronization,
>so the last writer can discard another route’s entries; route-module handlers then synchronously
>load that manifest and use the missing route or fallback metadata for request handling.
></pre>
>
> <code>[packages/next/src/server/dev/next-dev-server.ts[847-853]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/server/dev/next-dev-server.ts/#L847-L853)</code>
> <code>[packages/next/src/server/dev/next-dev-server.ts[877-900]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/server/dev/next-dev-server.ts/#L877-L900)</code>
> <code>[packages/next/src/server/route-modules/route-module.ts[159-188]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/server/route-modules/route-module.ts/#L159-L188)</code>
> <code>[packages/next/src/build/templates/pages.ts[215-241]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/build/templates/pages.ts/#L215-L241)</code>
> <code>[packages/next/src/server/dev/next-dev-server.ts[877-899]](https://github.com/drape-io/crbench-qodo-2026-09/blob/4dc38c3f02abf2e64bfc592715ff737deeb3f761/packages/next/src/server/dev/next-dev-server.ts/#L877-L899)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>`DevServer.getStaticPaths` updates a shared development prerender manifest through an unsynchronized read-modify-write cycle. Concurrent static-path generation for different routes can overwrite each other’s additions, causing route handlers to observe missing static-path or fallback metadata.
>
>## Fix Focus Areas
>- packages/next/src/server/dev/next-dev-server.ts[847-853]
>- packages/next/src/server/dev/next-dev-server.ts[877-900]
>
>## Recommended Fix
>Serialize all development prerender-manifest mutations through a server-level shared lock, mutex, or coalesced operation independent of pathname. Perform the read, merge, and write inside that critical section so every update reads the latest manifest state before merging its route entries, then replace the manifest file atomically.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-context:start -->
<details><summary><strong>Context sources</strong></summary>
<div>Review mode: <code>🧠 Deep</code>: This is a high-density, cross-cutting rewrite of Next.js request handling, caching, ISR/PPR, routing, and error paths across 22 files, with many independent logic sites and substantial regression potential.</div>
<!-- qodo-context:end -->
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-daily-tip:start -->
<details>
<summary><strong>Tip of the day</strong></summary>
<br/>
<pre>💡 Did you know, you can reply 'qodo' on any finding to push back, ask questions, or dig deeper</pre>
<a href="https://docs.qodo.ai/tips-and-tricks">More tips ↗</a> | <a href="https://app.qodo.ai/configurations?tab=display-preferences">Customize Qodo ↗</a> | <a href="https://docs.qodo.ai">Qodo docs ↗</a>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-daily-tip:end -->
<!-- https://github.com/drape-io/crbench-qodo-2026-09/commit/4dc38c3f02abf2e64bfc592715ff737deeb3f761 -->
<a href="https://www.qodo.ai"><img src="https://www.qodo.ai/wp-content/uploads/2025/03/qodo-logo.svg" width="80" alt="Qodo Logo"></a>