Deopt durable use cache entries on dynamic process.env access (#102094)
### What?
A durable `"use cache"` function no longer gets durability metadata in
the server reference manifest when its module subgraph contains a
non-statically analyzable `process.env` access (for example
`process.env[key]`, or passing `process.env` to a function). Without
durability metadata, the runtime falls back to cache keys based on the
build/deployment ID, so these entries aren't reused across deployments.
Root param dependencies are still emitted.
Stacked on #102093, which adds `EnvVarInfo.runtime_all`.
### Why?
Durable entries are keyed by the code hash plus the values of the
runtime env vars the function's subgraph reads. When some module may
read *any* env var, that list is incomplete. A cache entry could then be
reused by a deployment with different env values and return wrong data.
### How?
- `compute_subtree_content_hash` (in
`crates/next-api/src/server_actions.rs`) marks a subgraph that contains
a module with `EnvVarInfo::runtime_all`. The manifest generation then
leaves out the worker's `durability` key and the action's `durability`
map entry.
- `next/dist/server/use-cache/use-cache-wrapper.js` (and its `dist/esm`
variant) is exempt. It's part of every `"use cache"` subgraph, and it
reads `process.env[k]` dynamically, but only to hash the values of the
env vars listed in the durability metadata. Without the exemption, every
function would lose durability. Its statically named env reads are still
tracked.
- `TURBOPACK_PRINT_USE_CACHE_SUBTREE=1` now marks modules with a dynamic
env access.
### Verification
- `pnpm test-start-turbo
test/production/app-dir/use-cache-code-hash/use-cache-code-hash.test.ts`:
18 passed. The existing `app/env-dynamic` fixture (which passes
`process.env` to a function) now has no durability, while all other
functions keep theirs.
- `pnpm test-start-turbo
test/production/app-dir/use-cache-cross-deployment/use-cache-cross-deployment.test.ts`
(existing test, confirms durable entries still work): 26 passed, 3
skipped (unchanged). `should recompute when runtime env var truthiness
changes` timed out at 60s with a locally built debug (unoptimized)
native binary, because it runs five builds. With the timeout temporarily
raised, it passed in 86s.
- `cargo clippy -p next-api`, `cargo fmt --check`
<!-- NEXT_JS_LLM -->
<!-- fleet 84a68acb-8a0a-4cf5-89c8-4dd63b2a53a6 -->
---------
Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: vercel-fleet <fleet@vercel.com>