Repository navigation
turbo-tasks: fail executions that use a cell of a task GC collected mid-execution - #102195
Draft
lukesandberg wants to merge 2 commits into
Draft
lukesandberg wants to merge 2 commits into
lukesandberg wants to merge 2 commits into
Conversation
Contributor
|
Checked (3)
|
Contributor
Tests PassedCommit: 74996a0 |
lukesandberg
commented
Nov 22, 2026
…id-execution Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lukesandberg
force-pushed
the
claude/gc-in-progress-reader
branch
from
November 22, 2026 18:43
74996a0 to
37f92a4
Compare
This branch has not been deployed
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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?
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:
KeyedReadReforLazyReadRefwhose cell's owner was collected. This used to panic withtask_pair, MustExist.Vc::drop_content_hinton a cell whose owner was collected. This used to panic withtask, 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
ResolvedVcargument or aKeyedReadRef. 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_hintnow returnsResult. The backend checks for the owner withtry_taskand returns the collected-task error if it is gone.refine_provisional_cell_dependencynow returnsResult. The backend checks the owner withtry_taskbefore callingtask_pair. That check is race-free: GC is excluded until the operation's context is dropped, andtask_pairrestores 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.turbo-tasksgives 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
tests/gc_in_progress_reader.rscovers 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 ofdrop_content_hint.🤖 Generated with Claude Code