turbo-tasks-gc: Invalidating a deleted task should be a no-op - #98614
Draft
lukesandberg wants to merge 1 commit into
Draft
turbo-tasks-gc: Invalidating a deleted task should be a no-op#98614lukesandberg wants to merge 1 commit into
lukesandberg wants to merge 1 commit into
Conversation
lukesandberg
added this pull request to stack #98592
September 13, 2026 17:21
Contributor
Failing test suitesCommit: 4e3ed32 | About building and testing Next.js
Expand output● instant-nav-panel › SPA captures › should capture when CookieStore writes are not reflected in document.cookie |
lukesandberg
commented
Sep 13, 2026
lukesandberg
commented
Sep 13, 2026
Comment on lines
+132
to
+141
| /// Opens a task the caller holds only a **weak** reference to, returning `None` if it is gone. | ||
| /// | ||
| /// "Gone" covers both a task that exists in neither memory nor persistent storage and one that | ||
| /// is soft-deleted but still resident: a weak holder must not distinguish them, since only the | ||
| /// timing of the next eviction separates the two. | ||
| /// | ||
| /// Use this where a stale reference is *expected* rather than a bug — notably invalidators, | ||
| /// which a `State` keeps by raw [`TaskId`] and which GC does not scrub, so the reader they name | ||
| /// may have been collected long before the state is mutated. Everywhere else, prefer | ||
| /// [`Self::task`]: silently skipping a task that was supposed to exist hides graph corruption. |
Contributor
Author
There was a problem hiding this comment.
simplify comment
lukesandberg
commented
Sep 13, 2026
| // Soft-deleted but still resident: GC has already unlinked this task and eviction will drop | ||
| // it outright. Report it as gone so callers see one state rather than a window that depends | ||
| // on snapshot timing — and so they cannot revive a tombstone by writing to it. | ||
| if task.task.flags.deleted() { |
Contributor
Author
There was a problem hiding this comment.
this condition should be part of open_task, it should not attempt to restore deleted tasks
lukesandberg
commented
Sep 13, 2026
| let mut roots = Vec::new(); | ||
| self.for_each_resident_persistent_in_shard(index, |task_id, storage| { | ||
| if storage.gc_is_root() { | ||
| if !task_id.is_transient() && storage.gc_is_root() { |
Contributor
Author
There was a problem hiding this comment.
is this diff in the wrong PR?
lukesandberg
force-pushed
the
gc-09-weak-access
branch
from
September 13, 2026 18:49
c89c583 to
9bcddd7
Compare
Some references to a task outlive the task. A `State` keeps its readers by raw `TaskId` and GC does not scrub those lists, so mutating a state can try to invalidate a reader that was collected long before. Today that panics: the open is `MustExist`, which is right for a graph edge but wrong for a reference the holder was never promised would stay valid. Add a third access mode. `TaskAccess::Weak` / `ExecuteContext::try_get_task` return `None` both when a task exists nowhere and when it is soft-deleted --- a weak holder cannot tell those apart, since only the timing of the next eviction separates them. The soft-delete check happens before the restore attempt, so a weak open never pays disk I/O to rehydrate a tombstone. Only invalidator-driven invalidation is weak. `make_task_dirty` keeps its `MustExist` open for invalidation that originates inside the graph --- task completion, cell updates, a collectibles change --- where the id came from an edge that is supposed to still be valid and a miss means corruption. The `InvalidateOperation::MakeDirty` path, which is what `Invalidator::invalidate` drives, uses the new weak variant. Removing the entry that a weak open had to materialize needs care. `Storage::access_mut` discards the `OccupiedEntry` that `entry()` produced, and a plain `RefMut` holds only `&mut V` --- the hashtable slot is unreachable through it, so removal would cost a second write lock on the same shard. Add `access_entry_mut`, which keeps the entry, and `TaskEntryGuard::discard`, which removes it under the lock already held. `StorageWriteGuard` cannot simply hold an entry instead: `access_pair_mut` builds guards from `get_disjoint_mut`, which has none to give. Left behind, that entry is not inert. It is indistinguishable from a live task that has not been restored yet, so GC treats it as collectible and deletes it, producing a `Delete` snapshot item for a task with no persistent task type. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
lukesandberg
force-pushed
the
gc-09-weak-access
branch
from
September 13, 2026 19:14
9bcddd7 to
4e3ed32
Compare
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.
Make invalidating deleted tasks a no-op.
Invalidators now represent a 'weak' reference to a task, and invalidations don't assert task existence. We know that the task exists when the invalidator is created but by the time an invalidation occurs it might not exist anymore. So treat the dependency as weak.
Take care to not create 'blank' tasks when querying for them, this can confuse assertions that occur later.