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

Fix Rust Panic In Next Dev With Rspack When Source-Mapping During Rebuild

Next.js dev server using rspack panics and aborts when error overlay or browser log forwarding requests original stack frames during a rebuild, due to stale compilation handle aliasing the in-progress compilation.

highConfidence 95%Next.jsReact Server Componentsnext buildTurbopackAffected V16.3.3Affected V16.3.4Affected V16.4.0-Canary.15

Origin Analysis

In middleware-webpack.ts, getModuleById accesses compilation.modules and chunkGraph.getModuleId without checking if the compiler is rebuilding. Under rspack, Stats.compilation is a raw pointer to the underlying Rust compilation object which is replaced during rebuild, leading to dereferencing stolen StealCell artifacts and panic.
1. Clone https://github.com/Dwlad90/next-rspack-stale-compilation-repro 2. Run npm install 3. Run npm run generate 4. Run npm run repro Alternatively, start next dev with rspack, open a page with console.error, and edit files repeatedly.

Fixing Code Block

Edge Case Audit

This fix relies on watcher.running being accurately set by the bundler. It may cause source maps to be temporarily unavailable during rebuilds, but requests will retry later. If watcher implementation changes or running is not updated synchronously, the guard could be bypassed. Also, multiple compilers (e.g., client/server) are not individually accounted for; but in dev mode with a single compiler this is fine. Rollback: remove the guard, but then the panic returns. No breaking changes to API.

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