← Back to Pull requests

feat: project-defined side-effects cache keys #18584

Closed
unknown closed this pull request without merging on Nov 30, 2026 21:25 UTC
View on GitHub
unknown unknown commented on Nov 30, 2026 17:48 UTC
Author

<!-- A maintainer will only start reviewing once CodeRabbit has approved and
CI is green. Please wait for those to pass before expecting human review. -->

Summary

Implements the RFC Project-defined side-effects cache keys.

sideEffectsCache:
  key:
    env: [npm_config_runtime, npm_config_target, npm_config_arch, npm_config_disturl]
    excludeNodeVersion: true

  • key.env: pnpm hashes the listed names and values (pnpm's environment with extraEnv applied) and appends ;env=<hash> to the local key and the remote input key. Built packages and their dependents also get the hash in their global virtual store slot.

  • key.excludeNodeVersion: the host part becomes <platform>;<arch>, with no Node.js detection. A package's own node@runtime: pin no longer replaces it (unresolved question 2). The remote tier presents and publishes compatibility tags without the Node.js dimension, such as pnpm:v1:linux-x64-glibc2.44.

  • With neither field set, no cache key, slot path, remote input key or layout-cache fingerprint changes.
  • Where it lives

  • pnpm-graph-hasher: the env_hash argument of calc_dep_state, calc_dep_state_input_key and calc_graph_node_hash (on BuildRequired). The hash is kept separate from the host part, because the slot hash replaces the host part with a package's own runtime pin. Also calc_env_hash and engine_name_without_node.

  • pnpm-shared-artifact-protocol: node_major: Option<u32> in the platform structs. Tags with three dimensions parse and rank, and their scope keys are <os>-<arch>. pnpr reads this vocabulary from the same crate.

  • pnpm-executor: is_script_reserved_env_name, which lists the names pnpm sets or removes for a script, and configured_env_value, an extraEnv-over-process lookup that is case-insensitive on Windows. Of two extraEnv spellings of one name, the one that sorts last wins, in the script environment and in the key alike. The pipeline task cache's env now uses the same lookup, which fixes its case-sensitive extraEnv match on Windows.

  • pnpm-config: SideEffectsCacheKeySettings, whose fields overlay one by one. ForEveryPackage<T> rejects the per-package map form with a clear error. SideEffectsCacheSetting gets a hand-written deserializer so that the error is not hidden by "did not match any variant". The hook input keeps the object form when key is set.

  • pnpm-deps-restorer: SideEffectsCacheKey::from_config is the single place the key is computed. The engine-name resolvers, the build phase, cached builds, VirtualStoreLayout and its fingerprint, the directory-clone cache and the remote tier all read it.

  • pnpm-package-manager: the workspace state records sideEffectsCacheExcludeNodeVersion and sideEffectsCacheEnvHash, both only when set. A change is drift: it skips the up-to-date shortcut and becomes PresentBuilds::Replaced, so the hoisted linker imports present packages that build again before it restores or builds them. An install that does not rebuild every project under today's key records one the next install sees as a change: a filtered install records a mixed marker, and an install under --ignore-scripts keeps the recorded key (the hoisted linker then also keeps its present builds). Install and rebuild reject a reserved name with ERR_PNPM_SIDE_EFFECTS_CACHE_KEY_RESERVED_ENV.

  • pnpm-cli: pnpm store status applies updateConfig (separate patch changeset). pnpm dlx and pnpm's own engine install drop the key.
  • Unresolved questions of the RFC

    | Question | Decision here |
    |---|---|
    | 1. Omitted read/write in hook output or the env object | Keeps the current value. An omitted gate in pnpm-workspace.yaml is still true. |
    | 2. excludeNodeVersion vs a package's own runtime pin | The pin is ignored as well. |
    | 3. Which slots get the env hash | The build-required set, which includes dependents. |
    | 4. Unset variable | Hashed as unset, no failure. |
    | 5. Project-local node_modules | The isolated linker already restores or re-runs the build once the drift forces a full install (covered by a test). The hoisted linker imports a present package that builds again (PresentBuilds::Replaced). |
    | 6. pnpm dlx | Ignores both fields. |
    | 7. --side-effects-cache flags | Set only read/write. A hook's key still applies. |
    | 8. pnpr without the new tags | Not implemented. A rejected lookup is a cache miss, as before. Warning once and skipping publication is left as a follow-up. |
    | 9. excludeNodeVersion without env | Allowed. The docs warn about it. |
    | 11. Reserved names | Fail. This includes NODE_OPTIONS and NODE_PATH, which the install rewrites for its build scripts. |

    Verification

  • Unit tests in graph-hasher, shared-artifact-protocol, executor, config, deps-restorer (including a remote restore filed under <platform>;<arch>;format=2;…;env=<hash> and the layout-cache fingerprint) and package-manager.

  • CLI tests in side_effects_cache_key.rs:

  • - Two projects that differ in a listed variable build their own, with and without the global virtual store.
    - Equal values share a build.
    - A value set by an updateConfig hook takes part in the key.
    - A changed variable replaces the linked build under the isolated linker, the hoisted linker and the global virtual store.
    - store status agrees with install on a value a hook sets.
    - A filtered install leaves the change to the next full install, including a round trip back to the first key.
    - An install under --ignore-scripts keeps the build until one with scripts.
    - A reserved name is rejected.
  • I checked that the hoisted, filtered-install, --ignore-scripts and store status tests fail without their fixes.

  • The repeat_install_read_set / repeat_install_records::opens tests could not run locally because the machine has no inotify instances left (inotify_init1: Too many open files before pnpm starts). CI will run them.
  • Checklist

  • Added a changeset (pnpm changeset) if this PR changes any published

  • package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.

  • Updated the documentation if needed.
  • ---
    Written by an agent (Claude Code, claude-opus-5-5).

    🤖 Generated with Claude Code

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    New Features
    Configure side-effects cache keys with selected environment variables, so builds with different values use separate cache entries.
    Optionally exclude the Node.js major version from cache compatibility while retaining platform and architecture checks.
    Bug Fixes
    pnpm store status now applies configuration hooks before checking store status.
    Installs recognize cache-key changes and update builds and cache entries accordingly.
    Pipeline environment inputs match extraEnv names regardless of case on Windows.
    Omitted read or write settings in environment or hook configuration preserve their current values.
    Documentation
    Added guidance on cache-key settings, compatibility tags, and Nix development shells.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: zkochan Review duration: 216m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #18584"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%
    Repository