Skip to content

refactor(resolving-npm-resolver): move metadata cache decisions into one policy module - #17024

Merged
zkochan merged 1 commit into
mainfrom
fix-146
Oct 17, 2026
Merged

zkochan merged 1 commit into
mainfrom
fix-146

Conversation

@zkochan

@zkochan zkochan commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Summary

First step of pnpm/tasks#146 (Related to pnpm/tasks#146), in pnpm v12 only. The request shape, the mirror header writes, and the uncacheable gate now live in one pure module, metadata_cache_policy. There is no behavior change.

Before, these decisions were spread over several places:

Decision Before After
Accept header, validators, Cache-Control: no-cache FetchAttempt::metadata_request + stored_full_etag DocumentKind::for_mirror, accept, revalidation
Which tag field records a fetched document DecodeMeta::persist, persist_upgraded_to_mirror (two constructors) MirrorWrite::headers (sole writer for fetched documents)
ETag / Cache-Control / Content-Type read off a 2xx, normalization DecodeMeta and document_from_response, separately MirrorWrite::on_response
Remove an uncacheable mirror after a failed save two copies MirrorWrite::discard_after_failed_save
May a pick read an uncacheable mirror mirror_fast_paths, pick_package mirror_may_answer

The release-age upgrade now requests a DocumentKind::FullInAbbreviatedMirror document, and UpgradeOutcome carries its MirrorWrite in place of loose full_etag / uncacheable fields.

Tests. Table-driven unit tests over kind × stored headers × bypass, response ETag × Cache-Control × Content-Type, and network policy × uncacheable. All 613 tests of pnpm-resolving-npm-resolver pass. Sabotage checks:

  • Sending the abbreviated tag for an upgraded mirror fails the new tests and upgraded_mirror_revalidation::*.
  • Always letting an uncacheable mirror answer fails the new tests and three version_selection::uncacheable_* tests.

Not in this PR. These parts of the task are left for follow-ups:

No changeset, since nothing changes for users.

Squash Commit Body

The registry metadata cache's decisions were spread across the fetchers and
the pick layers. The new metadata_cache_policy module holds them as pure
functions:

- DocumentKind (Abbreviated, Full, FullInAbbreviatedMirror) names the
  representation. for_mirror derives it from the mirror slot and its stored
  tags. accept and revalidation give the request shape. A mirror's
  validators go out only for the kind that recorded them.
- MirrorWrite::on_response reads a 2xx response once. Its headers method is
  the only place that builds a fetched document's header line, and
  discard_after_failed_save does the clean-up after a failed save.
- mirror_may_answer is the uncacheable gate for picks.

The release-age upgrade requests a FullInAbbreviatedMirror document through
fetch_metadata_document, and UpgradeOutcome carries its MirrorWrite.
MetaHeaders::for_full_meta_in_abbreviated_mirror is removed.

No behavior changes. Part of pnpm/tasks#146.

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • New features are implemented only in the Rust pnpm v12 CLI. Bug fixes
    are implemented in every affected version.
  • Added or updated tests.

Written by an agent (Claude Code, claude-opus-5-5).

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Bug Fixes
    • Improved package metadata refresh and cache handling. Requests now validate the appropriate metadata representation, and responses are normalized when needed before being stored.
    • Cache reuse now follows the selected network policy and the response’s caching directives, helping avoid serving stale metadata when a registry check is required while retaining eligible offline cache results.

…one policy module

The registry metadata cache's decisions were spread across the fetchers and
the pick layers:

- FetchAttempt::metadata_request and stored_full_etag decided the Accept
  header, the validators, and Cache-Control: no-cache.
- DecodeMeta::persist and persist_upgraded_to_mirror each chose which
  MetaHeaders constructor described the stored document. Each also removed
  an uncacheable mirror after a failed save, in its own copy.
- document_from_response and DecodeMeta each read ETag, Cache-Control, and
  Content-Type off the response and decided normalization separately.
- mirror_fast_paths and pick_package each tested `uncacheable` against the
  network policy.

The new metadata_cache_policy module holds these decisions as pure functions:

- DocumentKind (Abbreviated, Full, FullInAbbreviatedMirror) names the
  representation. for_mirror derives it from the mirror slot and its stored
  tags. accept and revalidation give the request shape. A mirror's
  validators go out only for the kind that recorded them.
- MirrorWrite::on_response reads a 2xx response once. Its headers method is
  the only place that builds a fetched document's header line, and
  discard_after_failed_save does the clean-up after a failed save.
- mirror_may_answer is the uncacheable gate for picks.

The release-age upgrade now requests a FullInAbbreviatedMirror document
through fetch_metadata_document, and UpgradeOutcome carries its MirrorWrite
in place of loose full_etag and uncacheable fields.
MetaHeaders::for_full_meta_in_abbreviated_mirror is removed.

No behavior changes. Table-driven unit tests cover each function, and the
existing fetch and pick tests still pass. Swapping the representation's tag,
or always allowing an uncacheable mirror, fails both the new tests and the
existing integration tests.

Part of pnpm/tasks#146. Out of scope here: a single decide() over the pick
layers, merging the two v12 request pipelines, the v11 counterpart, and the
request-log harnesses tracked in pnpm/tasks#141.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: pnpm/pnpm/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 00778a2b-f52e-45de-b061-ed9d35e9b9bd
📥 Commits

Reviewing files that changed from the base of the PR and between 157994e and 7601af3.

📒 Files selected for processing: 13
  • pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata.rs
  • pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs
  • pnpm/crates/resolving-npm-resolver/src/lib.rs
  • pnpm/crates/resolving-npm-resolver/src/metadata_cache_policy.rs
  • pnpm/crates/resolving-npm-resolver/src/metadata_cache_policy/tests.rs
  • pnpm/crates/resolving-npm-resolver/src/mirror/headers.rs
  • pnpm/crates/resolving-npm-resolver/src/pick_package.rs
  • pnpm/crates/resolving-npm-resolver/src/pick_package/cache_hit.rs
  • pnpm/crates/resolving-npm-resolver/src/pick_package/fetch_pick.rs
  • pnpm/crates/resolving-npm-resolver/src/pick_package/mirror_pick.rs
  • pnpm/crates/resolving-npm-resolver/src/pick_package/release_age_upgrade.rs
  • pnpm/crates/resolving-npm-resolver/src/pick_package/release_age_upgrade/tests.rs
  • pnpm/crates/resolving-npm-resolver/src/pick_package/state.rs
💤 Files with no reviewable changes: 1
  • pnpm/crates/resolving-npm-resolver/src/mirror/headers.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

📝 Walkthrough

The resolver centralizes metadata representation, revalidation, mirror-write, and mirror-eligibility decisions. Fetch and package-picking paths use these policies to select request headers, process responses, persist metadata, and determine when a stored mirror can answer.

Changes: Metadata cache policy

Layer / File(s) Summary
Define metadata cache policies
pnpm/crates/resolving-npm-resolver/src/metadata_cache_policy.rs, pnpm/crates/resolving-npm-resolver/src/metadata_cache_policy/tests.rs, pnpm/crates/resolving-npm-resolver/src/lib.rs
Adds DocumentKind, Revalidation, and MirrorWrite policies. Adds tests for representation selection, validators, response headers, failed saves, and mirror eligibility.
Apply policies to metadata fetches
pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata.rs, pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs
Fetch paths delegate representation, revalidation, normalization, and mirror-write decisions to the shared policies.
Persist release-age upgrades
pnpm/crates/resolving-npm-resolver/src/pick_package/release_age_upgrade.rs, pnpm/crates/resolving-npm-resolver/src/pick_package/release_age_upgrade/tests.rs, pnpm/crates/resolving-npm-resolver/src/mirror/headers.rs, pnpm/crates/resolving-npm-resolver/src/pick_package/{cache_hit.rs,fetch_pick.rs,state.rs}
Release-age upgrade outcomes carry MirrorWrite data. Persistence derives headers and failed-save handling from that data. Upgrade checks use the upgraded() method.
Use policy for mirror reads
pnpm/crates/resolving-npm-resolver/src/pick_package.rs, pnpm/crates/resolving-npm-resolver/src/pick_package/mirror_pick.rs
Disk-pick and mirror fast paths use the shared mirror-eligibility policy.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant FetchAttempt
  participant DocumentKind
  participant Registry
  participant MirrorWrite
  participant DecodeMeta
  participant Mirror
  FetchAttempt->>DocumentKind: Select representation and revalidation
  FetchAttempt->>Registry: Send metadata request
  Registry-->>FetchAttempt: Return response and headers
  FetchAttempt->>MirrorWrite: Derive response write policy
  MirrorWrite-->>DecodeMeta: Provide normalization and write policy
  DecodeMeta->>Mirror: Normalize and persist metadata
Loading

Suggested reviewers: altaywtf, ksxgithub

Merge Risk: ⚪ Minimal · up to 7601a

No actionable behavior change was identified; the PR is mergeable after normal checks.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.53%. Comparing base (086165d) to head (7601af3).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...m-resolver/src/pick_package/release_age_upgrade.rs 88.23% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #17024   +/-   ##
=======================================
  Coverage   92.53%   92.53%           
=======================================
  Files        1775     1776    +1     
  Lines      228551   228560    +9     
=======================================
+ Hits       211490   211509   +19     
+ Misses      17061    17051   -10     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     11.5±0.04ms    32.6 MB/sec    1.00     11.5±0.04ms    32.4 MB/sec
packument/parse                                  1.07     42.1±0.09µs  1574.4 MB/sec    1.00     39.5±0.08µs  1679.8 MB/sec
tarball/download_dependency                      1.00      3.4±0.06ms  1287.9 KB/sec    1.00      3.4±0.10ms  1288.9 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.00    182.1±1.95ms 87.9 KElem/sec    1.00    182.2±1.71ms 87.8 KElem/sec
version_pick/repeated_ranges_file                1.00      4.1±0.03ms  7.7 KElem/sec    1.01      4.1±0.03ms  7.6 KElem/sec
version_pick/repeated_ranges_raw                 1.00      4.1±0.02ms  7.7 KElem/sec    1.05      4.3±0.04ms  7.3 KElem/sec
workspace_resolution/hoist_heavy                 1.00    205.2±4.60ms        ? ?/sec    1.01    208.0±0.77ms        ? ?/sec
workspace_sort/chained_projects                  1.00     13.5±0.71ms        ? ?/sec    1.04     14.0±0.75ms        ? ?/sec

@github-actions

Copy link
Copy Markdown
Contributor

Same-run regression check

HEAD and main are measured on the same runner. The tolerance is 5% of the main median or 2 ms, whichever is larger. A regression requires both the median slowdown and the gap between the fastest retained HEAD sample and slowest retained main sample to exceed this tolerance, after trimming up to 10% from each tail. Suspected regressions are rerun once with target order reversed and only fail if reproduced. This conservative noise guard is not a statistical confidence interval.

Inconclusive rows do not fail the check. They remain visible for performance review. Bencher retains absolute minimum timings for historical tracking; historical alerts do not gate this PR. Sequential measurements can still be affected by runner drift.

Scenario Engine main median HEAD median Change Tolerance Result
isolated-fresh-restore-cold-cache-cold-store pacquet 2344.09 ms 2374.22 ms 1.3% 117.20 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store pnpr 1442.10 ms 1395.38 ms -3.2% 72.11 ms Within tolerance
isolated-fresh-restore-hot-cache-hot-store pacquet 233.53 ms 231.34 ms -0.9% 11.68 ms Within tolerance
isolated-fresh-restore-hot-cache-hot-store pnpr 246.34 ms 247.39 ms 0.4% 12.32 ms Within tolerance
isolated-repeat-install-hot-cache-hot-store pacquet 8.06 ms 7.74 ms -4.0% 2.00 ms Within tolerance
isolated-repeat-install-hot-cache-hot-store pnpr 8.56 ms 8.33 ms -2.6% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pacquet 11.83 ms 7.64 ms -35.4% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pnpr 7.89 ms 14.16 ms 79.6% 2.00 ms Inconclusive (not reproduced)
isolated-fresh-install-cold-cache-cold-store pacquet 2465.89 ms 2476.20 ms 0.4% 123.29 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pnpr 1525.56 ms 1515.78 ms -0.6% 76.28 ms Within tolerance
isolated-fresh-install-hot-cache-hot-store pacquet 449.49 ms 437.83 ms -2.6% 22.47 ms Within tolerance
isolated-fresh-install-hot-cache-hot-store pnpr 292.12 ms 298.17 ms 2.1% 14.61 ms Within tolerance
isolated-fresh-install-cold-cache-hot-store pacquet 1625.37 ms 1618.17 ms -0.4% 81.27 ms Within tolerance
isolated-fresh-install-cold-cache-hot-store pnpr 295.55 ms 290.76 ms -1.6% 14.78 ms Within tolerance
isolated-fresh-resolve-hot-cache-offline pacquet 275.97 ms 289.39 ms 4.9% 13.80 ms Within tolerance
isolated-fresh-resolve-hot-cache-offline pnpr 97.82 ms 98.40 ms 0.6% 4.89 ms Within tolerance
isolated-peer-heavy-resolve-hot-cache-offline pacquet 241.44 ms 245.98 ms 1.9% 12.07 ms Within tolerance
isolated-linked-workspace-resolve-hot-cache-offline pacquet 193.20 ms 192.59 ms -0.3% 9.66 ms Within tolerance
isolated-injected-workspace-repeat-install-hot-cache-hot-store pacquet 75.79 ms 69.31 ms -8.5% 3.79 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pacquet 4635.22 ms 4542.48 ms -2.0% 231.76 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pnpr 3493.22 ms 3513.72 ms 0.6% 174.66 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pacquet 211.51 ms 206.76 ms -2.2% 10.58 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pnpr 127.81 ms 134.29 ms 5.1% 6.39 ms Inconclusive (overlapping samples)
store-only-unlocked-direct-deps-cold-cache-hot-store pacquet 1156.25 ms 1103.22 ms -4.6% 57.81 ms Within tolerance

Integrated-Benchmark Report (Linux)

Commit: 7601af381c2a

Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm; the linked and injected workspace scenarios compare current Rust against main Rust. Bencher consumes pacquet@HEAD and pnpr@HEAD.

The tables below show mean ± σ. Bencher tracks absolute minimum latency; PR regression checks compare HEAD and main samples from the same runner. Historical timing alerts do not gate PRs.

Scenario: Isolated linker: fresh restore, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.407 ± 0.134 2.263 2.647 1.67 ± 0.19
pacquet@main 2.380 ± 0.116 2.234 2.564 1.65 ± 0.18
pnpr@HEAD 1.456 ± 0.141 1.294 1.655 1.01 ± 0.14
pnpr@main 1.443 ± 0.145 1.286 1.620 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.406893844,
      "stddev": 0.1338654444617656,
      "median": 2.3742158118,
      "user": 1.31856682,
      "system": 1.3932612999999998,
      "min": 2.2630275778,
      "max": 2.6473074018
    },
    {
      "command": "pacquet@main",
      "mean": 2.3795437246999995,
      "stddev": 0.11636417984411501,
      "median": 2.3440949213,
      "user": 1.1871532200000001,
      "system": 1.3205487999999999,
      "min": 2.2341657857999997,
      "max": 2.5643985498
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.45580571,
      "stddev": 0.14081613181304856,
      "median": 1.3953836478000001,
      "user": 1.12888612,
      "system": 1.2007508999999998,
      "min": 1.2941415508,
      "max": 1.6545811838
    },
    {
      "command": "pnpr@main",
      "mean": 1.4429766599999998,
      "stddev": 0.14537170494430493,
      "median": 1.4421002928,
      "user": 1.16612392,
      "system": 1.2373792,
      "min": 1.2858749628,
      "max": 1.6203182107999998
    }
  ]
}

Scenario: Isolated linker: fresh restore, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 232.1 ± 4.3 226.9 240.3 1.00
pacquet@main 235.3 ± 10.0 226.6 261.3 1.01 ± 0.05
pnpr@HEAD 247.8 ± 6.6 237.9 259.2 1.07 ± 0.03
pnpr@main 249.9 ± 12.4 236.7 274.5 1.08 ± 0.06
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.23208635192,
      "stddev": 0.004313432253218221,
      "median": 0.23134080182000002,
      "user": 0.26610822,
      "system": 0.58445876,
      "min": 0.22692866782,
      "max": 0.24028386082000003
    },
    {
      "command": "pacquet@main",
      "mean": 0.23530224932000002,
      "stddev": 0.010037845923038654,
      "median": 0.23353379832000004,
      "user": 0.27393622,
      "system": 0.5696512599999999,
      "min": 0.22664306982000001,
      "max": 0.26132898282
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.24784920221999998,
      "stddev": 0.006571094093282952,
      "median": 0.24738866782000002,
      "user": 0.28329842000000005,
      "system": 0.5584482599999999,
      "min": 0.23786458282000003,
      "max": 0.25920850682
    },
    {
      "command": "pnpr@main",
      "mean": 0.24992437912000004,
      "stddev": 0.012416733683928692,
      "median": 0.24633636332,
      "user": 0.27874871999999995,
      "system": 0.5831914599999999,
      "min": 0.23673246582000002,
      "max": 0.27452695282
    }
  ]
}

Scenario: Isolated linker: repeat install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 7.8 ± 0.5 7.0 9.8 1.00
pacquet@main 8.2 ± 0.6 6.9 11.3 1.05 ± 0.10
pnpr@HEAD 8.4 ± 0.5 7.2 10.5 1.08 ± 0.09
pnpr@main 8.6 ± 0.6 7.4 11.7 1.11 ± 0.10
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.0077790831107006405,
      "stddev": 0.00046177968480149453,
      "median": 0.00773653734,
      "user": 0.004540173248407644,
      "system": 0.0038927028662420395,
      "min": 0.00698563984,
      "max": 0.009778971840000001
    },
    {
      "command": "pacquet@main",
      "mean": 0.008183996384342508,
      "stddev": 0.0006085107051626989,
      "median": 0.00805809684,
      "user": 0.005104629051987771,
      "system": 0.003882185993883793,
      "min": 0.00690324484,
      "max": 0.011281396840000001
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.00840215713180328,
      "stddev": 0.0005158098964210538,
      "median": 0.008330097840000002,
      "user": 0.005003204590163932,
      "system": 0.004246559868852452,
      "min": 0.007241510840000001,
      "max": 0.010497843840000002
    },
    {
      "command": "pnpr@main",
      "mean": 0.00863081291073955,
      "stddev": 0.0005835309170287393,
      "median": 0.00855594284,
      "user": 0.005495968167202573,
      "system": 0.003996453311897106,
      "min": 0.00736202784,
      "max": 0.011687089840000001
    }
  ]
}

Scenario: Isolated linker: repeat install, cold cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 7.7 ± 0.5 6.9 11.6 1.00
pacquet@main 11.2 ± 3.3 7.0 20.4 1.46 ± 0.44
pnpr@HEAD 13.8 ± 1.7 7.4 17.5 1.79 ± 0.26
pnpr@main 7.9 ± 0.4 7.0 10.2 1.03 ± 0.09

Confirmation (reversed target order)

Command Mean [ms] Min [ms] Max [ms] Relative
pnpr@main 8.4 ± 0.3 7.7 10.1 1.01 ± 0.05
pnpr@HEAD 8.4 ± 0.3 7.7 10.1 1.01 ± 0.05
pacquet@main 8.3 ± 0.3 7.6 9.1 1.00
pacquet@HEAD 8.4 ± 0.4 7.5 9.8 1.00 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.007704555800000008,
      "stddev": 0.0005386704584853986,
      "median": 0.0076352768,
      "user": 0.004517405961538463,
      "system": 0.003845098557692307,
      "min": 0.0069269073,
      "max": 0.011596291300000002
    },
    {
      "command": "pacquet@main",
      "mean": 0.011211724887837837,
      "stddev": 0.0033206565443437207,
      "median": 0.0118253403,
      "user": 0.00644899081081081,
      "system": 0.0057018243243243255,
      "min": 0.0070364433,
      "max": 0.020351611300000003
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.013817687408108107,
      "stddev": 0.0017384990638855602,
      "median": 0.0141604928,
      "user": 0.007682878108108103,
      "system": 0.007114331081081084,
      "min": 0.007398943300000001,
      "max": 0.017518245300000002
    },
    {
      "command": "pnpr@main",
      "mean": 0.007929824177622379,
      "stddev": 0.0004346092409354325,
      "median": 0.0078861328,
      "user": 0.0047768478321678345,
      "system": 0.0039038391608391594,
      "min": 0.0070103743,
      "max": 0.0102069233
    }
  ],
  "confirmation": {
    "results": [
      {
        "command": "pnpr@main",
        "mean": 0.00837002582106464,
        "stddev": 0.0003476127463641182,
        "median": 0.00836773338,
        "user": 0.004570851482889734,
        "system": 0.004558033079847907,
        "min": 0.00767684538,
        "max": 0.01006465238
      },
      {
        "command": "pnpr@HEAD",
        "mean": 0.008378416464558825,
        "stddev": 0.0002984015851251827,
        "median": 0.00839283138,
        "user": 0.005143743970588234,
        "system": 0.004070232205882352,
        "min": 0.007670463380000001,
        "max": 0.01007981238
      },
      {
        "command": "pacquet@main",
        "mean": 0.008316564641194032,
        "stddev": 0.00026579514171718024,
        "median": 0.00834743538,
        "user": 0.004909600149253728,
        "system": 0.004248177686567165,
        "min": 0.007621801380000001,
        "max": 0.009077627380000002
      },
      {
        "command": "pacquet@HEAD",
        "mean": 0.008356840057902616,
        "stddev": 0.00036882857980970624,
        "median": 0.00837626038,
        "user": 0.004922552284644194,
        "system": 0.00427021138576779,
        "min": 0.007452102380000001,
        "max": 0.009759549380000001
      }
    ]
  }
}

Scenario: Isolated linker: fresh install, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.476 ± 0.018 2.447 2.502 1.62 ± 0.12
pacquet@main 2.465 ± 0.015 2.445 2.490 1.61 ± 0.12
pnpr@HEAD 1.543 ± 0.102 1.431 1.757 1.01 ± 0.10
pnpr@main 1.528 ± 0.112 1.402 1.671 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.4758235620600004,
      "stddev": 0.01844805094030008,
      "median": 2.4761958496600003,
      "user": 1.6532847,
      "system": 1.5174751999999998,
      "min": 2.44652125716,
      "max": 2.50212965016
    },
    {
      "command": "pacquet@main",
      "mean": 2.4653794644600002,
      "stddev": 0.01479021244994916,
      "median": 2.4658898326600003,
      "user": 1.6845016000000002,
      "system": 1.478945,
      "min": 2.4453695031600002,
      "max": 2.49023730116
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.54293964086,
      "stddev": 0.10199048346933431,
      "median": 1.5157848886599998,
      "user": 1.1246262,
      "system": 1.181026,
      "min": 1.43086074816,
      "max": 1.7570519011599999
    },
    {
      "command": "pnpr@main",
      "mean": 1.52802729446,
      "stddev": 0.11161332154073651,
      "median": 1.52556061166,
      "user": 1.0948124,
      "system": 1.2056448,
      "min": 1.40150940716,
      "max": 1.67117711416
    }
  ]
}

Scenario: Isolated linker: fresh install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 437.4 ± 18.5 403.2 461.4 1.50 ± 0.07
pacquet@main 474.6 ± 70.3 431.7 668.0 1.63 ± 0.24
pnpr@HEAD 318.0 ± 48.4 281.9 422.9 1.09 ± 0.17
pnpr@main 291.2 ± 6.7 275.7 301.1 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.43744764640000006,
      "stddev": 0.01847358293867846,
      "median": 0.43782897620000005,
      "user": 0.62762116,
      "system": 0.72718146,
      "min": 0.40323448370000003,
      "max": 0.46139220670000003
    },
    {
      "command": "pacquet@main",
      "mean": 0.47458323680000003,
      "stddev": 0.07033801171059839,
      "median": 0.4494927027000001,
      "user": 0.69626596,
      "system": 0.78293726,
      "min": 0.4316560347,
      "max": 0.6679900697000001
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.3180034996000001,
      "stddev": 0.04835070998907029,
      "median": 0.29817186320000005,
      "user": 0.28794435999999995,
      "system": 0.61505656,
      "min": 0.28192697070000006,
      "max": 0.42293647970000003
    },
    {
      "command": "pnpr@main",
      "mean": 0.2911997343,
      "stddev": 0.006677378668025698,
      "median": 0.29212241120000004,
      "user": 0.25059665999999997,
      "system": 0.5777893599999999,
      "min": 0.2757065287,
      "max": 0.30108661570000006
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.616 ± 0.019 1.581 1.652 5.63 ± 0.24
pacquet@main 1.654 ± 0.097 1.599 1.925 5.77 ± 0.41
pnpr@HEAD 0.287 ± 0.012 0.260 0.304 1.00
pnpr@main 0.293 ± 0.007 0.279 0.300 1.02 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.61646874486,
      "stddev": 0.018867881829044548,
      "median": 1.61817095296,
      "user": 0.8765425199999999,
      "system": 0.8715444399999999,
      "min": 1.58131312146,
      "max": 1.65220044846
    },
    {
      "command": "pacquet@main",
      "mean": 1.6539619216600001,
      "stddev": 0.09689648982017496,
      "median": 1.62537071196,
      "user": 0.92636782,
      "system": 0.96225804,
      "min": 1.5991114664600001,
      "max": 1.9246100464600002
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.28686555696,
      "stddev": 0.01188457392904141,
      "median": 0.29075676796000005,
      "user": 0.24433952000000003,
      "system": 0.56335174,
      "min": 0.25982781946000005,
      "max": 0.30353977046
    },
    {
      "command": "pnpr@main",
      "mean": 0.29348019556000005,
      "stddev": 0.006597045444757363,
      "median": 0.29554796796000005,
      "user": 0.26622112,
      "system": 0.5573062399999998,
      "min": 0.27933250746000005,
      "max": 0.29951307946000005
    }
  ]
}

Scenario: Isolated linker: fresh resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 286.0 ± 17.1 260.8 307.8 2.94 ± 0.20
pacquet@main 273.8 ± 6.7 259.9 281.1 2.81 ± 0.11
pnpr@HEAD 98.6 ± 2.2 94.9 102.5 1.01 ± 0.04
pnpr@main 97.3 ± 3.0 91.2 103.0 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.28596448854,
      "stddev": 0.01708587048163046,
      "median": 0.28938578114,
      "user": 0.25391674000000003,
      "system": 0.12439942,
      "min": 0.26075629714000004,
      "max": 0.30779534514
    },
    {
      "command": "pacquet@main",
      "mean": 0.27376480441272727,
      "stddev": 0.006743397115607006,
      "median": 0.27596610114000003,
      "user": 0.26074604909090904,
      "system": 0.11904364727272726,
      "min": 0.25992983614000004,
      "max": 0.28107680714
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.09864836593310343,
      "stddev": 0.0021702833119382364,
      "median": 0.09839849914,
      "user": 0.04490803655172413,
      "system": 0.017544057931034484,
      "min": 0.09492329714,
      "max": 0.10246325414
    },
    {
      "command": "pnpr@main",
      "mean": 0.09731167010666666,
      "stddev": 0.0029918794902646932,
      "median": 0.09782306864000001,
      "user": 0.04294494,
      "system": 0.01683378666666667,
      "min": 0.09118393213999999,
      "max": 0.10298883514
    }
  ]
}

Scenario: Isolated linker: peer-heavy resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 246.7 ± 8.3 234.2 262.9 1.00
pacquet@main 265.8 ± 42.9 231.5 352.1 1.08 ± 0.18
pnpm@HEAD 4085.7 ± 290.3 3807.2 4585.9 16.56 ± 1.30
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.24668367337333333,
      "stddev": 0.008310293621489214,
      "median": 0.24598414104000002,
      "user": 0.2479533711111111,
      "system": 0.06305299555555555,
      "min": 0.23424626904,
      "max": 0.26291547104
    },
    {
      "command": "pacquet@main",
      "mean": 0.26575365404,
      "stddev": 0.042900132608395966,
      "median": 0.24144330004,
      "user": 0.26723003777777776,
      "system": 0.06857332888888888,
      "min": 0.23145830404,
      "max": 0.35209063004
    },
    {
      "command": "pnpm@HEAD",
      "mean": 4.085683648151111,
      "stddev": 0.2902592227904482,
      "median": 4.03635655404,
      "user": 5.795362371111111,
      "system": 0.4556903288888889,
      "min": 3.8072041630399998,
      "max": 4.58591703904
    }
  ]
}

Scenario: Isolated linker: linked-workspace resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 193.0 ± 5.3 184.0 201.1 1.00 ± 0.04
pacquet@main 192.9 ± 5.1 186.5 201.1 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.19299027858750004,
      "stddev": 0.005288085059958609,
      "median": 0.1925912489,
      "user": 0.1549037325,
      "system": 0.07470169500000001,
      "min": 0.18400495790000002,
      "max": 0.2011389359
    },
    {
      "command": "pacquet@main",
      "mean": 0.19291375196666666,
      "stddev": 0.00509518508814311,
      "median": 0.1932026769,
      "user": 0.15251942,
      "system": 0.07477465333333333,
      "min": 0.18651160390000002,
      "max": 0.2010569619
    }
  ]
}

Scenario: Isolated linker: injected workspace repeat install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 69.8 ± 1.9 67.5 75.3 1.00
pacquet@main 76.8 ± 4.7 69.7 90.2 1.10 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.06984122455142858,
      "stddev": 0.0018707004336609308,
      "median": 0.06930889298000001,
      "user": 0.027829221904761912,
      "system": 0.046958416190476186,
      "min": 0.06753624248000001,
      "max": 0.07528326748000001
    },
    {
      "command": "pacquet@main",
      "mean": 0.07680023128487805,
      "stddev": 0.00468853471577764,
      "median": 0.07578579348,
      "user": 0.025829106341463418,
      "system": 0.056702342439024375,
      "min": 0.06969733948000001,
      "max": 0.09017751848000001
    }
  ]
}

Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.543 ± 0.130 4.372 4.795 1.29 ± 0.05
pacquet@main 4.604 ± 0.107 4.437 4.775 1.31 ± 0.05
pnpr@HEAD 3.523 ± 0.093 3.411 3.661 1.00
pnpr@main 3.531 ± 0.117 3.410 3.799 1.00 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.542857126220001,
      "stddev": 0.13015705299866165,
      "median": 4.542479051420001,
      "user": 1.4891795799999998,
      "system": 1.5744912999999996,
      "min": 4.37249257092,
      "max": 4.794689449920001
    },
    {
      "command": "pacquet@main",
      "mean": 4.60353763362,
      "stddev": 0.10743227379460497,
      "median": 4.635217781420001,
      "user": 1.4002904800000002,
      "system": 1.4087280999999998,
      "min": 4.4371490409200005,
      "max": 4.77512247092
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.52345466632,
      "stddev": 0.0931223895608491,
      "median": 3.51371616592,
      "user": 1.3517810799999999,
      "system": 1.3300918999999998,
      "min": 3.41110438692,
      "max": 3.66084074592
    },
    {
      "command": "pnpr@main",
      "mean": 3.5308566631199994,
      "stddev": 0.1166796894889577,
      "median": 3.4932161749199997,
      "user": 1.32945258,
      "system": 1.3057599999999998,
      "min": 3.40952972692,
      "max": 3.79936757192
    }
  ]
}

Scenario: GVS linker: fresh restore, hot cache + hot store

Same install as the isolated fresh-restore hot/hot scenario, into the shared virtual store, the layout pnpm 12 installs into by default. Scenarios run on separate machines, so compare main and branch within each table.

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 188.3 ± 41.6 115.3 247.2 1.47 ± 0.33
pacquet@main 211.5 ± 18.0 178.5 238.8 1.65 ± 0.15
pnpr@HEAD 145.5 ± 37.6 129.4 252.2 1.14 ± 0.30
pnpr@main 128.0 ± 3.3 122.5 136.5 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.18832999939473682,
      "stddev": 0.04162124015386866,
      "median": 0.2067641195,
      "user": 0.2244489084210526,
      "system": 0.18485060105263157,
      "min": 0.11533776350000001,
      "max": 0.2472018215
    },
    {
      "command": "pacquet@main",
      "mean": 0.21149669434615387,
      "stddev": 0.01796527504548687,
      "median": 0.21150831050000002,
      "user": 0.24817307846153847,
      "system": 0.19925517999999995,
      "min": 0.1785463725,
      "max": 0.23881578450000002
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.1455128268,
      "stddev": 0.037588155029135324,
      "median": 0.134294638,
      "user": 0.18117444,
      "system": 0.13226768,
      "min": 0.1293951055,
      "max": 0.2522400845
    },
    {
      "command": "pnpr@main",
      "mean": 0.12801011885,
      "stddev": 0.00326325981748227,
      "median": 0.12780973950000002,
      "user": 0.15085888999999997,
      "system": 0.12361138,
      "min": 0.12246693850000001,
      "max": 0.1364715915
    }
  ]
}

Scenario: Store only: unlocked direct deps, cold cache + hot store

Store-only install (enableModulesDir: false, per-file store index, trusted lockfile) against a lockfile missing the direct dependencies that have peers, with the metadata cache wiped per iteration: the install resolves those from the registry, reuses their subtrees from the lockfile and checks the store, linking nothing. Direct installs only.

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.104 ± 0.017 1.073 1.129 1.00
pacquet@main 1.184 ± 0.082 1.099 1.305 1.07 ± 0.08
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.1037728269600002,
      "stddev": 0.017332841147652187,
      "median": 1.1032236795600001,
      "user": 0.49007366,
      "system": 0.21309921999999998,
      "min": 1.07332995156,
      "max": 1.12859712656
    },
    {
      "command": "pacquet@main",
      "mean": 1.1843497505600002,
      "stddev": 0.08215096838142286,
      "median": 1.1562541100600001,
      "user": 0.63900476,
      "system": 0.26367251999999997,
      "min": 1.09949045556,
      "max": 1.30534131056
    }
  ]
}

@zkochan
zkochan marked this pull request as ready for review October 17, 2026 09:37
@zkochan

zkochan commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

Copilot AI balanced review requested due to automatic review settings October 17, 2026 09:37

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Centralize npm metadata cache decisions in a policy module

✨ Enhancement 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Centralizes metadata request, mirror-write, and cache-read decisions without intended behavior
 changes.
• Preserves representation-specific revalidation when release-age upgrades store full metadata in
 abbreviated mirrors.
• Adds table-driven tests for validators, response headers, normalization, and uncacheable mirrors.
Diagram

graph TD
  Mirror[("Metadata mirror")] --> Picker["Package picker"] --> Policy["Cache policy"] --> Fetchers["Metadata fetchers"] --> Registry["Registry"]
  Picker --> Upgrade["Release-age upgrade"] --> Policy
  Registry --> Mirror
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Unify the metadata fetch pipelines first
  • ➕ Would leave fewer fetch paths to integrate with the policy.
  • ➖ Would substantially expand this behavior-preserving refactor and increase regression risk.

Recommendation: Keep the incremental policy extraction. It gives the existing fetch and pick paths a shared decision point while leaving pipeline consolidation to a separately reviewable follow-up.

Files changed (13) +491 / -190

Refactor (11) +269 / -186
fetch_full_metadata.rsUse document kinds and mirror-write outcomes in direct fetches +28/-35

Use document kinds and mirror-write outcomes in direct fetches

• Direct metadata requests choose their Accept header through DocumentKind. Modified responses carry MirrorWrite instead of separate ETag and uncacheable fields, allowing release-age upgrades to retain the response's recording policy.

pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata.rs

fetch_full_metadata_cached.rsDelegate cached-fetch decisions to the policy +19/-65

Delegate cached-fetch decisions to the policy

• Cached fetch attempts derive their document kind from the mirror and use it for revalidation and response recording. Decode and persistence now use MirrorWrite for normalization, stored headers, and failed-save cleanup.

pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached.rs

lib.rsRegister the metadata cache policy module +1/-0

Register the metadata cache policy module

• Adds the internal policy module to the resolver crate.

pnpm/crates/resolving-npm-resolver/src/lib.rs

metadata_cache_policy.rsCentralize metadata cache request and mirror decisions +173/-0

Centralize metadata cache request and mirror decisions

• Introduces DocumentKind and revalidation rules for representation-specific requests. MirrorWrite owns response-header interpretation, normalization, stored header construction, and failed-save cleanup; mirror_may_answer owns the network-policy gate.

pnpm/crates/resolving-npm-resolver/src/metadata_cache_policy.rs

headers.rsRemove the separate upgraded-mirror header constructor +0/-14

Remove the separate upgraded-mirror header constructor

• Deletes the constructor for full metadata stored in an abbreviated mirror. MirrorWrite now constructs fetched-document headers for that case.

pnpm/crates/resolving-npm-resolver/src/mirror/headers.rs

pick_package.rsUse the shared gate for lowest-version disk picks +3/-8

Use the shared gate for lowest-version disk picks

• Replaces the local uncacheable-mirror check with the policy-backed mirror eligibility method while retaining cache-first behavior.

pnpm/crates/resolving-npm-resolver/src/pick_package.rs

cache_hit.rsDerive cache-hit upgrade status from the write outcome +3/-3

Derive cache-hit upgrade status from the write outcome

• Uses UpgradeOutcome::upgraded() when deciding whether upgraded metadata was registry-verified, should be persisted, and should be marked as checked.

pnpm/crates/resolving-npm-resolver/src/pick_package/cache_hit.rs

fetch_pick.rsUse the derived upgrade status during fetch picks +1/-1

Use the derived upgrade status during fetch picks

• Checks UpgradeOutcome::upgraded() before reloading an upgraded mirror.

pnpm/crates/resolving-npm-resolver/src/pick_package/fetch_pick.rs

mirror_pick.rsShare mirror eligibility across pick paths +9/-9

Share mirror eligibility across pick paths

• Routes mirror fast paths through mirror_may_answer and provides the same policy check to the lowest-version disk-pick path.

pnpm/crates/resolving-npm-resolver/src/pick_package/mirror_pick.rs

release_age_upgrade.rsCarry mirror-write policy through release-age upgrades +31/-50

Carry mirror-write policy through release-age upgrades

• Requests a FullInAbbreviatedMirror document and stores its MirrorWrite in UpgradeOutcome instead of loose status, ETag, and cacheability fields. Upgrade persistence uses that policy for headers and failed-save cleanup.

pnpm/crates/resolving-npm-resolver/src/pick_package/release_age_upgrade.rs

state.rsUse derived upgrade status for cached state +1/-1

Use derived upgrade status for cached state

• Checks UpgradeOutcome::upgraded() before promoting metadata that did not undergo a release-age upgrade.

pnpm/crates/resolving-npm-resolver/src/pick_package/state.rs

Tests (2) +222 / -4
tests.rsCover metadata cache policy decisions +208/-0

Cover metadata cache policy decisions

• Adds table-driven tests for document kinds, Accept headers, validators, bypass behavior, mirror writes, normalization, failed-save cleanup, and online versus cache-first reads.

pnpm/crates/resolving-npm-resolver/src/metadata_cache_policy/tests.rs

tests.rsConstruct upgrade test outcomes through MirrorWrite +14/-4

Construct upgrade test outcomes through MirrorWrite

• Updates test fixtures to build upgrade outcomes from response headers, exercising the new full-document-in-abbreviated-mirror recording path.

pnpm/crates/resolving-npm-resolver/src/pick_package/release_age_upgrade/tests.rs

@qodo-code-review

qodo-code-review Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Repeated installs lack log coverage 📎 Requirement gap ≡ Correctness
Description
The added tests exercise pure cache-policy helpers but do not run repeated installs against a mock
registry or assert the resulting request and response sequence. As a result, unchanged metadata can
still be fetched incorrectly on later installs, and v11/v12 request-log regressions remain
undetected.
Code

pnpm/crates/resolving-npm-resolver/src/metadata_cache_policy/tests.rs[R55-60]

+#[test]
+fn document_kind_follows_the_mirror_slot_and_its_stored_tags() {
+    let abbreviated = stored(Some(ABBREVIATED_ETAG), None, false);
+    let upgraded = stored(None, Some(FULL_ETAG), false);
+    let empty_full_etag = stored(None, Some(""), false);
+    let cases = [
Relevance

●● Moderate

Integration coverage is explicitly deferred, but recent cache behavior precedents sometimes require
request-sequence regression tests.

PR-#14931
PR-#13952

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The checklist requires table-driven transition coverage plus a three-install mock-registry
request-log test and a v11/v12 differential. The added test module contains only isolated
policy-helper tests for document kinds, validators, response headers, failed saves, and mirror
selection; it contains no install harness, request-log assertions, 304-body checks, or version
differential.

Test registry cache transitions and request behavior
pnpm/crates/resolving-npm-resolver/src/metadata_cache_policy/tests.rs[55-124]
pnpm/crates/resolving-npm-resolver/src/metadata_cache_policy/tests.rs[127-208]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new unit tests cover individual policy functions but not the required repeated-install request behavior, 304-only revalidation, release-age transitions, or the v11/v12 request-log differential.

## Fix Focus Areas
- pnpm/crates/resolving-npm-resolver/src/metadata_cache_policy/tests.rs[55-208]
- pnpm/crates/resolving-npm-resolver/src/pick_package/release_age_upgrade/tests.rs[1-30]

## Recommended Fix
Add a mock-registry integration test that performs three installs, records requests separately for abbreviated and full representations, asserts the exact request log, and verifies that installs two and three receive only 304 responses for unchanged metadata. Add the required status and release-age transition cases and run the same request-log scenario through v11 and v12 for a differential comparison.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗



Informational

2. v11 keeps separate cache rules 📎 Requirement gap ⚙ Maintainability
Description
The new metadata_cache_policy module is wired only into the v12 resolver and exposes separate
DocumentKind, MirrorWrite, and mirror_may_answer helpers rather than a shared decide() state
machine. The pnpm11 resolver still derives validators, request representation, cache bypass, and
persistence behavior independently, so the two release lines do not share the centralized policy.
Code

pnpm/crates/resolving-npm-resolver/src/metadata_cache_policy.rs[R41-50]

+impl DocumentKind {
+    /// The document a request outside any mirror asks for.
+    pub(crate) fn requested(full_metadata: bool) -> Self {
+        if full_metadata { DocumentKind::Full } else { DocumentKind::Abbreviated }
+    }
+
+    /// The document a fetch for a mirror asks for. An abbreviated mirror that
+    /// holds an upgraded full document keeps asking for the full document, so
+    /// a registry with per-representation tags can answer `304`.
+    pub(crate) fn for_mirror(full_metadata: bool, stored: Option<&MetaHeaders>) -> Self {
Relevance

● Weak

Cross-release parity is explicitly deferred; recent precedent rejects requiring synchronized pnpm11
and Rust changes in one PR.

PR-#15340
PR-#14175

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new module centralizes document-kind and revalidation helpers for the v12 implementation, but it
does not provide the required shared decide() state machine or any pnpm11 integration. The pnpm11
resolver still computes fullEtag, cacheBypass, fullMetadata, and persistence independently,
demonstrating that cache decisions remain duplicated across release lines.

Centralize registry cache decisions and header writes
pnpm/crates/resolving-npm-resolver/src/metadata_cache_policy.rs[41-170]
pnpm11/resolving/npm-resolver/src/fetchFullMetadataCached.ts[78-97]
pnpm11/resolving/npm-resolver/src/fetchFullMetadataCached.ts[145-156]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The cache policy is centralized only for the v12 resolver, while pnpm11 continues to implement request and mirror decisions independently. This leaves the release lines vulnerable to behavioral drift and does not satisfy the shared state-machine design.

## Fix Focus Areas
- pnpm/crates/resolving-npm-resolver/src/metadata_cache_policy.rs[41-170]
- pnpm11/resolving/npm-resolver/src/fetchFullMetadataCached.ts[78-97]
- pnpm11/resolving/npm-resolver/src/fetchFullMetadataCached.ts[145-156]

## Recommended Fix
Define the shared `decide()` policy and case table required for metadata cache decisions, then adapt the pnpm11 resolver to use the same document-kind, revalidation, mirror-write, and mirror-answer functions as v12. Add equivalent pnpm11 unit coverage over the shared cases and remove the duplicated request and persistence decisions.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Grey Divider

Context sources
❌ Tickets: failed to load — Ticket collection could not establish complete evidence
✅ Compliance rules (platform): 66 rules
✅ Cross-repo context — repo relationships
Review mode: Auto: 🧠 Deep: Dense cache-policy refactor spans multiple performance-critical paths and representations.

Grey Divider

Tip of the day
💡 Did you know, you can see how risky a PR is at a glance with blast radius labels

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Oct 17, 2026
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants