Skip to content

turbo-tasks: fail executions that use a cell of a task GC collected mid-execution - #102195

Draft
lukesandberg wants to merge 2 commits into
canaryfrom
claude/gc-in-progress-reader
Draft

lukesandberg wants to merge 2 commits into
canaryfrom
claude/gc-in-progress-reader

Conversation

@lukesandberg

Copy link
Copy Markdown
Contributor

What?

With GC enabled, a task can still be executing while GC collects the task that owns a cell it is using. Two code paths hit this and crashed with an internal panic. Both now fail the task's execution with the same "task no longer exists (it was garbage collected)" error that cell reads already return:

  • Dropping a KeyedReadRef or LazyReadRef whose cell's owner was collected. This used to panic with task_pair, MustExist.
  • Vc::drop_content_hint on a cell whose owner was collected. This used to panic with task, MustExist.

Why?

GC only waits for in-flight backend operations, not for task executions, so it can run while a task is mid-execution. It never collects a task that is in progress, and its collectibility check deliberately ignores cell dependents. As a result, when the owner of a cell loses its last parent, GC collects it even while another, still-executing task holds that cell through a ResolvedVc argument or a KeyedReadRef. The typical case is a parent that drops both tasks: the reader keeps running and later touches the collected owner.

Reads already handle this by returning an error. These two paths opened the owner with a "must exist" open instead, which panics once a snapshot has written the owner's tombstone and eviction has dropped it from memory. Failing the reader is the right outcome, because its parent is usually discarding it anyway.

How?

  • drop_task_cell_content_hint now returns Result. The backend checks for the owner with try_task and returns the collected-task error if it is gone.
  • refine_provisional_cell_dependency now returns Result. The backend checks the owner with try_task before calling task_pair. That check is race-free: GC is excluded until the operation's context is dropped, and task_pair restores an owner that was only evicted. When the owner is gone, the backend also removes the reader's half of the provisional edge (GC normally removes it already) and returns the error.
  • The drops can't return an error, so turbo-tasks gives each execution an error slot (ProvisionalReadDependency::fail_execution). When the execution completes, a successful result is replaced by that error. The first error is kept, and an execution that already failed keeps its own error.

The conversion of the remaining provisional edges at task completion needed no change: it only follows edges the reader still has, and GC removes those when it collects the owner.

Verification

  • New tests/gc_in_progress_reader.rs covers both paths. Each test holds the reader in its execution, disconnects and collects the owner, evicts it, then releases the reader. Both tests reproduced the panics before the fix, and they passed on 5 repeated runs after it.
  • cargo nextest r -p turbo-tasks -p turbo-tasks-backend: all 645 tests pass.
  • cargo check -p turbopack-ecmascript, the only non-test caller of drop_content_hint.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Vercel Agent finished reviewing your changes and found no issues.
37f92a4 • Sun, 22 Nov 2026 18:44:26 GMT • 1m 6s • Details

Checked (3)

     Check Location
Collected cell owners produce an error rather than a must-exist open in both changed backend paths.
Traced try_task through AllowMissing handling for deleted and absent storage entries, and checked provisional-edge cleanup.
mod.rs:1254
Deferred drop errors replace successful execution results without overwriting existing execution errors.
Traced both read-ref Drop implementations into fail_execution and the result match after local tasks are awaited.
manager.rs:1937
The regression scenarios hold the reader until after an explicit GC snapshot and eviction.
Traced gate ordering, selector disconnection, Full eviction configuration, and the collected-task error assertion; tests were not run because Cargo is unavailable.
gc_in_progress_reader.rs:106
Review steps

     Step Time
Preparing the workspace 15.9s
Analyzing the changes 47.5s
Finalizing the review 2.9s

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: 74996a0
View workflow run

@github-actions github-actions Bot added created-by: Turbopack team PRs by the Turbopack team. Turbopack Related to Turbopack with Next.js. labels Nov 22, 2026
lukesandberg and others added 2 commits November 22, 2026 10:40
…id-execution

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lukesandberg
lukesandberg force-pushed the claude/gc-in-progress-reader branch from 74996a0 to 37f92a4 Compare November 22, 2026 18:43

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

created-by: Turbopack team PRs by the Turbopack team. Turbopack Related to Turbopack with Next.js.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant