Skip to content

fix(deps-graph-hasher): give local directory deps their own global-virtual-store slot - #13383

Merged
zkochan merged 6 commits into
mainfrom
fix-13335
Jul 26, 2026
Merged

zkochan merged 6 commits into
mainfrom
fix-13335

Conversation

@zkochan

@zkochan zkochan commented Jul 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #13335.

Installing a file: directory dependency with the global virtual store enabled crashed the headless install:

TypeError: Cannot read properties of undefined (reading 'split')
    at assertNoPathTraversal
    at formatGlobalVirtualStorePath
    at calcGraphNodeHash

pnpm deliberately omits version from a directory snapshot (toLockfileDependency skips it for type: 'directory'), so nameVerFromPkgSnapshot hands the hasher undefined, and the traversal guard added in #12872 dereferences it. Directory snapshots now use a fixed directory segment in place of the version.

While reproducing that, I found a second, quieter defect underneath it. A directory resolution is the one resolution with no integrity — it is a path relative to the lockfile — so file:dep hashed identically in every project depending on a directory of that name, and they all shared one global-virtual-store slot:

$ # two unrelated projects, each with its own ./dep
$ cd projectA && pnpm install --config.enable-global-virtual-store=true
$ cd ../projectB && pnpm install --config.enable-global-virtual-store=true
$ cat projectA/node_modules/dep/index.js
content-B          # <- projectA is now linked to projectB's files

Both resolved to <store>/v11/links/@/dep/1.0.0/28c8453e…. Because the source directory is mutable, pnpm re-imports directory deps on every install, so the two projects went on overwriting each other's copy. The lockfile directory now joins the hash payload for directory resolutions, giving each project its own slot; every other resolution hashes exactly as before.

Fixing the version segment also settles a disagreement between the two install paths: the resolver reads the version off the manifest and the headless install reads it off the lockfile, where there is none, so the same package used to land on two different slots depending on which path ran.

Notes for reviewers

  • Why not keep directory deps out of the global virtual store entirely? That is the cleaner semantics, but when GVS is on virtualStoreDir is the global store (extendInstallOptions), so there is no project-local virtual store left to fall back to. Scoping the slot achieves the same isolation without introducing a second virtual-store root. Directory deps take the cold re-import path on every install anyway, so they never benefited from a shared slot.
  • Old .../undefined/<hash> slots left by earlier pnpm 11 versions become unreachable and are collected by the existing mark-and-sweep pruneGlobalVirtualStore.
  • iterateHashedGraphNodes takes an options object now — it was already up to five positional parameters, and this change would have added a sixth.

pacquet

The Rust port had both defects and is fixed in the same PR, so the two stacks derive the same slot:

  • gvs_version_segment rendered the literal undefined for every file: dep — what the TypeScript side produced before its traversal guard turned the missing version into a crash. It now anchors a directory resolution to the directory segment, and prefers PackageMetadata::version, so a local tarball (content-addressed, and carrying a version in the lockfile) no longer shares the directory dep's fallback. That last part was an existing divergence from the TypeScript CLI.
  • VirtualStoreLayout::new took no resolution into account when inserting a slot suffix, so directory deps collided across projects the same way. It takes the lockfile directory now and folds it into the hash payload for directory resolutions, via a new project argument on calc_graph_node_hash.
  • Added local_directory_dependency_works_with_global_virtual_store (pnpm/crates/cli/tests/global_virtual_store.rs) and directory_deps_get_a_slot_per_project (virtual_store_layout/tests.rs) — there was no coverage for a plain, non-injected file: directory dependency under GVS.

Squash Commit Body

Installing a `file:` directory dependency with the global virtual store
enabled crashed the headless install:

    TypeError: Cannot read properties of undefined (reading 'split')
        at assertNoPathTraversal
        at formatGlobalVirtualStorePath
        at calcGraphNodeHash

pnpm omits `version` from a directory snapshot, so `nameVerFromPkgSnapshot`
hands the hasher `undefined` and the traversal guard added in
pnpm/pnpm#12872 dereferences it. Directory snapshots now use a fixed
`directory` segment in place of the version. That also settles a
disagreement between the two install paths: the resolver reads the version
off the manifest and the headless install off the lockfile, where there is
none, so the same package landed on two different slots.

The crash hid a worse defect. A directory resolution is the one resolution
with no integrity — it is a path relative to the lockfile — so `file:dep`
hashed identically in every project that depended on a directory of that
name, and all of them linked to whichever project installed first. Since
the source directory is mutable, pnpm re-imports it on every install, so
the projects went on overwriting each other's copy. The lockfile directory
now joins the hash payload for directory resolutions, giving each project
its own slot; every other resolution hashes exactly as before.

`iterateHashedGraphNodes` takes an options object now — it was up to five
positional parameters before this change added a sixth.

Closes pnpm/pnpm#13335

Checklist

  • 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).

Summary by CodeRabbit

  • Bug Fixes
    • Fixed installation issues for local file: directory dependencies when Global Virtual Store is enabled.
    • Improved frozen-lockfile reinstalls to reuse the same Global Virtual Store slot reliably.
    • Scopes hashing so file: directory dependencies get deterministic, project-specific slots and don’t collide across projects with the same dependency name.
  • Tests
    • Added integration and end-to-end coverage for stable reinstalls and project-specific isolation for local directory dependencies with Global Virtual Store.

…rtual-store slot

Installing a `file:` directory dependency with the global virtual store
enabled crashed the headless install:

    TypeError: Cannot read properties of undefined (reading 'split')
        at assertNoPathTraversal
        at formatGlobalVirtualStorePath
        at calcGraphNodeHash

pnpm omits `version` from a directory snapshot, so `nameVerFromPkgSnapshot`
hands the hasher `undefined` and the traversal guard added in
#12872 dereferences it. Directory snapshots now use a fixed
`directory` segment in place of the version. That also settles a
disagreement between the two install paths: the resolver reads the version
off the manifest and the headless install off the lockfile, where there is
none, so the same package landed on two different slots.

The crash hid a worse defect. A directory resolution is the one resolution
with no integrity — it is a path relative to the lockfile — so `file:dep`
hashed identically in every project that depended on a directory of that
name, and all of them linked to whichever project installed first. Since
the source directory is mutable, pnpm re-imports it on every install, so
the projects went on overwriting each other's copy. The lockfile directory
now joins the hash payload for directory resolutions, giving each project
its own slot; every other resolution hashes exactly as before.

`iterateHashedGraphNodes` takes an options object now — it was up to five
positional parameters before this change added a sixth.

Fixes #13335

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings July 25, 2026 23:06

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 Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@zkochan, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 12 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 17fec64e-357b-493e-b38d-6b81bad2e5cd

📥 Commits

Reviewing files that changed from the base of the PR and between 1bab61f and d474e4f.

📒 Files selected for processing (2)
  • pnpm/crates/package-manager/src/virtual_store_layout.rs
  • pnpm/crates/package-manager/src/virtual_store_layout/tests.rs
📝 Walkthrough

Walkthrough

Global virtual store hashing now scopes local directory dependencies by lockfile directory, uses a stable directory segment, and propagates this context through Rust and TypeScript install paths. Tests cover frozen reinstalls, hash behavior, and separation of same-named dependencies across projects.

Changes

Global virtual store local directory dependencies

Layer / File(s) Summary
Rust layout hashing
pnpm/crates/graph-hasher/..., pnpm/crates/package-manager/src/virtual_store_layout.rs
Virtual store hashing accepts project scope from lockfile_dir, uses metadata to identify directory resolutions, and emits a stable directory segment.
Rust install wiring and validation
pnpm/crates/cli/..., pnpm/crates/package-manager/src/..., pnpm/crates/graph-hasher/src/global_virtual_store_path/tests.rs, .changeset/...
Install, frozen-lockfile, license, marker, and package-map paths pass the expanded layout inputs; Rust tests and the changeset cover the updated behavior.
TypeScript hashing pipeline
pnpm11/deps/..., pnpm11/installing/deps-resolver/..., pnpm11/building/..., pnpm11/engine/...
Structured graph-hashing options propagate lockfileDir through dependency resolution, virtual-store generation, rebuilds, and self-update lookup.
TypeScript validation
pnpm11/deps/graph-hasher/test/..., pnpm11/installing/deps-installer/test/install/globalVirtualStore.ts
Tests verify directory hash scoping, registry hash invariance, frozen reinstall slot reuse, and distinct slots for same-named dependencies in separate projects.

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

Sequence Diagram(s)

sequenceDiagram
  participant ProjectInstall
  participant DependencyResolver
  participant GraphHasher
  participant GlobalVirtualStore
  ProjectInstall->>DependencyResolver: resolve local file: directory dependency
  DependencyResolver->>GraphHasher: pass lockfileDir and dependency resolution
  GraphHasher->>GraphHasher: include project scope and directory segment
  GraphHasher-->>GlobalVirtualStore: compute project-scoped slot
  GlobalVirtualStore-->>ProjectInstall: materialize dependency in GVS slot
Loading

Possibly related issues

  • Rust Roadmap #11633 — Covers the Global Virtual Store local-directory dependency hashing and installation behavior changed here.

Possibly related PRs

  • pnpm/pnpm#13368 — Also changes virtual-store slot hash derivation in the Rust layout and hashing pathway.

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

Suggested reviewers: copilot

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-13335

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Fix global virtual store hashing for local directory dependencies

🐞 Bug fix 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Prevent headless installs from crashing when hashing file: directory deps under GVS
• Scope local directory/injected workspace deps to per-project GVS slots via lockfileDir
• Refactor graph-hasher iteration API to use an options object and add regression coverage
Diagram

graph TD
  I["Install paths"] --> D["lockfileToDepGraph"] --> N["iterateHashedGraphNodes (opts)"] --> H["calcGraphNodeHash"] --> C["localDirectoryScope (lockfileDir)"] --> S["Global virtual store slot"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Exclude directory deps from GVS entirely
  • ➕ Simpler semantics: local directories never share a global cache
  • ➕ Avoids needing project identity in the hash payload
  • ➖ With GVS enabled, pnpm effectively has no project-local virtual store to fall back to (would require introducing a second root)
  • ➖ Behavioral divergence between GVS and non-GVS modes may complicate expectations
2. Scope by resolved absolute directory path
  • ➕ Uniquely identifies the source directory, even if multiple lockfiles share a directory name
  • ➖ Absolute paths can reduce reproducibility across machines/CI and leak environment-specific data into store layout
  • ➖ Path normalization across platforms becomes another source of subtle bugs
3. Persist a synthetic stable ID for directory snapshots in the lockfile
  • ➕ Keeps hashing independent of filesystem layout while still distinguishing projects
  • ➖ Requires lockfile format changes/migrations and careful back-compat handling
  • ➖ More complex than leveraging existing lockfileDir context already available at install time

Recommendation: The chosen approach (fixed directory slot segment + adding lockfileDir only for type: &#x27;directory&#x27; resolutions) is the best tradeoff: it restores headless-install stability, prevents cross-project slot collisions for mutable local sources, and keeps hashing identical for all non-directory resolution types. The alternatives either require introducing a second virtual-store root, risk non-portable hash inputs, or entail lockfile format evolution.

Files changed (10) +240 / -31

Bug fix (5) +90 / -30
index.tsPass lockfileDir into hashed graph iteration during rebuild +6/-3

Pass lockfileDir into hashed graph iteration during rebuild

• Updates the rebuild flow to call 'iterateHashedGraphNodes' with an options object and includes 'lockfileDir' so slot computation matches the new directory-dependency scoping behavior.

pnpm11/building/after-install/src/index.ts

iteratePkgsForVirtualStore.tsThread lockfileDir through virtual-store iteration and hashing +8/-12

Thread lockfileDir through virtual-store iteration and hashing

• Extends virtual-store package iteration APIs to require 'lockfileDir' and passes it through to 'iterateHashedGraphNodes'/'calcGraphNodeHash'. Refactors helper signatures to use the shared 'GraphNodeHashOptions' type.

pnpm11/deps/graph-builder/src/iteratePkgsForVirtualStore.ts

index.tsScope directory resolutions by lockfileDir and avoid undefined version segment +65/-13

Scope directory resolutions by lockfileDir and avoid undefined version segment

• Introduces 'GraphNodeHashOptions' (incl. optional 'lockfileDir') and updates 'iterateHashedGraphNodes' to take a single options object. Fixes hashing for directory snapshots by using a fixed 'directory' segment instead of a missing version and includes 'lockfileDir' in the hash payload only for 'type: 'directory'' resolutions; also carries 'resolution' into the dep graph so the hasher can detect directory resolutions.

pnpm11/deps/graph-hasher/src/index.ts

installPnpm.tsSwitch self-updater hashing call to options-object API +4/-1

Switch self-updater hashing call to options-object API

• Migrates 'iterateHashedGraphNodes' usage to the new '{ allowBuild }' options form and documents why 'lockfileDir' is intentionally omitted for the self-updater lockfile context.

pnpm11/engine/pm/commands/src/self-updater/installPnpm.ts

index.tsPass lockfileDir into GVS hash iteration in deps resolver +7/-1

Pass lockfileDir into GVS hash iteration in deps resolver

• Updates the resolver-side global virtual store path calculation to use the new options object and include 'lockfileDir', ensuring directory deps land on the same scoped slot as headless installs.

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

Tests (4) +138 / -1
allowBuildIdentity.test.tsUpdate allowBuildIdentity test for new options-object API +1/-1

Update allowBuildIdentity test for new options-object API

• Adjusts the test to pass '{ allowBuild }' to 'iterateHashedGraphNodes' after the signature change.

pnpm11/deps/graph-hasher/test/allowBuildIdentity.test.ts

calcGraphNodeHash.test.tsAdd unit tests for directory dependency scoping and slot segment +67/-0

Add unit tests for directory dependency scoping and slot segment

• Adds coverage ensuring directory deps use the fixed 'directory' path segment, remain stable between resolver/headless paths, get distinct slots per project via differing 'lockfileDir', and do not affect registry-resolved packages.

pnpm11/deps/graph-hasher/test/calcGraphNodeHash.test.ts

lockfileToDepGraph.test.tsExpect dep graph nodes to include snapshot resolution +3/-0

Expect dep graph nodes to include snapshot resolution

• Updates assertions to include 'resolution' on graph nodes now that 'lockfileToDepGraph' preserves it for hashing/scoping decisions.

pnpm11/deps/graph-hasher/test/lockfileToDepGraph.test.ts

globalVirtualStore.tsAdd integration tests for directory deps under global virtual store +67/-0

Add integration tests for directory deps under global virtual store

• Adds regression tests that a local 'file:' directory dependency installs and reinstalls without relocation under GVS, and that two projects with same-named local directory deps do not share the same GVS slot or overwrite each other.

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

Documentation (1) +12 / -0
gvs-local-directory-deps.mdAdd changeset for GVS local-directory hashing fixes +12/-0

Add changeset for GVS local-directory hashing fixes

• Adds a patch changeset describing the crash fix for directory deps under the global virtual store and the new per-project slot isolation for local directory/injected workspace dependencies.

.changeset/gvs-local-directory-deps.md

@greptile-apps

greptile-apps Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

The previously reported pacquet parity defect is fixed: production install and inspection paths now supply the lockfile directory, directory resolutions use the stable directory segment, and the project identity participates in the Rust hash as it does in TypeScript. No blocking failure remains.

Reviews (6): Last reviewed commit: "perf(virtual-store-layout): convert the ..." | Re-trigger Greptile

Comment thread pnpm11/deps/graph-hasher/src/index.ts Resolved
@qodo-code-review

qodo-code-review Bot commented Jul 25, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

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

Context used
✅ Compliance rules (platform): 24 rules

Grey Divider


Remediation recommended

1. Optional lockfileDir crash path ✓ Resolved 🐞 Bug ☼ Reliability
Description
calcGraphNodeHash() still falls back to the raw version segment when lockfileDir is omitted,
even for resolution.type==='directory'; directory snapshots can have version===undefined, which
will crash in assertNoPathTraversal(version) via version.split(...). This leaves a latent
DoS/crash hazard for any current/future caller that hashes directory resolutions without passing
lockfileDir (and also risks resolver/headless slot disagreement in that case).
Code

pnpm11/deps/graph-hasher/src/index.ts[R263-268]

+  const project = localDirectoryScope(graph[depPath]?.resolution, lockfileDir)
+  const hexDigest = project == null
+    ? hashObjectWithoutSorting({ engine, deps }, { encoding: 'hex' })
+    : hashObjectWithoutSorting({ engine, deps, project }, { encoding: 'hex' })
+  return formatGlobalVirtualStorePath(name, project == null ? version : LOCAL_DIRECTORY_SEGMENT, hexDigest)
+}
Relevance

⭐⭐⭐ High

Crash-prevention via guarding unsafe string ops on non-strings/undefined is accepted.

PR-#12491

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The hash path segment currently depends on whether localDirectoryScope() returns a value, which
requires lockfileDir; when it returns undefined, calcGraphNodeHash() uses version directly and
passes it to formatGlobalVirtualStorePath(), which calls version.split(...) in
assertNoPathTraversal(). The added unit test demonstrates version can be undefined for
directory deps coming from the lockfile.

pnpm11/deps/graph-hasher/src/index.ts[233-301]
pnpm11/deps/graph-hasher/src/index.ts[334-353]
pnpm11/deps/graph-hasher/test/calcGraphNodeHash.test.ts[478-501]

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

### Issue description
`calcGraphNodeHash()` chooses the GVS path segment based on whether `project` is set (i.e. whether `lockfileDir` was provided). For `resolution.type==='directory'`, the lockfile can omit `version`, so callers that omit `lockfileDir` can still pass `undefined` into `formatGlobalVirtualStorePath()`, which calls `assertNoPathTraversal(version)` and crashes.

### Issue Context
The PR already documents that omitting `lockfileDir` is only safe when there are no directory deps, but the code path currently crashes instead of remaining safe/consistent for directory resolutions.

### Fix Focus Areas
- pnpm11/deps/graph-hasher/src/index.ts[260-301]

### Suggested fix
- Determine whether a node is a directory dependency based on `resolution.type === 'directory'` (not on whether `lockfileDir` is present).
- Always use `LOCAL_DIRECTORY_SEGMENT` for the *path segment* when the resolution is a directory dependency, regardless of `lockfileDir`.
- Only add the `project` field to the hash payload when `lockfileDir` is present (to keep the per-project isolation behavior), but do not let its absence re-enable the `version` segment for directory deps.

This preserves:
- no-crash behavior even if `lockfileDir` is accidentally omitted,
- resolver/headless slot consistency for directory deps,
- per-project slot isolation when `lockfileDir` is provided.

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


2. GVS hashing not synced 📘 Rule violation ⌂ Architecture
Description
This PR changes user-visible global-virtual-store slot derivation in pnpm TypeScript, but the PR
does not include an equivalent pacquet/Rust change or an explicit divergence callout, risking
pnpm/pacquet behavior mismatch.
Code

pnpm11/deps/graph-hasher/src/index.ts[R263-268]

+  const project = localDirectoryScope(graph[depPath]?.resolution, lockfileDir)
+  const hexDigest = project == null
+    ? hashObjectWithoutSorting({ engine, deps }, { encoding: 'hex' })
+    : hashObjectWithoutSorting({ engine, deps, project }, { encoding: 'hex' })
+  return formatGlobalVirtualStorePath(name, project == null ? version : LOCAL_DIRECTORY_SEGMENT, hexDigest)
+}
Relevance

⭐⭐⭐ High

Repo enforces pnpm TS and pacquet Rust user-visible parity; sync/divergence callouts are accepted.

PR-#12789
PR-#12840
PR-#12153

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713428 requires pnpm TypeScript and pacquet Rust user-visible behavior changes to
be kept in sync (or explicitly called out). The diff changes the GVS slot derivation (hash inputs
and version segment) for directory dependencies, which is user-visible store/layout behavior.

Rule 713428: Keep pnpm TypeScript and pacquet Rust user-visible behavior changes in sync
pnpm11/deps/graph-hasher/src/index.ts[263-268]
.changeset/gvs-local-directory-deps.md[10-12]

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 pnpm TypeScript implementation changes the global-virtual-store slot identity for local directory dependencies (hash payload and path segment). Per compliance, equivalent user-visible behavior must be kept in sync with the pacquet/Rust implementation, or the divergence must be clearly called out.

## Issue Context
The slot path now uses a fixed `directory` segment and scopes directory resolutions by `lockfileDir` via the hash payload.

## Fix Focus Areas
- pnpm11/deps/graph-hasher/src/index.ts[263-268]
- .changeset/gvs-local-directory-deps.md[10-12]

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


3. Historical used to crash comment ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
A newly added test comment uses historical phrasing (used to), which violates the requirement that
comments describe current behavior rather than past implementations.
Code

pnpm11/installing/deps-installer/test/install/globalVirtualStore.ts[R539-541]

+// The lockfile records no version for a directory snapshot, so a headless
+// install used to crash while building the slot path.
+// See https://github.com/pnpm/pnpm/issues/13335.
Relevance

⭐⭐ Medium

Historical/temporal comment rewrites show mixed outcomes; enforcement in tests is inconsistent.

PR-#13125
PR-#12954

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 772199 forbids historical phrasing in comments. The added comment explicitly says
the install used to crash, which describes past behavior instead of the current contract being
tested.

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

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

## Issue description
Comments must describe current behavior, not historical behavior (avoid phrasing like `used to`).

## Issue Context
This comment is adjacent to a regression test and should explain the current invariant the test enforces.

## Fix Focus Areas
- pnpm11/installing/deps-installer/test/install/globalVirtualStore.ts[539-541]

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



Informational

4. Project scope path not normalized 🐞 Bug ➹ Performance ⭐ New
Description
VirtualStoreLayout::new hashes the local-directory project scope from
lockfile_dir.to_string_lossy() without normalizing the path, so equivalent spellings of the same
directory (e.g. ./.. segments, symlinked entry points, or Windows case variations) will create
different GVS slots for the same project. This can cause redundant directory-dep materializations
and unnecessary store growth/churn when the same project is invoked through different textual paths.
Code

pnpm/crates/package-manager/src/virtual_store_layout.rs[R203-210]

+        // One conversion for the whole lockfile: the same string scopes every
+        // local directory snapshot in it.
+        //
+        // Lossy on purpose: the TypeScript CLI hashes the same slot from a JS
+        // string, and Node decodes a path as UTF-8 with replacement, so this is
+        // the identical input. Hashing the raw bytes instead would give the two
+        // stacks different slots for the same project.
+        let project_scope = lockfile_dir.map(|dir| dir.to_string_lossy());
Relevance

⭐ Low

Repo previously rejected path normalization/case-folding changes as too complex/behavior-changing
for path-based logic.

PR-#13173

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new project scope is derived directly from lockfile_dir.to_string_lossy() and then used to
decide whether to include a project field in the hash payload for local-directory snapshots. There
is no normalization step visible at the hashing boundary, and CLI state derives lockfile_dir from
the manifest/workspace directory without canonicalization, so different textual paths can reach the
hashing code unchanged.

pnpm/crates/package-manager/src/virtual_store_layout.rs[203-210]
pnpm/crates/package-manager/src/virtual_store_layout.rs[247-248]
pnpm/crates/cli/src/state.rs[106-114]

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

### Issue description
Local-directory dependency GVS slot scoping uses the raw `lockfile_dir` string (`to_string_lossy`) as hash input. Equivalent textual paths that refer to the same directory can therefore produce different hashes and separate slots, reducing cache reuse and increasing store churn.

### Issue Context
This affects only the new local-directory scoping behavior (directory deps / injected workspace packages) when GVS is enabled.

### Fix Focus Areas
- pnpm/crates/package-manager/src/virtual_store_layout.rs[203-210]
- pnpm/crates/package-manager/src/virtual_store_layout.rs[247-248]

### Implementation notes
- Decide what “project identity” should mean: typically a *lexically normalized* absolute path (no filesystem IO / no symlink resolution), so `a/../b` and `b` match.
- Consider using an existing normalization helper (e.g. `pacquet_fs::lexical_normalize(lockfile_dir)`) before converting to string.
- If you normalize here, ensure parity with the TypeScript hashing input (same normalization rule), otherwise Rust/TS may compute different slots for the same lockfile.

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


5. Repeated lockfileDir allocations ✓ Resolved 🐞 Bug ➹ Performance
Description
For each local-directory snapshot, local_directory_scope() converts the same lockfile_dir Path
into a newly-owned String, causing repeated allocations/copies during GVS suffix precomputation.
In large workspaces with many injected/local-directory snapshots, this adds avoidable overhead on
the install path.
Code

pnpm/crates/package-manager/src/virtual_store_layout.rs[R491-495]

+    // Lossy on purpose: the TypeScript CLI hashes the same slot from a JS
+    // string, and Node decodes a path as UTF-8 with replacement, so this is
+    // the identical input. Hashing the raw bytes instead would give the two
+    // stacks different slots for the same project.
+    lockfile_dir.map(|dir| dir.to_string_lossy().into_owned())
Relevance

⭐⭐⭐ High

Team often accepts small perf wins removing repeated per-item work; caching lockfile_dir string is
low-risk.

PR-#13288
PR-#13172

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The layout builder calls local_directory_scope(...) once per snapshot to derive the optional
project scope, and local_directory_scope currently performs an allocating Path→String conversion
when lockfile_dir is present.

pnpm/crates/package-manager/src/virtual_store_layout.rs[237-252]
pnpm/crates/package-manager/src/virtual_store_layout.rs[483-495]

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

### Issue description
`local_directory_scope()` allocates a new `String` via `to_string_lossy().into_owned()` each time it is called for a local-directory snapshot, even though `lockfile_dir` is constant for the whole `VirtualStoreLayout::new()` run.

### Issue Context
This happens in GVS mode when computing per-snapshot graph hashes/suffixes. For many local-directory/injected snapshots, the repeated Path→String conversion is unnecessary.

### Fix Focus Areas
- pnpm/crates/package-manager/src/virtual_store_layout.rs[239-252]
- pnpm/crates/package-manager/src/virtual_store_layout.rs[483-495]

### Suggested approach
- In `VirtualStoreLayout::new()`, precompute `lockfile_dir_str: Option<String>` once (e.g., `lockfile_dir.map(|d| d.to_string_lossy().into_owned())`).
- Change `local_directory_scope(...)` to accept `lockfile_dir_str: Option<&str>` (or `Option<&String>`) and return `Option<&str>` / `Option<String>` without re-allocating.
- Pass the borrowed string through to `calc_graph_node_hash(..., project: Option<&str>)`.

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


6. Lossy lockfileDir hashing 🐞 Bug ☼ Reliability
Description
local_directory_scope() converts lockfile_dir to a String via to_string_lossy() and feeds it
into the GVS hash payload; on Unix, distinct non-UTF8 paths can collapse to the same lossy string
and produce identical slot hashes. This can (rarely) defeat the new per-project isolation for local
directory dependencies by making two different projects share a slot again.
Code

pnpm/crates/package-manager/src/virtual_store_layout.rs[R466-469]

+    match resolution {
+        Some(LockfileResolution::Directory(_)) => {
+            lockfile_dir.map(|dir| dir.to_string_lossy().into_owned())
+        }
Relevance

⭐ Low

Repo previously rejected replacing to_string_lossy for non-UTF8 path correctness due to added
complexity.

PR-#13160

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The per-project scoping input is produced via lossy path-to-string conversion, and that string is
included in the GVS hash payload when present; therefore any lossy collision directly risks a
slot-hash collision across projects.

pnpm/crates/package-manager/src/virtual_store_layout.rs[462-471]
pnpm/crates/graph-hasher/src/global_virtual_store_path.rs[55-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
`local_directory_scope()` derives the `project` scoping string from `lockfile_dir.to_string_lossy()`. On Unix, paths are arbitrary byte sequences and do not have to be valid UTF-8; `to_string_lossy()` is not injective (it replaces invalid sequences), so different directory byte-paths can become the same string and collide in the slot hash.

### Issue Context
This PR intentionally includes `project` in the hash payload for directory resolutions to prevent cross-project slot sharing. If the `project` identity collapses, that isolation guarantee can be undermined for projects living under non-UTF8 paths.

### Fix Focus Areas
- pnpm/crates/package-manager/src/virtual_store_layout.rs[462-471]
- pnpm/crates/graph-hasher/src/global_virtual_store_path.rs[55-95]

### Suggested fix
Instead of using a lossy UTF-8 string for `project`, derive a lossless, stable identifier from the path:

- **Option A (preferred):** encode the raw OS path bytes/wide-chars into an unambiguous string and use that as `project`.
 - On Unix: `std::os::unix::ffi::OsStrExt::as_bytes()`
 - On Windows: `std::os::windows::ffi::OsStrExt::encode_wide()`
 - Then hex/base64 encode those bytes (or hash them to a hex digest) and use the encoded string as the `project` value.

- **Option B:** hash the raw path bytes to a fixed digest (e.g., sha256) and use *that digest* as the `project` string in the payload.

This preserves uniqueness for all valid OS paths without relying on UTF-8 conversion.

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


View more (2)
7. hashDependencyPaths missing comma 📘 Rule violation ⚙ Maintainability
Description
A multi-line TypeScript function signature is missing a trailing comma after the last parameter,
violating the required trailing-comma style.
Code

pnpm11/deps/graph-builder/src/iteratePkgsForVirtualStore.ts[R92-95]

function hashDependencyPaths (
  lockfile: LockfileObject,
-  {
-    allowBuild,
-    supportedArchitectures,
-    nodeVersion,
-  }: {
-    allowBuild?: AllowBuild
-    supportedArchitectures?: SupportedArchitectures
-    nodeVersion?: string
-  }
+  opts: GraphNodeHashOptions
): IterableIterator<HashedDepPath<PkgMetaAndSnapshot>> {
-  const graph = lockfileToDepGraph(lockfile, supportedArchitectures)
-  return iterateHashedGraphNodes(graph, iteratePkgMeta(lockfile, graph), allowBuild, supportedArchitectures, nodeVersion)
Relevance

⭐ Low

Trailing-comma suggestions in multi-line TS signatures have clear rejection precedents.

PR-#13133
PR-#12876
PR-#13288

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713434 requires trailing commas for multi-line TypeScript constructs. The
hashDependencyPaths(...) signature spans multiple lines but the final parameter line has no
trailing comma.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/deps/graph-builder/src/iteratePkgsForVirtualStore.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
Multi-line TypeScript parameter lists must include a trailing comma on the last parameter.

## Issue Context
This is a style compliance requirement to reduce diff churn.

## Fix Focus Areas
- pnpm11/deps/graph-builder/src/iteratePkgsForVirtualStore.ts[92-95]

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


8. iterateHashedGraphNodes missing comma 📘 Rule violation ⚙ Maintainability
Description
Multi-line TypeScript parameter lists are missing a trailing comma, which violates the required
trailing-comma style and creates noisier diffs on future edits.
Code

pnpm11/deps/graph-hasher/src/index.ts[R202-206]

+export function * iterateHashedGraphNodes<T extends PkgMeta> (
+  graph: DepsGraph<DepPath>,
+  pkgMetaIterator: PkgMetaIterator<T>,
+  opts: GraphNodeHashOptions = {}
): IterableIterator<HashedDepPath<T>> {
Relevance

⭐ Low

Same trailing-comma style finding repeatedly rejected across pnpm11 TS files.

PR-#13133
PR-#12816
PR-#13289

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713434 requires trailing commas in multi-line TypeScript constructs. In
iterateHashedGraphNodes(...) and localDirectoryScope(...), the last parameter lines lack
trailing commas.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/deps/graph-hasher/src/index.ts[202-206]
pnpm11/deps/graph-hasher/src/index.ts[293-296]

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

## Issue description
Multi-line function parameter lists in TypeScript must end the last parameter with a trailing comma.

## Issue Context
The repo’s compliance rule requires trailing commas for multi-line TypeScript constructs to keep diffs minimal.

## Fix Focus Areas
- pnpm11/deps/graph-hasher/src/index.ts[202-206]
- pnpm11/deps/graph-hasher/src/index.ts[293-296]

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


Grey Divider

Previous review results

Review updated until commit d474e4f

Results up to commit 7c03ebd ⚖️ Balanced


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


Remediation recommended
1. GVS hashing not synced 📘 Rule violation ⌂ Architecture
Description
This PR changes user-visible global-virtual-store slot derivation in pnpm TypeScript, but the PR
does not include an equivalent pacquet/Rust change or an explicit divergence callout, risking
pnpm/pacquet behavior mismatch.
Code

pnpm11/deps/graph-hasher/src/index.ts[R263-268]

+  const project = localDirectoryScope(graph[depPath]?.resolution, lockfileDir)
+  const hexDigest = project == null
+    ? hashObjectWithoutSorting({ engine, deps }, { encoding: 'hex' })
+    : hashObjectWithoutSorting({ engine, deps, project }, { encoding: 'hex' })
+  return formatGlobalVirtualStorePath(name, project == null ? version : LOCAL_DIRECTORY_SEGMENT, hexDigest)
+}
Relevance

⭐⭐⭐ High

Repo enforces pnpm TS and pacquet Rust user-visible parity; sync/divergence callouts are accepted.

PR-#12789
PR-#12840
PR-#12153

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713428 requires pnpm TypeScript and pacquet Rust user-visible behavior changes to
be kept in sync (or explicitly called out). The diff changes the GVS slot derivation (hash inputs
and version segment) for directory dependencies, which is user-visible store/layout behavior.

Rule 713428: Keep pnpm TypeScript and pacquet Rust user-visible behavior changes in sync
pnpm11/deps/graph-hasher/src/index.ts[263-268]
.changeset/gvs-local-directory-deps.md[10-12]

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 pnpm TypeScript implementation changes the global-virtual-store slot identity for local directory dependencies (hash payload and path segment). Per compliance, equivalent user-visible behavior must be kept in sync with the pacquet/Rust implementation, or the divergence must be clearly called out.

## Issue Context
The slot path now uses a fixed `directory` segment and scopes directory resolutions by `lockfileDir` via the hash payload.

## Fix Focus Areas
- pnpm11/deps/graph-hasher/src/index.ts[263-268]
- .changeset/gvs-local-directory-deps.md[10-12]

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


2. Optional lockfileDir crash path ✓ Resolved 🐞 Bug ☼ Reliability
Description
calcGraphNodeHash() still falls back to the raw version segment when lockfileDir is omitted,
even for resolution.type==='directory'; directory snapshots can have version===undefined, which
will crash in assertNoPathTraversal(version) via version.split(...). This leaves a latent
DoS/crash hazard for any current/future caller that hashes directory resolutions without passing
lockfileDir (and also risks resolver/headless slot disagreement in that case).
Code

pnpm11/deps/graph-hasher/src/index.ts[R263-268]

+  const project = localDirectoryScope(graph[depPath]?.resolution, lockfileDir)
+  const hexDigest = project == null
+    ? hashObjectWithoutSorting({ engine, deps }, { encoding: 'hex' })
+    : hashObjectWithoutSorting({ engine, deps, project }, { encoding: 'hex' })
+  return formatGlobalVirtualStorePath(name, project == null ? version : LOCAL_DIRECTORY_SEGMENT, hexDigest)
+}
Relevance

⭐⭐⭐ High

Crash-prevention via guarding unsafe string ops on non-strings/undefined is accepted.

PR-#12491

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The hash path segment currently depends on whether localDirectoryScope() returns a value, which
requires lockfileDir; when it returns undefined, calcGraphNodeHash() uses version directly and
passes it to formatGlobalVirtualStorePath(), which calls version.split(...) in
assertNoPathTraversal(). The added unit test demonstrates version can be undefined for
directory deps coming from the lockfile.

pnpm11/deps/graph-hasher/src/index.ts[233-301]
pnpm11/deps/graph-hasher/src/index.ts[334-353]
pnpm11/deps/graph-hasher/test/calcGraphNodeHash.test.ts[478-501]

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

### Issue description
`calcGraphNodeHash()` chooses the GVS path segment based on whether `project` is set (i.e. whether `lockfileDir` was provided). For `resolution.type==='directory'`, the lockfile can omit `version`, so callers that omit `lockfileDir` can still pass `undefined` into `formatGlobalVirtualStorePath()`, which calls `assertNoPathTraversal(version)` and crashes.

### Issue Context
The PR already documents that omitting `lockfileDir` is only safe when there are no directory deps, but the code path currently crashes instead of remaining safe/consistent for directory resolutions.

### Fix Focus Areas
- pnpm11/deps/graph-hasher/src/index.ts[260-301]

### Suggested fix
- Determine whether a node is a directory dependency based on `resolution.type === 'directory'` (not on whether `lockfileDir` is present).
- Always use `LOCAL_DIRECTORY_SEGMENT` for the *path segment* when the resolution is a directory dependency, regardless of `lockfileDir`.
- Only add the `project` field to the hash payload when `lockfileDir` is present (to keep the per-project isolation behavior), but do not let its absence re-enable the `version` segment for directory deps.

This preserves:
- no-crash behavior even if `lockfileDir` is accidentally omitted,
- resolver/headless slot consistency for directory deps,
- per-project slot isolation when `lockfileDir` is provided.

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


3. Historical used to crash comment ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
A newly added test comment uses historical phrasing (used to), which violates the requirement that
comments describe current behavior rather than past implementations.
Code

pnpm11/installing/deps-installer/test/install/globalVirtualStore.ts[R539-541]

+// The lockfile records no version for a directory snapshot, so a headless
+// install used to crash while building the slot path.
+// See https://github.com/pnpm/pnpm/issues/13335.
Relevance

⭐⭐ Medium

Historical/temporal comment rewrites show mixed outcomes; enforcement in tests is inconsistent.

PR-#13125
PR-#12954

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 772199 forbids historical phrasing in comments. The added comment explicitly says
the install used to crash, which describes past behavior instead of the current contract being
tested.

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

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

## Issue description
Comments must describe current behavior, not historical behavior (avoid phrasing like `used to`).

## Issue Context
This comment is adjacent to a regression test and should explain the current invariant the test enforces.

## Fix Focus Areas
- pnpm11/installing/deps-installer/test/install/globalVirtualStore.ts[539-541]

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



Informational
4. hashDependencyPaths missing comma 📘 Rule violation ⚙ Maintainability
Description
A multi-line TypeScript function signature is missing a trailing comma after the last parameter,
violating the required trailing-comma style.
Code

pnpm11/deps/graph-builder/src/iteratePkgsForVirtualStore.ts[R92-95]

function hashDependencyPaths (
  lockfile: LockfileObject,
-  {
-    allowBuild,
-    supportedArchitectures,
-    nodeVersion,
-  }: {
-    allowBuild?: AllowBuild
-    supportedArchitectures?: SupportedArchitectures
-    nodeVersion?: string
-  }
+  opts: GraphNodeHashOptions
): IterableIterator<HashedDepPath<PkgMetaAndSnapshot>> {
-  const graph = lockfileToDepGraph(lockfile, supportedArchitectures)
-  return iterateHashedGraphNodes(graph, iteratePkgMeta(lockfile, graph), allowBuild, supportedArchitectures, nodeVersion)
Relevance

⭐ Low

Trailing-comma suggestions in multi-line TS signatures have clear rejection precedents.

PR-#13133
PR-#12876
PR-#13288

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713434 requires trailing commas for multi-line TypeScript constructs. The
hashDependencyPaths(...) signature spans multiple lines but the final parameter line has no
trailing comma.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/deps/graph-builder/src/iteratePkgsForVirtualStore.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
Multi-line TypeScript parameter lists must include a trailing comma on the last parameter.

## Issue Context
This is a style compliance requirement to reduce diff churn.

## Fix Focus Areas
- pnpm11/deps/graph-builder/src/iteratePkgsForVirtualStore.ts[92-95]

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


5. iterateHashedGraphNodes missing comma 📘 Rule violation ⚙ Maintainability
Description
Multi-line TypeScript parameter lists are missing a trailing comma, which violates the required
trailing-comma style and creates noisier diffs on future edits.
Code

pnpm11/deps/graph-hasher/src/index.ts[R202-206]

+export function * iterateHashedGraphNodes<T extends PkgMeta> (
+  graph: DepsGraph<DepPath>,
+  pkgMetaIterator: PkgMetaIterator<T>,
+  opts: GraphNodeHashOptions = {}
): IterableIterator<HashedDepPath<T>> {
Relevance

⭐ Low

Same trailing-comma style finding repeatedly rejected across pnpm11 TS files.

PR-#13133
PR-#12816
PR-#13289

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713434 requires trailing commas in multi-line TypeScript constructs. In
iterateHashedGraphNodes(...) and localDirectoryScope(...), the last parameter lines lack
trailing commas.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/deps/graph-hasher/src/index.ts[202-206]
pnpm11/deps/graph-hasher/src/index.ts[293-296]

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

## Issue description
Multi-line function parameter lists in TypeScript must end the last parameter with a trailing comma.

## Issue Context
The repo’s compliance rule requires trailing commas for multi-line TypeScript constructs to keep diffs minimal.

## Fix Focus Areas
- pnpm11/deps/graph-hasher/src/index.ts[202-206]
- pnpm11/deps/graph-hasher/src/index.ts[293-296]

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


Results up to commit 901d9ea ⚖️ Balanced


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


Informational
1. Lossy lockfileDir hashing 🐞 Bug ☼ Reliability
Description
local_directory_scope() converts lockfile_dir to a String via to_string_lossy() and feeds it
into the GVS hash payload; on Unix, distinct non-UTF8 paths can collapse to the same lossy string
and produce identical slot hashes. This can (rarely) defeat the new per-project isolation for local
directory dependencies by making two different projects share a slot again.
Code

pnpm/crates/package-manager/src/virtual_store_layout.rs[R466-469]

+    match resolution {
+        Some(LockfileResolution::Directory(_)) => {
+            lockfile_dir.map(|dir| dir.to_string_lossy().into_owned())
+        }
Relevance

⭐ Low

Repo previously rejected replacing to_string_lossy for non-UTF8 path correctness due to added
complexity.

PR-#13160

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The per-project scoping input is produced via lossy path-to-string conversion, and that string is
included in the GVS hash payload when present; therefore any lossy collision directly risks a
slot-hash collision across projects.

pnpm/crates/package-manager/src/virtual_store_layout.rs[462-471]
pnpm/crates/graph-hasher/src/global_virtual_store_path.rs[55-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
`local_directory_scope()` derives the `project` scoping string from `lockfile_dir.to_string_lossy()`. On Unix, paths are arbitrary byte sequences and do not have to be valid UTF-8; `to_string_lossy()` is not injective (it replaces invalid sequences), so different directory byte-paths can become the same string and collide in the slot hash.

### Issue Context
This PR intentionally includes `project` in the hash payload for directory resolutions to prevent cross-project slot sharing. If the `project` identity collapses, that isolation guarantee can be undermined for projects living under non-UTF8 paths.

### Fix Focus Areas
- pnpm/crates/package-manager/src/virtual_store_layout.rs[462-471]
- pnpm/crates/graph-hasher/src/global_virtual_store_path.rs[55-95]

### Suggested fix
Instead of using a lossy UTF-8 string for `project`, derive a lossless, stable identifier from the path:

- **Option A (preferred):** encode the raw OS path bytes/wide-chars into an unambiguous string and use that as `project`.
 - On Unix: `std::os::unix::ffi::OsStrExt::as_bytes()`
 - On Windows: `std::os::windows::ffi::OsStrExt::encode_wide()`
 - Then hex/base64 encode those bytes (or hash them to a hex digest) and use the encoded string as the `project` value.

- **Option B:** hash the raw path bytes to a fixed digest (e.g., sha256) and use *that digest* as the `project` string in the payload.

This preserves uniqueness for all valid OS paths without relying on UTF-8 conversion.

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


Results up to commit 1bab61f ⚖️ Balanced


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


Informational
1. Repeated lockfileDir allocations ✓ Resolved 🐞 Bug ➹ Performance
Description
For each local-directory snapshot, local_directory_scope() converts the same lockfile_dir Path
into a newly-owned String, causing repeated allocations/copies during GVS suffix precomputation.
In large workspaces with many injected/local-directory snapshots, this adds avoidable overhead on
the install path.
Code

pnpm/crates/package-manager/src/virtual_store_layout.rs[R491-495]

+    // Lossy on purpose: the TypeScript CLI hashes the same slot from a JS
+    // string, and Node decodes a path as UTF-8 with replacement, so this is
+    // the identical input. Hashing the raw bytes instead would give the two
+    // stacks different slots for the same project.
+    lockfile_dir.map(|dir| dir.to_string_lossy().into_owned())
Relevance

⭐⭐⭐ High

Team often accepts small perf wins removing repeated per-item work; caching lockfile_dir string is
low-risk.

PR-#13288
PR-#13172

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The layout builder calls local_directory_scope(...) once per snapshot to derive the optional
project scope, and local_directory_scope currently performs an allocating Path→String conversion
when lockfile_dir is present.

pnpm/crates/package-manager/src/virtual_store_layout.rs[237-252]
pnpm/crates/package-manager/src/virtual_store_layout.rs[483-495]

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

### Issue description
`local_directory_scope()` allocates a new `String` via `to_string_lossy().into_owned()` each time it is called for a local-directory snapshot, even though `lockfile_dir` is constant for the whole `VirtualStoreLayout::new()` run.

### Issue Context
This happens in GVS mode when computing per-snapshot graph hashes/suffixes. For many local-directory/injected snapshots, the repeated Path→String conversion is unnecessary.

### Fix Focus Areas
- pnpm/crates/package-manager/src/virtual_store_layout.rs[239-252]
- pnpm/crates/package-manager/src/virtual_store_layout.rs[483-495]

### Suggested approach
- In `VirtualStoreLayout::new()`, precompute `lockfile_dir_str: Option<String>` once (e.g., `lockfile_dir.map(|d| d.to_string_lossy().into_owned())`).
- Change `local_directory_scope(...)` to accept `lockfile_dir_str: Option<&str>` (or `Option<&String>`) and return `Option<&str>` / `Option<String>` without re-allocating.
- Pass the borrowed string through to `calc_graph_node_hash(..., project: Option<&str>)`.

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


Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

No code suggestions found for the PR.

…quet

Mirrors the TypeScript change on the Rust side, so both stacks derive the
same global-virtual-store slot for a package resolved from a local
directory.

`gvs_version_segment` rendered the literal `undefined` for every `file:`
dependency, which is what the TypeScript side produced before its
traversal guard turned the missing version into a crash. It now anchors a
directory resolution to the `directory` segment and prefers the metadata's
own version, so a local tarball — content-addressed, and carrying a
version in the lockfile — no longer shares the directory dep's fallback.

`VirtualStoreLayout::new` inserted a suffix for every snapshot with no
resolution check, so directory deps collided across projects exactly as
they did in the TypeScript CLI. It takes the lockfile directory now and
folds it into the hash payload for directory resolutions.

Also applies two review findings to the TypeScript side: the slot's
version segment is chosen from the resolution alone, so a caller that
leaves `lockfileDir` out still produces a well-formed path instead of
dereferencing the missing version.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings July 25, 2026 23:32

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.

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 25, 2026
@github-actions

github-actions Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                          main                                   pr
-----                          ----                                   --
lockfile/parse_pnpm_lock       1.00     11.2±0.11ms    33.3 MB/sec    1.01     11.3±0.02ms    33.1 MB/sec
packument/parse                1.03     39.8±0.15µs  1667.1 MB/sec    1.00     38.8±0.12µs  1711.7 MB/sec
tarball/download_dependency    1.03      2.4±0.06ms  1809.2 KB/sec    1.00      2.3±0.06ms  1856.2 KB/sec

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 901d9ea

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

…ath string

`to_string_lossy` is what keeps the Rust and TypeScript stacks on one slot:
Node decodes a path as UTF-8 with replacement, so the JS string the
TypeScript CLI hashes is already the lossy form. Hashing the raw bytes here
instead would give the two stacks different slots for the same project.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings July 25, 2026 23:38

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.

…ath component

The assertion matched the `dep/directory/` substring, which only holds where
`/` is the native separator — it failed on Windows against the correct
`@\dep\directory\<hash>` slot.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 6ae27c8

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

No code suggestions found for the PR.

Copilot AI review requested due to automatic review settings July 25, 2026 23:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@zkochan

zkochan commented Jul 25, 2026 •

Copy link
Copy Markdown
Member Author

Notes on the outstanding automated findings.

"GVS hashing not synced" — already addressed

The pacquet port landed in 901d9ea, one commit after the finding was first raised. VirtualStoreLayout::new takes the lockfile directory and folds it into the hash payload for directory resolutions (through a new project argument on calc_graph_node_hash), and gvs_version_segment anchors those snapshots to the same directory segment the TypeScript CLI uses. Greptile re-reviewed after that commit and now reports the parity defect fixed.

"Lossy lockfileDir hashing" — intentional, and the alternative would break parity

The concern is that to_string_lossy collapses paths whose bytes differ only in invalid UTF-8, so two such projects would share a slot.

to_string_lossy is exactly what keeps the two stacks on one slot. Node decodes a path as UTF-8 with replacement, so the lockfileDir string the TypeScript CLI hashes is already the lossy form:

$ ls -b utf8/          # two directories differing only in invalid UTF-8 bytes
p\377  p\376
$ node -e 'for (const e of require("fs").readdirSync("utf8")) console.log([...e].map(c => c.codePointAt(0).toString(16)).join(","))'
70,fffd
70,fffd

Hashing the raw bytes on the Rust side would give the two stacks different slots for the same project — a divergence reachable by every user, traded for one that no user can reach. A project rooted at such a path cannot be installed by the TypeScript CLI at all, because Node cannot address it through its string path APIs:

$ node -e 'const fs=require("fs"),path=require("path");
  const p = path.join("utf8", fs.readdirSync("utf8")[0]);
  console.log(fs.existsSync(p));'
false

The rationale is recorded at the conversion site in 6ae27c8.

Trailing commas in multi-line parameter lists (rule 713434)

Not applicable to this repository: the shared config (pnpm11/__utils__/eslint-config/index.js:72) sets @stylistic/comma-dangle to functions: 'never', so a trailing comma after the last parameter is a lint error here. pnpm run lint passes on this branch.


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

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 801bbf6

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

`local_directory_scope` turned the same `lockfile_dir` into a fresh
`String` for every local directory snapshot, though the value is constant
for the whole `VirtualStoreLayout::new` run. The conversion moves to the
caller and the scope is borrowed from there.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings July 26, 2026 00:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@qodo-code-review

Copy link
Copy Markdown

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

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

No code suggestions found for the PR.

@zkochan

zkochan commented Jul 26, 2026

Copy link
Copy Markdown
Member Author

On the new finding, "Project scope path not normalized" — not fixing this, deliberately.

The TypeScript CLI does not normalize lockfileDir either: it is opts.lockfileDir ?? opts.dir ?? process.cwd() (installing/deps-installer/src/install/extendInstallOptions.ts:328), passed through as given. Canonicalizing on the Rust side alone would give the two stacks different slots for the same project on every install — a divergence reachable by everyone, traded for one that costs a duplicate directory of hardlinks. It is the same trade as the lossy-path finding above, and the same answer.

It is also the safe direction of error. An unnormalized spelling produces an extra slot, each holding the correct content for the project that created it. The failure this PR fixes is the opposite — two projects collapsing onto one slot and overwriting each other. Over-scoping wastes a little store space; under-scoping corrupts an install.

If normalization is wanted, it belongs in both stacks at once, with a decision about whether to resolve symlinks (canonicalize would, and that changes which projects are considered the same). That is its own change, not a rider on this fix.

The Code Coverage check is red on this PR, but it is red on main too — 1590aeb17c fails identically, with step 12 (cargo codecov) ending in a null conclusion and no retrievable log, which is the runner dying rather than a test failing. Unrelated to this branch.


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

@github-actions

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: d474e4f37894

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.548 ± 0.135 2.335 2.753 1.63 ± 0.19
pacquet@main 2.500 ± 0.122 2.348 2.679 1.60 ± 0.18
pnpr@HEAD 1.563 ± 0.160 1.346 1.768 1.00
pnpr@main 1.577 ± 0.181 1.346 1.795 1.01 ± 0.16
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.54767331138,
      "stddev": 0.13488259785714346,
      "median": 2.5352290058799998,
      "user": 1.6326796799999996,
      "system": 1.30752092,
      "min": 2.33530746038,
      "max": 2.75318410238,
      "times": [
        2.5294442253800002,
        2.53660595338,
        2.6769163863800003,
        2.3551819643800003,
        2.75318410238,
        2.33530746038,
        2.48096217938,
        2.66376625938,
        2.53385205838,
        2.61151252438
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.50008859858,
      "stddev": 0.12197056467687066,
      "median": 2.5054928383800004,
      "user": 1.60843508,
      "system": 1.3190633199999997,
      "min": 2.34784055338,
      "max": 2.67856956638,
      "times": [
        2.53986881238,
        2.3667317053800003,
        2.67856956638,
        2.3604264173800003,
        2.65904304738,
        2.43884844638,
        2.58609894938,
        2.5523416233800003,
        2.34784055338,
        2.4711168643800003
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.5627635153800001,
      "stddev": 0.1603861046063119,
      "median": 1.6015731718800001,
      "user": 1.2025164799999999,
      "system": 1.1404911199999999,
      "min": 1.34617481838,
      "max": 1.7681876643799999,
      "times": [
        1.48942261838,
        1.60443687638,
        1.71282355938,
        1.7681876643799999,
        1.34617481838,
        1.68678451638,
        1.59870946738,
        1.6929719453799998,
        1.3734889693799999,
        1.35463471838
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.57720289718,
      "stddev": 0.18068210182028077,
      "median": 1.61600659088,
      "user": 1.19115608,
      "system": 1.1635867199999999,
      "min": 1.34580037638,
      "max": 1.79454320738,
      "times": [
        1.36555066738,
        1.34580037638,
        1.59652142538,
        1.71513161938,
        1.74051166838,
        1.37532829638,
        1.4330114003799999,
        1.7701385543800001,
        1.63549175638,
        1.79454320738
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 252.6 ± 5.6 245.5 260.0 1.00
pacquet@main 253.8 ± 6.8 245.7 265.7 1.00 ± 0.03
pnpr@HEAD 268.2 ± 4.4 263.2 277.7 1.06 ± 0.03
pnpr@main 266.2 ± 7.9 250.9 276.4 1.05 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.2526490681600001,
      "stddev": 0.005646801542682622,
      "median": 0.25257945715999996,
      "user": 0.19414896,
      "system": 0.5209980599999999,
      "min": 0.24545854516,
      "max": 0.26004000016,
      "times": [
        0.25340877316,
        0.25970655316,
        0.24637218716000003,
        0.25967233216,
        0.25175014116,
        0.25359987916,
        0.24893584216000003,
        0.24545854516,
        0.24754642816000003,
        0.26004000016
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.25380021726,
      "stddev": 0.006773772737646805,
      "median": 0.25232791716,
      "user": 0.19561426,
      "system": 0.51048776,
      "min": 0.24573473416000002,
      "max": 0.26565156216,
      "times": [
        0.24605465316000003,
        0.24573473416000002,
        0.25138197016,
        0.25815410616,
        0.24766178016000004,
        0.26565156216,
        0.25043284416,
        0.26041083416,
        0.25924582415999997,
        0.25327386416
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.26820293776,
      "stddev": 0.004374577404407154,
      "median": 0.26742023116,
      "user": 0.21095026,
      "system": 0.5163206600000001,
      "min": 0.26317076816,
      "max": 0.27766702316,
      "times": [
        0.26731559016,
        0.27064537916,
        0.26960262116,
        0.26317076816,
        0.26752487216,
        0.26350048216,
        0.27766702316,
        0.27122298516,
        0.26715674616,
        0.26422291016
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.26615116826,
      "stddev": 0.007940756458555328,
      "median": 0.26762225916,
      "user": 0.20896966,
      "system": 0.51221256,
      "min": 0.25087938516,
      "max": 0.27639796816,
      "times": [
        0.26857311316,
        0.26336839516,
        0.27639796816,
        0.27058163716,
        0.26330700616,
        0.27173953416,
        0.27376536616,
        0.25622787216,
        0.25087938516,
        0.26667140516
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.766 ± 0.012 2.746 2.783 1.70 ± 0.11
pacquet@main 2.741 ± 0.020 2.715 2.779 1.68 ± 0.11
pnpr@HEAD 1.631 ± 0.106 1.485 1.775 1.00
pnpr@main 1.654 ± 0.157 1.439 1.874 1.01 ± 0.12
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.76585598244,
      "stddev": 0.011786212757515149,
      "median": 2.76236952954,
      "user": 1.8226094,
      "system": 1.36115918,
      "min": 2.74589095904,
      "max": 2.78269707104,
      "times": [
        2.78269707104,
        2.77706928104,
        2.78090675804,
        2.76210931004,
        2.75721774404,
        2.76262974904,
        2.77124550104,
        2.75794952904,
        2.76084392204,
        2.74589095904
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.7413376894399994,
      "stddev": 0.01962844045402973,
      "median": 2.73812043354,
      "user": 1.8304372999999998,
      "system": 1.32462788,
      "min": 2.71525893504,
      "max": 2.77861744304,
      "times": [
        2.74516045104,
        2.74051286304,
        2.77861744304,
        2.71525893504,
        2.76527154604,
        2.72400266604,
        2.7349024690399997,
        2.73572800404,
        2.7510642070399998,
        2.72285831004
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.6308469301400002,
      "stddev": 0.10627234390530138,
      "median": 1.6258821435400002,
      "user": 1.194411,
      "system": 1.13729208,
      "min": 1.48467060504,
      "max": 1.7753235420400002,
      "times": [
        1.7753235420400002,
        1.7502041290400001,
        1.51537791904,
        1.6894263360400001,
        1.5070038590400001,
        1.73839443804,
        1.48467060504,
        1.63698254804,
        1.59630418604,
        1.61478173904
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.6537744588399999,
      "stddev": 0.15709222029483666,
      "median": 1.6279898730400002,
      "user": 1.1765323999999997,
      "system": 1.18157668,
      "min": 1.4385699900400002,
      "max": 1.87373594304,
      "times": [
        1.7814440820400002,
        1.5366520040400002,
        1.8125063590400001,
        1.8099693760400002,
        1.56680448304,
        1.5231785740400001,
        1.4385699900400002,
        1.87373594304,
        1.5057085140400002,
        1.68917526304
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 587.0 ± 10.1 572.2 609.0 1.97 ± 0.06
pacquet@main 574.4 ± 8.7 561.5 585.3 1.92 ± 0.06
pnpr@HEAD 298.4 ± 7.6 286.8 313.2 1.00
pnpr@main 303.0 ± 10.0 288.5 319.0 1.02 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.5870113399200001,
      "stddev": 0.010119567172710559,
      "median": 0.58476717962,
      "user": 0.7142541399999999,
      "system": 0.6773213799999999,
      "min": 0.5722492171200001,
      "max": 0.6090216881200001,
      "times": [
        0.5800671151200001,
        0.5914040441200001,
        0.5812802621200001,
        0.5722492171200001,
        0.5865782071200001,
        0.6090216881200001,
        0.5901851691200001,
        0.5948733641200001,
        0.5829561521200001,
        0.5814981801200001
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.5743751946200002,
      "stddev": 0.008685939797466577,
      "median": 0.5742832631200001,
      "user": 0.6845271399999999,
      "system": 0.68341048,
      "min": 0.5614812811200001,
      "max": 0.5853159001200001,
      "times": [
        0.5614812811200001,
        0.5660926731200001,
        0.5738980611200001,
        0.5851214971200001,
        0.56301201712,
        0.5816785291200001,
        0.5853159001200001,
        0.5731407591200001,
        0.5793427631200001,
        0.5746684651200001
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.29838494781999997,
      "stddev": 0.007613417380181638,
      "median": 0.29934259411999997,
      "user": 0.19287263999999998,
      "system": 0.50034308,
      "min": 0.28678762812,
      "max": 0.31324892912,
      "times": [
        0.29965769912,
        0.28818249512,
        0.30166965012,
        0.29336970312,
        0.30160868512,
        0.28678762812,
        0.29902748912,
        0.30209323212,
        0.31324892912,
        0.29820396712
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.30304337582000007,
      "stddev": 0.009987449033819549,
      "median": 0.30164757412,
      "user": 0.19202483999999997,
      "system": 0.51452688,
      "min": 0.28846420012,
      "max": 0.31897848012,
      "times": [
        0.30140072912,
        0.30578469112,
        0.28846420012,
        0.30064778212000004,
        0.30657786412000004,
        0.30189441912000003,
        0.28915533412,
        0.31722512412000003,
        0.31897848012,
        0.30030513412000004
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.909 ± 0.016 1.891 1.943 6.43 ± 0.15
pacquet@main 1.894 ± 0.009 1.879 1.911 6.38 ± 0.14
pnpr@HEAD 0.300 ± 0.008 0.289 0.310 1.01 ± 0.03
pnpr@main 0.297 ± 0.007 0.288 0.307 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.9092378022599998,
      "stddev": 0.01576049353083383,
      "median": 1.9055740665599998,
      "user": 0.9497885399999998,
      "system": 0.77113854,
      "min": 1.89145574456,
      "max": 1.94268765956,
      "times": [
        1.94268765956,
        1.89325059656,
        1.91294526056,
        1.89861791756,
        1.90883077156,
        1.90231736156,
        1.89145574456,
        1.92401397656,
        1.9178445525599999,
        1.90041418156
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.89387511426,
      "stddev": 0.008754498318316135,
      "median": 1.89329050806,
      "user": 0.9424783400000001,
      "system": 0.7515350399999999,
      "min": 1.87934219656,
      "max": 1.91091287656,
      "times": [
        1.87934219656,
        1.89053530156,
        1.89485677656,
        1.8999770565599998,
        1.8967495935599998,
        1.89896283056,
        1.88414153056,
        1.91091287656,
        1.89172423956,
        1.89154874056
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.29986367756,
      "stddev": 0.0075037510945715575,
      "median": 0.30111675106,
      "user": 0.18788584000000003,
      "system": 0.50523924,
      "min": 0.28915861756000005,
      "max": 0.30953320456000005,
      "times": [
        0.29470115456,
        0.30953320456000005,
        0.29086283656,
        0.30935622556000003,
        0.30140036856,
        0.28915861756000005,
        0.30469847056000005,
        0.29301020856000004,
        0.30083313356,
        0.30508255556
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.29677732586,
      "stddev": 0.006520152752544529,
      "median": 0.29638499956000003,
      "user": 0.19399033999999996,
      "system": 0.50595064,
      "min": 0.28807792856000003,
      "max": 0.30731216756,
      "times": [
        0.30731216756,
        0.29771006556,
        0.28932790256,
        0.29249286856,
        0.28807792856000003,
        0.29260873656,
        0.29774772656000004,
        0.29505993356000004,
        0.30506248256,
        0.30237344656000004
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 362.0 ± 6.4 351.7 374.7 4.05 ± 0.14
pacquet@main 367.1 ± 5.1 360.7 375.7 4.11 ± 0.14
pnpr@HEAD 90.1 ± 3.8 85.4 103.0 1.01 ± 0.05
pnpr@main 89.3 ± 2.7 85.1 94.0 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.36203441136000003,
      "stddev": 0.006388904365973551,
      "median": 0.36154279886000007,
      "user": 0.3531151999999999,
      "system": 0.07132051999999998,
      "min": 0.35170222586000005,
      "max": 0.37467050386000006,
      "times": [
        0.36710699786000006,
        0.35760565786000004,
        0.36057472586000006,
        0.36222492386000005,
        0.35170222586000005,
        0.36575617986000003,
        0.36374634086,
        0.36086067386000004,
        0.35609588386,
        0.37467050386000006
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.36708023016000013,
      "stddev": 0.00512571573260837,
      "median": 0.36558856186,
      "user": 0.35905489999999995,
      "system": 0.06633911999999999,
      "min": 0.36070657786000004,
      "max": 0.37572987586000006,
      "times": [
        0.36332501986000004,
        0.36562502186,
        0.37572987586000006,
        0.36722271786000005,
        0.37208903486000006,
        0.36555210186000003,
        0.36290750786000003,
        0.36363216786,
        0.37401227586,
        0.36070657786000004
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.09009923273500002,
      "stddev": 0.003805879785554764,
      "median": 0.09005455886,
      "user": 0.020177737500000004,
      "system": 0.012818101250000002,
      "min": 0.08544509186,
      "max": 0.10295055486,
      "times": [
        0.08889482386,
        0.09378295686,
        0.09062800686,
        0.08673102086000001,
        0.09230796486000001,
        0.09385390786,
        0.08699175186000001,
        0.09059843386000001,
        0.09254256886000001,
        0.08957111586000001,
        0.09150383186000001,
        0.09468821486000001,
        0.09134695186000001,
        0.09138905486,
        0.09191510886000001,
        0.08544509186,
        0.08707402086,
        0.09116109486,
        0.09182589586,
        0.08723045486,
        0.08978955186000001,
        0.09009955686,
        0.08644617686,
        0.08569909786,
        0.10295055486,
        0.09000956086,
        0.08633362286,
        0.08638161386,
        0.08584981386,
        0.08596868586,
        0.09685726486,
        0.08730767486
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.08933200402666666,
      "stddev": 0.0026789233702815703,
      "median": 0.08982901986,
      "user": 0.0215919,
      "system": 0.010732186666666664,
      "min": 0.08513306486000001,
      "max": 0.09404218886,
      "times": [
        0.09179093786,
        0.08699604886000001,
        0.08659491186,
        0.09160426886,
        0.08701997486,
        0.08652227386,
        0.09197318286,
        0.09080009786,
        0.09073202886000001,
        0.09404218886,
        0.08979022286,
        0.09309314686,
        0.08996022286000001,
        0.08670349586000001,
        0.09223253186000001,
        0.09239048686000001,
        0.08761066686,
        0.09247939586000001,
        0.09081758386000001,
        0.08666432486,
        0.09191086086,
        0.08986781686,
        0.09257689486000001,
        0.08513306486000001,
        0.08615815186,
        0.08746582186,
        0.08611438186,
        0.08708791686,
        0.08670477486,
        0.08712244286000001
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.659 ± 0.152 4.409 4.799 1.31 ± 0.06
pacquet@main 4.547 ± 0.138 4.416 4.849 1.28 ± 0.05
pnpr@HEAD 3.547 ± 0.098 3.451 3.726 1.00
pnpr@main 3.571 ± 0.163 3.441 3.897 1.01 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.658732967900001,
      "stddev": 0.15163363587336956,
      "median": 4.7274065205,
      "user": 1.76886954,
      "system": 1.42263466,
      "min": 4.4094161995,
      "max": 4.799260836499999,
      "times": [
        4.4094161995,
        4.799260836499999,
        4.4885870274999995,
        4.4398939455,
        4.7588922915,
        4.7526636105,
        4.7160953605,
        4.7387176805,
        4.7958037104999995,
        4.6879990165
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.546756309499999,
      "stddev": 0.1375346489645903,
      "median": 4.523932697999999,
      "user": 1.78351084,
      "system": 1.39087646,
      "min": 4.4160859565,
      "max": 4.849406710499999,
      "times": [
        4.4160859565,
        4.5984005004999995,
        4.4530423515,
        4.452447610499999,
        4.849406710499999,
        4.5948230445,
        4.5953032735,
        4.438040465499999,
        4.4244082495,
        4.6456049324999995
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.5474082673,
      "stddev": 0.0981746316782055,
      "median": 3.5007864675,
      "user": 1.31451904,
      "system": 1.2069657599999997,
      "min": 3.4507094895,
      "max": 3.7259883095000004,
      "times": [
        3.4563672215000003,
        3.7259883095000004,
        3.5018396545,
        3.6438134205000003,
        3.4507094895,
        3.4997332805,
        3.4873920365,
        3.6077444425,
        3.6405593345000002,
        3.4599354835000002
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.570959966,
      "stddev": 0.16345863272059372,
      "median": 3.4850472220000004,
      "user": 1.32446494,
      "system": 1.21174506,
      "min": 3.4408611535,
      "max": 3.8973345825,
      "times": [
        3.4814479705,
        3.5757980025,
        3.8195929915,
        3.8973345825,
        3.4624713425,
        3.4408611535,
        3.4480568205,
        3.6265471335000004,
        3.4688431895000003,
        3.4886464735000002
      ]
    }
  ]
}

@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13383
Testbedpacquet
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
2,745.89 ms
(+0.38%)Baseline: 2,735.36 ms
3,282.43 ms
(83.65%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
1,891.46 ms
(+0.07%)Baseline: 1,890.14 ms
2,268.17 ms
(83.39%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
572.25 ms
(-0.19%)Baseline: 573.32 ms
687.98 ms
(83.18%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
351.70 ms
(+0.93%)Baseline: 348.47 ms
418.16 ms
(84.11%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,335.31 ms
(-1.01%)Baseline: 2,359.21 ms
2,831.05 ms
(82.49%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,409.42 ms
(-0.39%)Baseline: 4,426.46 ms
5,311.75 ms
(83.01%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
245.46 ms
(-0.72%)Baseline: 247.23 ms
296.67 ms
(82.74%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13383
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,484.67 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
289.16 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
286.79 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
85.45 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,346.17 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,450.71 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
263.17 ms
🐰 View full continuous benchmarking report in Bencher

@zkochan
zkochan merged commit 51c849f into main Jul 26, 2026
35 of 36 checks passed
@zkochan
zkochan deleted the fix-13335 branch July 26, 2026 07:25
kairosci added a commit to kairosci/pnpm that referenced this pull request Jul 27, 2026
…rtual-store slot (pnpm#13383)

Installing a `file:` directory dependency with the global virtual store
enabled crashed the headless install:

    TypeError: Cannot read properties of undefined (reading 'split')
        at assertNoPathTraversal
        at formatGlobalVirtualStorePath
        at calcGraphNodeHash

pnpm omits `version` from a directory snapshot, so `nameVerFromPkgSnapshot`
hands the hasher `undefined` and the traversal guard added in
pnpm#12872 dereferences it. Directory snapshots now use a fixed
`directory` segment in place of the version. That also settles a
disagreement between the two install paths: the resolver reads the version
off the manifest and the headless install off the lockfile, where there is
none, so the same package landed on two different slots.

The crash hid a worse defect. A directory resolution is the one resolution
with no integrity — it is a path relative to the lockfile — so `file:dep`
hashed identically in every project that depended on a directory of that
name, and all of them linked to whichever project installed first. Since
the source directory is mutable, pnpm re-imports it on every install, so
the projects went on overwriting each other's copy. The lockfile directory
now joins the hash payload for directory resolutions, giving each project
its own slot; every other resolution hashes exactly as before.

`iterateHashedGraphNodes` takes an options object now — it was up to five
positional parameters before this change added a sixth.

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pnpm 11 global virtual store crashes on file directory dependencies

2 participants