next.js
0748ae8a - turbo-tasks-backend: don't panic reconstructing an error chain into a collected task (#102231)

Commit
13 hours ago
turbo-tasks-backend: don't panic reconstructing an error chain into a collected task (#102231) ### What? With GC enabled, a long-running `next dev` session could abort with: ``` task TaskId … (task, MustExist): task is missing in memory or persistent storage — a stale reference to an already-collected or never-created task ``` Reading a task's output now returns its error with "Error no longer available" as the innermost cause when that error's source task was garbage collected. It no longer panics. ### Why? A task that fails because it awaited a failed task doesn't copy that error into its output. It stores a `TaskError::TaskChain`: the ids of the tasks the error passed through. The last `TaskId` points at the task whose output holds the actual error, and reading the output rebuilds the error from there. Those ids are not references GC knows about. When the task at the end of the chain is dropped by its parent, GC collects it. Meanwhile the failed task can keep its stale error output, because in dev a dirty task isn't recomputed until something needs it. An eventually consistent read of that output then rebuilt the error and opened the collected task with `ctx.task()`, which panics once GC+Eviction has dropped the task from memory. This reproduced in a GC stress run of a large app (vercel-marketing): random edits plus `compile_route` calls, with GC verification and full eviction. It hit the panic at this call site after about a minute. Over 2.3 hours, 1,151 verified GC passes and about 1.5M collected tasks, it was the only failure. ### How? `task_error_to_turbo_tasks_execution_error` opens the last task of the chain with `try_task`. A missing task takes the existing "Error no longer available" fallback, which already covers a source error that went away through eventual consistency. The task names in the chain were already resolved with `try_task`, so the collected task shows up as `unknown`. ### Verification - New `tests/gc_error_chain.rs` reproduces it across a session restart. `outer` fails with the chain `[middle, inner]`. In the next session nothing connects `outer`, `middle` stops calling `inner`, and GC collects and evicts `inner`. An eventually consistent read of `outer`'s stale output then panicked at this call site (`task, MustExist`) before the fix. - `cargo nextest r -p turbo-tasks -p turbo-tasks-backend` passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- NEXT_JS_LLM --> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Author
Parents
Loading