Skip to content

perf: absorb a removed workspace project into the fast lockfile update - #13784

Merged
zkochan merged 3 commits into
mainfrom
unignore
Aug 10, 2026
Merged

zkochan merged 3 commits into
mainfrom
unignore

Conversation

@zkochan

@zkochan zkochan commented Aug 10, 2026 •

Copy link
Copy Markdown
Member

Summary

Item 3 of #13696, narrowed to the half that is actually broken.

The item covered adding and removing a dependency-free workspace package. Measured first: adding one already works — getContext seeds an empty importer for every project before the gate runs, so the counts match and the frozen path handles it with zero package requests. Removing one does not: the lockfile then holds an importer no project claims, the count check importers.length === projects.length fails, and the install pays a full re-resolution. That check is live for ordinary workspace installs, since pruneLockfileImporters defaults to true for an unfiltered recursive install.

The importers handler now drops importer entries no project claims and records their aliases as dropped, so the shared epilogue prunes whatever that orphans, recomputes optional flags, and applies the peer-suffix guard. The gate only requires that no project is missing an importer. This is not limited to dependency-free projects as the item framed it — a departing project with dependencies works the same way, because pruning orphans is what the epilogue already does.

A guard the existing tests earned: removing a project that a surviving project still links to must fail, and my first cut silently succeeded, leaving a project depending on something that no longer exists. multipleImporters.ts's "some projects were removed from the workspace and the ones that are left depend on them" caught it. Such a stale importer now keeps the resolver, with its own regression test alongside.

No pacquet mirror. pacquet does not prune stale importers at all — verified with a workspace where the removed project's importer survives the reinstall — so there is no behavior to make fast yet. That is a divergence in its own right (the stale importer is a root in every reachability walk, so it also keeps dead packages alive), filed as #13783; the mirror belongs with it.

Squash Commit Body

The fast path required the lockfile's importer count to equal the
project count whenever pruneLockfileImporters was on — which is the
default for an unfiltered recursive install — so deleting a package
from a workspace always paid a full resolution. The importers handler
now drops importer entries no project claims and records their aliases
as dropped, leaving the shared epilogue to prune whatever that
orphans, and the gate only requires that no project is *missing* an
importer.

A stale importer that a surviving importer still links to keeps the
resolver: a project that is gone while something depends on it is a
broken workspace, which must be reported rather than quietly rewritten
— the behavior an existing multipleImporters test already pinned.

No pacquet mirror yet: it does not prune stale importers at all,
filed as pnpm/pnpm#13783.

Item 3 of pnpm/pnpm#13696.

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

  • New Features

    • Lockfiles now update incrementally when a workspace package is removed.
    • Removed workspace entries and dependencies used only by them are automatically pruned.
    • Shared dependencies are preserved, avoiding unnecessary package resolution.
  • Bug Fixes

    • Updates now detect and handle removed workspace links safely.
    • An error is reported when a remaining project still links to a removed package.

The fast path required the lockfile's importer count to equal the
project count whenever pruneLockfileImporters was on — which is the
default for an unfiltered recursive install — so deleting a package
from a workspace always paid a full resolution. The importers handler
now drops importer entries no project claims and records their aliases
as dropped, leaving the shared epilogue to prune whatever that
orphans, and the gate only requires that no project is *missing* an
importer.

A stale importer that a surviving importer still links to keeps the
resolver: a project that is gone while something depends on it is a
broken workspace, which must be reported rather than quietly rewritten
— the behavior an existing multipleImporters test already pinned.

No pacquet mirror yet: it does not prune stale importers at all,
filed as #13783.

Item 3 of #13696.
Copilot AI lite review requested due to automatic review settings August 10, 2026 20:04

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 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9c1a61a1-2434-43ac-b653-45173d78dc1b

📥 Commits

Reviewing files that changed from the base of the PR and between f17a915 and 4980d7e.

📒 Files selected for processing (3)
  • pnpm11/installing/deps-installer/src/install/index.ts
  • pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts
  • pnpm11/installing/deps-installer/test/install/removedImporterFastUpdate.ts
💤 Files with no reviewable changes (1)
  • pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • pnpm11/installing/deps-installer/src/install/index.ts
  • pnpm11/installing/deps-installer/test/install/removedImporterFastUpdate.ts

📝 Walkthrough

Walkthrough

Fast lockfile updates can remove stale workspace importers and prune dependencies used only by them. The flow preserves shared dependencies and falls back to resolution when surviving projects link to removed workspace packages.

Changes

Removed importer fast update

Layer / File(s) Summary
Fast-update pruning wiring
pnpm11/installing/deps-installer/src/install/index.ts, pnpm11/installing/deps-installer/src/install/tryComposeFastUpdates.ts, pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts
The install flow propagates pruneLockfileImporters. Fast updates require every active project importer to exist while allowing stale importers.
Stale importer pruning
pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts
The update logic detects stale importers, removes them, records dropped aliases, and aborts when a surviving importer links to a stale importer.
Pruning validation and release metadata
pnpm11/installing/deps-installer/test/install/removedImporterFastUpdate.ts, .changeset/removed-importer-fast-update.md
Tests cover dependency pruning, shared dependency retention, lockfile equivalence, and workspace-link fallback behavior. The changeset documents the patch releases.

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

Sequence Diagram(s)

sequenceDiagram
  participant Install
  participant FastUpdate
  participant Lockfile
  participant Resolver
  Install->>FastUpdate: enable pruneLockfileImporters
  FastUpdate->>Lockfile: detect stale importers
  alt No surviving link targets a stale importer
    FastUpdate->>Lockfile: remove stale importers and exclusive dependencies
  else Surviving link targets a stale importer
    FastUpdate->>Resolver: fall back to resolution
  end
Loading

Possibly related issues

Possibly related PRs

  • pnpm/pnpm#13477 — Modifies the same tryFastUpdateImporters flow extended here with stale-importer pruning.
  • pnpm/pnpm#13698 — Modifies fast importer updates for removal and pruning scenarios.
  • pnpm/pnpm#13712 — Modifies fast lockfile importer pruning for a different removal scenario.

Suggested labels: product: pnpm@11

Suggested reviewers: greptile-apps

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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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

perf: Prune stale workspace importers during fast lockfile updates

🐞 Bug fix ✨ Enhancement 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Allow fast lockfile updates when workspace projects are removed.
• Prune lockfile importers/packages for removed projects without triggering full resolution.
• Add regression tests for removal behavior and linked-workspace failure cases.
Diagram

graph TD
  A["mutateModules (install)"] --> B["Fast-path gate"] --> C["tryComposeFastUpdates"] --> D["tryFastUpdateImporters"] --> E[("wantedLockfile.importers")]
  D --> F["Shared epilogue prune"] --> G[("wantedLockfile.packages")]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Keep strict importer-count gate; always fall back to resolver on mismatch
  • ➕ Simpler eligibility rule; less mutation in fast path
  • ➕ Avoids needing to reason about stale-importer pruning correctness
  • ➖ Workspace project removal always triggers full re-resolution (the current performance regression)
  • ➖ Misses an opportunity to reuse the existing prune epilogue for safe cleanup
2. Run a separate pre-pass to prune stale importers before gating
  • ➕ Fast-path gate can stay simple while still benefiting from pruning
  • ➕ Could be reused by other install modes or tools
  • ➖ Adds another lockfile mutation phase and ordering complexity
  • ➖ May duplicate logic already co-located with importer drift handling

Recommendation: Current approach is the better tradeoff: prune stale importers inside the importer drift handler (where project↔importer correspondence is already handled), record dropped aliases, and let the shared epilogue perform reachability pruning. The added guard that refuses fast-path pruning when a surviving project still links to the removed project is important to preserve correct error reporting and should be kept.

Files changed (5) +176 / -5

Enhancement (1) +6 / -1
tryComposeFastUpdates.tsThread pruneLockfileImporters into importer fast-update handler +6/-1

Thread pruneLockfileImporters into importer fast-update handler

• Extends fast-update compose options with pruneLockfileImporters and defaults it for existing call sites. Invokes tryFastUpdateImporters with an options object to support conditional pruning behavior.

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

Bug fix (2) +51 / -4
index.tsRelax fast-path gate to allow extra lockfile importers +5/-2

Relax fast-path gate to allow extra lockfile importers

• Updates the composed fast-update eligibility checks to require only that each current project has an importer entry (rather than importer count equality). Passes pruneLockfileImporters into the composed update pipeline and includes stale-importer pruning in the specifier-change detection path.

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

tryFastUpdateImporters.tsPrune stale importers and guard against linked-to removed projects +46/-2

Prune stale importers and guard against linked-to removed projects

• Adds stale-importer detection and optional pruning when pruneLockfileImporters is enabled, recording removed specifier aliases in edits.dropped for downstream pruning. Introduces a safety check that forces resolver fallback if any surviving importer still references a removed importer via link: dependencies.

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

Tests (1) +113 / -0
removedImporterFastUpdate.tsAdd tests for fast-path importer pruning on workspace project removal +113/-0

Add tests for fast-path importer pruning on workspace project removal

• Introduces tests ensuring removed workspace projects are pruned from lockfile importers without package resolution requests, and that orphaned packages are pruned while shared dependencies remain. Adds a regression test asserting resolver fallback/error when a surviving project links to a removed workspace project.

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

Documentation (1) +6 / -0
removed-importer-fast-update.mdDocument fast-path behavior when removing a workspace project +6/-0

Document fast-path behavior when removing a workspace project

• Adds a changeset entry noting that removing a workspace package no longer forces a full re-resolution. Clarifies that linked-to removed projects still surface as errors (per #13696).

.changeset/removed-importer-fast-update.md

@greptile-apps

greptile-apps Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "test: pin that the pruned-importer fast ..." | Re-trigger Greptile

@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

🤖 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 `@pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts`:
- Around line 42-63: Port the stale-importer handling from the TypeScript
fast-update flow to the Rust pacquet implementation: prune stale importers,
reject fast updates when a stale importer is still linked from a surviving
project, and drop their specifier aliases through the existing graph-edit
cleanup path. Add regression coverage for workspace removal and include the Rust
release target in the changeset when the behavior is complete.

In `@pnpm11/installing/deps-installer/test/install/removedImporterFastUpdate.ts`:
- Around line 110-112: Update the install rejection assertion in the
removedImporterFastUpdate test to verify the specific
ERR_PNPM_WORKSPACE_PKG_NOT_FOUND error code instead of accepting any thrown
error. Preserve the existing invalid workspace dependency setup and ensure the
assertion checks the fallback resolution error.
🪄 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: b6e04e0d-cd92-4d18-addf-a56a18764f1b

📥 Commits

Reviewing files that changed from the base of the PR and between a30a1fa and f17a915.

📒 Files selected for processing (5)
  • .changeset/removed-importer-fast-update.md
  • pnpm11/installing/deps-installer/src/install/index.ts
  • pnpm11/installing/deps-installer/src/install/tryComposeFastUpdates.ts
  • pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts
  • pnpm11/installing/deps-installer/test/install/removedImporterFastUpdate.ts

The suite now runs the same workspace removal through the fast path
and through forceFullResolution and requires the two lockfiles to be
deep-equal, which is what makes this a path change rather than a
behavior change. The linked-survivor test asserts
ERR_PNPM_WORKSPACE_PKG_NOT_FOUND instead of accepting any rejection.
Copilot AI review requested due to automatic review settings August 10, 2026 20:10

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 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 10, 2026
@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Remediation recommended

1. Missing comma in isLinkedFromASurvivor params 📘 Rule violation ⚙ Maintainability
Description
The new multi-line parameter list for isLinkedFromASurvivor omits a trailing comma on the last
parameter, violating the required TypeScript trailing-comma style. This increases diff noise and
reduces consistency in future edits.
Code

pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[R155-158]

+  lockfile: LockfileObject,
+  importerId: ProjectId,
+  stale: ProjectId[]
+): boolean {
Relevance

●●● Strong

Exact trailing-comma fix in same file was accepted very recently; low-risk formatting change.

PR-#13779

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713434 requires trailing commas for multi-line TypeScript parameter lists;
isLinkedFromASurvivor is newly added with its last parameter stale: ProjectId[] lacking a
trailing comma.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[153-158]

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

## Issue description
A new multi-line TypeScript function parameter list is missing a trailing comma on the last parameter.

## Issue Context
Repo style requires trailing commas in TypeScript multi-line constructs to minimize diff churn.

## Fix Focus Areas
- pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[154-158]

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


2. Stale-link check scales poorly 🐞 Bug ➹ Performance
Description
tryFastUpdateImporters() checks each stale importer with isLinkedFromASurvivor(), which scans all
importers and uses stale.includes() (linear) in the inner loop. For workspaces with many stale
importers, this can multiply into high worst-case overhead during fast-update pruning.
Code

pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[R160-163]

+    if (stale.includes(survivorId as ProjectId)) return false
+    return DEPENDENCIES_FIELDS.some((group) =>
+      Object.values(importer[group] ?? {}).some((reference) =>
+        reference.startsWith('link:') &&
Relevance

●● Moderate

Perf refactor (Set membership/scan changes) is plausible but team often rejects micro-opts unless
proven impactful.

PR-#13698
PR-#13779

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new prune path calls isLinkedFromASurvivor once per stale importer. isLinkedFromASurvivor then
iterates all importers and uses stale.includes() to filter out stale ones, adding a linear
membership test inside that scan.

pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[47-53]
pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[153-166]

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 stale-importer safety check is implemented as:
- compute `stale` array
- for each stale importer: scan all importers; in that scan, use `stale.includes()` to exclude stale survivors

This adds unnecessary repeated work and linear membership checks.

### Issue Context
This runs on the fast-update path when `pruneLockfileImporters` is enabled and stale importers exist (e.g., after removing many workspace projects). The check can be made linear by:
- converting `stale` to `Set<ProjectId>` for O(1) membership (`has()`)
- scanning survivor importers once to build a `Set<ProjectId>` of link targets (normalized), then checking whether any target is in `staleSet`.

### Fix Focus Areas
- pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[47-61]
- pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[153-166]

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



Informational

3. Missing comma in install params 📘 Rule violation ⚙ Maintainability
Description
The new install function in the test file uses a multi-line parameter list but omits a trailing
comma after the last parameter. This violates the required trailing-comma style and makes future
diffs noisier.
Code

pnpm11/installing/deps-installer/test/install/removedImporterFastUpdate.ts[R92-95]

+  const install = async (
+    projects: WorkspaceProject[],
+    extraOptions?: { forceFullResolution: boolean }
+  ): Promise<string[]> => {
Relevance

● Weak

Trailing-comma style nits in TS tests have been explicitly rejected before.

PR-#13289

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713434 requires trailing commas for multi-line TypeScript parameter lists; the
newly added install function signature spans multiple lines and the last parameter `extraOptions?:
{ forceFullResolution: boolean }` has no trailing comma.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/installing/deps-installer/test/install/removedImporterFastUpdate.ts[92-95]

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

## Issue description
A new multi-line TypeScript function parameter list is missing a trailing comma on the last parameter.

## Issue Context
Repo style requires trailing commas in TypeScript multi-line constructs to minimize diff churn.

## Fix Focus Areas
- pnpm11/installing/deps-installer/test/install/removedImporterFastUpdate.ts[92-95]

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


4. Unconditional importer scan 🐞 Bug ➹ Performance
Description
hasChangedProjectSpecifiers() now computes staleImporterIds() whenever pruneLockfileImporters is
true, which scans all lockfile importers and allocates a Set/array during the fast-path gating
phase. This adds avoidable O(importers) work to ordinary installs where there are no stale importers
to prune.
Code

pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[R19-22]

+  pruneLockfileImporters: boolean = false
): boolean {
+  if (pruneLockfileImporters && staleImporterIds(lockfile, projects).length > 0) return true
  return projects.some((project) => {
Relevance

● Weak

Similar fast-path micro-optimization (avoid Set/sort allocations) was previously rejected in same
file.

PR-#13779

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new early-return calls staleImporterIds(), which builds a Set from projects and filters all
importer keys. mutateModules computes hasChangedSpecifiers by calling hasChangedProjectSpecifiers(),
so this scan is on the normal install path whenever pruneLockfileImporters is enabled.

pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[16-31]
pnpm11/installing/deps-installer/src/install/index.ts[730-740]

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

### Issue description
`hasChangedProjectSpecifiers()` performs a full `staleImporterIds()` scan when `pruneLockfileImporters` is enabled, even in the common case where the lockfile has no stale importer entries. This introduces extra linear work on a hot gating path.

### Issue Context
- The goal of the new stale-importer check is to detect removed workspace projects so the fast update can prune their importers.
- You can avoid scanning all lockfile importers in the common case by first checking inexpensive conditions (e.g., `Object.keys(lockfile.importers).length > projects.length` and/or `projects.every(p => lockfile.importers[p.id] != null)`) and only computing `staleImporterIds()` when stale importers are actually possible.

### Fix Focus Areas
- pnpm11/installing/deps-installer/src/install/tryFastUpdateImporters.ts[16-31]
- pnpm11/installing/deps-installer/src/install/index.ts[730-740]

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


Grey Divider

Context used
✅ Compliance rules (platform): 18 rules

Grey Divider

Tip of the day
💡 Did you know, you can reply 'qodo' on any finding to push back, ask questions, or dig deeper

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

No code suggestions found for the PR.

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