Skip to content

fix: decline a fast lockfile update that leaves a patch unused - #13828

Merged
zkochan merged 8 commits into
mainfrom
fix-13827
Aug 11, 2026
Merged

zkochan merged 8 commits into
mainfrom
fix-13827

Conversation

@zkochan

@zkochan zkochan commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

Summary

A patch whose last dependent is dropped has nothing left to apply to.
verifyPatches runs from the resolver, so the composed fast-update pipeline
was the only path that could reach that state and not report it — it wrote a
lockfile whose patchedDependencies named a package it had just pruned, where
a resolution raises ERR_PNPM_UNUSED_PATCH:

applied: true
patchedDependencies: {"[email protected]":"sha512-patch"}
packages: ["[email protected]"]

The check already existed, but only inside the patched-dependencies handler,
which runs only when the patch configuration itself drifted. A removal is
exactly a run where it did not, so all three removal shapes were affected: a
dependency dropped from a manifest, a widened ignoredOptionalDependencies,
and a removal override.

It now runs over the settled graph at the end of the pipeline, after every
handler's removals are pruned, in both stacks. allowUnusedPatches keeps its
existing meaning — it downgrades the error to a warning the resolution emits,
and as elsewhere in these handlers a warning alone is not worth a full
resolution.

Both new tests were confirmed to fail against the unfixed source, so they pin
the behaviour rather than passing either way.

Closes #13827.

Squash Commit Body

A patch whose last dependent is dropped has nothing left to apply to.
`verifyPatches` runs from the resolver, so the composed pipeline was the
only path that could reach that state and not report it: it wrote a
lockfile whose `patchedDependencies` named a package it had just pruned,
where a resolution raises `ERR_PNPM_UNUSED_PATCH`.

The check existed, but only inside the patched-dependencies handler,
which runs only when the patch configuration itself drifted. A removal
is exactly a run where it did not — whether the edge goes away with a
manifest dependency, a widened `ignoredOptionalDependencies`, or a
removal override.

It now runs over the settled graph at the end of the pipeline, where
every handler's removals are already pruned. `allowUnusedPatches` keeps
its existing meaning: it downgrades the error to a warning the
resolution emits, and as elsewhere in these handlers a warning alone is
not worth a full resolution.

Closes pnpm/pnpm#13827.

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.

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


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

Summary by CodeRabbit

  • Bug Fixes
    • Installs now perform full resolution when removing the last dependent of a patched package.
    • Unused patches are reported instead of silently updating the lockfile.
    • Fast updates now correctly fall back to resolution when configured patches are no longer applied.
    • Patched snapshots are pruned when unused patches are explicitly allowed.
    • Unused-patch warnings are shown only for successfully committed lockfile updates.
  • Tests
    • Added coverage for patched dependency removal, overrides, transitive dependencies, and unused-patch handling.

Copilot AI lite review requested due to automatic review settings August 11, 2026 12:28

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.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Fast update paths now validate configured patches after dependency removal and lockfile composition. Unapplied patches trigger resolution fallback unless unused patches are allowed. Rust and TypeScript tests cover removal, retained reachability, and allowed unused patches.

Changes

Patched dependency validation

Layer / File(s) Summary
Patch applicability helpers
pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs, pnpm11/installing/deps-installer/src/install/tryFastUpdatePatchedDependencies.ts
Added validation for configured patch applicability and unused-patch reporting.
Composed update validation
pnpm/crates/package-manager/src/fast_update_compose.rs, pnpm11/installing/deps-installer/src/install/tryComposeFastUpdates.ts
Hashes configured patches once and validates them after composed updates.
Lockfile warning reporting
pnpm/crates/package-manager/src/install/lockfile_freshness.rs, pnpm/crates/package-manager/src/install/run.rs, pnpm11/installing/deps-installer/src/install/index.ts
Reports unused patches only after a fast lockfile candidate passes validation and is committed.
Removal behavior coverage
pnpm/crates/package-manager/src/fast_update_compose/tests.rs, pnpm11/installing/deps-installer/test/install/patchedDependenciesFastUpdate.ts, pnpm/crates/cli/tests/suite/lockfile_resolution_reuse.rs, .changeset/unused-patch-after-removal.md
Added coverage and release metadata for orphaned patches, retained patched dependencies, allowed unused patches, and warning output.

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

Assessment against linked issues

Objective Addressed Explanation
[#13827] Reject fast updates that leave configured patches unused ✅
[#13827] Preserve successful fast updates when patched dependencies remain reachable or unused patches are allowed ✅

Suggested labels: product: pacquet, product: pnpm@11

Sequence Diagram(s)

sequenceDiagram
  participant Install
  participant FastUpdateHandlers
  participant PatchValidation
  participant Resolver
  Install->>FastUpdateHandlers: compose dependency and graph updates
  FastUpdateHandlers-->>Install: return candidate lockfile
  Install->>PatchValidation: validate configured patches
  PatchValidation-->>Install: return validation result
  Install->>Resolver: fall back when a patch is unapplied
Loading
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-13827

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.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Fix fast lockfile updates that leave patchedDependencies entries unused

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Prevent fast-update pipeline from writing lockfiles with unused patchedDependencies entries.
• Add a final “all configured patches are applied” verification for both TS and Rust paths.
• Add regression tests for removal scenarios; document behavior via changeset.
Diagram

graph TD
  A["Fast update compose"] --> B["Apply drift handlers"] --> C["Candidate lockfile"] --> D{ "Every patch applied?" } --> E["Accept fast update"]
  D -->|"No"| F["Fallback: full resolution"]

  subgraph Legend
    direction LR
    _proc["Process step"] ~~~ _dec{"Decision"}
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Validate unused patches inside each drift handler
  • ➕ Keeps checks close to the code that prunes edges
  • ➕ Potentially provides more specific decline reasons per handler
  • ➖ Easy to miss new removal paths (the root cause here)
  • ➖ Duplicates logic across handlers/stacks
2. Always fallback to full resolution when removals occur and patches are configured
  • ➕ Simplest correctness model; avoids subtle fast-path corner cases
  • ➖ Unnecessarily slow for common removals that still keep patches applied
  • ➖ Regresses performance for large workspaces
3. Auto-prune patchedDependencies entries during graph pruning
  • ➕ Keeps lockfile internally consistent without forcing a resolver run
  • ➕ Avoids extra verification pass
  • ➖ Risks changing semantics (may silently drop misconfigurations that resolver should report)
  • ➖ Requires careful alignment with resolver’s verifyPatches behavior across stacks

Recommendation: Current approach is the best tradeoff: a single, end-of-pipeline check over the settled/pruned graph reliably catches all removal shapes (manifest drops, ignoredOptionalDependencies widening, removal overrides) without duplicating logic. It preserves existing semantics of allowUnusedPatches (warning-only) and correctly declines to the resolver when an actual ERR_PNPM_UNUSED_PATCH would be raised.

Files changed (7) +221 / -7

Bug fix (3) +48 / -0
fast_update_compose.rsRun final unused-patch verification in Rust fast-update compose +8/-0

Run final unused-patch verification in Rust fast-update compose

• Adds a final step to the Rust fast-update composition pipeline to ensure all configured patches are still applied in the settled lockfile graph. Declines fast update (returns None) to force a full resolution when an unused patch would remain.

pnpm/crates/package-manager/src/fast_update_compose.rs

fast_update_patched_dependencies.rsExtract Rust helper to verify all configured patches are applied +32/-0

Extract Rust helper to verify all configured patches are applied

• Introduces every_configured_patch_is_applied(lockfile, config) to detect when configured patch keys lack corresponding applied packages in the lockfile graph. Encodes allow_unused_patches behavior by short-circuiting to true, keeping warning-only cases on the fast path.

pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs

tryComposeFastUpdates.tsAdd final patch-application verification to TS fast-update compose +8/-0

Add final patch-application verification to TS fast-update compose

• Ensures the composed TS fast-update pipeline runs a final check after all drift handlers complete. Falls back (returns false) when patches would be left unused, rather than writing an inconsistent lockfile.

pnpm11/installing/deps-installer/src/install/tryComposeFastUpdates.ts

Refactor (1) +30 / -7
tryFastUpdatePatchedDependencies.tsFactor patch-application verification into reusable TS helper +30/-7

Factor patch-application verification into reusable TS helper

• Replaces inline allowUnusedPatches/applied-key checking with a dedicated everyConfiguredPatchIsApplied() helper. This enables reuse from compose so that removals/overrides that orphan a patch also decline the fast path.

pnpm11/installing/deps-installer/src/install/tryFastUpdatePatchedDependencies.ts

Tests (2) +136 / -0
tests.rsAdd Rust regression tests for removals orphaning patches +50/-0

Add Rust regression tests for removals orphaning patches

• Adds tests that create a lockfile with a recorded patch and then remove the last dependent via manifest changes. Verifies fast update declines when allow_unused_patches is false and succeeds (while pruning the patched package) when it is true.

pnpm/crates/package-manager/src/fast_update_compose/tests.rs

patchedDependenciesFastUpdate.tsAdd TS tests for fast-update fallback when removals orphan patches +86/-0

Add TS tests for fast-update fallback when removals orphan patches

• Adds tests that construct a lockfile with a patched transitive dependency and then remove the last dependent via manifest drift or removal override. Asserts fast update falls back when allowUnusedPatches is false, and remains absorbable when the patch stays applied or warnings are allowed.

pnpm11/installing/deps-installer/test/install/patchedDependenciesFastUpdate.ts

Documentation (1) +7 / -0
unused-patch-after-removal.mdAdd changeset documenting unused patch prevention after removals +7/-0

Add changeset documenting unused patch prevention after removals

• Introduces a release note describing the fast-update bug where a patched dependency could be pruned while its patchedDependencies entry remained, and notes the scenarios that triggered it.

.changeset/unused-patch-after-removal.md

@greptile-apps

greptile-apps Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (7): Last reviewed commit: "style(package-manager): drop the needles..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     13.8±1.04ms    27.2 MB/sec    1.12     15.4±1.88ms    24.3 MB/sec
packument/parse                                  1.00     40.7±1.06µs  1629.5 MB/sec    1.06     43.3±2.40µs  1530.9 MB/sec
tarball/download_dependency                      1.09      2.8±0.34ms  1563.6 KB/sec    1.00      2.6±0.17ms  1701.1 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.07   223.6±16.42ms 71.6 KElem/sec    1.00   209.5±15.03ms 76.4 KElem/sec
workspace_resolution/hoist_heavy                 1.06   379.2±24.60ms        ? ?/sec    1.00   358.7±24.75ms        ? ?/sec

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Caution

CodeRabbit couldn't update its existing comment. The review summary may be out of date.

Error details
putComment timed out

@codecov-commenter

codecov-commenter commented Aug 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.33962% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.24%. Comparing base (d25c634) to head (cef6769).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ge-manager/src/fast_update_patched_dependencies.rs 93.54% 2 Missing ⚠️
.../package-manager/src/install/lockfile_freshness.rs 91.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #13828   +/-   ##
=======================================
  Coverage   88.23%   88.24%           
=======================================
  Files         625      625           
  Lines      102801   102847   +46     
=======================================
+ Hits        90710    90756   +46     
  Misses      12091    12091           

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

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
pnpm11/installing/deps-installer/test/install/patchedDependenciesFastUpdate.ts (1)

272-324: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add composed-update coverage for widened ignoredOptionalDependencies.

The added cases exercise importer and override removals. They do not exercise the required optional-dependency removal path.

  • pnpm11/installing/deps-installer/test/install/patchedDependenciesFastUpdate.ts#L272-L324: add a drift.ignoredOptionalDependencies case that removes the final patched package edge.
  • pnpm/crates/package-manager/src/fast_update_compose/tests.rs#L220-L251: add the equivalent pacquet regression case.

The PR objective explicitly requires coverage for widened ignoredOptionalDependencies.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@pnpm11/installing/deps-installer/test/install/patchedDependenciesFastUpdate.ts`
around lines 272 - 324, Add composed-update regression coverage for removing the
final patched package edge through drift.ignoredOptionalDependencies in
pnpm11/installing/deps-installer/test/install/patchedDependenciesFastUpdate.ts,
asserting the update falls back when unused patches are disallowed; add the
equivalent pacquet regression case in
pnpm/crates/package-manager/src/fast_update_compose/tests.rs. Preserve the
existing importer and override removal cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.changeset/unused-patch-after-removal.md:
- Line 7: Update the changeset description to accurately state that configured
patchedDependencies entries remain during fast updates; when the fast path
detects an unused patch, it falls back to full resolution, which reports the
applicable error or warning.

In
`@pnpm11/installing/deps-installer/src/install/tryFastUpdatePatchedDependencies.ts`:
- Around line 75-85: Do not let allowUnusedPatches bypass resolution when a
configured patch is unapplied: update tryFastUpdatePatchedDependencies.ts (lines
75-85) and fast_update_patched_dependencies.rs (lines 257-274) to detect the
missing applied patch and return false/None. Update
patchedDependenciesFastUpdate.ts (lines 316-324) and
fast_update_compose/tests.rs (lines 237-250) to expect fast-update composition
to decline, and add coverage that resolution emits the unused-patch warning.

---

Nitpick comments:
In
`@pnpm11/installing/deps-installer/test/install/patchedDependenciesFastUpdate.ts`:
- Around line 272-324: Add composed-update regression coverage for removing the
final patched package edge through drift.ignoredOptionalDependencies in
pnpm11/installing/deps-installer/test/install/patchedDependenciesFastUpdate.ts,
asserting the update falls back when unused patches are disallowed; add the
equivalent pacquet regression case in
pnpm/crates/package-manager/src/fast_update_compose/tests.rs. Preserve the
existing importer and override removal cases.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c83a8346-bb06-4fc8-9aa0-39e69f311ccf

📥 Commits

Reviewing files that changed from the base of the PR and between 7e57836 and 3da062b.

📒 Files selected for processing (7)
  • .changeset/unused-patch-after-removal.md
  • pnpm/crates/package-manager/src/fast_update_compose.rs
  • pnpm/crates/package-manager/src/fast_update_compose/tests.rs
  • pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs
  • pnpm11/installing/deps-installer/src/install/tryComposeFastUpdates.ts
  • pnpm11/installing/deps-installer/src/install/tryFastUpdatePatchedDependencies.ts
  • pnpm11/installing/deps-installer/test/install/patchedDependenciesFastUpdate.ts

@qodo-code-review

qodo-code-review Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (4) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Redundant unused-patch scan 🐞 Bug ➹ Performance ⭐ New
Description
try_fast_update_lockfile always calls unused_patches() after freshness checks, which can perform
a full applied-patch inspection over lockfile.snapshots even when allow_unused_patches is false.
In strict mode, the pipeline already checked patch usage, so this second scan adds avoidable CPU
work on the successful fast-update hot path.
Code

pnpm/crates/package-manager/src/install/lockfile_freshness.rs[R64-66]

+    if let Some(unused) =
+        crate::fast_update_patched_dependencies::unused_patches(&candidate, patch_hashes.as_ref())
+    {
Relevance

●● Moderate

Perf micro-optimizations (avoiding extra scans/allocations) have been rejected before; unclear if
they’ll prioritize this hot-path win.

PR-#13506
PR-#13790
PR-#13803

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new reporting block calls unused_patches() unconditionally after freshness gates, and
unused_patches() computes applied_patch_keys() by iterating lockfile.snapshots.keys().
Separately, the fast-update pipeline already enforces patch usage via
every_configured_patch_is_applied() when allow_unused_patches is false, so strict-mode success
pays for a second applied-patch inspection whose result is discarded.

pnpm/crates/package-manager/src/install/lockfile_freshness.rs[27-72]
pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[269-330]
pnpm/crates/package-manager/src/fast_update_compose.rs[112-122]

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

### Issue description
`try_fast_update_lockfile` emits an unused-patch warning by calling `unused_patches()` unconditionally. When `allow_unused_patches` is false, a successful candidate already passed `every_configured_patch_is_applied` inside the fast-update pipeline, so `unused_patches()` cannot produce a warning but may still do a costly scan.

### Issue Context
- The fast-update pipeline already rejects unused patches in strict mode.
- The post-freshness reporting is only needed when `allow_unused_patches` is enabled.

### Fix Focus Areas
- pnpm/crates/package-manager/src/install/lockfile_freshness.rs[61-71]

### Suggested change
Wrap the `unused_patches()` call (and the `Reporter::emit`) with `if opts.config.allow_unused_patches { ... }`, so strict-mode successful fast updates do not re-scan the lockfile.

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


2. Named-registry patch mismatch 🐞 Bug ➹ Performance
Description
The new unused-patch guard derives (name, version) from snapshot keys and uses that version string
for patch lookup; for named-registry keys like foo@work:1.1.0, the version is not plain semver, so
configured semver selectors like [email protected] / ranges are not recognized as applied. With the new
end-of-pipeline guard, this can force fast-update to fall back to full resolution more often for
patched projects using named registries.
Code

pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[R255-260]

+pub(crate) fn every_configured_patch_is_applied(
+    lockfile: &Lockfile,
+    hashes: Option<&BTreeMap<String, String>>,
+    allow_unused_patches: bool,
+) -> bool {
+    if allow_unused_patches {
Relevance

●●● Strong

Team previously accepted fixes for named-registry name@work:version parsing so patch applicability
matches semver selectors.

PR-#13680

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new guard calls into logic that parses versions directly from snapshot-key strings. For
named-registry snapshot keys, the parsed version includes the registry prefix (work:), and
get_patch_info() does not semver-range-match non-semver target strings; repository tests
explicitly document that the resolver decides patches for work: keys based on plain semver,
highlighting the mismatch.

pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[255-273]
pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[292-310]
pnpm/crates/deps-restorer/src/build_modules/slots.rs[244-252]
pnpm/crates/patching/src/get_patch_info.rs[48-57]
pnpm/crates/package-manager/src/fast_update_patched_dependencies/tests.rs[47-63]
pnpm/crates/package-manager/src/fast_update_patched_dependencies/tests.rs[319-331]
PR-#13680

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

### Issue description
`every_configured_patch_is_applied()` relies on `applied_patch_keys()`, which parses `(name, version)` from snapshot keys and passes the raw `version` string into `get_patch_info()`. For named-registry snapshot keys (e.g. `foo@work:1.1.0`), the parsed version is `work:1.1.0`, which prevents exact/range patch selectors like `[email protected]` from matching.

Because the new end-of-pipeline guard runs for any fast-update attempt with configured patches, this mismatch can cause unnecessary fallback to full resolution even when the lockfile may already be consistent with configured patches.

### Issue Context
- `parse_name_version_from_key()` splits on the last `@` and returns the remainder unchanged as the version.
- `get_patch_info()` only range-matches when the target version parses as semver; otherwise it only matches exact-string or wildcard.
- There is an existing test showing that resolver semantics for named registries differ from the lockfile key’s version slot.

### Fix Focus Areas
- pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[255-273]
- pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[292-310]

### Suggested approach
- Normalize named-registry versions before calling `get_patch_info()` in the applied-patch detection path (e.g., if the version matches `<registry>:<semver>`, strip the `<registry>:` prefix and use `<semver>` for patch lookup).
 - There is already a `deps-path` module for registry-qualified parsing; reusing that (or equivalent logic used by the resolver) would avoid duplicating parsing rules.
- Add a regression test that constructs a lockfile snapshot key containing a named-registry version and asserts that `every_configured_patch_is_applied()` returns `true` when the configured patch is actually applied.

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


3. Misleading changeset behavior ✓ Resolved 🐞 Bug ⚙ Maintainability
Description
The changeset states that an install which orphans a configured patch “now falls back to a full
resolution” and reports ERR_PNPM_UNUSED_PATCH, but the implementation explicitly keeps fast-update
when allowUnusedPatches is enabled, so this release note is incomplete for that supported
configuration.
Code

.changeset/unused-patch-after-removal.md[7]

+An install that drops the last dependent of a patched package no longer updates the lockfile in place and succeeds silently. Removing a dependency, widening `ignoredOptionalDependencies`, or adding a removal override could each prune the package while the patch stayed configured; such an install now falls back to a full resolution, which reports the unused patch with `ERR_PNPM_UNUSED_PATCH` [#13827](https://github.com/pnpm/pnpm/issues/13827).
Relevance

●●● Strong

Team often updates changeset wording to match actual behavior/scope; this is a straightforward
accuracy fix.

PR-#11362
PR-#12772

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The changeset claims orphaned patches “now fall back to a full resolution” that reports
ERR_PNPM_UNUSED_PATCH, but the code paths explicitly bypass the guard when unused patches are
allowed, so fallback is not guaranteed in that configuration.

.changeset/unused-patch-after-removal.md[7-7]
pnpm11/installing/deps-installer/src/install/tryFastUpdatePatchedDependencies.ts[71-77]
pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[256-259]

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 changeset text implies orphaned patches always force a full resolution that reports `ERR_PNPM_UNUSED_PATCH`, but the code intentionally *does not* force fallback when `allowUnusedPatches` is enabled.

## Issue Context
Both the TS and Rust implementations short-circuit the “unused patch” guard when `allowUnusedPatches` is set, meaning fast-update can still proceed (and will not surface the resolver warning).

## Fix Focus Areas
- .changeset/unused-patch-after-removal.md[7-7]

## Proposed fix
Adjust the changeset sentence to explicitly scope the fallback/error behavior to the default case (`allowUnusedPatches: false`), and mention that with `allowUnusedPatches` enabled the fast path may still be used (unused patch becomes a resolver warning, which fast-update won’t emit).

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



Informational

4. Extra snapshot scan added 🐞 Bug ➹ Performance
Description
The new end-of-pipeline patch guard runs on every successful fast-update attempt when
allow_unused_patches is false and patches are configured, and it computes applied patches by
iterating all lockfile.snapshots keys. This adds O(#snapshots) CPU work to the fast-update hot
path even in cases where no removals occurred (the only scenario that can orphan a patch).
Code

pnpm/crates/package-manager/src/fast_update_compose.rs[R122-124]

+        &candidate,
+        patch_hashes.as_ref(),
+        config.allow_unused_patches,
Relevance

● Weak

Similar perf-only proposals to avoid full lockfile scans in fast-update were rejected as unnecessary
complexity.

PR-#13600
PR-#13803

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new guard is executed before returning the fast-updated lockfile candidate. The guard
implementation computes applied patches by scanning all snapshot keys, which scales with lockfile
size and is executed even if the fast-update changes were limited to importer/settings updates (no
removals).

pnpm/crates/package-manager/src/fast_update_compose.rs[61-73]
pnpm/crates/package-manager/src/fast_update_compose.rs[121-127]
pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[255-273]
pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[292-313]

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 `every_configured_patch_is_applied()` guard is executed unconditionally before returning `Some(candidate)`. Internally it scans `lockfile.snapshots` to determine which patch keys are applied; this is O(N snapshots) work added to fast-update attempts whenever patches are configured and `allow_unused_patches` is false.

Unused patches can only be created by removals (dropping the last dependent / pruning the last reachable patched package), so running a full scan even when no packages were removed is avoidable overhead.

### Issue Context
- The guard is called at the end of `try_compose_fast_updates()`.
- `every_configured_patch_is_applied()` calls `applied_patch_keys()`, which iterates over `lockfile.snapshots.keys()`.

### Fix Focus Areas
- pnpm/crates/package-manager/src/fast_update_compose.rs[61-73]
- pnpm/crates/package-manager/src/fast_update_compose.rs[121-127]
- pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[255-273]

### Suggested approach
- Thread a “had removals” signal from the graph-edit/prune phase (e.g., via `GraphEdits`, or via a boolean returned from `finish_graph_edits`) and only run `every_configured_patch_is_applied()` when removals occurred.
- Keep current behavior for safety when removals occurred (this is the bugfix target).

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


5. Duplicate patch file hashing ✓ Resolved 🐞 Bug ➹ Performance
Description
In Rust pacquet fast-update, the new end-of-pipeline unused-patch guard calls
Config::patched_dependency_hashes() again, which (if uncached) re-reads and hashes patch files a
second time in the same fast-update attempt. This adds redundant filesystem I/O on the install fast
path for workspaces with configured patches.
Code

pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[R260-263]

+    let hashes = match config.patched_dependency_hashes() {
+        Ok(Some(hashes)) => hashes,
+        Ok(None) => return true,
+        Err(_) => return false,
Relevance

● Weak

Similar perf micro-optimizations around patch verification/duplicate work were previously rejected.

PR-#13506
PR-#13600

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
detect_patched_drift() already computes patch hashes via config.patched_dependency_hashes(). The
new every_configured_patch_is_applied() calls config.patched_dependency_hashes() again, and that
method resolves patch file paths and hashes each file, so it is potentially redundant I/O per
fast-update attempt.

pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[35-48]
pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[256-274]
pnpm/crates/package-manager/src/fast_update_compose.rs[111-118]
pnpm/crates/config/src/lib.rs[2322-2339]

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

### Issue description
Rust fast-update drift detection already computes patch hashes via `Config::patched_dependency_hashes()`. The new `every_configured_patch_is_applied()` guard recomputes them, which likely re-reads and re-hashes patch files.

### Issue Context
- `detect_patched_drift()` computes `hashes` to compare `recorded` vs `current`.
- The new end-of-pipeline guard calls `every_configured_patch_is_applied(&candidate, config)` which calls `config.patched_dependency_hashes()` again.
- `patched_dependency_hashes()` resolves patch file paths and calls `calc_patch_hashes(...)` (file I/O + hashing).

### Fix Focus Areas
- pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[35-48]
- pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[256-274]
- pnpm/crates/package-manager/src/fast_update_compose.rs[111-118]
- pnpm/crates/config/src/lib.rs[2322-2339]

### Suggested fix
- Avoid calling `config.patched_dependency_hashes()` in `every_configured_patch_is_applied()`.
- Reuse already-available hashes:
 - If `patched` drift is `Absorb(plan)`, use `plan.current`.
 - If `patched` drift is `Clean`, `lockfile.patched_dependencies` equals the current hashes (because drift detection compared them), so reuse `lockfile.patched_dependencies`.
- Consider skipping the final guard when `patched` drift was `Absorb(_)` and `allow_unused_patches` is false, since `apply_patched_update()` already performed the unused-patch validation on the settled graph.

(Any approach is fine as long as it preserves the new behavior: decline fast-update when a configured patch becomes unused due to removals.)

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


6. Extra lockfile scan for patches 🐞 Bug ➹ Performance
Description
In the TS composed fast-update pipeline, the new final everyConfiguredPatchIsApplied() guard adds
a full scan of lockfile.packages to detect unused patches even when patchedDependencies drift
did not occur. For patched workspaces this adds extra O(N packages) work to the fast-update hot
path.
Code

pnpm11/installing/deps-installer/src/install/tryComposeFastUpdates.ts[R128-131]

+  if (opts.patchedDependencies != null &&
+    !everyConfiguredPatchIsApplied(candidate, opts.patchedDependencies)) {
+    return false
+  }
Relevance

● Weak

Team has rejected suggestions to avoid extra full lockfile scans on fast-update paths.

PR-#13600
PR-#13779
PR-#13803

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new final guard runs in tryComposeFastUpdates and calls everyConfiguredPatchIsApplied, which
(when patches are configured and allowUnusedPatches is false) builds groups and scans every
package in the lockfile via appliedPatchKeys. The install pipeline always passes a non-null
patchedDependencies options object into compose, so patched workspaces will hit this scan on every
composed fast-update attempt.

pnpm11/installing/deps-installer/src/install/tryComposeFastUpdates.ts[111-133]
pnpm11/installing/deps-installer/src/install/tryFastUpdatePatchedDependencies.ts[71-86]
pnpm11/installing/deps-installer/src/install/tryFastUpdatePatchedDependencies.ts[220-236]
pnpm11/installing/deps-installer/src/install/index.ts[844-855]

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 end-of-pipeline `everyConfiguredPatchIsApplied()` validation scans `lockfile.packages` (via `appliedPatchKeys`) to confirm each configured patch still applies. This is correct for the bug being fixed, but it adds an extra full-packages pass to composed fast updates when patches are configured.

### Issue Context
- `tryComposeFastUpdates` now always runs `everyConfiguredPatchIsApplied` when `opts.patchedDependencies != null`.
- In the install flow, `tryComposeFastUpdates` is always passed a `patchedDependencies: { patchedDependencies, allowUnusedPatches }` options object.
- `everyConfiguredPatchIsApplied` calls `appliedPatchKeys`, which loops over `Object.entries(lockfile.packages ?? {})`.

### Fix Focus Areas
- pnpm11/installing/deps-installer/src/install/tryComposeFastUpdates.ts[125-132]
- pnpm11/installing/deps-installer/src/install/tryFastUpdatePatchedDependencies.ts[71-86]
- pnpm11/installing/deps-installer/src/install/tryFastUpdatePatchedDependencies.ts[220-236]
- pnpm11/installing/deps-installer/src/install/index.ts[844-855]

### Suggested fix
Keep the correctness behavior, but reduce the cost:
- Implement the check as a streaming/early-exit scan:
 - Build a `missing` set from `allPatchKeys(groups)`.
 - Iterate packages; when a package matches a patch key, delete it from `missing`.
 - Return `true` as soon as `missing.size === 0`.
 - This avoids building a full `applied` set and can exit early when patches are few.
- Optionally avoid double scanning when `tryFastUpdatePatchedDependencies()` already called `everyConfiguredPatchIsApplied()` and there are no subsequent drift handlers that can drop edges (e.g. when `opts.drift.overrides` is false).

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


Grey Divider

Context
✅ Compliance rules (platform): 26 rules

Grey Divider

Tip of the day
💡 Did you know, you can group findings by type and pick your Finding display, from Minimal to Full

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous review results

Review updated until commit cef6769

Results up to commit 3da062b ⚖️ Balanced


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


Informational
1. Duplicate patch file hashing ✓ Resolved 🐞 Bug ➹ Performance
Description
In Rust pacquet fast-update, the new end-of-pipeline unused-patch guard calls
Config::patched_dependency_hashes() again, which (if uncached) re-reads and hashes patch files a
second time in the same fast-update attempt. This adds redundant filesystem I/O on the install fast
path for workspaces with configured patches.
Code

pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[R260-263]

+    let hashes = match config.patched_dependency_hashes() {
+        Ok(Some(hashes)) => hashes,
+        Ok(None) => return true,
+        Err(_) => return false,
Relevance

● Weak

Similar perf micro-optimizations around patch verification/duplicate work were previously rejected.

PR-#13506
PR-#13600

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
detect_patched_drift() already computes patch hashes via config.patched_dependency_hashes(). The
new every_configured_patch_is_applied() calls config.patched_dependency_hashes() again, and that
method resolves patch file paths and hashes each file, so it is potentially redundant I/O per
fast-update attempt.

pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[35-48]
pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[256-274]
pnpm/crates/package-manager/src/fast_update_compose.rs[111-118]
pnpm/crates/config/src/lib.rs[2322-2339]

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

### Issue description
Rust fast-update drift detection already computes patch hashes via `Config::patched_dependency_hashes()`. The new `every_configured_patch_is_applied()` guard recomputes them, which likely re-reads and re-hashes patch files.

### Issue Context
- `detect_patched_drift()` computes `hashes` to compare `recorded` vs `current`.
- The new end-of-pipeline guard calls `every_configured_patch_is_applied(&candidate, config)` which calls `config.patched_dependency_hashes()` again.
- `patched_dependency_hashes()` resolves patch file paths and calls `calc_patch_hashes(...)` (file I/O + hashing).

### Fix Focus Areas
- pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[35-48]
- pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[256-274]
- pnpm/crates/package-manager/src/fast_update_compose.rs[111-118]
- pnpm/crates/config/src/lib.rs[2322-2339]

### Suggested fix
- Avoid calling `config.patched_dependency_hashes()` in `every_configured_patch_is_applied()`.
- Reuse already-available hashes:
 - If `patched` drift is `Absorb(plan)`, use `plan.current`.
 - If `patched` drift is `Clean`, `lockfile.patched_dependencies` equals the current hashes (because drift detection compared them), so reuse `lockfile.patched_dependencies`.
- Consider skipping the final guard when `patched` drift was `Absorb(_)` and `allow_unused_patches` is false, since `apply_patched_update()` already performed the unused-patch validation on the settled graph.

(Any approach is fine as long as it preserves the new behavior: decline fast-update when a configured patch becomes unused due to removals.)

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


2. Extra lockfile scan for patches 🐞 Bug ➹ Performance
Description
In the TS composed fast-update pipeline, the new final everyConfiguredPatchIsApplied() guard adds
a full scan of lockfile.packages to detect unused patches even when patchedDependencies drift
did not occur. For patched workspaces this adds extra O(N packages) work to the fast-update hot
path.
Code

pnpm11/installing/deps-installer/src/install/tryComposeFastUpdates.ts[R128-131]

+  if (opts.patchedDependencies != null &&
+    !everyConfiguredPatchIsApplied(candidate, opts.patchedDependencies)) {
+    return false
+  }
Relevance

● Weak

Team has rejected suggestions to avoid extra full lockfile scans on fast-update paths.

PR-#13600
PR-#13779
PR-#13803

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new final guard runs in tryComposeFastUpdates and calls everyConfiguredPatchIsApplied, which
(when patches are configured and allowUnusedPatches is false) builds groups and scans every
package in the lockfile via appliedPatchKeys. The install pipeline always passes a non-null
patchedDependencies options object into compose, so patched workspaces will hit this scan on every
composed fast-update attempt.

pnpm11/installing/deps-installer/src/install/tryComposeFastUpdates.ts[111-133]
pnpm11/installing/deps-installer/src/install/tryFastUpdatePatchedDependencies.ts[71-86]
pnpm11/installing/deps-installer/src/install/tryFastUpdatePatchedDependencies.ts[220-236]
pnpm11/installing/deps-installer/src/install/index.ts[844-855]

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 end-of-pipeline `everyConfiguredPatchIsApplied()` validation scans `lockfile.packages` (via `appliedPatchKeys`) to confirm each configured patch still applies. This is correct for the bug being fixed, but it adds an extra full-packages pass to composed fast updates when patches are configured.

### Issue Context
- `tryComposeFastUpdates` now always runs `everyConfiguredPatchIsApplied` when `opts.patchedDependencies != null`.
- In the install flow, `tryComposeFastUpdates` is always passed a `patchedDependencies: { patchedDependencies, allowUnusedPatches }` options object.
- `everyConfiguredPatchIsApplied` calls `appliedPatchKeys`, which loops over `Object.entries(lockfile.packages ?? {})`.

### Fix Focus Areas
- pnpm11/installing/deps-installer/src/install/tryComposeFastUpdates.ts[125-132]
- pnpm11/installing/deps-installer/src/install/tryFastUpdatePatchedDependencies.ts[71-86]
- pnpm11/installing/deps-installer/src/install/tryFastUpdatePatchedDependencies.ts[220-236]
- pnpm11/installing/deps-installer/src/install/index.ts[844-855]

### Suggested fix
Keep the correctness behavior, but reduce the cost:
- Implement the check as a streaming/early-exit scan:
 - Build a `missing` set from `allPatchKeys(groups)`.
 - Iterate packages; when a package matches a patch key, delete it from `missing`.
 - Return `true` as soon as `missing.size === 0`.
 - This avoids building a full `applied` set and can exit early when patches are few.
- Optionally avoid double scanning when `tryFastUpdatePatchedDependencies()` already called `everyConfiguredPatchIsApplied()` and there are no subsequent drift handlers that can drop edges (e.g. when `opts.drift.overrides` is false).

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


Results up to commit 5f010b9 ⚖️ Balanced


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


Remediation recommended
1. Misleading changeset behavior ✓ Resolved 🐞 Bug ⚙ Maintainability
Description
The changeset states that an install which orphans a configured patch “now falls back to a full
resolution” and reports ERR_PNPM_UNUSED_PATCH, but the implementation explicitly keeps fast-update
when allowUnusedPatches is enabled, so this release note is incomplete for that supported
configuration.
Code

.changeset/unused-patch-after-removal.md[7]

+An install that drops the last dependent of a patched package no longer updates the lockfile in place and succeeds silently. Removing a dependency, widening `ignoredOptionalDependencies`, or adding a removal override could each prune the package while the patch stayed configured; such an install now falls back to a full resolution, which reports the unused patch with `ERR_PNPM_UNUSED_PATCH` [#13827](https://github.com/pnpm/pnpm/issues/13827).
Relevance

●●● Strong

Team often updates changeset wording to match actual behavior/scope; this is a straightforward
accuracy fix.

PR-#11362
PR-#12772

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The changeset claims orphaned patches “now fall back to a full resolution” that reports
ERR_PNPM_UNUSED_PATCH, but the code paths explicitly bypass the guard when unused patches are
allowed, so fallback is not guaranteed in that configuration.

.changeset/unused-patch-after-removal.md[7-7]
pnpm11/installing/deps-installer/src/install/tryFastUpdatePatchedDependencies.ts[71-77]
pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[256-259]

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 changeset text implies orphaned patches always force a full resolution that reports `ERR_PNPM_UNUSED_PATCH`, but the code intentionally *does not* force fallback when `allowUnusedPatches` is enabled.

## Issue Context
Both the TS and Rust implementations short-circuit the “unused patch” guard when `allowUnusedPatches` is set, meaning fast-update can still proceed (and will not surface the resolver warning).

## Fix Focus Areas
- .changeset/unused-patch-after-removal.md[7-7]

## Proposed fix
Adjust the changeset sentence to explicitly scope the fallback/error behavior to the default case (`allowUnusedPatches: false`), and mention that with `allowUnusedPatches` enabled the fast path may still be used (unused patch becomes a resolver warning, which fast-update won’t emit).

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


Results up to commit 29618e8 ⚖️ Balanced


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


Remediation recommended
1. Named-registry patch mismatch 🐞 Bug ➹ Performance
Description
The new unused-patch guard derives (name, version) from snapshot keys and uses that version string
for patch lookup; for named-registry keys like foo@work:1.1.0, the version is not plain semver, so
configured semver selectors like [email protected] / ranges are not recognized as applied. With the new
end-of-pipeline guard, this can force fast-update to fall back to full resolution more often for
patched projects using named registries.
Code

pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[R255-260]

+pub(crate) fn every_configured_patch_is_applied(
+    lockfile: &Lockfile,
+    hashes: Option<&BTreeMap<String, String>>,
+    allow_unused_patches: bool,
+) -> bool {
+    if allow_unused_patches {
Relevance

●●● Strong

Team previously accepted fixes for named-registry name@work:version parsing so patch applicability
matches semver selectors.

PR-#13680

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new guard calls into logic that parses versions directly from snapshot-key strings. For
named-registry snapshot keys, the parsed version includes the registry prefix (work:), and
get_patch_info() does not semver-range-match non-semver target strings; repository tests
explicitly document that the resolver decides patches for work: keys based on plain semver,
highlighting the mismatch.

pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[255-273]
pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[292-310]
pnpm/crates/deps-restorer/src/build_modules/slots.rs[244-252]
pnpm/crates/patching/src/get_patch_info.rs[48-57]
pnpm/crates/package-manager/src/fast_update_patched_dependencies/tests.rs[47-63]
pnpm/crates/package-manager/src/fast_update_patched_dependencies/tests.rs[319-331]
PR-#13680

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

### Issue description
`every_configured_patch_is_applied()` relies on `applied_patch_keys()`, which parses `(name, version)` from snapshot keys and passes the raw `version` string into `get_patch_info()`. For named-registry snapshot keys (e.g. `foo@work:1.1.0`), the parsed version is `work:1.1.0`, which prevents exact/range patch selectors like `[email protected]` from matching.

Because the new end-of-pipeline guard runs for any fast-update attempt with configured patches, this mismatch can cause unnecessary fallback to full resolution even when the lockfile may already be consistent with configured patches.

### Issue Context
- `parse_name_version_from_key()` splits on the last `@` and returns the remainder unchanged as the version.
- `get_patch_info()` only range-matches when the target version parses as semver; otherwise it only matches exact-string or wildcard.
- There is an existing test showing that resolver semantics for named registries differ from the lockfile key’s version slot.

### Fix Focus Areas
- pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[255-273]
- pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[292-310]

### Suggested approach
- Normalize named-registry versions before calling `get_patch_info()` in the applied-patch detection path (e.g., if the version matches `<registry>:<semver>`, strip the `<registry>:` prefix and use `<semver>` for patch lookup).
 - There is already a `deps-path` module for registry-qualified parsing; reusing that (or equivalent logic used by the resolver) would avoid duplicating parsing rules.
- Add a regression test that constructs a lockfile snapshot key containing a named-registry version and asserts that `every_configured_patch_is_applied()` returns `true` when the configured patch is actually applied.

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



Informational
2. Extra snapshot scan added 🐞 Bug ➹ Performance
Description
The new end-of-pipeline patch guard runs on every successful fast-update attempt when
allow_unused_patches is false and patches are configured, and it computes applied patches by
iterating all lockfile.snapshots keys. This adds O(#snapshots) CPU work to the fast-update hot
path even in cases where no removals occurred (the only scenario that can orphan a patch).
Code

pnpm/crates/package-manager/src/fast_update_compose.rs[R122-124]

+        &candidate,
+        patch_hashes.as_ref(),
+        config.allow_unused_patches,
Relevance

● Weak

Similar perf-only proposals to avoid full lockfile scans in fast-update were rejected as unnecessary
complexity.

PR-#13600
PR-#13803

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new guard is executed before returning the fast-updated lockfile candidate. The guard
implementation computes applied patches by scanning all snapshot keys, which scales with lockfile
size and is executed even if the fast-update changes were limited to importer/settings updates (no
removals).

pnpm/crates/package-manager/src/fast_update_compose.rs[61-73]
pnpm/crates/package-manager/src/fast_update_compose.rs[121-127]
pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[255-273]
pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[292-313]

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 `every_configured_patch_is_applied()` guard is executed unconditionally before returning `Some(candidate)`. Internally it scans `lockfile.snapshots` to determine which patch keys are applied; this is O(N snapshots) work added to fast-update attempts whenever patches are configured and `allow_unused_patches` is false.

Unused patches can only be created by removals (dropping the last dependent / pruning the last reachable patched package), so running a full scan even when no packages were removed is avoidable overhead.

### Issue Context
- The guard is called at the end of `try_compose_fast_updates()`.
- `every_configured_patch_is_applied()` calls `applied_patch_keys()`, which iterates over `lockfile.snapshots.keys()`.

### Fix Focus Areas
- pnpm/crates/package-manager/src/fast_update_compose.rs[61-73]
- pnpm/crates/package-manager/src/fast_update_compose.rs[121-127]
- pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs[255-273]

### Suggested approach
- Thread a “had removals” signal from the graph-edit/prune phase (e.g., via `GraphEdits`, or via a boolean returned from `finish_graph_edits`) and only run `every_configured_patch_is_applied()` when removals occurred.
- Keep current behavior for safety when removals occurred (this is the bugfix target).

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


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.

Copilot AI review requested due to automatic review settings August 11, 2026 12: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[bot]
greptile-apps Bot previously approved these changes Aug 11, 2026
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 5f010b9

@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 Aug 11, 2026
Copilot AI review requested due to automatic review settings August 11, 2026 12:45
@greptile-apps
greptile-apps Bot dismissed their stale review August 11, 2026 12:45

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

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.

@zkochan

zkochan commented Aug 11, 2026 •

Copy link
Copy Markdown
Member Author

Duplicate patch file hashing — fixed (29618e8). Correct:
patched_dependency_hashes resolves and SHA-256s every configured patch file on
each call, with no cache, so the guard was repeating what the drift check had
just done. The pipeline now hashes once and passes the result to both
detect_patched_drift and every_configured_patch_is_applied. Besides the I/O,
that removes the chance of the two calls disagreeing about a file that changed
underneath them. It also brings pacquet closer to the TypeScript side, which has
always had the hashes computed once by the caller.

(The review lists this twice, as findings 1 and 2; they are the same finding and
the one change covers both.)


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

greptile-apps[bot]
greptile-apps Bot previously approved these changes Aug 11, 2026

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs`:
- Around line 260-264: Update the fast-update guard around allow_unused_patches
and the hashes filter so unused patches fall back to full resolution instead of
returning true; preserve the existing fast path when all patches are used. Apply
the equivalent change in the TypeScript allowUnusedPatches implementation, and
add parity tests covering unused-patch warnings in both Rust and TypeScript.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 38986011-a650-4c29-af3f-5edaba4244c0

📥 Commits

Reviewing files that changed from the base of the PR and between 5f010b9 and 29618e8.

📒 Files selected for processing (2)
  • pnpm/crates/package-manager/src/fast_update_compose.rs
  • pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 29618e8

@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 review requested due to automatic review settings August 11, 2026 12:56

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
pnpm/crates/cli/tests/suite/lockfile_resolution_reuse.rs (1)

1721-1816: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Move the add-command tests to a separate change.

These tests cover locked-version reuse for add. They do not exercise unused-patch validation, warnings, or patch lockfile behavior. Keep this PR limited to the stated unused-patch fix.

As per path instructions, “Keep the PR narrowly scoped.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pnpm/crates/cli/tests/suite/lockfile_resolution_reuse.rs` around lines 1721 -
1816, Remove the add_command_reuses_a_locked_version_without_resolving and
add_command_resolves_a_version_the_lockfile_does_not_hold tests from this
change. Keep the PR scoped to the unused-patch fix, including only tests
covering unused-patch validation, warnings, or patch lockfile behavior.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pnpm/crates/package-manager/src/install/lockfile_freshness.rs`:
- Around line 55-57: Update check_lockfile_freshness and the surrounding
fast-update flow to compute Config::patched_dependency_hashes() once before
candidate composition, then reuse that snapshot for composition, freshness
validation, and fast_update_patched_dependencies::unused_patches instead of
reading the patch files again.

---

Nitpick comments:
In `@pnpm/crates/cli/tests/suite/lockfile_resolution_reuse.rs`:
- Around line 1721-1816: Remove the
add_command_reuses_a_locked_version_without_resolving and
add_command_resolves_a_version_the_lockfile_does_not_hold tests from this
change. Keep the PR scoped to the unused-patch fix, including only tests
covering unused-patch validation, warnings, or patch lockfile behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0ebe40a0-794d-4d23-8f08-246945a80356

📥 Commits

Reviewing files that changed from the base of the PR and between 985e1f3 and de5b664.

📒 Files selected for processing (8)
  • .changeset/unused-patch-after-removal.md
  • pnpm/crates/cli/tests/suite/lockfile_resolution_reuse.rs
  • pnpm/crates/package-manager/src/fast_update_patched_dependencies.rs
  • pnpm/crates/package-manager/src/install/lockfile_freshness.rs
  • pnpm/crates/package-manager/src/install/run.rs
  • pnpm11/installing/deps-installer/src/install/index.ts
  • pnpm11/installing/deps-installer/src/install/tryFastUpdatePatchedDependencies.ts
  • pnpm11/installing/deps-installer/test/install/patchedDependenciesFastUpdate.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/unused-patch-after-removal.md

The unused-patch report added a third read-and-hash of every configured
patch file to a successful fast update, on top of the composition's and
the freshness check's. The caller now takes that snapshot once and hands
it to the pipeline, leaving the flow with the two it had before this
branch.

Passing the hashes in also puts the failure in one place: an unreadable
patch file declines the attempt, where computing them per consumer left
each free to read `Err` as "none configured" instead.
Copilot AI review requested due to automatic review settings August 11, 2026 14:12
@greptile-apps
greptile-apps Bot dismissed their stale review August 11, 2026 14:12

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

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

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

@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 195c5f4 into main Aug 11, 2026
42 checks passed
@zkochan
zkochan deleted the fix-13827 branch August 11, 2026 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pacquet product: pnpm@11 reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A fast lockfile update that drops the last dependent of a patched package leaves the patch unused

3 participants