turbo-tasks: Fix recomputation loop by allowing cell cleanup on error during recomputation#92725
Merged
Merged
Conversation
… during recomputation Normally, cell cleanup is skipped when a task errors because the error is assumed to be a transient eventual-consistency issue (reading stale inputs). Keeping old cell data avoids "cell no longer exists" errors for dependents. During recomputation (task re-executing without being dirty), however, nothing has changed, so the error is not transient. Skipping cell cleanup in this case leaves stale cells that trigger further recomputations, creating an infinite loop. Fix: allow cell_type_max_index updates and cell data removal to proceed during recomputation even when the result is an error. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Tests Passed |
Merging this PR will improve performance by 3.46%
Performance Changes
Comparing Footnotes
|
Contributor
Stats from current PR✅ No significant changes detected📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📎 Tarball URL |
mischnic
approved these changes
Apr 13, 2026
Contributor
|
Is there any test we could write for this? Forcing a recomputation of an error's task deep in a graph? |
andrewimm
pushed a commit
that referenced
this pull request
Apr 15, 2026
… during recomputation (#92725) ### What? Fix an infinite recomputation loop in turbo-tasks by allowing cell cleanup to proceed during recomputation even when the task result is an error. ### Why? When a task errors during normal execution, cell cleanup is intentionally skipped. The rationale is that errors during normal execution are often transient eventual-consistency issues caused by reading stale inputs — keeping old cell data prevents "cell no longer exists" errors for dependent tasks that are reading those cells. However, during **recomputation** (a task re-executing without being marked dirty), nothing about its inputs has changed. Any error it produces is therefore not transient. If cell cleanup is skipped in this case, stale cells remain in place, which trigger further recomputations, which produce further errors, which skip further cleanups — creating an infinite loop. ### How? - Detect whether a task execution is a recomputation by checking `task.is_dirty().is_none()` at completion time (a recomputing task was not dirty when it started executing). - Propagate `is_recomputation` through `TaskExecutionCompletePrepareResult` to both `task_execution_completed_prepare` and `task_execution_completed_cleanup`. - In both places where cell cleanup is gated on `result.is_ok()` / `!is_error`, extend the condition to also allow cleanup when `is_recomputation` is true. This ensures that stale cells produced by a erroring recomputation are cleaned up, breaking the infinite loop. <!-- NEXT_JS_LLM_PR --> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This was referenced Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Fix an infinite recomputation loop in turbo-tasks by allowing cell cleanup to proceed during recomputation even when the task result is an error.
Why?
When a task errors during normal execution, cell cleanup is intentionally skipped. The rationale is that errors during normal execution are often transient eventual-consistency issues caused by reading stale inputs — keeping old cell data prevents "cell no longer exists" errors for dependent tasks that are reading those cells.
However, during recomputation (a task re-executing without being marked dirty), nothing about its inputs has changed. Any error it produces is therefore not transient. If cell cleanup is skipped in this case, stale cells remain in place, which trigger further recomputations, which produce further errors, which skip further cleanups — creating an infinite loop.
How?
task.is_dirty().is_none()at completion time (a recomputing task was not dirty when it started executing).is_recomputationthroughTaskExecutionCompletePrepareResultto bothtask_execution_completed_prepareandtask_execution_completed_cleanup.result.is_ok()/!is_error, extend the condition to also allow cleanup whenis_recomputationis true.This ensures that stale cells produced by a erroring recomputation are cleaned up, breaking the infinite loop.