Fix startTime and shutdown delivery of forwarded Turbopack trace spans (#98426)
before: <img width="1358" height="313" alt="Bildschirmfoto 2026-09-09 um 14 33 59" src="https://github.com/user-attachments/assets/69c2dc9c-06f1-4df1-b5eb-e6878f2abe32" /> after: <img width="1273" height="207" alt="Bildschirmfoto 2026-09-09 um 16 32 57" src="https://github.com/user-attachments/assets/a601e1c6-c0b8-425f-b977-b58d92289ab6" /> ## Summary Two fixes for Turbopack compilation events forwarded to the JS trace (`.next/trace`). The span-forwarding work stacks on top of this PR. - **`Span.manualTraceChild` serialized the event recording time as `startTime`** instead of the supplied epoch start, so forwarded spans rendered shifted forward by their own duration and overflowed their parent span. `startTime` now reflects the supplied start. - **Compilation events were lost at build shutdown**: `CompilationEventQueue` delivered events via an untracked `tokio::spawn`, and the build teardown aborted the events subscription right after `project.shutdown()` resolved, so shutdown-time events (e.g. `turbopack-persistence` on cold builds, where it is the only persistence event since builds use `ReadWriteOnShutdown`) were discarded whenever delivery lost the race. The queue now tracks in-flight deliveries and flushes/closes subscriber channels at the end of `stop_and_wait`, and the build waits for the subscription to drain before aborting it. ## Verification - New `trace.test.ts` unit test: a `manualTraceChild` span started in the past keeps its own start time (fails before the fix, passes after). - New `message_queue::test_flush_and_close` unit test: events are delivered before the channel closes; post-close subscriptions replay history and close. - `cargo check` / `cargo test -p turbo-tasks --lib message_queue`, root `pnpm typescript`. - The stacked PR on top verifies end-to-end that `turbopack-persistence` is now emitted on every cold build. <!-- NEXT_JS_LLM --> <!-- fleet 107de4c7-6206-422b-a422-9cc8d7047774 --> --------- Co-authored-by:vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Showing
Please
register
or
sign in
to comment