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

Turbopack Dev: Route Handler Compilation After Pages Causes Linear Memory Blow-Up (Regression In 16.3.0-Canary.101)

Turbopack dev server consumes ~16 MB × number of previously compiled pages for each subsequent route handler compilation. Ordering matters: requesting handlers before pages avoids the blow-up. Regression introduced in 16.3.0-canary.101.

criticalConfidence 68%Next.jsReact Server ComponentsHydrationRoute HandlersAffected V16.3.0-Canary.101Affected V16.3.0Affected V16.3.4Affected V16.3.5

Origin Analysis

A Turbopack incremental graph bug introduced by one of the server-HMR changes (#94948, #95661, #95795, #95546) causes each route handler compilation to include all previously compiled page modules, leading to linear memory growth with page count.
1. Reproduce with provided script: node gen.mjs generates 50 pages and 34 handlers. 2. Run `node drive.mjs pages-first` (pages then handlers) -> RSS grows from 1.1 GB to ~29 GB. 3. Run `node drive.mjs handlers-first` -> RSS stays ~1.4 GB. 4. Confirm regression with bisect: 16.3.0-canary.100 good, 16.3.0-canary.101 bad.

Fixing Code Block

Edge Case Audit

Clearing the cache may increase compile latency for subsequent requests and can introduce race conditions under concurrent handler requests. This is not a root-cause fix; users should test thoroughly and rollback by removing the patch if performance degrades. Upstream fix should be preferred.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state