Skip to content

refactor(resolving-npm-resolver): decide the pick's mirror shortcuts in one pure route - #17032

Merged
zkochan merged 2 commits into
mainfrom
fix-146-decide
Oct 17, 2026
Merged

zkochan merged 2 commits into
mainfrom
fix-146-decide

Conversation

@zkochan

@zkochan zkochan commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Third step of pnpm/tasks#146 (Related to pnpm/tasks#146), after #17024 and #17028. It covers the pick side of the task's "no explicit state machine" item. There is no behavior change.

Before a pick asks the registry, it can try several mirror reads. Each read checked its own eligibility in a different place:

Read Eligibility, before Now
uncacheable gate mirror_fast_paths MirrorShortcuts::decide
pinned version version_spec_pick MirrorShortcuts::exact_version
dominant lockfile version range_pick_is_stable MirrorShortcuts::dominant_lockfile_version
ETag-less public mirror range_can_reuse_unvalidated_mirror + scope/ETag checks MirrorShortcuts::unvalidated_mirror (+ unvalidated_mirror_is_fresh)
release-age mtime shortcut published_by_pick RouteInputs::written_after
disk read after the permit condition in pick_package DiskFirst::decide
mirror fallback after a failed fetch disk_fallback fetch_failure_falls_back

The new pick_package::route module is pure. It decides from the request, the policy, and the mirror's header line. The reads keep only their content checks: whether the mirror holds the version, whether its pick agrees, and the mtime against the age or the cutoff. The mirror mtime is still read only by a shortcut that needs it, so the hot path gains no stat.

The release-age exclusion (release_age_applies_to, a policy lookup) stays lazy. RouteInputs holds the pick policy, not a precomputed answer:

  • range_pick_is_stable checks it last, after the cheap flags.
  • RouteInputs::written_after runs only after the other shortcuts missed.

A pinned version the mirror answers does no lookup. A stable range that falls through does at most two, where the old code did up to three because it checked range stability twice.

Tests. Table-driven unit tests cover each decision. All 623 tests of pnpm-resolving-npm-resolver pass. Sabotage checks:

  • Dropping the offline-range exclusion from the release-age shortcut fails the new route test. No test covered it before.
  • Dropping the pnpm update exclusion from the ETag-less shortcut fails the new test and 4 existing integration tests.

Still open on the task. These are left for later PRs:

No changeset, since nothing changes for users.

Squash Commit Body

Each read a pick tries before the registry checked its own eligibility in
a different place. The new pick_package::route module decides them all
from the request, the policy, and the mirror's header line:

- MirrorShortcuts::decide returns which of the first three pre-permit
  reads apply, or None when the mirror may not answer at all.
- RouteInputs::written_after returns the release-age cutoff for the last
  read. It is asked only after the others missed, so the release-age
  exclusion lookup stays as lazy as before.
- unvalidated_mirror_is_fresh holds the mtime age rule.
- DiskFirst::decide gates the read after the fetch permit.
- fetch_failure_falls_back is the private-route rule for a failed fetch.

The reads keep only their content checks, and the mirror mtime is still
read only when a shortcut needs it. No behavior changes. Table-driven tests
cover each decision. 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

Summary by CodeRabbit

  • Bug Fixes
    • Package resolution now selects cached data, mirror shortcuts, or registry requests based on network settings and request details.
    • Eligible mirror data can serve package requests, while stale, unvalidated mirror data is avoided.
    • Registry fetch failures fall back to cached data based on package visibility and error type; access-denied errors for private packages do not trigger fallback.

…in one pure route

Each read a pick tries before the registry checked its own eligibility:
- the uncacheable gate in mirror_fast_paths
- the spec-type and flag checks in version_spec_pick
- range_pick_is_stable and range_can_reuse_unvalidated_mirror
- the scope and ETag checks in fresh_unvalidated_mirror_pick
- the offline-range and release-age checks in published_by_pick
- the cache-first condition in pick_package
- the private-route rule in disk_fallback

The new pick_package::route module decides them all from the request, the
policy, and the mirror's header line:

- MirrorShortcuts::decide returns which of the four pre-permit reads apply:
  exact_version, dominant_lockfile_version, unvalidated_mirror, and
  written_after with the release-age cutoff.
- unvalidated_mirror_is_fresh holds the mtime age rule, and
  UNVALIDATED_MIRROR_MAX_AGE moves with it.
- DiskFirst::decide (Never, Always, UnlessUncacheable) gates the read after
  the fetch permit.
- fetch_failure_falls_back is the private-route rule for a failed fetch.

The shortcuts keep only their content checks: whether the mirror holds the
version, whether its pick agrees, and the mtime against the age or cutoff.
The mirror's mtime is still read only by a shortcut that needs it.

No behavior changes. Table-driven tests cover each decision. The offline
range exclusion from the release-age shortcut had no test before, and
removing it now fails one.

Part of pnpm/tasks#146.

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: 44cbaa73-6ff5-4ad8-bc01-7fbbdc3463e1
📥 Commits

Reviewing files that changed from the base of the PR and between c8d2011 and a70b6ee.

📒 Files selected for processing: 3
  • pnpm/crates/resolving-npm-resolver/src/pick_package/mirror_pick.rs
  • pnpm/crates/resolving-npm-resolver/src/pick_package/route.rs
  • pnpm/crates/resolving-npm-resolver/src/pick_package/route/tests.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 now centralizes decisions for mirror shortcuts, disk-first picks, and fetch-failure fallback. Package picking uses these decisions to determine which mirror or disk paths are eligible.

Changes: Package resolution routing

Layer / File(s) Summary
Mirror shortcut rules
pnpm/crates/resolving-npm-resolver/src/pick_package/route.rs, pnpm/crates/resolving-npm-resolver/src/pick_package/route/tests.rs
Route inputs and policies determine eligibility for exact-version, dominant-lockfile, unvalidated-mirror, and release-age shortcuts. An unvalidated mirror is considered fresh when its modification time is less than five minutes from the current time. Tests cover shortcut conditions and freshness boundaries.
Mirror and disk route integration
pnpm/crates/resolving-npm-resolver/src/pick_package.rs, pnpm/crates/resolving-npm-resolver/src/pick_package/mirror_pick.rs, pnpm/crates/resolving-npm-resolver/src/pick_package/route.rs, pnpm/crates/resolving-npm-resolver/src/pick_package/route/tests.rs
Mirror shortcut selection now uses MirrorShortcuts::decide. Disk-first selection now uses DiskFirst::decide. Tests cover shortcut eligibility and disk-first selection.
Fetch failure fallback
pnpm/crates/resolving-npm-resolver/src/pick_package/fetch_pick.rs, pnpm/crates/resolving-npm-resolver/src/pick_package/route.rs, pnpm/crates/resolving-npm-resolver/src/pick_package/route/tests.rs
Fetch fallback now uses fetch_failure_falls_back: public routes fall back after any fetch error, while private routes do not fall back after access-denied errors. Tests cover these cases.

Priority: ⬇️ Low

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

Change: Refactor

Suggested labels: product: pacquet

Suggested reviewers: shuuren

Merge Risk: ⚪ Minimal · up to a70b6

The inspected package-pick paths preserve their prior routing behavior, with no actionable issue identified before merge.

✨ 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

codecov-commenter commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.55%. Comparing base (2c01cc5) to head (a70b6ee).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #17032   +/-   ##
=======================================
  Coverage   92.55%   92.55%           
=======================================
  Files        1777     1779    +2     
  Lines      228522   228563   +41     
=======================================
+ Hits       211499   211543   +44     
+ Misses      17023    17020    -3     

☔ 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

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.06     12.3±0.06ms    30.5 MB/sec    1.00     11.6±0.07ms    32.3 MB/sec
packument/parse                                  1.00     38.7±0.19µs  1714.4 MB/sec    1.00     38.6±0.10µs  1718.4 MB/sec
tarball/download_dependency                      1.00      3.3±0.13ms  1326.8 KB/sec    1.05      3.4±0.08ms  1266.4 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.01    191.0±2.76ms 83.8 KElem/sec    1.00    189.0±3.04ms 84.7 KElem/sec
version_pick/repeated_ranges_file                1.00      4.2±0.03ms  7.4 KElem/sec    1.03      4.4±0.03ms  7.1 KElem/sec
version_pick/repeated_ranges_raw                 1.00      4.2±0.04ms  7.4 KElem/sec    1.04      4.4±0.03ms  7.1 KElem/sec
workspace_resolution/hoist_heavy                 1.00    206.4±1.56ms        ? ?/sec    1.00    206.1±1.40ms        ? ?/sec
workspace_sort/chained_projects                  1.00     14.0±0.53ms        ? ?/sec    1.01     14.1±0.39ms        ? ?/sec

@github-actions

github-actions Bot commented Oct 17, 2026 •

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 2316.77 ms 2303.71 ms -0.6% 115.84 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store pnpr 1366.29 ms 1389.93 ms 1.7% 68.31 ms Within tolerance
isolated-fresh-restore-hot-cache-hot-store pacquet 288.32 ms 289.39 ms 0.4% 14.42 ms Within tolerance
isolated-fresh-restore-hot-cache-hot-store pnpr 318.25 ms 454.97 ms 43.0% 15.91 ms Inconclusive (overlapping samples)
isolated-repeat-install-hot-cache-hot-store pacquet 8.90 ms 9.01 ms 1.3% 2.00 ms Within tolerance
isolated-repeat-install-hot-cache-hot-store pnpr 8.53 ms 8.46 ms -0.8% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pacquet 8.10 ms 8.15 ms 0.7% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pnpr 8.08 ms 8.01 ms -0.9% 2.00 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pacquet 2489.69 ms 2486.85 ms -0.1% 124.48 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pnpr 1504.88 ms 1624.46 ms 7.9% 75.24 ms Inconclusive (overlapping samples)
isolated-fresh-install-hot-cache-hot-store pacquet 448.18 ms 441.39 ms -1.5% 22.41 ms Within tolerance
isolated-fresh-install-hot-cache-hot-store pnpr 306.22 ms 291.12 ms -4.9% 15.31 ms Within tolerance
isolated-fresh-install-cold-cache-hot-store pacquet 1614.75 ms 1607.51 ms -0.4% 80.74 ms Within tolerance
isolated-fresh-install-cold-cache-hot-store pnpr 272.83 ms 286.53 ms 5.0% 13.64 ms Inconclusive (overlapping samples)
isolated-fresh-resolve-hot-cache-offline pacquet 223.79 ms 223.81 ms 0.0% 11.19 ms Within tolerance
isolated-fresh-resolve-hot-cache-offline pnpr 92.01 ms 88.05 ms -4.3% 4.60 ms Within tolerance
isolated-peer-heavy-resolve-hot-cache-offline pacquet 234.97 ms 239.85 ms 2.1% 11.75 ms Within tolerance
isolated-linked-workspace-resolve-hot-cache-offline pacquet 204.51 ms 201.89 ms -1.3% 10.23 ms Within tolerance
isolated-injected-workspace-repeat-install-hot-cache-hot-store pacquet 82.04 ms 85.46 ms 4.2% 4.10 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pacquet 4391.07 ms 4471.79 ms 1.8% 219.55 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pnpr 3470.45 ms 3478.46 ms 0.2% 173.52 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pacquet 193.47 ms 119.38 ms -38.3% 9.67 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pnpr 130.20 ms 227.28 ms 74.6% 6.51 ms Inconclusive (overlapping samples)
store-only-unlocked-direct-deps-cold-cache-hot-store pacquet 1140.56 ms 1127.80 ms -1.1% 57.03 ms Within tolerance

Integrated-Benchmark Report (Linux)

Commit: a70b6eef7e82

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.344 ± 0.114 2.251 2.635 1.68 ± 0.15
pacquet@main 2.337 ± 0.095 2.254 2.572 1.67 ± 0.14
pnpr@HEAD 1.398 ± 0.104 1.286 1.595 1.00
pnpr@main 1.414 ± 0.118 1.303 1.634 1.01 ± 0.11
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.3438979245,
      "stddev": 0.11422433382257574,
      "median": 2.3037143121000003,
      "user": 1.2198740999999997,
      "system": 1.26715736,
      "min": 2.2509289136,
      "max": 2.6349100286000002
    },
    {
      "command": "pacquet@main",
      "mean": 2.3365334043,
      "stddev": 0.09474199167039568,
      "median": 2.3167654816,
      "user": 1.1767553,
      "system": 1.29109846,
      "min": 2.2536326606,
      "max": 2.5715167666000003
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.3981808704,
      "stddev": 0.10401874824672323,
      "median": 1.3899265316,
      "user": 1.1365162999999998,
      "system": 1.1609964600000002,
      "min": 1.2862210076,
      "max": 1.5947041946000002
    },
    {
      "command": "pnpr@main",
      "mean": 1.4137282472000003,
      "stddev": 0.11839825720161522,
      "median": 1.3662860196,
      "user": 1.0903676,
      "system": 1.2228055599999998,
      "min": 1.3028455076,
      "max": 1.6339559756000002
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 293.2 ± 10.6 284.5 316.6 1.01 ± 0.05
pacquet@main 291.3 ± 11.3 282.8 321.7 1.00
pnpr@HEAD 439.3 ± 111.5 314.8 579.3 1.51 ± 0.39
pnpr@main 317.4 ± 5.6 306.7 325.4 1.09 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.29318161186,
      "stddev": 0.010565053640808432,
      "median": 0.2893866433600001,
      "user": 0.34918442,
      "system": 0.7655852799999999,
      "min": 0.28451503336000006,
      "max": 0.31662231636000004
    },
    {
      "command": "pacquet@main",
      "mean": 0.29134917016000006,
      "stddev": 0.011321305550963631,
      "median": 0.28832387186,
      "user": 0.33498091999999996,
      "system": 0.78912698,
      "min": 0.28276323136000003,
      "max": 0.32174636136000007
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.43930794316000005,
      "stddev": 0.11145265092111777,
      "median": 0.45496523586000004,
      "user": 0.50599172,
      "system": 1.09023278,
      "min": 0.31482465436000007,
      "max": 0.57926094636
    },
    {
      "command": "pnpr@main",
      "mean": 0.31741613916,
      "stddev": 0.005622652639672289,
      "median": 0.3182451418600001,
      "user": 0.34695792000000003,
      "system": 0.81074798,
      "min": 0.30670816436000004,
      "max": 0.32535781336
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 9.1 ± 0.6 7.6 11.0 1.07 ± 0.10
pacquet@main 9.0 ± 1.4 7.7 29.3 1.06 ± 0.18
pnpr@HEAD 8.5 ± 0.5 7.4 10.6 1.00
pnpr@main 8.6 ± 0.7 7.5 12.3 1.01 ± 0.10
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.009092610929523811,
      "stddev": 0.000622086037095533,
      "median": 0.009014247620000002,
      "user": 0.0052093378231292545,
      "system": 0.004746172789115645,
      "min": 0.007613476619999999,
      "max": 0.011000579620000001
    },
    {
      "command": "pacquet@main",
      "mean": 0.009040601493333333,
      "stddev": 0.0013889973571758214,
      "median": 0.008901139620000002,
      "user": 0.0053029300000000034,
      "system": 0.004444534000000002,
      "min": 0.007746367620000001,
      "max": 0.029287523620000002
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.008507531025498278,
      "stddev": 0.0005395743950543903,
      "median": 0.00846265562,
      "user": 0.0052603092096219954,
      "system": 0.0039483147766323015,
      "min": 0.007430472620000001,
      "max": 0.01055877862
    },
    {
      "command": "pnpr@main",
      "mean": 0.00863305405260188,
      "stddev": 0.0006675513926523101,
      "median": 0.008534609620000001,
      "user": 0.005160968087774295,
      "system": 0.004172923510971788,
      "min": 0.007512146620000001,
      "max": 0.012287149620000002
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 8.1 ± 0.4 7.1 10.9 1.01 ± 0.07
pacquet@main 8.1 ± 0.5 7.2 10.9 1.01 ± 0.08
pnpr@HEAD 8.1 ± 0.4 7.2 10.0 1.00
pnpr@main 8.2 ± 0.4 7.3 10.7 1.01 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.008141470540638976,
      "stddev": 0.0004252979541275584,
      "median": 0.00814996894,
      "user": 0.0049863514376996855,
      "system": 0.003943777507987219,
      "min": 0.00710579694,
      "max": 0.010858900940000001
    },
    {
      "command": "pacquet@main",
      "mean": 0.008147823479249142,
      "stddev": 0.00051247373318617,
      "median": 0.00809582694,
      "user": 0.005106081911262797,
      "system": 0.0037767283276450513,
      "min": 0.0072080489400000005,
      "max": 0.010945442940000001
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.008054905977037036,
      "stddev": 0.0004044065160317706,
      "median": 0.00800675094,
      "user": 0.004978771043771043,
      "system": 0.0038452283501683496,
      "min": 0.00721333894,
      "max": 0.00998119094
    },
    {
      "command": "pnpr@main",
      "mean": 0.008150890408401494,
      "stddev": 0.00042710068593493643,
      "median": 0.00808027794,
      "user": 0.005164918215613384,
      "system": 0.003732119851301115,
      "min": 0.00731589094,
      "max": 0.01074315294
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.535 ± 0.134 2.452 2.878 1.66 ± 0.13
pacquet@main 2.495 ± 0.031 2.464 2.577 1.64 ± 0.10
pnpr@HEAD 1.597 ± 0.122 1.389 1.754 1.05 ± 0.10
pnpr@main 1.525 ± 0.093 1.426 1.734 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.5350084152399996,
      "stddev": 0.13370109651193765,
      "median": 2.48684564624,
      "user": 2.1468857199999998,
      "system": 1.7457574799999995,
      "min": 2.45189022674,
      "max": 2.87849994774
    },
    {
      "command": "pacquet@main",
      "mean": 2.4953291078399995,
      "stddev": 0.031066301685335442,
      "median": 2.4896893257399997,
      "user": 2.02360332,
      "system": 1.5727593800000002,
      "min": 2.46419625874,
      "max": 2.57698486374
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.5973744665400003,
      "stddev": 0.12201133028467413,
      "median": 1.62446096874,
      "user": 1.3442246199999999,
      "system": 1.3670513799999997,
      "min": 1.38852543674,
      "max": 1.7540492567400001
    },
    {
      "command": "pnpr@main",
      "mean": 1.5250991691400002,
      "stddev": 0.09331004268669499,
      "median": 1.5048769907400001,
      "user": 1.37595602,
      "system": 1.3316106799999998,
      "min": 1.4261648297399998,
      "max": 1.73378078474
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 446.1 ± 18.2 426.2 477.9 1.53 ± 0.08
pacquet@main 451.9 ± 15.5 435.1 479.8 1.55 ± 0.08
pnpr@HEAD 291.5 ± 10.0 278.3 305.6 1.00
pnpr@main 352.1 ± 85.6 285.0 497.8 1.21 ± 0.30
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.44612621846000006,
      "stddev": 0.018204707865164965,
      "median": 0.44138754676,
      "user": 0.6301427000000001,
      "system": 0.7454945800000001,
      "min": 0.42620831276,
      "max": 0.47792093176
    },
    {
      "command": "pacquet@main",
      "mean": 0.45192252086000007,
      "stddev": 0.015490644087548949,
      "median": 0.44817662276000003,
      "user": 0.6530693,
      "system": 0.7193256800000001,
      "min": 0.43506990976,
      "max": 0.47977878976
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.29154975496,
      "stddev": 0.01001312336400722,
      "median": 0.29111572525999996,
      "user": 0.252502,
      "system": 0.57237128,
      "min": 0.27825806076,
      "max": 0.30559019576
    },
    {
      "command": "pnpr@main",
      "mean": 0.3520516987600001,
      "stddev": 0.08556371581655292,
      "median": 0.30621841476,
      "user": 0.3139439,
      "system": 0.6885047799999999,
      "min": 0.28502881176,
      "max": 0.49779955376
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.646 ± 0.103 1.589 1.935 6.02 ± 0.50
pacquet@main 1.643 ± 0.104 1.589 1.936 6.01 ± 0.50
pnpr@HEAD 0.282 ± 0.011 0.262 0.294 1.03 ± 0.07
pnpr@main 0.273 ± 0.015 0.251 0.293 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.6461572435,
      "stddev": 0.10334149153558726,
      "median": 1.6075144694,
      "user": 0.9539340600000001,
      "system": 0.9546226599999998,
      "min": 1.5886914439,
      "max": 1.9348191739
    },
    {
      "command": "pacquet@main",
      "mean": 1.6429954354000003,
      "stddev": 0.10399695613212812,
      "median": 1.6147498994,
      "user": 0.9249624599999999,
      "system": 0.94634196,
      "min": 1.5886511059000001,
      "max": 1.9359750809000003
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.28165865740000007,
      "stddev": 0.011337226457402,
      "median": 0.28653253190000005,
      "user": 0.25273566000000003,
      "system": 0.5287999600000001,
      "min": 0.26234250890000005,
      "max": 0.29446704690000003
    },
    {
      "command": "pnpr@main",
      "mean": 0.2732936361,
      "stddev": 0.014749696395078168,
      "median": 0.27283424440000004,
      "user": 0.21704126,
      "system": 0.52994826,
      "min": 0.2506115929,
      "max": 0.2925657849
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 229.1 ± 18.6 207.5 265.3 2.56 ± 0.22
pacquet@main 226.9 ± 19.4 207.5 274.7 2.54 ± 0.23
pnpr@HEAD 89.5 ± 2.5 86.3 95.2 1.00
pnpr@main 91.5 ± 2.3 86.6 95.2 1.02 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.22907601586666662,
      "stddev": 0.018600427226030083,
      "median": 0.2238139667,
      "user": 0.20984455666666665,
      "system": 0.07637479,
      "min": 0.2075070242,
      "max": 0.2653455852
    },
    {
      "command": "pacquet@main",
      "mean": 0.22690975691428572,
      "stddev": 0.019357715164461158,
      "median": 0.2237913497,
      "user": 0.21252806857142856,
      "system": 0.07871189714285713,
      "min": 0.2075282842,
      "max": 0.2746883122
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.08948696376666666,
      "stddev": 0.00254336546071998,
      "median": 0.0880470837,
      "user": 0.030403873333333324,
      "system": 0.014080071999999999,
      "min": 0.08628870620000001,
      "max": 0.0952010622
    },
    {
      "command": "pnpr@main",
      "mean": 0.09145861471515153,
      "stddev": 0.0023175620105692985,
      "median": 0.0920146282,
      "user": 0.0327380793939394,
      "system": 0.014934492121212123,
      "min": 0.08656005620000001,
      "max": 0.09521278320000001
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 241.5 ± 13.1 225.5 259.4 1.03 ± 0.08
pacquet@main 235.2 ± 12.6 220.3 264.8 1.00
pnpm@HEAD 3784.3 ± 163.0 3523.0 4045.6 16.09 ± 1.10
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.24151702890444446,
      "stddev": 0.013140100704814762,
      "median": 0.23984558846,
      "user": 0.2506972244444444,
      "system": 0.05569835777777778,
      "min": 0.22551257246,
      "max": 0.25937422646
    },
    {
      "command": "pacquet@main",
      "mean": 0.2351885012377778,
      "stddev": 0.0125582038719515,
      "median": 0.23496571646,
      "user": 0.24164800222222219,
      "system": 0.05712769111111111,
      "min": 0.22029726046,
      "max": 0.26483851946000003
    },
    {
      "command": "pnpm@HEAD",
      "mean": 3.784287482126667,
      "stddev": 0.1630069561691188,
      "median": 3.77310875046,
      "user": 5.788350335555555,
      "system": 0.34777502444444447,
      "min": 3.52301226146,
      "max": 4.04555425546
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 202.0 ± 5.9 193.1 211.9 1.00
pacquet@main 205.0 ± 5.5 195.3 213.8 1.01 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.20200558976285718,
      "stddev": 0.005862944809655519,
      "median": 0.20188634262000002,
      "user": 0.16140836285714283,
      "system": 0.07815602285714286,
      "min": 0.19307520112,
      "max": 0.21185270812
    },
    {
      "command": "pacquet@main",
      "mean": 0.20502529912000003,
      "stddev": 0.005503170277561106,
      "median": 0.20451004212,
      "user": 0.17055495076923072,
      "system": 0.07423599538461538,
      "min": 0.19534709312,
      "max": 0.21376386112
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 85.1 ± 2.8 79.7 92.0 1.03 ± 0.04
pacquet@main 82.7 ± 2.2 79.4 89.6 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.08506496772352941,
      "stddev": 0.002833427073480814,
      "median": 0.08545891289999999,
      "user": 0.032339170588235294,
      "system": 0.0590978294117647,
      "min": 0.0797143924,
      "max": 0.0920149914
    },
    {
      "command": "pacquet@main",
      "mean": 0.08266002617777778,
      "stddev": 0.0021846233647958,
      "median": 0.0820391464,
      "user": 0.03181464444444445,
      "system": 0.05712127222222222,
      "min": 0.07939909839999999,
      "max": 0.0896486654
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.478 ± 0.088 4.377 4.653 1.28 ± 0.04
pacquet@main 4.436 ± 0.127 4.367 4.782 1.27 ± 0.04
pnpr@HEAD 3.499 ± 0.073 3.424 3.669 1.00
pnpr@main 3.508 ± 0.123 3.399 3.791 1.00 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.47819219446,
      "stddev": 0.08849763864832308,
      "median": 4.47178557786,
      "user": 1.52324096,
      "system": 1.5716118000000001,
      "min": 4.37744151386,
      "max": 4.65344134186
    },
    {
      "command": "pacquet@main",
      "mean": 4.43571440066,
      "stddev": 0.1270435357508586,
      "median": 4.39107027336,
      "user": 1.44655296,
      "system": 1.4543570999999997,
      "min": 4.36731595586,
      "max": 4.78179816486
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.49867523996,
      "stddev": 0.07285870711417972,
      "median": 3.47846199536,
      "user": 1.32830996,
      "system": 1.3757107,
      "min": 3.42380150686,
      "max": 3.66876471586
    },
    {
      "command": "pnpr@main",
      "mean": 3.5084540118599996,
      "stddev": 0.12283926065338215,
      "median": 3.47045215336,
      "user": 1.3058734600000002,
      "system": 1.3897756999999997,
      "min": 3.39908664186,
      "max": 3.79144240986
    }
  ]
}

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 120.3 ± 8.7 110.5 154.7 1.00
pacquet@main 191.6 ± 27.0 151.9 235.2 1.59 ± 0.25
pnpr@HEAD 224.9 ± 19.9 199.2 251.7 1.87 ± 0.21
pnpr@main 166.1 ± 58.4 126.6 260.1 1.38 ± 0.50
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.12026627946000003,
      "stddev": 0.008740497286229916,
      "median": 0.11937722396,
      "user": 0.14900317818181816,
      "system": 0.12414568909090908,
      "min": 0.11050551446000001,
      "max": 0.15470653046000002
    },
    {
      "command": "pacquet@main",
      "mean": 0.19164495061384618,
      "stddev": 0.027018068101747287,
      "median": 0.19347428346,
      "user": 0.23119112923076918,
      "system": 0.18282628,
      "min": 0.15187719646,
      "max": 0.23523174246
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.22493955296,
      "stddev": 0.019922313994448295,
      "median": 0.22728352446,
      "user": 0.24991511,
      "system": 0.21065744666666664,
      "min": 0.19922836946,
      "max": 0.25167699046
    },
    {
      "command": "pnpr@main",
      "mean": 0.16605708656,
      "stddev": 0.058423816205311195,
      "median": 0.13019900896,
      "user": 0.19045716,
      "system": 0.15890917999999996,
      "min": 0.12655179246,
      "max": 0.26008066046000006
    }
  ]
}

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.127 ± 0.022 1.094 1.152 1.00
pacquet@main 1.177 ± 0.080 1.103 1.299 1.04 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.1265889001799998,
      "stddev": 0.0215499895343932,
      "median": 1.12780273528,
      "user": 0.5146650600000001,
      "system": 0.21402525999999997,
      "min": 1.09416889878,
      "max": 1.1522687837799999
    },
    {
      "command": "pacquet@main",
      "mean": 1.17688357508,
      "stddev": 0.08024097902248124,
      "median": 1.1405619907799998,
      "user": 0.6155192599999999,
      "system": 0.24695996,
      "min": 1.1031260297799999,
      "max": 1.29935432678
    }
  ]
}

@zkochan
zkochan marked this pull request as ready for review October 17, 2026 11:25
Copilot AI balanced review requested due to automatic review settings October 17, 2026 11:25
@zkochan

zkochan commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@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 mirror shortcut decisions in a pure pick route

✨ Enhancement 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Centralizes pre-registry mirror eligibility, disk-first reads, and fetch-failure fallback
 decisions without intended behavior changes.
• Keeps mirror content checks and mtime reads in the paths that need them.
• Adds table-driven tests for routing, freshness boundaries, and private-route fallback.
Diagram

graph TD
  Pick["Package pick"] --> Route["Pure route"] --> Shortcuts{"Mirror shortcuts"} --> Mirror["Pre-permit read"] -->|miss| Fetch["Registry fetch"]
  Route --> DiskFirst{"Disk first"} --> DiskRead["Post-permit read"] -->|miss| Fetch
  Fetch -->|failure| Fallback["Fallback rule"] -->|allowed| Mirror
Loading
High-Level Assessment

The pure route is a good fit for consolidating eligibility without moving mirror content checks or introducing eager mtime reads. A broader state-machine rewrite would add scope to a behavior-preserving refactor without a clear benefit here.

Files changed (5) +463 / -105

Refactor (4) +233 / -105
pick_package.rsUse the route's disk-first decision +8/-2

Use the route's disk-first decision

• Registers the route module and replaces the inline post-permit disk-read condition with 'DiskFirst::decide'. The uncacheable-mirror check remains conditional on the selected route.

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

fetch_pick.rsDelegate failed-fetch fallback eligibility +6/-13

Delegate failed-fetch fallback eligibility

• Uses the route's pure fallback rule before reading the scoped mirror, retaining the distinction between public errors and private-route access denials.

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

mirror_pick.rsDrive mirror reads from shortcut decisions +56/-90

Drive mirror reads from shortcut decisions

• Builds route inputs and tries only eligible pre-permit mirror shortcuts. Individual reads retain version, pick-agreement, and mtime checks instead of repeating eligibility rules.

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

route.rsDefine pure mirror and fallback routing rules +163/-0

Define pure mirror and fallback routing rules

• Introduces request, policy, and mirror-header inputs for deciding mirror shortcuts, disk-first reads, and fetch-failure fallback. It also owns the ETag-less mirror freshness rule and release-age cutoff eligibility.

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

Tests (1) +230 / -0
tests.rsCover route decisions with table-driven tests +230/-0

Cover route decisions with table-driven tests

• Tests shortcut exclusions, ETag and scope handling, release-age and offline cases, uncacheable mirrors, freshness boundaries, disk-first choices, and private-route fallback.

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

@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.

@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Remediation recommended

1. The claimed speedup lacks proof 📜 Skill insight ➹ Performance ⭐ New
Description
The refactor claims fewer metadata lookups and no added hot-path stat calls, but supplies no
numeric before-and-after measurement. Because the route changes shortcut evaluation and disk-read
decisions in pick_package, its performance impact remains unverified for resolver workloads.
Code

pnpm/crates/resolving-npm-resolver/src/pick_package/mirror_pick.rs[R26-30]

+        let inputs = self.route_inputs(ctx, spec, opts, headers.as_ref());
+        let shortcuts = MirrorShortcuts::decide(&inputs)?;
+        if shortcuts.exact_version
+            && let Some(result) = self.version_spec_pick(ctx, spec, opts, disk_meta).await
+        {
Relevance

●●● Strong

Recent performance reviews accept quantifying unverified speedup claims, especially for resolver and
hot-path changes.

PR-#16888
PR-#13491

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The checklist requires numeric before-and-after measurements whenever a PR claims a performance
improvement. The PR description claims fewer policy lookups and no added hot-path stat calls,
while the changed code centralizes shortcut and disk-read decisions without providing benchmark
results.

pnpm/crates/resolving-npm-resolver/src/pick_package/mirror_pick.rs[26-30]
pnpm/crates/resolving-npm-resolver/src/pick_package/route.rs[87-112]
Skill: review-code

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 PR claims performance benefits from centralizing shortcut decisions and reducing metadata lookups, but provides no quantitative before-and-after evidence.

## Fix Focus Areas
- pnpm/crates/resolving-npm-resolver/src/pick_package/mirror_pick.rs[26-30]
- pnpm/crates/resolving-npm-resolver/src/pick_package/route.rs[87-112]

## Recommended Fix
Add a representative resolver benchmark with repeated runs comparing the pre-refactor and post-refactor implementations, and record numeric before/after timings and variability in the PR description or an appropriate benchmark result file.

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

Dismiss ↗ | View ↗


2. Registry request behavior lacks tests 📎 Requirement gap ⚙ Maintainability
Description
The new test module exercises pure shortcut predicates but does not test mirror state transitions
through a mock registry. Installs two and three, representation-specific ETags, exact request logs,
304-only revalidation, and the v11/v12 differential therefore remain unverified for this change.
Code

pnpm/crates/resolving-npm-resolver/src/pick_package/route/tests.rs[R63-88]

+#[test]
+fn a_stable_range_pick_may_use_the_lockfile_version() {
+    let tagged = headers(Some(r#""etag""#), false);
+    assert_eq!(MirrorShortcuts::decide(&range_pick(Some(&tagged))), RANGE_SHORTCUTS);
+    assert_eq!(MirrorShortcuts::decide(&range_pick(None)), RANGE_SHORTCUTS);
+}
+
+#[test]
+fn every_option_that_needs_fresh_metadata_rules_out_the_range_shortcuts() {
+    let tagged = headers(Some(r#""etag""#), false);
+    let base = range_pick(Some(&tagged));
+    let cases: [(&str, RouteInputs<'_>); 7] = [
+        ("prefer-offline", RouteInputs { network: NetworkPolicy::PreferCache, ..base }),
+        ("pick lowest", with_request(base, |request| request.pick_lowest_version = true)),
+        ("latest tag", with_request(base, |request| request.include_latest_tag = true)),
+        ("update checksums", with_request(base, |request| request.update_checksums = true)),
+        ("release age", with_policy(base, |policy| policy.release_age_applies = true)),
+        ("no-downgrade", with_policy(base, |policy| policy.trust_no_downgrade = true)),
+        ("blocked versions", with_request(base, |request| request.has_blocked_versions = true)),
+    ];
+    for (name, inputs) in cases {
+        let shortcuts = MirrorShortcuts::decide(&inputs);
+        assert!(!shortcuts.dominant_lockfile_version, "{name}");
+        assert!(!shortcuts.unvalidated_mirror, "{name}");
+    }
+}
Evidence
The checklist requires table-driven coverage of cache and request dimensions plus a three-install
request-log test with 304-only responses and a v11/v12 differential. The changed tests cover pure
route outputs and helper decisions only; they contain no mock-registry install sequence, request-log
assertions, body-download assertions, or version differential.

Test registry cache state and request behavior
pnpm/crates/resolving-npm-resolver/src/pick_package/route/tests.rs[63-142]
pnpm/crates/resolving-npm-resolver/src/pick_package/route/tests.rs[144-229]

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 added tests verify only pure route decisions and do not cover the registry cache transitions and request behavior required by the checklist. The unchanged-cache install sequence, representation-specific ETags, 304-only responses on installs two and three, and the v11/v12 request-log differential remain untested.

## Fix Focus Areas
- pnpm/crates/resolving-npm-resolver/src/pick_package/route/tests.rs[63-229]
- pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached/tests.rs[1-161]

## Recommended Fix
Add a mock-registry integration test that performs three installs, records the complete request log, uses separate ETags for abbreviated and full representations, and asserts that installs two and three receive only 304 responses without downloading bodies. Include the equivalent v11 and v12 request-log comparison, while retaining the existing table-driven route tests for individual policy dimensions.

ⓘ 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
  Explored: repo: pnpm/update (sha: 2457663d) — View relationship
Review mode: Auto: ⚖️ Balanced: Downgraded extended -> standard: change is below the extended eligibility bar (hunks 14/18, lines 591/200; both must reach the floor). Router rationale: Multiple independent routing and caching paths create dense, subtle correctness and performance risks.

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

Previous reviews

Review updated until commit a70b6ee

Results up to commit c8d2011 ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (1) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Remediation recommended
1. Registry request behavior lacks tests 📎 Requirement gap ⚙ Maintainability
Description
The new test module exercises pure shortcut predicates but does not test mirror state transitions
through a mock registry. Installs two and three, representation-specific ETags, exact request logs,
304-only revalidation, and the v11/v12 differential therefore remain unverified for this change.
Code

pnpm/crates/resolving-npm-resolver/src/pick_package/route/tests.rs[R63-88]

+#[test]
+fn a_stable_range_pick_may_use_the_lockfile_version() {
+    let tagged = headers(Some(r#""etag""#), false);
+    assert_eq!(MirrorShortcuts::decide(&range_pick(Some(&tagged))), RANGE_SHORTCUTS);
+    assert_eq!(MirrorShortcuts::decide(&range_pick(None)), RANGE_SHORTCUTS);
+}
+
+#[test]
+fn every_option_that_needs_fresh_metadata_rules_out_the_range_shortcuts() {
+    let tagged = headers(Some(r#""etag""#), false);
+    let base = range_pick(Some(&tagged));
+    let cases: [(&str, RouteInputs<'_>); 7] = [
+        ("prefer-offline", RouteInputs { network: NetworkPolicy::PreferCache, ..base }),
+        ("pick lowest", with_request(base, |request| request.pick_lowest_version = true)),
+        ("latest tag", with_request(base, |request| request.include_latest_tag = true)),
+        ("update checksums", with_request(base, |request| request.update_checksums = true)),
+        ("release age", with_policy(base, |policy| policy.release_age_applies = true)),
+        ("no-downgrade", with_policy(base, |policy| policy.trust_no_downgrade = true)),
+        ("blocked versions", with_request(base, |request| request.has_blocked_versions = true)),
+    ];
+    for (name, inputs) in cases {
+        let shortcuts = MirrorShortcuts::decide(&inputs);
+        assert!(!shortcuts.dominant_lockfile_version, "{name}");
+        assert!(!shortcuts.unvalidated_mirror, "{name}");
+    }
+}
Evidence
The checklist requires table-driven coverage of cache and request dimensions plus a three-install
request-log test with 304-only responses and a v11/v12 differential. The changed tests cover pure
route outputs and helper decisions only; they contain no mock-registry install sequence, request-log
assertions, body-download assertions, or version differential.

Test registry cache state and request behavior
pnpm/crates/resolving-npm-resolver/src/pick_package/route/tests.rs[63-142]
pnpm/crates/resolving-npm-resolver/src/pick_package/route/tests.rs[144-229]

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 added tests verify only pure route decisions and do not cover the registry cache transitions and request behavior required by the checklist. The unchanged-cache install sequence, representation-specific ETags, 304-only responses on installs two and three, and the v11/v12 request-log differential remain untested.

## Fix Focus Areas
- pnpm/crates/resolving-npm-resolver/src/pick_package/route/tests.rs[63-229]
- pnpm/crates/resolving-npm-resolver/src/fetch_full_metadata_cached/tests.rs[1-161]

## Recommended Fix
Add a mock-registry integration test that performs three installs, records the complete request log, uses separate ETags for abbreviated and full representations, and asserts that installs two and three receive only 304 responses without downloading bodies. Include the equivalent v11 and v12 request-log comparison, while retaining the existing table-driven route tests for individual policy dimensions.

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

Dismiss ↗ | View ↗


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.

RouteInputs computed release_age_applies_to for every pick that reached
the mirror shortcuts. That included a pinned version the mirror answers,
which the old code never asked about. The inputs now hold the pick policy
and the package name, so the lookup runs only where it is needed:

- range_pick_is_stable tests it last, after the cheap flags.
- written_after, moved onto RouteInputs, runs only after the other
  shortcuts missed.

A pinned-version hit does no lookup, and a stable range that falls
through does at most two. The old code did up to three, because it
checked range stability twice. The route tests now build a real
PackagePickPolicy, with a minimumReleaseAgeExclude rule for the excluded
cases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 17, 2026 11:47

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.

@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.

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit a70b6ee

@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.

@zkochan

zkochan commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

On Qodo's "The claimed speedup lacks proof": this PR claims no speedup over main, so there is nothing to benchmark. a70b6ee restores the laziness the first commit lost, where release_age_applies_to ran on every pick.

The lookup counts in the description come from the code paths:

  • A pinned version the mirror answers never reaches range_pick_is_stable's release-age check, because spec_type short-circuits first. It never reaches written_after either, because the version read returns first.
  • On main, a falling-through stable range called range_pick_is_stable twice, once in dominant_version_pick and once via range_can_reuse_unvalidated_mirror, plus once in published_by_pick. Here decide calls it once.

No stat was added, because get_file_mtime is still called only inside the two shortcuts that need it.


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

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

Labels

product: pacquet reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants