Skip to content

fix(deps-resolver): preserve workspace link: on re-resolution (fixes pnpm/pnpm#10433) - #13112

Merged
zkochan merged 15 commits into
pnpm:mainfrom
omril1:fix/preserve-workspace-link-partial-update
Jul 30, 2026
Merged

zkochan merged 15 commits into
pnpm:mainfrom
omril1:fix/preserve-workspace-link-partial-update

Conversation

@omril1

@omril1 omril1 commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Related to #10433. #12800 (already merged) fixed the first mechanism; this PR closes the remaining re-resolution paths, so the reported corruption no longer reproduces.

The issue is a workspace link: that correctly deduped being spuriously rewritten to a peer-suffixed file:. There were two such mechanisms: a same-version peer-suffix decoration that dedupeInjectedDeps failed to collapse (fixed in #12800), and re-resolution of an untargeted workspace dependency on pnpm update/plain install (fixed here). With both landed, the reporter's exact repro produces zero corruptions (validated end-to-end below).

With injectWorkspacePackages: true, a workspace dependency that correctly deduped to link: on install can be spuriously rewritten to a peer-suffixed file: when an unrelated dependency changes — e.g. pnpm update <pkg> (with or without --recursive), a version bump of a root/catalog dependency, or a plain pnpm install after such a change. On a workspace where consumer → pkg-d resolved to link:../pkg-d, running:

pnpm add -D [email protected] -w
pnpm update [email protected] --recursive

flips it to file:packages/pkg-d(@repro/pkg-a@…)(@repro/pkg-b@…([email protected])) — even though pkg-d and everything it depends on is untouched by the change. Under nodeLinker: hoisted the file: entry copies a stale/unbuilt snapshot into node_modules instead of symlinking the live workspace source, which surfaces as build/e2e failures.

#12800 fixed the plain-install path where dedupeInjectedDeps collapses a peer-suffix decoration back to link:. The paths here re-resolve untouched injected workspace deps and either bypass that dedupe (the update-style runs) or land on a genuine peer-context divergence that dedupe correctly keeps as file: — so the importer entry is re-derived as file: even though the dependency wasn't touched.

Reproduction (still reproduces on 11.13.0, which already contains #12800): https://github.com/omril1/pnpm-workspace-link-corruption-repro — the winston add+update sequence above.

Fix

When finalizing importer dependency refs in resolveDependencies, preserve the previous link: for a workspace dependency that this run does not target. A dependency is targeted when it is new, its specifier changed (prevSpecifier !== bareSpecifier), or it is matched by updateMatching (pnpm update <name>). A workspace dependency resolved to link: has no version to update, so a run that doesn't target it must not flip it to file:; a dependency the run actually targets still resolves freely.

updateSpec is deliberately not part of the targeting criterion: a plain pnpm install marks every manifest dependency with updateSpec: true (it means "re-check the spec", not "the user asked to change this"), so consulting it would treat every dependency as targeted and defeat the guard on the plain-install path. The guard is not specific to any one command — it applies to every mutation type that re-resolves importers (install, installSome, uninstallSome), covering the install, update, add, and remove entry points.

Regression tests

injectWorkspacePackagesPersistence.test.ts gains two tests, both verified non-vacuous (they fail on git checkout main -- installing/deps-resolver/src/index.ts and pass with the fix):

  1. Update path — drives the update exactly as the CLI lowers pnpm update [email protected] --recursive (see installing/commands/src/recursive.ts): the importer whose manifest has winston gets mutation: 'installSome' with the selector; every other importer gets installSome with no selectors and update: true. Without the fix it fails with Received: "file:d(a@file:a)(b@file:b(a@file:a)([email protected]))"; with it, consumer → d stays link:../d and winston still updates to 3.19.0.
  2. Plain-install path — a genuine peer-context divergence that dedupeInjectedDeps rightly keeps file:: q peer-depends @pnpm.e2e/foo, provided by the root at 100.0.0, so the injected copy of n matches and dedupes to link: on install. Adding [email protected] to the consumer and running a plain install makes the injected q diverge (100.1.0) from n's own context (100.0.0); the untouched consumer → n entry must stay link:. This is the case that exercises the updateSpec criterion above.

Also validated end to end: built from this branch and run against the reproduction, pkg-d stays link:, winston updates, and pnpm install --frozen-lockfile accepts the result unchanged. The existing injectWorkspacePackagesPersistence and dedupeInjectedDeps suites still pass.

Rust (pnpm/) port

The equivalent guard is ported to pacquet-package-manager's fresh-lockfile builder (dependencies_graph_to_lockfile::build_importer): after computing an importer dependency's version cell, if it resolved to file:, the previous lockfile recorded it as link:, and the run doesn't target it, the prior link: is restored. Targeting is derived from the importer's effective update scope together with a specifier change — the same criterion as the TS side. The effective scope mirrors the resolver's update_reuse_scope_for: a global None (bare update) applies to every importer, otherwise the per-importer scope wins with the global as fallback. This is what lets pacquet update <name> --recursive (a ByImporter policy: global All, named packages recorded per importer) target the named dependency in the importer that declares it while leaving untouched importers' link: entries intact. Both the previous importer entries and the per-importer update scopes are threaded from install_with_fresh_lockfile into the builder. Adds unit tests for: preserve when untargeted; keep file: on a first install, on a single-project update <name>, on a scope-wide bare update, and on a specifier change; the recursive per-importer case (named dep flips to file:); and the #10433 recursive-protection case (a recursive update of another package preserves n's link:) — the last verified non-vacuous by neutering the per-importer resolution.

Squash Commit Body

A workspace dependency that deduped to `link:` on install could be rewritten to
a peer-suffixed `file:` by any run that re-resolves it without deduping back to
`link:` — e.g. `pnpm update <other-pkg>` (with or without --recursive), a
root/catalog bump, or a plain install that hits a genuine peer-context
divergence.

When finalizing importer refs, keep the previous `link:` for a workspace
dependency the run doesn't target: not new, specifier unchanged, and not matched
by `pnpm update <name>`. `updateSpec` is intentionally excluded from the
criterion because a plain install marks every manifest dependency with it. A
workspace `link:` dependency has no version to update, so a run that doesn't
target it must not flip it to `file:`; targeted dependencies still resolve
freely.

Adds regression tests for the update-recursive and plain-install paths (both
fail without the fix) and ports the guard to the Rust package-manager crate.

Completes the fix for pnpm/pnpm#10433 — the first mechanism was fixed in #12800.

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust pnpm/ port.
  • Added a changeset.
  • Added or updated tests — regression tests on both paths verified to fail without the fix and pass with it, on both the TS and Rust sides.
  • Updated the documentation if needed — not applicable.

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

Summary by CodeRabbit

  • Bug Fixes

    • Preserved existing workspace link: dependency entries during partial installs and unrelated dependency updates.
    • Prevented untouched injected workspace dependencies from being rewritten into peer-suffixed file: entries.
    • Kept the correct link: form during lockfile rebuilds when the dependency isn’t targeted, while still switching to file: for truly targeted updates.
  • Tests

    • Added regression coverage for partial updates, recursive updates, fresh-lockfile and lockfile-only flows, plus injected workspace persistence scenarios.

@coderabbitai

coderabbitai Bot commented Jul 17, 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

The resolver and Rust lockfile builder now carry previous importer data and update scopes to preserve untouched workspace link: references. Rust and installer tests cover untargeted installs, targeted updates, changed specifiers, scoped targeting, and peer divergence.

Changes

Workspace link preservation

Layer / File(s) Summary
Resolver ref preservation
pnpm11/installing/deps-resolver/src/index.ts
Preserves an untargeted prior link: reference when recalculation produces a file: reference.
Fresh lockfile state plumbing
pnpm/crates/package-manager/src/install_with_fresh_lockfile.rs
Passes prior importer snapshots and update scopes through lockfile-only and normal installation paths.
Importer preservation guard
pnpm/crates/package-manager/src/dependencies_graph_to_lockfile.rs
Preserves prior link: versions unless the dependency is targeted or its manifest specifier changed.
Regression coverage
pnpm/crates/package-manager/src/dependencies_graph_to_lockfile/tests.rs, pnpm11/installing/deps-installer/test/install/injectWorkspacePackagesPersistence.test.ts
Covers reuse behavior, targeted updates, peer divergence, and injected workspace dependencies.
Release metadata
.changeset/preserve-workspace-link-on-partial-update.md
Declares patch releases and documents the workspace link preservation fix.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant InstallWithFreshLockfile
  participant build_fresh_lockfile
  participant dependencies_graph_to_lockfile
  participant build_importer
  participant PreviousImporter
  InstallWithFreshLockfile->>build_fresh_lockfile: pass previous importers and update scope
  build_fresh_lockfile->>dependencies_graph_to_lockfile: forward lockfile build inputs
  dependencies_graph_to_lockfile->>build_importer: pass prior importer and update scope
  build_importer->>PreviousImporter: read prior dependency reference
  build_importer-->>dependencies_graph_to_lockfile: preserve link or emit file
Loading

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

Suggested reviewers: zkochan

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@omril1
omril1 force-pushed the fix/preserve-workspace-link-partial-update branch from 7ff0e67 to ea3fa4c Compare July 17, 2026 20:27
@codecov-commenter

codecov-commenter commented Jul 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.87%. Comparing base (0f1c467) to head (504a968).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13112      +/-   ##
==========================================
+ Coverage   87.86%   87.87%   +0.01%     
==========================================
  Files         549      549              
  Lines       96091    96151      +60     
==========================================
+ Hits        84429    84492      +63     
+ Misses      11662    11659       -3     

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

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

@github-actions

github-actions Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 504a96846cd9

Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD.

The tables below show mean ± σ; Bencher thresholds on the minimum latency, which is far less perturbed by shared-runner contention (noise only adds time).

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.744 ± 0.051 2.638 2.809 1.57 ± 0.12
pacquet@main 2.850 ± 0.210 2.661 3.371 1.63 ± 0.17
pnpr@HEAD 1.781 ± 0.193 1.572 2.095 1.02 ± 0.13
pnpr@main 1.745 ± 0.130 1.615 1.968 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.7440469053600003,
      "stddev": 0.05101540573281461,
      "median": 2.74877682046,
      "user": 2.7836663,
      "system": 2.0229925,
      "min": 2.63768305946,
      "max": 2.8087714414600002,
      "times": [
        2.80597401446,
        2.74473259046,
        2.75282105046,
        2.63768305946,
        2.77100312046,
        2.8087714414600002,
        2.6897268424600003,
        2.73126359146,
        2.74171694146,
        2.7567764014600002
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.84970250106,
      "stddev": 0.20953989145992022,
      "median": 2.79639372446,
      "user": 2.949760199999999,
      "system": 2.0063907,
      "min": 2.66070984446,
      "max": 3.37086988946,
      "times": [
        2.67432364746,
        2.91045855946,
        2.66070984446,
        2.69839309446,
        2.85597649846,
        2.77260889346,
        2.82017855546,
        3.37086988946,
        2.75939949546,
        2.97410653246
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.78136751606,
      "stddev": 0.19315394369831893,
      "median": 1.70405954746,
      "user": 2.0709110999999996,
      "system": 1.8723759999999998,
      "min": 1.5723402214600002,
      "max": 2.09517503646,
      "times": [
        2.09517503646,
        1.71759033846,
        1.69052875646,
        2.06176656846,
        1.9050714644600002,
        1.62557048946,
        1.89644107146,
        1.64321602946,
        1.5723402214600002,
        1.60597518446
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.7445495598599998,
      "stddev": 0.1302678062623,
      "median": 1.7028034819600002,
      "user": 1.8537358999999998,
      "system": 1.7662612,
      "min": 1.61468814146,
      "max": 1.9676935714600001,
      "times": [
        1.62499265046,
        1.6228091124600001,
        1.83529092146,
        1.66419390546,
        1.9332917814600001,
        1.61468814146,
        1.73526085346,
        1.77692855046,
        1.9676935714600001,
        1.6703461104600001
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 440.7 ± 31.8 387.1 484.6 1.02 ± 0.10
pacquet@main 430.8 ± 28.7 395.7 488.9 1.00
pnpr@HEAD 485.0 ± 50.0 397.1 544.3 1.13 ± 0.14
pnpr@main 473.7 ± 21.1 433.8 506.0 1.10 ± 0.09
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.44069508052,
      "stddev": 0.03177374093516833,
      "median": 0.44026168772,
      "user": 0.39244434000000006,
      "system": 0.7880976999999999,
      "min": 0.38714904522000004,
      "max": 0.48463860022000005,
      "times": [
        0.44169256222000003,
        0.45764937522000004,
        0.43883081322,
        0.38714904522000004,
        0.48463860022000005,
        0.43554540622000004,
        0.46553661422000003,
        0.47492933422,
        0.42382463422,
        0.39715442022
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.43078329452,
      "stddev": 0.028667673383034983,
      "median": 0.42516055872,
      "user": 0.39177634,
      "system": 0.7781338999999999,
      "min": 0.39570432422,
      "max": 0.48894069622,
      "times": [
        0.45834103022,
        0.43171301522,
        0.48894069622,
        0.41860810222,
        0.41358695022,
        0.40345682922000004,
        0.45242348622,
        0.43321025022000004,
        0.39570432422,
        0.41184826122
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.48501956992000006,
      "stddev": 0.05004512084495434,
      "median": 0.48340788222000003,
      "user": 0.42478614,
      "system": 0.7958657999999998,
      "min": 0.39714110622000004,
      "max": 0.54428831022,
      "times": [
        0.39714110622000004,
        0.54428831022,
        0.53820674622,
        0.5250353962200001,
        0.48608866922000005,
        0.53376875122,
        0.46279101822,
        0.43324664022000003,
        0.48072709522,
        0.44890196622
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.47369603902,
      "stddev": 0.02113469752084153,
      "median": 0.47260198722,
      "user": 0.41281033999999994,
      "system": 0.7807164999999998,
      "min": 0.43377205122,
      "max": 0.5060183392200001,
      "times": [
        0.48355172322,
        0.46837388122,
        0.49553514222,
        0.5060183392200001,
        0.48968800122,
        0.45661401422000003,
        0.46487370722000004,
        0.47683009322000003,
        0.46170343722,
        0.43377205122
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 3.201 ± 0.098 3.055 3.345 1.74 ± 0.16
pacquet@main 3.077 ± 0.062 2.973 3.171 1.67 ± 0.15
pnpr@HEAD 1.858 ± 0.207 1.611 2.239 1.01 ± 0.14
pnpr@main 1.838 ± 0.156 1.664 2.119 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 3.2010035762599998,
      "stddev": 0.09789828982808513,
      "median": 3.20086972876,
      "user": 2.9858979999999997,
      "system": 2.1001395,
      "min": 3.05498709576,
      "max": 3.34518325076,
      "times": [
        3.30477968676,
        3.12832717676,
        3.20758813876,
        3.08155615176,
        3.14579659476,
        3.2674052477599997,
        3.05498709576,
        3.34518325076,
        3.19415131876,
        3.28026110076
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 3.0773842763599997,
      "stddev": 0.06235243227292206,
      "median": 3.07509600876,
      "user": 2.7701723999999994,
      "system": 2.0638456999999995,
      "min": 2.97332495576,
      "max": 3.17052375376,
      "times": [
        3.07746221776,
        3.11691525876,
        2.97332495576,
        3.0107083227599998,
        3.03871409576,
        3.17052375376,
        3.07272979976,
        3.06935541276,
        3.07785957676,
        3.16624936976
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.8576154694600002,
      "stddev": 0.20656138975477872,
      "median": 1.86040728526,
      "user": 1.9390304000000005,
      "system": 1.8780388999999995,
      "min": 1.61143663476,
      "max": 2.23935803176,
      "times": [
        1.98671884976,
        1.84082008276,
        1.72235194476,
        1.63547818276,
        2.23935803176,
        1.6690106127600002,
        1.61143663476,
        1.89804268676,
        1.8799944877599999,
        2.09294318076
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.83771271006,
      "stddev": 0.156221990076029,
      "median": 1.76236198676,
      "user": 1.9465776,
      "system": 1.8833109000000001,
      "min": 1.66384715176,
      "max": 2.11921414276,
      "times": [
        1.75439458576,
        1.66384715176,
        1.7432805287600002,
        1.91886552176,
        2.09504591776,
        1.8187076067599999,
        1.77032938776,
        1.7417534567600002,
        1.75168880076,
        2.11921414276
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 926.6 ± 36.5 845.3 964.6 1.86 ± 0.23
pacquet@main 728.1 ± 60.7 645.1 844.1 1.46 ± 0.21
pnpr@HEAD 499.5 ± 59.8 419.1 639.8 1.00
pnpr@main 499.7 ± 32.9 452.8 550.8 1.00 ± 0.14
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.9266261087800001,
      "stddev": 0.0364814716638094,
      "median": 0.93971508808,
      "user": 1.2484594999999998,
      "system": 1.10204062,
      "min": 0.84534461758,
      "max": 0.9646077645800001,
      "times": [
        0.88537044758,
        0.9646077645800001,
        0.9388756795800001,
        0.94449350858,
        0.94055449658,
        0.94352107358,
        0.91617655558,
        0.9608141075800001,
        0.92650283658,
        0.84534461758
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.7281267038800001,
      "stddev": 0.06069566347190242,
      "median": 0.7066889730800001,
      "user": 1.0135782,
      "system": 0.9785107199999998,
      "min": 0.6450555275800001,
      "max": 0.84411092858,
      "times": [
        0.81552430858,
        0.6929185745800001,
        0.70069855158,
        0.69346203058,
        0.73919765258,
        0.7126793945800001,
        0.7456039585800001,
        0.84411092858,
        0.69201611158,
        0.6450555275800001
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.49952392188,
      "stddev": 0.059837843132071196,
      "median": 0.49042415958,
      "user": 0.3776015,
      "system": 0.8220297200000001,
      "min": 0.41910595758,
      "max": 0.63983895658,
      "times": [
        0.41910595758,
        0.45356146058,
        0.48966990158,
        0.46184219358,
        0.49859219358,
        0.48682050558,
        0.54553056658,
        0.49117841758,
        0.63983895658,
        0.5090990655800001
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.49967939738,
      "stddev": 0.032903385882991326,
      "median": 0.50224538108,
      "user": 0.3967891,
      "system": 0.7776178200000001,
      "min": 0.45282904858,
      "max": 0.5507781765800001,
      "times": [
        0.48514823158000003,
        0.52717723258,
        0.51934253058,
        0.5199031885800001,
        0.46652888458,
        0.45282904858,
        0.52713929058,
        0.47369080658,
        0.47425658358,
        0.5507781765800001
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.315 ± 0.059 2.245 2.400 5.07 ± 0.48
pacquet@main 2.293 ± 0.070 2.178 2.381 5.02 ± 0.48
pnpr@HEAD 0.502 ± 0.028 0.464 0.539 1.10 ± 0.12
pnpr@main 0.457 ± 0.041 0.406 0.528 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.3147615456799997,
      "stddev": 0.059385920542954405,
      "median": 2.3242327920799997,
      "user": 1.6322159799999998,
      "system": 1.28745544,
      "min": 2.24511061008,
      "max": 2.4004613940799997,
      "times": [
        2.4004613940799997,
        2.2682548260799997,
        2.24627891408,
        2.3097699170799997,
        2.37185465608,
        2.24695454908,
        2.36793528108,
        2.24511061008,
        2.3386956670799997,
        2.3522996420799998
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.29314799548,
      "stddev": 0.06994015824651333,
      "median": 2.3067487510799998,
      "user": 1.6562268799999997,
      "system": 1.2203524399999999,
      "min": 2.17750817108,
      "max": 2.38078310008,
      "times": [
        2.17750817108,
        2.31656859208,
        2.37615060008,
        2.19940329008,
        2.2681583820799998,
        2.38078310008,
        2.2969289100799997,
        2.32226564108,
        2.3480034970799997,
        2.24570977108
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.50191163678,
      "stddev": 0.02802390126504078,
      "median": 0.50082718708,
      "user": 0.39967408,
      "system": 0.7799032399999999,
      "min": 0.46405288808,
      "max": 0.53884385808,
      "times": [
        0.53119327508,
        0.5298863000799999,
        0.48102718208,
        0.52140181408,
        0.5144905250799999,
        0.46405288808,
        0.48716384908000004,
        0.48036938108000005,
        0.47068729508,
        0.53884385808
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.45691251708,
      "stddev": 0.041339160986654265,
      "median": 0.45418708158000004,
      "user": 0.34952237999999997,
      "system": 0.7344510399999998,
      "min": 0.40616467808,
      "max": 0.52812627008,
      "times": [
        0.44947477608,
        0.50681873108,
        0.46421692708,
        0.41765491408000005,
        0.42003224008,
        0.42554164408,
        0.40616467808,
        0.52812627008,
        0.49219560308000004,
        0.45889938708000005
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 462.6 ± 61.4 359.3 531.0 3.75 ± 0.64
pacquet@main 409.1 ± 35.3 355.5 457.5 3.31 ± 0.45
pnpr@HEAD 126.7 ± 13.4 101.7 146.0 1.03 ± 0.15
pnpr@main 123.5 ± 13.0 106.2 147.1 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.46260043381999993,
      "stddev": 0.061417166747529256,
      "median": 0.48285363872000003,
      "user": 0.46321373999999993,
      "system": 0.11712022,
      "min": 0.35927098272,
      "max": 0.5309579277200001,
      "times": [
        0.5309579277200001,
        0.5069966117200001,
        0.49489023172,
        0.50425088072,
        0.35927098272,
        0.38287113672000006,
        0.45563744772000003,
        0.39946923972000004,
        0.5208428337200001,
        0.47081704572000005
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.4091113029200001,
      "stddev": 0.035268021342552185,
      "median": 0.42357413122000004,
      "user": 0.41247343999999997,
      "system": 0.10320562,
      "min": 0.35547097172000003,
      "max": 0.45749214672000005,
      "times": [
        0.37670837972000004,
        0.43010189172,
        0.37014736172,
        0.37936881872000006,
        0.45749214672000005,
        0.43867003672000004,
        0.41704637072000006,
        0.43310985672,
        0.43299719472000003,
        0.35547097172000003
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.12670387214857143,
      "stddev": 0.01338809626112298,
      "median": 0.12917717672,
      "user": 0.04446458761904762,
      "system": 0.016332876190476193,
      "min": 0.10172378472,
      "max": 0.14598441571999998,
      "times": [
        0.13442937572000002,
        0.13270477372,
        0.14598441571999998,
        0.13772960272,
        0.13625252572000002,
        0.14551099372000004,
        0.13847636172,
        0.12917717672,
        0.13313526572,
        0.11869909872000001,
        0.11341937972,
        0.10987565472000001,
        0.11872131072,
        0.13678395872,
        0.11429323772000001,
        0.11503894572000001,
        0.11306925872000001,
        0.12767439272000003,
        0.14583265972000004,
        0.11224914172,
        0.10172378472
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.12351045081523808,
      "stddev": 0.013032595137803573,
      "median": 0.12101521972000001,
      "user": 0.04311853999999998,
      "system": 0.016701405714285713,
      "min": 0.10621198172,
      "max": 0.14713610872,
      "times": [
        0.13280054372,
        0.14432843272,
        0.11655996372,
        0.10911014972000001,
        0.11280411772000001,
        0.13000190372000003,
        0.10650909272,
        0.10989717472,
        0.11447795672000001,
        0.11416620772000001,
        0.11854337572000001,
        0.12101521972000001,
        0.13122193572000002,
        0.12720756072,
        0.14338395072,
        0.13330950472000003,
        0.13945819372,
        0.14713610872,
        0.12275411072,
        0.11282198172,
        0.10621198172
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 5.184 ± 0.233 4.905 5.536 1.36 ± 0.08
pacquet@main 5.023 ± 0.126 4.867 5.302 1.32 ± 0.06
pnpr@HEAD 3.803 ± 0.158 3.678 4.089 1.00
pnpr@main 3.821 ± 0.125 3.675 4.105 1.00 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 5.184260053040001,
      "stddev": 0.23310388173035418,
      "median": 5.15021724124,
      "user": 3.4570569,
      "system": 2.3563659400000003,
      "min": 4.90470784474,
      "max": 5.53558306574,
      "times": [
        5.05842830774,
        5.331293011740001,
        4.9684063407400005,
        4.93511580174,
        5.42171900774,
        5.53558306574,
        5.42100024574,
        5.0243407297400005,
        4.90470784474,
        5.24200617474
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 5.02268569254,
      "stddev": 0.12603941488686426,
      "median": 5.00867033924,
      "user": 3.4499495,
      "system": 2.39571784,
      "min": 4.86719891174,
      "max": 5.30246820274,
      "times": [
        5.01166877974,
        5.014694055740001,
        4.86719891174,
        4.95364428474,
        5.15430275874,
        5.30246820274,
        4.94562664974,
        5.00567189874,
        5.05395945574,
        4.91762192774
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.8032241371400004,
      "stddev": 0.1576127803609377,
      "median": 3.74912528324,
      "user": 2.1291021999999997,
      "system": 1.9375259399999998,
      "min": 3.6782994337400003,
      "max": 4.08909749774,
      "times": [
        3.79734373474,
        3.78649516774,
        4.08909749774,
        4.08728010874,
        3.69022904974,
        3.6782994337400003,
        3.80456273374,
        3.7117553987400003,
        3.6994295067400005,
        3.6877487397400004
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.821441363140001,
      "stddev": 0.12510462846192322,
      "median": 3.8092251932400005,
      "user": 2.1903288,
      "system": 1.9700411399999997,
      "min": 3.6749444447400004,
      "max": 4.10539320974,
      "times": [
        3.6867691817400003,
        3.90590312474,
        3.6749444447400004,
        4.10539320974,
        3.8826538647400004,
        3.8078561847400003,
        3.7371180557400003,
        3.82945123674,
        3.7737301267400003,
        3.8105942017400003
      ]
    }
  ]
}

@github-actions

github-actions Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13112
Testbedpacquet

🚨 2 Alerts

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Upper Boundary
(Limit %)
isolated-linker.fresh-install.hot-cache.hot-storeLatency
milliseconds (ms)
📈 plot
🚷 threshold
🚨 alert (🔔)
845.34 ms
(+32.50%)Baseline: 638.02 ms
765.62 ms
(110.41%)

isolated-linker.fresh-restore.hot-cache.hot-storeLatency
milliseconds (ms)
📈 plot
🚷 threshold
🚨 alert (🔔)
387.15 ms
(+37.95%)Baseline: 280.64 ms
336.76 ms
(114.96%)

Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
3,054.99 ms
(+8.43%)Baseline: 2,817.60 ms
3,381.11 ms
(90.35%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
2,245.11 ms
(+14.59%)Baseline: 1,959.31 ms
2,351.17 ms
(95.49%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
🚨 view alert (🔔)
845.34 ms
(+32.50%)Baseline: 638.02 ms
765.62 ms
(110.41%)

isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
359.27 ms
(-6.21%)Baseline: 383.05 ms
459.66 ms
(78.16%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,637.68 ms
(+8.64%)Baseline: 2,427.85 ms
2,913.42 ms
(90.54%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,904.71 ms
(+8.51%)Baseline: 4,520.18 ms
5,424.22 ms
(90.42%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
🚨 view alert (🔔)
387.15 ms
(+37.95%)Baseline: 280.64 ms
336.76 ms
(114.96%)

🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/13112
Testbedpnpr

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds flag.

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,424.47 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
287.32 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
298.18 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
84.74 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,355.17 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,450.42 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
252.40 ms
🐰 View full continuous benchmarking report in Bencher

@omril1
omril1 force-pushed the fix/preserve-workspace-link-partial-update branch from 837e757 to 7f76033 Compare July 18, 2026 15:41
@omril1 omril1 changed the title fix(deps-resolver): preserve workspace link: on partial update (#10433 follow-up) fix(deps-resolver): preserve workspace link: on re-resolution (fixes pnpm/pnpm#10433) Jul 18, 2026
@omril1 omril1 closed this Jul 18, 2026
@omril1 omril1 reopened this Jul 18, 2026
@omril1
omril1 marked this pull request as ready for review July 18, 2026 21:09
@omril1
omril1 requested a review from zkochan as a code owner July 18, 2026 21:09
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@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: 3

🤖 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/preserve-workspace-link-on-partial-update.md:
- Line 7: Update the release note so it does not claim pacquet supports the
recursive-update behavior while its per-importer handling differs from
TypeScript pnpm. Split or qualify the pacquet note to accurately describe
supported behavior, or implement equivalent recursive-update handling before
retaining the shared claim; preserve identical observable behavior between
pacquet and TypeScript pnpm.

In `@pnpm/crates/package-manager/src/install_with_fresh_lockfile.rs`:
- Around line 1263-1270: Preserve per-importer update targets during
fresh-lockfile construction instead of forwarding only the global update scope:
in pnpm/crates/package-manager/src/install_with_fresh_lockfile.rs:1263-1270,
pass the target map or a dedicated matcher into lockfile building; in
pnpm/crates/package-manager/src/dependencies_graph_to_lockfile.rs:328-382,
select targets by importer ID and close the parity gap so recursive named
updates produce TypeScript-equivalent paths; in
pnpm/crates/package-manager/src/dependencies_graph_to_lockfile/tests.rs:2028-2053,
add a recursive ByImporter regression covering this behavior. Pacquet and
TypeScript observable behavior must remain identical.

In
`@pnpm11/installing/deps-installer/test/install/injectWorkspacePackagesPersistence.test.ts`:
- Around line 513-518: Extend the assertions in the install regression test to
inspect both the injected and original divergent q peer contexts in the
resulting lockfile. Verify that each context resolves `@pnpm.e2e/foo` to 100.1.0
and 100.0.0 respectively, while preserving the existing consumer and link:
assertions so the test meaningfully covers peer-context deduplication.
🪄 Autofix (Beta)

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: e13cdc09-186b-48a3-9340-219f1f8a47c2

📥 Commits

Reviewing files that changed from the base of the PR and between bfb1b13 and 82499b2.

📒 Files selected for processing (6)
  • .changeset/preserve-workspace-link-on-partial-update.md
  • pnpm/crates/package-manager/src/dependencies_graph_to_lockfile.rs
  • pnpm/crates/package-manager/src/dependencies_graph_to_lockfile/tests.rs
  • pnpm/crates/package-manager/src/install_with_fresh_lockfile.rs
  • pnpm11/installing/deps-installer/test/install/injectWorkspacePackagesPersistence.test.ts
  • pnpm11/installing/deps-resolver/src/index.ts

@greptile-apps

greptile-apps Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge. The guard is narrowly scoped (only fires when the fresh resolution is file: and the prior was link:), is disabled for all targeting cases, and is validated by integration tests on both the update and plain-install paths.

Both the TypeScript and Rust implementations are well-reasoned and internally consistent. The internal lockfile representation (ResolvedDependencies = Record<string, string>) confirms the startsWith('link:') check is valid. The updateSpec-exclusion rationale is correctly documented. No new regressions are introduced — existing tests are updated with the three new struct fields using safe defaults, and the two new TypeScript integration tests were confirmed non-vacuous.

Files Needing Attention: No files require special attention.

Reviews (10): Last reviewed commit: "chore: drop unrelated bytes downgrade fr..." | Re-trigger Greptile

@greptile-apps

greptile-apps Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

@omril1
omril1 force-pushed the fix/preserve-workspace-link-partial-update branch from 9dbb12d to 55a59f4 Compare July 20, 2026 07:03
@omril1

omril1 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

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

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 20, 2026
@omril1
omril1 force-pushed the fix/preserve-workspace-link-partial-update branch 2 times, most recently from a258bf9 to 36927b5 Compare July 22, 2026 05:31
@danielmar121

Copy link
Copy Markdown

Nice!

omril1 and others added 15 commits July 30, 2026 10:58
A workspace dependency that deduped to `link:` on install could be rewritten to
a peer-suffixed `file:` by a partial update (e.g. `pnpm update <other-pkg>
--recursive`) that re-resolves it without going through dedupeInjectedDeps.
When finalizing importer refs, keep the previous `link:` for a workspace
dependency the run doesn't target (no spec change, not matched by
`pnpm update <name>`). Follow-up to pnpm#12800 for the update path of
pnpm#10433.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…lated dependency is updated

Reproduces pnpm#10433's update path exactly as the CLI lowers it
(installing/commands/src/recursive.ts): the importer whose manifest has the
updated dependency gets `installSome` with the selector, every other importer
gets `installSome` with no selectors and `update: true`. Without the fix the
untouched injected workspace dep flips from link:../d to
file:d(a@file:a)(b@file:b(a@file:a)([email protected])); with it, the entry stays
link:../d while the targeted dependency still updates.

Co-Authored-By: Claude Fable 5 <[email protected]>
…ecursive

The guard applies to any install that re-resolves an untargeted workspace
dependency, not only `pnpm update --recursive`; say so in the comments and
the changeset.

Co-Authored-By: Claude Fable 5 <[email protected]>
… as targeting

A plain `pnpm install` marks every manifest dependency with `updateSpec: true`
(deps-installer install/index.ts), so consulting it made the preserve-link:
guard consider every workspace dependency "targeted" and never fire on the
install path — precisely the catalog/root version-bump scenario from
pnpm#10433. Real targeting is already captured by `isNew`, an actual
specifier change (`prevSpecifier !== bareSpecifier`, which covers explicit
`pnpm update <pkg>@<version>` selectors), and `updateMatching`
(`pnpm update <name>`).

Co-Authored-By: Claude Fable 5 <[email protected]>
…nstall

Add a non-vacuous regression test for the plain `pnpm install` path of
pnpm#10433: when a consumer change makes an ancestor-provided peer of an
injected workspace dependency diverge, dedupeInjectedDeps correctly keeps the
injected copy `file:`, but the untouched importer entry must be preserved as
`link:` rather than rewritten to a peer-suffixed `file:`. This exercises the
criterion that a plain install's blanket `updateSpec` must not count as
targeting a dependency. Fails without the deps-resolver fix.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…nstall

Port the pnpm#10433 preserve-`link:` guard to the Rust
(`pacquet-package-manager`) fresh-lockfile builder. When an install does
not target a workspace dependency (a plain install / add, or an update
whose scope doesn't name it, with no specifier change), keep its previous
`link:` importer entry instead of rewriting it to a peer-suffixed `file:`
that the divergent fresh resolution produced. `dedupe_injected_deps` runs
earlier in the resolver and does not reach this importer-ref
finalization path, mirroring the TS resolver bug.

Threads the previous run's importer entries and the update reuse scope
from `install_with_fresh_lockfile` into `build_importer`, and adds
non-vacuous unit tests (preserve when untargeted; keep file: on a first
install, when an update targets the dep, or when the specifier changed).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…nk: guard

Codecov flagged two uncovered lines in the pnpm#10433 guard:
the `UpdateReuseScope::None` (bare `update`) arm and the `name_ver`
branch of `node_pkg_name`. Add a scope-wide-update test (file: stands)
and an update-targets-a-named-node test (injected node carries a
structured name_ver), bringing the guard's branches to full coverage.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
`cargo doc --document-private-items` with `-D warnings` rejects a public
item that intra-doc-links to a private one
(rustdoc::private_intra_doc_links). The `previous_importers` /
`update_reuse_scope` field docs linked `[build_importer]` (private);
demote those to plain code spans. Fixes the Rust CI / Doc job.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
The fix also preserves link: on a plain install after a root/catalog
change, not only on pnpm update <pkg>; widen the changeset accordingly.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…-update parity gap

Address review of the Rust port:
- Add "pacquet": patch to the changeset — the lockfile-shape change lands
  in the Rust stack too, so the parity change carries the wrapper per
  CLAUDE.md.
- Document, in build_importer, that the guard reads the global update
  scope (not the per-importer scope), so pnpm update <name> --recursive
  targeting of a workspace-link dep that also flips its peer context is
  not honored, and why threading the per-importer scope would reintroduce
  pnpm#10433.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Address review of the Rust port. The guard read the workspace-wide update
scope, so `pacquet update <name> --recursive` (a ByImporter policy whose
global scope is All, with the named packages recorded per importer) did
not target the named workspace-link dep — diverging from the TS side's
per-importer `updateMatching`. Resolve each importer's effective scope the
same way the resolver does (`update_reuse_scope_for`: global None applies
to all, else per-importer entry, else global) and thread the per-importer
scope map from install_with_fresh_lockfile into build_importer.

This is safe (does not reintroduce pnpm#10433): a recursive update of
<name> lowers non-target importers to the global All fallback (importers
lacking the dep are skipped), never a side-effect DropAll, so untouched
workspace edges are still preserved.

Also, per review:
- Strengthen the plain-install TS regression test to assert both foo
  versions resolved, proving the peer context genuinely diverged (guards
  against a vacuous pass).
- Add Rust tests for the recursive per-importer target and the recursive
  pnpm#10433-protection case (updating another package preserves the link:).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
The Dylint custom lint rejects a bare `#NNN` (ambiguous). Qualify the
pnpm#10433 reference in the recursive-guard test comment. Fixes the
Rust CI / Dylint job.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
The fresh-lockfile builder now rejects unkeyed dep paths, so the guard
tests' bare file:packages/n fixture no longer parses. Reuse the existing
make_file_node helper (the realistic n@file:packages/n shape) instead of
a duplicate, and test node_pkg_name's name_ver arm directly: a node with
name_ver set parses to a Regular version, so the end-to-end named-node
scenario can no longer reach the guard — and never occurs for directory
resolutions.

Co-Authored-By: Claude Fable 5 <[email protected]>
@zkochan
zkochan force-pushed the fix/preserve-workspace-link-partial-update branch from 66b50f7 to 504a968 Compare July 30, 2026 09:18
@zkochan
zkochan marked this pull request as ready for review July 30, 2026 09:18
Copilot AI review requested due to automatic review settings July 30, 2026 09:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Preserve workspace link: refs during partial re-resolution (#10433)

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Prevent untargeted workspace deps from flipping link: to peer-suffixed file: on
 update/install.
• Thread previous importer snapshots + update scope into lockfile finalization to preserve prior
 link:.
• Add regression tests covering recursive update and plain-install re-resolution paths (pnpm#10433).
Diagram

graph TD
  A["pnpm install / update"] --> B["deps-resolver (TS)"] --> C["deps graph"] --> D["fresh lockfile builder (Rust)"] --> E["lockfile importers"]
  P[("previous lockfile importers")] --> B --> D
  U["update reuse scope"] --> B --> D

  subgraph Legend
    direction LR
    _db[("Persisted state")] ~~~ _svc(["Component"]) ~~~ _cfg["Policy / scope"]
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Force dedupeInjectedDeps to run on all re-resolution paths
  • ➕ Keeps all normalization in one place (dedupe step), fewer special-case guards later
  • ➕ Potentially avoids needing previous lockfile importer snapshots at finalization time
  • ➖ Doesn't address genuine peer-context divergence cases where dedupe must correctly keep file:
  • ➖ Harder to ensure it runs in every update/install variant without regressions
2. Track a first-class 'targeted dependency' bit through resolution
  • ➕ More explicit than re-deriving targeting from spec changes and update selectors
  • ➕ Could reduce subtle differences between TS and Rust targeting logic
  • ➖ Larger refactor: needs plumbing across resolver graph, lockfile builder inputs, and CLI lowering
  • ➖ Higher risk of behavior changes outside the bug scenario
3. Always prefer `link:` for workspace deps when injectWorkspacePackages is enabled
  • ➕ Simplifies lockfile/importer ref policy for workspace deps
  • ➖ Incorrect for real peer-context divergence where file: is required to preserve correctness
  • ➖ Would break scenarios that intentionally produce distinct injected copies

Recommendation: Keep the PR’s approach: preserving the prior link: only when the run demonstrably did not target that dependency. It’s narrowly scoped to #10433, respects legitimate file: outcomes when targeted (spec change / update selector / scope-wide update), and is backed by focused regression tests covering both update-style and plain-install re-resolution paths.

Files changed (7) +703 / -9

Bug fix (3) +190 / -3
dependencies_graph_to_lockfile.rsPreserve prior 'link:' when importer dep is untargeted (pnpm#10433) +116/-2

Preserve prior 'link:' when importer dep is untargeted (#10433)

• Threads previous importer snapshots and update reuse scope into importer construction, and adds a guard that keeps a prior 'link:' entry when the current resolution yields a peer-suffixed 'file:' but the dependency wasn’t targeted by the run. Adds helper lookups for prior importer deps and package name extraction for update-scope matching.

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

install_with_fresh_lockfile.rsPlumb previous importers + update scopes into fresh lockfile build +34/-0

Plumb previous importers + update scopes into fresh lockfile build

• Captures the previous lockfile importer map and update reuse scope(s) before resolver options move/shadow them, then passes those through to the fresh lockfile builder so the pnpm#10433 guard can preserve untargeted workspace 'link:' entries.

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

index.tsPreserve previous 'link:' for untargeted workspace deps during ref finalization +40/-1

Preserve previous 'link:' for untargeted workspace deps during ref finalization

• Captures previous importer dependency refs before rebuilding the importer snapshot, derives a set of update-targeted aliases (new/spec-changed or matched by 'updateMatching'), and restores the previous 'link:' ref when the new ref would otherwise become a peer-suffixed 'file:' for an untargeted workspace dependency.

pnpm11/installing/deps-resolver/src/index.ts

Tests (2) +504 / -4
tests.rsAdd targeted/untargeted link-vs-file preservation tests +290/-3

Add targeted/untargeted link-vs-file preservation tests

• Extends options to pass previous importers and update scopes, and adds a comprehensive fixture-based test matrix proving the guard preserves 'link:' only when untargeted (plain install, recursive update targeting other dep) while allowing flips to 'file:' when targeted (update naming dep, specifier change, scope-wide update).

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

injectWorkspacePackagesPersistence.test.tsRegression tests for link preservation on recursive update and plain install +214/-1

Regression tests for link preservation on recursive update and plain install

• Adds end-to-end Jest coverage reproducing pnpm#10433: updating an unrelated dependency via recursive update must not rewrite an untouched workspace dep from 'link:' to peer-suffixed 'file:'. Adds a second test ensuring a plain install also preserves 'link:' even when a consumer change creates a genuine peer-context divergence that keeps injected copies as 'file:'.

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

Documentation (1) +7 / -0
preserve-workspace-link-on-partial-update.mdAdd changeset for workspace link preservation fix +7/-0

Add changeset for workspace link preservation fix

• Documents the patch behavior change for pnpm/pacquet: untargeted injected workspace deps keep their prior 'link:' ref instead of flipping to peer-suffixed 'file:' during partial updates or subsequent installs.

.changeset/preserve-workspace-link-on-partial-update.md

Other (1) +2 / -2
Cargo.lockBump Rust crate 'bytes' to 1.12.1 +2/-2

Bump Rust crate 'bytes' to 1.12.1

• Updates the locked 'bytes' crate version and checksum, likely from a dependency refresh needed by the Rust workspace.

Cargo.lock

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

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

Context used
✅ Compliance rules (platform): 24 rules

Grey Divider


Remediation recommended

1. Unexplained bytes lock bump 📘 Rule violation ⚙ Maintainability
Description
This bug-fix PR updates Cargo.lock to bump bytes from 1.12.0 to 1.12.1 without any
corresponding manifest change shown in the diff, which looks like unrelated churn. Unrelated
dependency/lock updates make the fix harder to audit and can introduce risk outside the stated bug
scope.
Code

Cargo.lock[R712-714]

+version = "1.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ae3f5d315924270530207e2a68396c3cc547f6dca3fbdca317cfb1a51edb593"
+checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
Relevance

●●● Strong

Team has accepted requests to revert/justify unrelated lockfile churn; likely will drop unexplained
Cargo.lock bump.

PR-#11450

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The checklist requires bug-fix PRs to avoid unrelated refactors/churn. The diff shows a standalone
lockfile dependency version bump (bytes 1.12.0 -> 1.12.1) not otherwise explained/necessitated by
the shown code changes.

Rule 2255067: Bug fix changes must not include unrelated refactors or reformatting
Cargo.lock[712-714]

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

## Issue description
`Cargo.lock` was modified (dependency `bytes` bumped) in a bug-fix PR without clear linkage to the fix.

## Issue Context
Compliance requires bug-fix PRs to avoid unrelated refactors/reformatting/churn so reviewers can isolate risk.

## Fix Focus Areas
- Cargo.lock[712-714]

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


2. Comments describe pre-fix behavior 📘 Rule violation ⚙ Maintainability
Description
New comments in the regression test describe historical behavior using phrases like `without the
fix`, rather than describing only the current contract being asserted. This risks comments becoming
stale and violates the requirement to avoid historical-implementation commentary in source.
Code

pnpm11/installing/deps-installer/test/install/injectWorkspacePackagesPersistence.test.ts[R318-326]

+// Regression test for https://github.com/pnpm/pnpm/issues/10433: updating one
+// dependency must not rewrite an untouched workspace dependency's `link:` entry
+// to a peer-suffixed `file:`.
+//
+// `d` peer-depends on `a` and `b`; `b` has an optional `winston` peer. On the
+// initial install `consumer` -> `d` dedupes to `link:../d`. Updating the
+// unrelated `winston` re-resolves the untouched injected workspace deps on a
+// path dedupeInjectedDeps doesn't reach and, without the fix, flips
+// `consumer` -> `d` to `file:d(a@file:a)(b@file:b(a@file:a)([email protected]))`.
Relevance

●●● Strong

They’ve accepted rewriting comments to avoid historical phrasing in tests; this matches that
precedent closely.

PR-#13383

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The checklist forbids historical-implementation phrasing in comments. The added test comment
explicitly references the pre-fix behavior (without the fix) rather than only stating the
invariant the test enforces.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm11/installing/deps-installer/test/install/injectWorkspacePackagesPersistence.test.ts[318-326]

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

## Issue description
Added comments use historical phrasing (e.g., `without the fix`) describing prior behavior instead of only documenting the current expected behavior.

## Issue Context
Comments should describe current behavior/contract and avoid embedding historical implementation notes.

## Fix Focus Areas
- pnpm11/installing/deps-installer/test/install/injectWorkspacePackagesPersistence.test.ts[318-326]

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


3. Unvalidated link ref preserved 🐞 Bug ⛨ Security
Description
The new guard overwrites a freshly resolved file: ref with the previous lockfile’s link: ref for
untargeted deps, so an attacker-controlled lockfile can keep a link: path even when the resolver
would otherwise switch it to a file:-based ref. That preserved link: is later resolved as an
absolute-or-relative filesystem path during install without workspace-boundary validation,
increasing supply-chain risk from malicious lockfile content.
Code

pnpm11/installing/deps-resolver/src/index.ts[R389-401]

+      // A workspace dependency resolved to `link:` has no version to update, so
+      // it should stay `link:` unless this run specifically targets it (a spec
+      // change or `pnpm update <name>`). Preserving it stops an update of an
+      // unrelated dependency (e.g. `pnpm update <other-pkg>`) from re-resolving
+      // an untouched injected workspace dep and flipping its `link:` to a
+      // peer-suffixed `file:` on paths dedupeInjectedDeps doesn't reach. See
+      // pnpm/pnpm#10433.
+      const previousRef = previousDirectRefs[alias]
+      const targetedByUpdate = updateTargetedAliases.has(alias) ||
+        (updateMatching?.(depNode.name) ?? false)
+      if (!targetedByUpdate && ref.startsWith('file:') && previousRef?.startsWith('link:')) {
+        ref = previousRef
+      }
Relevance

●● Moderate

Security concern is plausible but behavior is intentional for the fix; no closely matching prior
lockfile link:-preservation precedent.

PR-#12558
PR-#13279

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The diff adds logic that prefers previousRef (from the existing lockfile) over the newly computed
ref when the new ref is file: and the old is link:. The repo’s review guide explicitly treats
lockfiles as attacker-controlled. Downstream, pnpm’s installer resolves link: payloads to
filesystem paths (including absolute paths) without workspace containment checks, so preserving a
lockfile-provided link: increases exposure to malicious lockfile paths in scenarios where the
resolver output would otherwise move away from link:.

pnpm11/installing/deps-resolver/src/index.ts[311-401]
pnpm11/installing/deps-restorer/src/index.ts[873-923]
pnpm/crates/package-manager/src/dependencies_graph_to_lockfile.rs[378-417]
pnpm/crates/package-manager/src/symlink_direct_dependencies.rs[641-708]
REVIEW_GUIDE.md[30-46]

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 “preserve prior `link:`” guard can cause lockfile content to override the resolver’s freshly computed `file:` ref. Because lockfiles are attacker-controlled input in pnpm’s threat model, this expands the cases where a malicious/stale `link:` path persists into the regenerated lockfile and is then used by the installer as a filesystem symlink target.

### Issue Context
- The guard currently preserves `previousRef` purely based on string prefixes (`file:`→`link:`) and “targeted” heuristics.
- Downstream install code resolves `link:` payloads to real filesystem paths (including absolute paths) without checking containment.

### Fix Focus Areas
- pnpm11/installing/deps-resolver/src/index.ts[311-401]
- pnpm11/installing/deps-restorer/src/index.ts[873-923]
- pnpm/crates/package-manager/src/dependencies_graph_to_lockfile.rs[378-417]
- pnpm/crates/package-manager/src/symlink_direct_dependencies.rs[641-708]

### What to change
1. **When preserving a prior `link:` ref, validate it matches the workspace package resolved this run**:
  - Compute the *expected* workspace target directory for this alias from the current resolution (e.g., via the resolved node’s `dir`/workspace metadata) and compare it to the path implied by the prior `link:` payload resolved against the importer root.
  - Only preserve the previous `link:` if it resolves to the same canonicalized path as the current workspace package.
2. **Reject obviously unsafe `link:` payloads in the preservation path** (even if they were present previously):
  - Do not preserve absolute `link:` payloads.
  - Canonicalize/normalize and ensure the resolved path is inside the workspace root (or inside the known workspace package directory).
3. Mirror the same validation approach in the Rust lockfile builder guard so pacquet and pnpm maintain parity.

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



Informational

4. Eager per-importer allocations 🐞 Bug ➹ Performance
Description
resolveDependencies now eagerly builds a merged previousDirectRefs object and an
updateTargetedAliases set for every importer, and evaluates updateMatching per direct dep, even
when no preserved-link case applies. This adds avoidable allocations and iteration overhead on the
install/update hot path for large workspaces.
Code

pnpm11/installing/deps-resolver/src/index.ts[R316-336]

+    const previousImporterSnapshot = opts.wantedLockfile.importers[project.id]
+    const previousDirectRefs: Record<string, string> = {
+      ...previousImporterSnapshot?.dependencies,
+      ...previousImporterSnapshot?.devDependencies,
+      ...previousImporterSnapshot?.optionalDependencies,
+    }
+    // Aliases this run actually targets (added, spec-changed, or matched by a
+    // `pnpm update <name>`). Only these may legitimately change their
+    // `link:`/`file:` form; the preserve-prior-link guard below is limited to
+    // dependencies outside this set. `updateSpec` is deliberately not
+    // consulted: a plain install marks every manifest dependency with it, so
+    // it signals "re-check the spec", not "the user targeted this dependency".
+    const importer = importers[index]
+    const updateMatching = importer.updateMatching
+    const updateTargetedAliases = new Set(
+      project.wantedDependencies.flatMap(({ alias, bareSpecifier, isNew, prevSpecifier }) =>
+        alias != null && (isNew === true || (prevSpecifier != null && bareSpecifier !== prevSpecifier))
+          ? [alias]
+          : []
+      )
+    )
Relevance

●● Moderate

Perf feedback is sometimes accepted, sometimes rejected as over-optimization; no close precedent for
this exact allocation pattern.

PR-#12491
PR-#13477

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The added code constructs a merged previous-deps object and a new Set for targeted aliases for every
importer before iterating its deps, which is extra allocation/iteration work even when no dependency
is eligible for preservation.

pnpm11/installing/deps-resolver/src/index.ts[311-401]

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 pnpm/pnpm#10433 guard adds per-importer work unconditionally: it materializes merged maps/sets even if no dependency ends up needing the preserve-`link:` check.

### Issue Context
This code runs once per importer inside `Promise.all(...)` during resolution finalization.

### Fix Focus Areas
- pnpm11/installing/deps-resolver/src/index.ts[311-401]

### What to change
1. **Avoid building `previousDirectRefs` eagerly**:
  - Replace the merged object with a small helper that checks `previousImporterSnapshot.dependencies/devDependencies/optionalDependencies` lazily for a given alias.
2. **Only compute `updateTargetedAliases` when needed**:
  - If `project.wantedDependencies` has no `isNew/spec-changed` entries and `importer.updateMatching` is null, skip set creation entirely.
3. **Short-circuit the guard**:
  - Evaluate “targeted” and fetch `previousRef` only when the freshly computed `ref` starts with `file:` (the only case where preservation can apply).

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


Grey Divider

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

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.

@omril1

omril1 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

@zkochan — thanks for carrying this the rest of the way; the reproduction-repo case is handled now.

One ask before this auto-closes #10433: we've seen the same link: → file: rewrite in a few other injected-workspace scenarios, and I'm still confirming whether this change covers all of them (working on reducing them to a shareable minimal repro). Could we keep #10433 open — or drop the closing keyword from the PR description — until I can either confirm coverage or post the remaining case? I'll follow up with a repro either way.


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

@zkochan
zkochan merged commit d36e0fd into pnpm:main Jul 30, 2026
35 of 36 checks passed
@omril1
omril1 deleted the fix/preserve-workspace-link-partial-update branch July 30, 2026 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants