Skip to content

refactor(npm-resolver): decide the pick's mirror shortcuts and cache hit from inputs alone - #17064

Merged
zkochan merged 3 commits into
mainfrom
fix-146-v11-cache-policy
Oct 17, 2026
Merged

zkochan merged 3 commits into
mainfrom
fix-146-v11-cache-policy

Conversation

@zkochan

@zkochan zkochan commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Part of pnpm/tasks#146, v11 only. This is the v11 counterpart of #17032 and #17051. It changes no behavior.

src/route.ts holds the decisions pickPackage makes before it reads a mirror's content:

Decision Replaces
readsMirrorFirst the guard at the top of pickFromMirrorPreferringOffline
decideMirrorShortcuts (exactVersion, dominantLockfileVersion, unvalidatedMirror) the guards of pickExactVersionFromMirror, pickStableRangeFromMirror, pickFromFreshUnvalidatedMirror, and canReuseStableCachedRange
mirrorWrittenAfter the guard of pickFromMirrorWrittenAfterCutoff
isMirrorWithoutEtag, isFreshUnvalidatedMirror isReusableMirrorWithoutEtag, isYoungerThanUnvalidatedMirrorMaxAge
decideCacheHitCheck (serve, stableRangePick, revalidate) isUnverifiedPickSafe and the cacheResultCanReturn expression

pickPackage.ts keeps the reads and the content checks.

Hot path. No pick does more work than before. The shortcuts are a few flag reads, decided only after the mirror-first read misses. The publishedByExclude lookup still runs last, and only when a cutoff is set. A test pins that order. The cache hit now computes the dominant lockfile version only for an unverified stable-range pick. Before, it computed it for every unverified hit.

Tests. test/route.test.ts has table tests with v12's route cases. To test the tests, I made decideCacheHitCheck serve where it returns stableRangePick, and let pnpm update reuse an unvalidated mirror. The new table tests failed, and so did the existing metaCache.test.ts tests. The full npm-resolver suite passes: 580 tests.

Where v11 and v12 differ. I kept these as they are. Each would be its own fix with its own tests:

  • Stable-range shortcuts with minimumReleaseAge. v11 rules them out whenever minimumReleaseAge is set, even for an excluded package. v12 rules them out only where the release age applies, so v11 is more conservative.
  • Stable-range shortcuts after prefer-offline. v12 also rules them out for prefer-offline and offline. In v11 a prefer-offline pick that the mirror-first read missed still tries them.
  • The unvalidated-mirror shortcut on private routes. v12 limits it to public routes, so a private route still contacts the registry and a 401 is not hidden. v11 has no public/private route split.
  • A failed fetch. v12 fails closed on a private route's 401/403/private 404. v11 falls back to the mirror on any error.

No changeset: there is no user-visible change.

Squash Commit Body

`route.ts` holds the decisions `pickPackage` makes before it reads a
mirror's content, as pnpm v12's `pick_package::route` does:
`readsMirrorFirst`, `decideMirrorShortcuts`, `mirrorWrittenAfter`, the
unvalidated-mirror checks, and `decideCacheHitCheck` for an in-memory
hit. `pickPackage.ts` keeps the reads and the content checks.
`canReuseStableCachedRange` and `isUnverifiedPickSafe` are gone: both
asked the same stable-range question. No behavior change. Table 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.
  • 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

  • Improvements
    • Package resolution now applies consistent cache and mirror-selection rules for online, offline, and prefer-offline requests.
    • Exact-version requests and stable version ranges follow their applicable shortcuts, while release cutoffs and mirror freshness guide when cached metadata can be reused.
    • Cached package metadata is served, revalidated, or selected based on verification status and request options, helping keep results aligned with lockfile versions.
    • Unvalidated mirror metadata is reused only when it meets freshness and cacheability checks.

…hit from inputs alone

`route.ts` holds the decisions `pickPackage` makes before it reads a
mirror's content, as pnpm v12's `pick_package::route` does:
`readsMirrorFirst`, `decideMirrorShortcuts`, `mirrorWrittenAfter`, the
unvalidated-mirror checks, and `decideCacheHitCheck` for an in-memory
hit. `pickPackage.ts` keeps the reads and the content checks.
`canReuseStableCachedRange` and `isUnverifiedPickSafe` are gone: both
asked the same stable-range question. No behavior change. Table tests
cover each decision.

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: 7f6f948e-24dc-42bb-81e3-166ed863b2d9
📥 Commits

Reviewing files that changed from the base of the PR and between e140edf and 093e584.

📒 Files selected for processing: 1
  • pnpm11/resolving/npm-resolver/src/route.ts
🚧 Files skipped from review as they are similar to previous changes: 1
  • pnpm11/resolving/npm-resolver/src/route.ts

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

📝 Walkthrough

The resolver now delegates cache-hit and mirror-routing decisions to route.ts. pickPackage.ts uses those decisions to select cache and mirror paths. Tests cover routing helper behavior.

Changes: npm resolver routing

Layer / File(s) Summary
Mirror routing rules
pnpm11/resolving/npm-resolver/src/route.ts, pnpm11/resolving/npm-resolver/test/route.test.ts
Adds mirror-first selection, mirror shortcut eligibility, cutoff handling, and unvalidated-mirror header and freshness checks. Tests cover these rules.
Cache-hit decisions
pnpm11/resolving/npm-resolver/src/route.ts, pnpm11/resolving/npm-resolver/test/route.test.ts
Adds cache-hit outcomes for verified, offline, picked, and stable-range entries. Tests cover the decision cases.
Resolver integration
pnpm11/resolving/npm-resolver/src/pickPackage.ts
Uses routing decisions for cache hits and mirror reads. Mirror and registry fallbacks remain in the resolution flow.

Priority: ⬇️ Low

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

Change: Refactor

Suggested labels: product: pnpm@11

Suggested reviewers: ksxgithub

Merge Risk: ⚪ Minimal · up to 093e5

This refactor moves npm resolver routing decisions into a dedicated module without intended behavior changes. No concrete merge-blocking risk was identified.

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

@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 20:25

@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

Refactor v11 npm resolver mirror and cache-hit routing

✨ Enhancement 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Centralizes mirror shortcut and cache-hit decisions in request-driven routing helpers without
 intended behavior changes.
• Keeps mirror reads and content validation in pickPackage, preserving fallback order.
• Adds table tests for routing policies, cache-hit decisions, and mirror freshness boundaries.
Diagram

graph TD
  A["Pick request"] --> B{"Memory hit?"} -->|yes| C["Cache policy"] --> D{"Serve hit?"} -->|yes| E["Return pick"]
  D -->|no| F["Mirror route policy"] --> G["Mirror reads"] -->|miss| H["Registry fetch"] --> E
  B -->|no| F
  G -->|match| E
Loading
High-Level Assessment

The request-driven policy helpers are a good fit: they make routing decisions independently testable while leaving I/O and content checks in the existing resolver. Keeping the guards embedded in pickPackage was considered, but would retain duplicated stable-range policy and make the decisions harder to test in isolation.

Files changed (3) +320 / -87

Refactor (2) +172 / -87
pickPackage.tsDelegate routing decisions while retaining mirror reads +40/-87

Delegate routing decisions while retaining mirror reads

• Replaces inline mirror-shortcut and cache-hit guards with calls to 'route.ts'. It preserves ordered mirror attempts and content checks, and calculates the dominant lockfile version for an in-memory hit only when the policy requires it.

pnpm11/resolving/npm-resolver/src/pickPackage.ts

route.tsExtract request-driven mirror and cache-hit policies +132/-0

Extract request-driven mirror and cache-hit policies

• Adds helpers for mirror-first reads, eligible shortcuts, release-age cutoffs, ETag-less mirror freshness, and cache-hit checks. The stable-range eligibility rule is shared between mirror and in-memory cache decisions.

pnpm11/resolving/npm-resolver/src/route.ts

Tests (1) +148 / -0
route.test.tsCover routing decisions with table tests +148/-0

Cover routing decisions with table tests

• Tests mirror and cache policies across offline modes, pinned versions, ranges, release-age restrictions, and refresh options. It also checks exclusion-callback order, ETag handling, and both freshness boundaries.

pnpm11/resolving/npm-resolver/test/route.test.ts

@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Action required

1. Cache regressions lack request-log proof ✗ Dismissed
Description
The added route.test.ts exercises only pure routing decisions and never runs the resolver against
a mock registry to verify mirror writes, validators, or response bodies. A routing change can
therefore pass these tests while still issuing unexpected requests or downloading bodies on repeated
installs, leaving the cache transition behavior unverified.
Code

pnpm11/resolving/npm-resolver/test/route.test.ts[R121-125]

+describe('decideCacheHitCheck', () => {
+  test.each([true, false])('a verified or offline hit is served, picked: %s', (picked) => {
+    expect(decideCacheHitCheck(rangePick(), true, picked)).toBe('serve')
+    expect(decideCacheHitCheck(rangePick({}, { offline: true }), false, picked)).toBe('serve')
+  })
Relevance

●●● Strong

A same-day resolver precedent accepted adding three-install request-log and 304-response coverage
for cache behavior.

PR-#17044

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The compliance rule requires table-driven cache-transition and response-write coverage, including a
three-install request-log assertion with only 304 responses on later installs. The added tests
invoke only decideCacheHitCheck, decideMirrorShortcuts, and related pure helpers, so they do not
exercise registry responses, mirror writes, or repeated-install request behavior.

Test cache transitions and unchanged-registry requests
pnpm11/resolving/npm-resolver/test/route.test.ts[33-147]

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 tests cover the pure route decision helpers but do not verify cache transitions or unchanged-registry requests. They cannot detect incorrect mirror header writes, validator handling, unexpected response bodies, or request behavior across repeated installs.

## Fix Focus Areas
- pnpm11/resolving/npm-resolver/test/route.test.ts[121-147]
- pnpm11/resolving/npm-resolver/test/metaCache.test.ts[1-1]

## Recommended Fix
Add an integration-level table or scenario using a mock registry with representation-specific ETags. Perform three installs, assert the exact request log, and verify that installs two and three receive only 304 responses without downloaded response bodies while covering mirror state, status, Cache-Control, ETag, network mode, document kind, and release-age cases.

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



Remediation recommended

2. Test helpers are declared before use ✓ Resolved
Description
The new rangePick and versionPick function declarations precede every call site in
route.test.ts. The table cases first invoke them after both declarations, so the file does not
place a usage before either helper definition.
Code

pnpm11/resolving/npm-resolver/test/route.test.ts[R19-24]

+function rangePick (overrides: Partial<RouteInputs['opts']> = {}, ctx: RouteInputs['ctx'] = {}): RouteInputs {
+  return { ctx, spec: { type: 'range', name: PKG_NAME }, opts: overrides }
+}
+
+function versionPick (overrides: Partial<RouteInputs['opts']> = {}, ctx: RouteInputs['ctx'] = {}): RouteInputs {
+  return { ctx, spec: { type: 'version', name: PKG_NAME }, opts: overrides }
Relevance

●●● Strong

Recent resolver-test precedent accepted moving helper declarations after their first usages under
this declaration-order rule.

PR-#16968

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
rangePick is declared at lines 19-21 and versionPick at lines 23-25, while their first usages
occur later in the table tests beginning at lines 35 and 64.

Rule 713432: Declare TypeScript functions only after their first usage
pnpm11/resolving/npm-resolver/test/route.test.ts[19-25]
pnpm11/resolving/npm-resolver/test/route.test.ts[33-40]
pnpm11/resolving/npm-resolver/test/route.test.ts[63-71]

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 top-level test helper declarations appear before their first usages in the same file, contrary to the declaration-order convention.

## Fix Focus Areas
- pnpm11/resolving/npm-resolver/test/route.test.ts[19-24]
- pnpm11/resolving/npm-resolver/test/route.test.ts[33-40]
- pnpm11/resolving/npm-resolver/test/route.test.ts[63-71]

## Recommended Fix
Reorder the test structure so each helper function has a call site before its declaration, or place the helper declarations after an initial usage while preserving the existing test behavior.

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



Informational

3. Route type list misses its final comma ⊘ Outdated
Description
The multi-line Pick<PickPackageOptions, ...> type in RouteInputs.opts ends with trustPolicy
without a trailing comma. Future additions to this type list will create an inconsistent multi-line
style and noisier diffs.
Code

pnpm11/resolving/npm-resolver/src/route.ts[R13-20]

+  opts: Pick<PickPackageOptions,
+  'includeLatestTag' |
+  'updateChecksums' |
+  'refreshMetadata' |
+  'pickLowestVersion' |
+  'publishedBy' |
+  'publishedByExclude' |
+  'trustPolicy'
Relevance

● Weak

Recent TypeScript formatting precedents rejected trailing-comma requests in multiline signatures and
calls.

PR-#17044
PR-#16968

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The added RouteInputs.opts type places each Pick member on its own line, but the final
trustPolicy member has no trailing comma.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/resolving/npm-resolver/src/route.ts[13-20]

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 multi-line TypeScript type argument list for `RouteInputs.opts` does not include a trailing comma after its final member.

## Fix Focus Areas
- pnpm11/resolving/npm-resolver/src/route.ts[13-20]

## Recommended Fix
Add a comma after `trustPolicy` so the final item in the multi-line `Pick` type follows the repository's required trailing-comma convention.

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


4. Published resolver change lacks a changeset 📘 Rule violation § Compliance
Description
The new resolver route code is part of the published @pnpm/resolving.npm-resolver package, but the
PR adds no .changeset entry. Because this source is compiled into the package distributed from
lib, the release process has no version bump metadata for the change.
Code

pnpm11/resolving/npm-resolver/src/route.ts[R1-3]

+import type { MetaHeaders } from './metaMirror.js'
+import type { RegistryPackageSpec } from './parseBareSpecifier.js'
+import type { PickPackageOptions } from './pickRequest.js'
Relevance

● Weak

Recent precedent rejected a no-changeset finding for an internal published resolver refactor with no
behavior change.

PR-#17023

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The changed route.ts file adds resolver source code, while the package manifest identifies
@pnpm/resolving.npm-resolver as a package distributed from lib. No changeset file appears in the
PR diff, violating the requirement for published package changes.

Rule 713441: Require changeset files for changes affecting published packages
pnpm11/resolving/npm-resolver/src/route.ts[1-3]
pnpm11/resolving/npm-resolver/package.json[1-3]

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 changes source code in the published `@pnpm/resolving.npm-resolver` package without adding release metadata.

## Fix Focus Areas
- pnpm11/resolving/npm-resolver/src/route.ts[1-3]
- pnpm11/resolving/npm-resolver/package.json[1-3]

## Recommended Fix
Add a new markdown file under `.changeset/` with a `patch` entry for `@pnpm/resolving.npm-resolver` and describe the resolver refactor as internal maintenance with no user-visible behavior change.

ⓘ 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): 55 rules
✅ Cross-repo context — repo relationships
Review mode: Auto: 🚀 Fast: Localized type-only refactor with no runtime behavior or security impact.

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 093e584

Results up to commit cbf03d4 ⚖️ Balanced


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


Action required
1. Cache regressions lack request-log proof ✗ Dismissed
Description
The added route.test.ts exercises only pure routing decisions and never runs the resolver against
a mock registry to verify mirror writes, validators, or response bodies. A routing change can
therefore pass these tests while still issuing unexpected requests or downloading bodies on repeated
installs, leaving the cache transition behavior unverified.
Code

pnpm11/resolving/npm-resolver/test/route.test.ts[R121-125]

+describe('decideCacheHitCheck', () => {
+  test.each([true, false])('a verified or offline hit is served, picked: %s', (picked) => {
+    expect(decideCacheHitCheck(rangePick(), true, picked)).toBe('serve')
+    expect(decideCacheHitCheck(rangePick({}, { offline: true }), false, picked)).toBe('serve')
+  })
Relevance

●●● Strong

A same-day resolver precedent accepted adding three-install request-log and 304-response coverage
for cache behavior.

PR-#17044

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The compliance rule requires table-driven cache-transition and response-write coverage, including a
three-install request-log assertion with only 304 responses on later installs. The added tests
invoke only decideCacheHitCheck, decideMirrorShortcuts, and related pure helpers, so they do not
exercise registry responses, mirror writes, or repeated-install request behavior.

Test cache transitions and unchanged-registry requests
pnpm11/resolving/npm-resolver/test/route.test.ts[33-147]

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 tests cover the pure route decision helpers but do not verify cache transitions or unchanged-registry requests. They cannot detect incorrect mirror header writes, validator handling, unexpected response bodies, or request behavior across repeated installs.

## Fix Focus Areas
- pnpm11/resolving/npm-resolver/test/route.test.ts[121-147]
- pnpm11/resolving/npm-resolver/test/metaCache.test.ts[1-1]

## Recommended Fix
Add an integration-level table or scenario using a mock registry with representation-specific ETags. Perform three installs, assert the exact request log, and verify that installs two and three receive only 304 responses without downloaded response bodies while covering mirror state, status, Cache-Control, ETag, network mode, document kind, and release-age cases.

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



Remediation recommended
2. Test helpers are declared before use ✓ Resolved
Description
The new rangePick and versionPick function declarations precede every call site in
route.test.ts. The table cases first invoke them after both declarations, so the file does not
place a usage before either helper definition.
Code

pnpm11/resolving/npm-resolver/test/route.test.ts[R19-24]

+function rangePick (overrides: Partial<RouteInputs['opts']> = {}, ctx: RouteInputs['ctx'] = {}): RouteInputs {
+  return { ctx, spec: { type: 'range', name: PKG_NAME }, opts: overrides }
+}
+
+function versionPick (overrides: Partial<RouteInputs['opts']> = {}, ctx: RouteInputs['ctx'] = {}): RouteInputs {
+  return { ctx, spec: { type: 'version', name: PKG_NAME }, opts: overrides }
Relevance

●●● Strong

Recent resolver-test precedent accepted moving helper declarations after their first usages under
this declaration-order rule.

PR-#16968

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
rangePick is declared at lines 19-21 and versionPick at lines 23-25, while their first usages
occur later in the table tests beginning at lines 35 and 64.

Rule 713432: Declare TypeScript functions only after their first usage
pnpm11/resolving/npm-resolver/test/route.test.ts[19-25]
pnpm11/resolving/npm-resolver/test/route.test.ts[33-40]
pnpm11/resolving/npm-resolver/test/route.test.ts[63-71]

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 top-level test helper declarations appear before their first usages in the same file, contrary to the declaration-order convention.

## Fix Focus Areas
- pnpm11/resolving/npm-resolver/test/route.test.ts[19-24]
- pnpm11/resolving/npm-resolver/test/route.test.ts[33-40]
- pnpm11/resolving/npm-resolver/test/route.test.ts[63-71]

## Recommended Fix
Reorder the test structure so each helper function has a call site before its declaration, or place the helper declarations after an initial usage while preserving the existing test behavior.

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



Informational
3. Published resolver change lacks a changeset 📘 Rule violation § Compliance
Description
The new resolver route code is part of the published @pnpm/resolving.npm-resolver package, but the
PR adds no .changeset entry. Because this source is compiled into the package distributed from
lib, the release process has no version bump metadata for the change.
Code

pnpm11/resolving/npm-resolver/src/route.ts[R1-3]

+import type { MetaHeaders } from './metaMirror.js'
+import type { RegistryPackageSpec } from './parseBareSpecifier.js'
+import type { PickPackageOptions } from './pickRequest.js'
Relevance

● Weak

Recent precedent rejected a no-changeset finding for an internal published resolver refactor with no
behavior change.

PR-#17023

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The changed route.ts file adds resolver source code, while the package manifest identifies
@pnpm/resolving.npm-resolver as a package distributed from lib. No changeset file appears in the
PR diff, violating the requirement for published package changes.

Rule 713441: Require changeset files for changes affecting published packages
pnpm11/resolving/npm-resolver/src/route.ts[1-3]
pnpm11/resolving/npm-resolver/package.json[1-3]

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 changes source code in the published `@pnpm/resolving.npm-resolver` package without adding release metadata.

## Fix Focus Areas
- pnpm11/resolving/npm-resolver/src/route.ts[1-3]
- pnpm11/resolving/npm-resolver/package.json[1-3]

## Recommended Fix
Add a new markdown file under `.changeset/` with a `patch` entry for `@pnpm/resolving.npm-resolver` and describe the resolver refactor as internal maintenance with no user-visible behavior change.

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

Dismiss ↗ | View ↗


4. Route type list misses its final comma ⊘ Outdated
Description
The multi-line Pick<PickPackageOptions, ...> type in RouteInputs.opts ends with trustPolicy
without a trailing comma. Future additions to this type list will create an inconsistent multi-line
style and noisier diffs.
Code

pnpm11/resolving/npm-resolver/src/route.ts[R13-20]

+  opts: Pick<PickPackageOptions,
+  'includeLatestTag' |
+  'updateChecksums' |
+  'refreshMetadata' |
+  'pickLowestVersion' |
+  'publishedBy' |
+  'publishedByExclude' |
+  'trustPolicy'
Relevance

● Weak

Recent TypeScript formatting precedents rejected trailing-comma requests in multiline signatures and
calls.

PR-#17044
PR-#16968

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The added RouteInputs.opts type places each Pick member on its own line, but the final
trustPolicy member has no trailing comma.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/resolving/npm-resolver/src/route.ts[13-20]

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 multi-line TypeScript type argument list for `RouteInputs.opts` does not include a trailing comma after its final member.

## Fix Focus Areas
- pnpm11/resolving/npm-resolver/src/route.ts[13-20]

## Recommended Fix
Add a comma after `trustPolicy` so the final item in the multi-line `Pick` type follows the repository's required trailing-comma convention.

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


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.

Copilot AI balanced review requested due to automatic review settings October 17, 2026 20:40

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.

@zkochan

zkochan commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

Qodo findings:

  1. Cache regressions lack request-log proof. Answered in the thread. The three-install request-log harness from test: share the three-install request-log cases between pnpm v11 and v12 #17063 already covers v11, and metaCache.test.ts catches a broken route decision.
  2. Test helpers are declared before use. Fixed in e140edf. rangePick and versionPick now sit at the end of route.test.ts.
  3. Published resolver change lacks a changeset. Declined. This is a refactor with no user-visible change, so there is no release note to write. The v12 refactors in refactor(resolving-npm-resolver): move metadata cache decisions into one policy module #17024, refactor(resolving-npm-resolver): decide the pick's mirror shortcuts in one pure route #17032, and refactor(resolving-npm-resolver): decide the in-memory cache hit's check from inputs alone #17051 also landed without one.

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

@qodo-code-review

Copy link
Copy Markdown

Qodo findings:

  1. Cache regressions lack request-log proof. Answered in the thread. The three-install request-log harness from test: share the three-install request-log cases between pnpm v11 and v12 #17063 already covers v11, and metaCache.test.ts catches a broken route decision.
  2. Test helpers are declared before use. Fixed in e140edf. rangePick and versionPick now sit at the end of route.test.ts.
  3. Published resolver change lacks a changeset. Declined. This is a refactor with no user-visible change, so there is no release note to write. The v12 refactors in refactor(resolving-npm-resolver): move metadata cache decisions into one policy module #17024, refactor(resolving-npm-resolver): decide the pick's mirror shortcuts in one pure route #17032, and refactor(resolving-npm-resolver): decide the in-memory cache hit's check from inputs alone #17051 also landed without one.

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

Thanks for the update. The current review state is:

The v12 precedents support the rationale for finding 3, but they do not automatically change this PR’s finding status.

@qodo-code-review

Copy link
Copy Markdown

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

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

Copilot AI balanced review requested due to automatic review settings October 17, 2026 21:00
@zkochan

zkochan commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

Qodo finding 4 (route type list misses its final comma): fixed in 093e584. The keys are now a named RouteOption union, one per line, so the Pick takes a single type argument. Finding 3 (changeset) stays declined, as explained above.


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

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

Qodo finding 4 (route type list misses its final comma): fixed in 093e584. The keys are now a named RouteOption union, one per line, so the Pick takes a single type argument. Finding 3 (changeset) stays declined, as explained above.


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

Understood. The route type-list finding is currently listed as finding 3 in the published review (despite your reference to finding 4), and your commit 093e58487e addresses it by introducing the RouteOption union. The changeset finding remains open/declined; I can’t change its review status here without an explicit dismissal request.

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 093e584

@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 merged commit 753896e into main Oct 17, 2026
38 checks passed
@zkochan
zkochan deleted the fix-146-v11-cache-policy branch October 17, 2026 21:16
@zkochan

zkochan commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

Correction to the description's "Where v11 and v12 differ" list. Two of the four items are not CLI differences. v12's MetadataCacheScope::Private comes only from a route hook, which pnpr sets when it embeds the resolver. The pnpm CLI has no route hook, so every v12 CLI fetch is Public (pnpm/crates/network/src/auth.rs).

  • The unvalidated-mirror shortcut on private routes: the v12 CLI always takes the public path, as v11 does.
  • Fail-closed after a failed fetch: the v12 CLI also falls back to the mirror on any error, including 401/403/404, as v11 does.

The other two items, the stable-range shortcuts under minimumReleaseAge exclusions and after a missed prefer-offline read, are real v11/v12 differences.


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: pnpm@11 reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants