simplify session dependent tasks and add TTL support#91729
Merged
Conversation
Contributor
Tests Passed |
Merging this PR will degrade performance by 3.5%
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 |
bgw
approved these changes
Mar 21, 2026
Member
bgw
left a comment
There was a problem hiding this comment.
Please update turbo-tasks/function.md with information about the new parameter
bgw
reviewed
Mar 21, 2026
5d52480 to
bbb97c0
Compare
55308e3 to
1a7464a
Compare
1a7464a to
d0d5a9f
Compare
Contributor
Author
Merge activity
|
lukesandberg
added a commit
that referenced
this pull request
Apr 3, 2026
This reverts commit fe99f0d.
lukesandberg
added a commit
that referenced
this pull request
Apr 3, 2026
#92320) This is causing OOMs in some applications running with a persistent cache See discussion: https://vercel.slack.com/archives/C03EWR7LGEN/p1775159630054759 The issue appears to be invalidating the chunk graph in an odd way that causes us to allocate an ~infinite number of error strings
lukesandberg
added a commit
that referenced
this pull request
Apr 3, 2026
lukesandberg
added a commit
that referenced
this pull request
Apr 3, 2026
lukesandberg
added a commit
that referenced
this pull request
Apr 4, 2026
lukesandberg
added a commit
that referenced
this pull request
Apr 6, 2026
lukesandberg
added a commit
that referenced
this pull request
Apr 6, 2026
lukesandberg
added a commit
that referenced
this pull request
Apr 7, 2026
lukesandberg
added a commit
that referenced
this pull request
Apr 7, 2026
lukesandberg
added a commit
that referenced
this pull request
Apr 8, 2026
This was referenced Apr 8, 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.

Summary
Three related improvements to turbo-tasks session-dependent task handling:
1. Make
session_dependenta function attributePreviously, tasks called
mark_session_dependent()at runtime to flag themselves. This PR makes it a compile-time#[turbo_tasks::function(session_dependent)]attribute instead. Benefits:mark_session_dependent()call needed — the attribute is declarative and statically checked.mark_session_dependent(),mark_own_task_as_session_dependent(), and thesession_dependentfield fromInProgressStateInner. The backend now readsis_session_dependentdirectly from theNativeFunctionmetadata viaTaskGuard::is_session_dependent().2. Fix fetch to respect HTTP
Cache-ControlheadersPreviously,
fetchresults were cached indefinitely meaning results would never be refreshed (unless the cache was invalidated). Now they aresession_dependentwith a TTL to ensure we respect the http settings (e.g. Google Fonts withmax-age=86400).New two-task pattern:
fetch_inner( NOTsession_dependent): Performs the HTTP request, grabs anInvalidatorfor itself, and returns the response + invalidator + absolute deadline. Cached across sessions.fetch(network,session_dependent): Reads the cachedfetch_innerresult and spawns a timer to invalidate when the TTL expires.On warm cache restore,
fetchre-executes (session-dependent), reads the persisted deadline fromfetch_inner's cached result, computes remaining TTL, and spawns a timer — no HTTP request unless the TTL has already expired. Mid-session, the timer fires and triggers a re-fetch.Error handling: On fetch failure,
fetch_innertakes a dependency onCompletion::session_dependent()so transient errors (network down, DNS failure) are retried on the next session without busy-looping.3. Drop
TransientStatein favor of inline solutionTransientStatewas only used in one place (EcmascriptModuleAsset::last_successful_parse) and brought unnecessary complexity — it registered invalidators and calledmark_session_dependent()on every read. Replaced with a simpleTransientCache<T>local toturbopack-ecmascriptthat is just aMutex<Option<T>>with#[bincode(skip)].Test Plan
turbo-tasks-fetch/tests/fetch.rs:ttl_invalidates_within_session— mock server returnsmax-age=1, body changes, verifies re-fetch after TTLttl_invalidates_on_session_restore— fetches with TTL, stops TT, waits for expiry, warm restores with new TT, verifies re-fetcherrors_retried_on_session_restore— server returns 500, stops TT, fixes server, warm restores, verifies successcargo check -p turbo-tasks -p turbo-tasks-backend -p turbo-tasks-fetch