Skip to content

feat(injected-deps-syncer): sync injected copies after the named scripts - #13834

Merged
zkochan merged 4 commits into
mainfrom
pacquet/sync-injected-deps
Aug 11, 2026
Merged

zkochan merged 4 commits into
mainfrom
pacquet/sync-injected-deps

Conversation

@zkochan

@zkochan zkochan commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Brings syncInjectedDepsAfterScripts to pacquet. The TypeScript CLI has honored the setting since it grew it; pacquet recognized the config key in config_types.rs and did nothing else with it, so a build script in a workspace package left every injected copy of that package stale until the next install.

An injected dependency is materialized as a tree of hardlinks into the virtual store. A build script that replaces a file — or adds or deletes one — writes inodes the copies do not share, so the copies have to be re-diffed against the source and patched in place. (A script that rewrites a file in place propagates through the hardlink on its own; that is why the tests below assert on a file the script creates rather than one it overwrites.)

What landed

  • A new pacquet-injected-deps-syncer crate. It reads the source and each target with the same DirectoryFetcher flags the installer uses for injected deps (include_only_package_files: false, resolve_symlinks: false, allow_path_escape: false), expands both into inode maps, diffs them, and patches each target.
  • Config::sync_injected_deps_after_scripts, wired from pnpm-workspace.yaml and PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS.
  • A call in run_stages, placed after the post<name> stage so it is reached only when every stage succeeded — the same condition as the TypeScript call site, where a failing runLifecycleHook throws before the sync.

Design notes

  • The inode map is a BTreeMap, which gets the ordering the patcher needs for free: a directory's path is a strict prefix of everything beneath it, so an ancestor always sorts before its descendants. The TypeScript side sorts explicitly with comparePaths because JS objects do not order.
  • apply_patch is sequential rather than concurrent. The TypeScript implementation runs its three phases under Promise.all, which is where its ordering hazards came from; doing the phases in sequence makes the invariants trivially hold.
  • Removals run before the changes. Writing the sequential version surfaced this: when the source turns a directory into a file of the same name, that path is a change while its old children are removals, and patching the change first leaves the removals hitting ENOTDIR. Under Promise.all the TypeScript side has the same hazard as a timing-dependent race — see the note below.
  • The two crates that this one builds on each define their own Host capability provider, and no single type implements both trait families. Since every test here uses a real TempDir fixture, the DI seam would not have earned its keep, so sync_injected_deps is not generic and uses each crate's own Host internally — per the gating rule in pnpm/AGENTS.md.
  • Skipping an inode that cannot be hardlinked (a FIFO, a socket, a device), and clearing one that blocks a target, mirror fix(injected-deps-syncer): skip inodes that cannot be hardlinked #13663.

Parity

This is the pacquet half of a setting the TypeScript CLI already implements, so there is no matching TypeScript change to make. One follow-up worth its own PR: applyPatch in @pnpm/workspace.injected-deps-syncer still runs its removals concurrently with its changes, so the ENOTDIR failure this PR fixes deterministically exists there as a latent race. I flagged it while reviewing #13663 and left it alone rather than swallow ENOTDIR without a test that could provoke it; the ordering fix used here is the better shape for it.

Tests

  • Seven unit tests over the patcher: ancestor expansion, skipping a real FIFO, replacing a skipped inode the target holds, leaving a skipped inode of the target's own alone, the file↔directory transition, removal of what the source dropped, and inode sharing with the source.
  • Two end-to-end tests in crates/cli/tests/suite/: a listed script refreshes every injected copy, and an unlisted one leaves them alone. Together they pin the gate — the first fails if the sync never fires, the second if it always does.

Squash Commit Body

An injected dependency is materialized as a tree of hardlinks into the
virtual store, so a build script that rewrites its source package leaves
every copy pointing at the old inodes. The TypeScript CLI has taken
syncInjectedDepsAfterScripts since it grew the setting; pacquet
recognized the config key and did nothing with it.

Add the crate that does the work. It walks the source and each target
with the same directory fetcher the installer uses, diffs the two into
inode maps, and patches each target: removals first, then directories
shallowest-first, then the hardlinks. An inode that cannot be
hardlinked — a FIFO, a socket, a device — is left out of the map, and a
target holding one is cleared and retried rather than failing the sync.
Bins are re-linked afterwards, since a build script can add or drop one.

pnpm run calls it after a script whose name the setting lists, and only
when the script succeeded, matching the TypeScript call site.

Removals run before the changes, which the sequential implementation
forced into the open: when the source turns a directory into a file of
the same name, that path is a change while its old children are
removals, and patching the change first leaves the removals hitting
ENOTDIR. The TypeScript applyPatch runs the two concurrently and has the
same hazard as a latent race; fixing it there is a separate PR.

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[1m]).


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

Summary by CodeRabbit

  • New Features

    • Added support for syncInjectedDepsAfterScripts, refreshing injected dependency copies after configured scripts complete successfully.
    • Added configuration through workspace settings and the PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS environment variable.
    • Synchronization now updates generated files and package links across affected workspace projects.
  • Tests

    • Added coverage for configured and unlisted scripts, non-workspace projects using environment-based configuration, and synchronization edge cases.

An injected dependency is materialized as a tree of hardlinks into the
virtual store, so a build script that rewrites its source package leaves
every copy pointing at the old inodes. The TypeScript CLI has taken
`syncInjectedDepsAfterScripts` since it grew the setting; pacquet
recognized the config key and did nothing with it.

Add the crate that does the work. It walks the source and each target
with the same directory fetcher the installer uses, diffs the two into
inode maps, and patches each target: removals first, then directories
shallowest-first, then the hardlinks. An inode that cannot be
hardlinked — a FIFO, a socket, a device — is left out of the map, and a
target holding one is cleared and retried rather than failing the sync.
Bins are re-linked afterwards, since a build script can add or drop one.

`pnpm run` calls it after a script whose name the setting lists, and
only when the script succeeded, matching the TypeScript call site.
Copilot AI lite review requested due to automatic review settings August 11, 2026 14:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds syncInjectedDepsAfterScripts configuration and a Rust syncer. Selected scripts refresh injected package copies and binary links after successful execution. Directory patching uses inode maps, hardlinks, and structured errors. End-to-end tests cover configured, unlisted, and environment-configured scripts.

Changes

Injected dependency synchronization

Layer / File(s) Summary
Configuration and crate wiring
.changeset/..., Cargo.toml, pnpm/crates/cli/Cargo.toml, pnpm/crates/config/..., pnpm/crates/deps-restorer/..., pnpm/crates/injected-deps-syncer/Cargo.toml
Adds syncInjectedDepsAfterScripts to workspace and environment configuration. Adds the syncer crate and its dependencies. Updates test configuration and the changeset.
Directory diff and patching
pnpm/crates/injected-deps-syncer/src/dir_patcher*
Adds inode-based directory diffs, hardlink patching, filesystem error handling, and tests for replacements, removals, unsupported entries, and inode sharing.
Synchronization service and script hook
pnpm/crates/injected-deps-syncer/src/lib.rs, pnpm/crates/cli/src/cli_args/run.rs
Adds injected-target synchronization and binary-link refresh. Runs synchronization after configured scripts complete successfully.
End-to-end validation
pnpm/crates/cli/tests/suite/*
Tests refreshes for configured scripts, unchanged copies for unlisted scripts, and environment-based configuration for non-workspace projects.

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

Sequence Diagram(s)

sequenceDiagram
  participant run_stages
  participant sync_injected_deps
  participant DirPatcher
  participant workspace_projects
  run_stages->>sync_injected_deps: invoke after a configured script
  sync_injected_deps->>DirPatcher: synchronize injected targets
  DirPatcher-->>sync_injected_deps: return patch result
  sync_injected_deps->>workspace_projects: refresh binary links
  workspace_projects-->>run_stages: return synchronization result
Loading

Possibly related PRs

  • pnpm/pnpm#13612: Refines injected-dependency synchronization for unsupported inode types.
  • pnpm/pnpm#13663: Refines DirPatcher inode handling.
  • pnpm/pnpm#13679: Registers synchronization tests in the consolidated CLI test binary.

Suggested labels: product: pacquet

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pacquet/sync-injected-deps

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

Sync injected workspace deps after configured scripts

✨ Enhancement 🧪 Tests ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Add a Rust syncer to refresh injected hardlink trees after selected lifecycle scripts.
• Wire syncInjectedDepsAfterScripts from workspace YAML and env into runtime config.
• Add unit and e2e tests to prevent stale injected copies after build outputs change.
Diagram

graph TD
  CFG["Workspace config"] --> CLI(["pnpm run_stages"]) --> SYNC(["Injected deps syncer"]) --> FETCH(["DirectoryFetcher"]) --> STORE[("Virtual store")]
  SYNC --> MODS[".modules.yaml"] --> STORE
  SYNC --> BINS[".bin shims"] --> STORE

  subgraph Legend
    direction LR
    _cfg["Config/file"] ~~~ _svc(["Component"]) ~~~ _db[("Filesystem/store")]
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Re-run install for affected package(s)
  • ➕ Reuses existing, battle-tested installer logic
  • ➕ Potentially simpler implementation surface area
  • ➖ Much higher runtime cost and more side effects than a targeted patch
  • ➖ May require broader context/locks and can touch unrelated deps
2. Copy-based sync (rsync-like) instead of inode diff + hardlink patch
  • ➕ Avoids inode/metadata corner cases (e.g., special files)
  • ➕ Conceptually straightforward to implement
  • ➖ Loses the primary benefit of injected deps (hardlink sharing) unless followed by extra linking work
  • ➖ More filesystem IO; worse performance on large trees
3. Parallelize patch application across targets
  • ➕ Faster when many injected copies exist
  • ➖ Harder to guarantee correct ordering for remove/dir/file phases
  • ➖ Higher complexity for modest typical gains

Recommendation: The PR’s approach (deterministic, sequential remove-then-create patching using an ordered inode map) is a good fit for correctness and performance: it preserves hardlink semantics, avoids race-y ordering hazards, and limits work to only changed paths. If performance becomes an issue with many injected copies, parallelism can be added later around per-target patchers without changing the diff model.

Files changed (14) +839 / -0

Enhancement (4) +529 / -0
run.rsTrigger injected-deps sync after configured successful script stages +9/-0

Trigger injected-deps sync after configured successful script stages

• Imports and invokes 'sync_injected_deps' when the executed script name is listed in 'config.sync_injected_deps_after_scripts'. The call is placed after post-script execution and only runs when the main stage succeeded.

pnpm/crates/cli/src/cli_args/run.rs

Cargo.tomlIntroduce new 'pacquet-injected-deps-syncer' crate +33/-0

Introduce new 'pacquet-injected-deps-syncer' crate

• Creates a new internal crate with dependencies on directory walking, modules manifest parsing, and bin linking. Adds dev dependencies for filesystem-based tests.

pnpm/crates/injected-deps-syncer/Cargo.toml

dir_patcher.rsImplement inode-map diff and hardlink patcher for directory trees +306/-0

Implement inode-map diff and hardlink patcher for directory trees

• Implements 'InodeMap' construction via 'DirectoryFetcher', diffs source vs target trees, and applies patches with correct ordering (remove first, then directories, then files). Handles special inodes by skipping them during map creation and retrying over 'AlreadyExists' by clearing the target path.

pnpm/crates/injected-deps-syncer/src/dir_patcher.rs

lib.rsSync injected dependency copies and refresh bin links +181/-0

Sync injected dependency copies and refresh bin links

• Adds the top-level 'sync_injected_deps' API: reads '.modules.yaml' injected mappings, patches each injected target directory to match the source package, and re-links package bins and workspace project '.bin' directories when needed.

pnpm/crates/injected-deps-syncer/src/lib.rs

Tests (3) +270 / -0
main.rsRegister new e2e suite module +1/-0

Register new e2e suite module

• Adds the 'sync_injected_deps_after_scripts' test module to the CLI integration test suite.

pnpm/crates/cli/tests/suite/main.rs

sync_injected_deps_after_scripts.rsE2E coverage for syncing injected copies after scripts +126/-0

E2E coverage for syncing injected copies after scripts

• Creates a workspace with injected workspace packages and a build script that generates a new file. Verifies injected copies are refreshed when 'syncInjectedDepsAfterScripts' lists the script, and remain stale when it does not.

pnpm/crates/cli/tests/suite/sync_injected_deps_after_scripts.rs

tests.rsUnit tests for directory patching and inode handling +143/-0

Unit tests for directory patching and inode handling

• Adds tests that validate ancestor directory inclusion, removal ordering, file/dir type replacement, inode sharing via hardlinks, and special-file (FIFO) skip/replace behaviors on Unix.

pnpm/crates/injected-deps-syncer/src/dir_patcher/tests.rs

Documentation (1) +5 / -0
pacquet-sync-injected-deps-after-scripts.mdDocument new 'syncInjectedDepsAfterScripts' support +5/-0

Document new 'syncInjectedDepsAfterScripts' support

• Adds a changeset announcing support for syncing injected dependency copies after configured scripts run. Explains the problem (stale injected copies after build scripts) and the user-facing behavior.

.changeset/pacquet-sync-injected-deps-after-scripts.md

Other (6) +35 / -0
Cargo.lockLockfile update for new injected-deps syncer crate +20/-0

Lockfile update for new injected-deps syncer crate

• Adds 'pacquet-injected-deps-syncer' and its dependency set to the workspace lockfile, and wires it into dependent crates.

Cargo.lock

Cargo.tomlRegister 'pacquet-injected-deps-syncer' as a workspace crate +1/-0

Register 'pacquet-injected-deps-syncer' as a workspace crate

• Adds the new crate path to the top-level workspace dependency list so other crates can reference it via 'workspace = true'.

Cargo.toml

Cargo.tomlAdd CLI dependency on injected-deps syncer +1/-0

Add CLI dependency on injected-deps syncer

• Introduces 'pacquet-injected-deps-syncer' as a dependency of 'pacquet-cli' so 'pnpm run' can trigger syncing after scripts.

pnpm/crates/cli/Cargo.toml

env_overlay.rsAdd env overlay for 'PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS' +1/-0

Add env overlay for 'PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS'

• Extends the environment overlay mapping to support 'SYNC_INJECTED_DEPS_AFTER_SCRIPTS', enabling runtime configuration via 'PNPM_CONFIG_*'.

pnpm/crates/config/src/env_overlay.rs

lib.rsAdd 'Config::sync_injected_deps_after_scripts' +6/-0

Add 'Config::sync_injected_deps_after_scripts'

• Introduces a new 'Vec<String>' config field representing 'syncInjectedDepsAfterScripts' from workspace YAML and env. Documents its semantics (names scripts after which injected copies are re-synced).

pnpm/crates/config/src/lib.rs

workspace_yaml.rsParse 'syncInjectedDepsAfterScripts' from pnpm-workspace.yaml +6/-0

Parse 'syncInjectedDepsAfterScripts' from pnpm-workspace.yaml

• Adds 'WorkspaceSettings::sync_injected_deps_after_scripts' to the YAML model and ensures it participates in settings clearing/merging. This allows the key to flow into 'Config' consistently with other workspace settings.

pnpm/crates/config/src/workspace_yaml.rs

@greptile-apps

greptile-apps Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (4): Last reviewed commit: "fix(injected-deps-syncer): key file iden..." | Re-trigger Greptile

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

76-126: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add coverage for a failed lifecycle stage.

The tests only cover successful script execution. Add a configured build script with a failing postbuild. Assert that the injected copy remains unchanged after the command fails.

This verifies the requirement that synchronization runs only after all stages succeed.

As per path instructions: CONTRIBUTING.md requires regression tests for feature behavior.

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

In `@pnpm/crates/cli/tests/suite/sync_injected_deps_after_scripts.rs` around lines
76 - 126, Add a regression test alongside
a_listed_script_refreshes_every_injected_copy that configures build and a
failing postbuild lifecycle script, runs build in project-1, and asserts the
command fails. Capture injected_copies before execution and verify each copy
remains unchanged afterward, confirming synchronization occurs only when all
lifecycle stages succeed.

Source: Path instructions

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

Inline comments:
In `@pnpm/crates/injected-deps-syncer/src/lib.rs`:
- Around line 115-121: Validate each target_dir before building resolved_targets
in the injected-dependency sync flow, rejecting absolute, prefixed, and
parent-relative paths and ensuring the joined path remains within the
workspace-managed store. Perform validation before calling
DirPatcher::from_multiple_targets, return the existing sync error type for
invalid entries, and add regression coverage for malformed target paths.
- Around line 141-150: Update the manifest handling around has_bin_and_name so
packages whose updated package.json no longer declares bin still reach the
cleanup-aware relinking logic instead of returning early. Preserve skipping
unrelated manifests without bin or name, and add an end-to-end test that removes
a previously declared bin and verifies its stale shims are removed from the
virtual-store and workspace .bin directories.

---

Nitpick comments:
In `@pnpm/crates/cli/tests/suite/sync_injected_deps_after_scripts.rs`:
- Around line 76-126: Add a regression test alongside
a_listed_script_refreshes_every_injected_copy that configures build and a
failing postbuild lifecycle script, runs build in project-1, and asserts the
command fails. Capture injected_copies before execution and verify each copy
remains unchanged afterward, confirming synchronization occurs only when all
lifecycle stages succeed.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1e81e01b-f688-44bc-81c3-43ee141b54c0

📥 Commits

Reviewing files that changed from the base of the PR and between 6536c01 and 84ac598.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock, !Cargo.lock
📒 Files selected for processing (13)
  • .changeset/pacquet-sync-injected-deps-after-scripts.md
  • Cargo.toml
  • pnpm/crates/cli/Cargo.toml
  • pnpm/crates/cli/src/cli_args/run.rs
  • pnpm/crates/cli/tests/suite/main.rs
  • pnpm/crates/cli/tests/suite/sync_injected_deps_after_scripts.rs
  • pnpm/crates/config/src/env_overlay.rs
  • pnpm/crates/config/src/lib.rs
  • pnpm/crates/config/src/workspace_yaml.rs
  • pnpm/crates/injected-deps-syncer/Cargo.toml
  • pnpm/crates/injected-deps-syncer/src/dir_patcher.rs
  • pnpm/crates/injected-deps-syncer/src/dir_patcher/tests.rs
  • pnpm/crates/injected-deps-syncer/src/lib.rs

@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Action required

1. Sync errors outside workspace ✓ Resolved 🐞 Bug ☼ Reliability
Description
run_stages now calls sync_injected_deps based solely on the configured script name; when
Config.workspace_dir is None (no pnpm-workspace.yaml), sync_injected_deps returns NoWorkspaceDir and
the error propagates, failing an otherwise successful script run. This can break users who set
PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS globally and run pacquet in a non-workspace project.
Code

pnpm/crates/cli/src/cli_args/run.rs[R392-395]

+        sync_injected_deps(&SyncInjectedDeps {
+            pkg_name: ctx.manifest.value().get("name").and_then(Value::as_str),
+            pkg_root_dir: ctx.dir,
+            workspace_dir: ctx.config.workspace_dir.as_deref(),
Relevance

●●● Strong

Likely treated as real reliability bug: avoid failing runs outside workspaces when workspace_dir is
None.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new call site passes workspace_dir as an Option and propagates errors. The syncer explicitly
errors when workspace_dir is missing, and config documents that workspace_dir is commonly None
outside workspaces.

pnpm/crates/cli/src/cli_args/run.rs[340-400]
pnpm/crates/injected-deps-syncer/src/lib.rs[77-90]
pnpm/crates/config/src/lib.rs[1461-1468]

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

## Issue description
`run_stages` invokes `sync_injected_deps(...)?` whenever the current script name matches `sync_injected_deps_after_scripts`. If `config.workspace_dir` is `None`, `sync_injected_deps` returns `NoWorkspaceDir`, which propagates and turns a successful script into a failing command.

## Issue Context
`Config::workspace_dir` is explicitly documented as `None` when no `pnpm-workspace.yaml` exists anywhere up the tree (i.e. ordinary single-package repos). Injected deps are a workspace feature, so in that case sync should be a no-op.

## Fix Focus Areas
- pnpm/crates/cli/src/cli_args/run.rs[391-397]
- pnpm/crates/injected-deps-syncer/src/lib.rs[77-90]
- pnpm/crates/config/src/lib.rs[1461-1468]

## Suggested fix
Option A (preferred at call site):
- In `run_stages`, add `&& ctx.config.workspace_dir.is_some()` to the condition (or early-return/skip with a debug log).

Option B (defensive in syncer):
- In `sync_injected_deps`, change `None => Err(NoWorkspaceDir)` into `None => Ok(())` (possibly with a debug log), since there cannot be injected deps without a workspace.

Add an integration/unit test that sets `PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS=build` in a non-workspace temp project and asserts `pacquet run build` still succeeds.

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


2. Injected target path escape ✗ Dismissed 🐞 Bug ⛨ Security
Description
sync_injected_deps joins injected target paths from node_modules/.modules.yaml directly onto
workspace_dir and then applies recursive deletions and hardlink writes there; absolute paths or
traversal (e.g. "../../") can escape the workspace. If .modules.yaml is corrupted or
attacker-controlled, a listed script can trigger deletion/overwrite of arbitrary paths reachable by
the current user.
Code

pnpm/crates/injected-deps-syncer/src/lib.rs[R115-117]

+    let resolved_targets: Vec<PathBuf> =
+        target_dirs.iter().map(|target_dir| workspace_dir.join(target_dir)).collect();
+    for patcher in DirPatcher::from_multiple_targets(&pkg_root_dir, &resolved_targets)
Relevance

●●● Strong

Repo has accepted path-escape hardening when joining untrusted paths; this prevents arbitrary
deletion outside workspace.

PR-#13178
PR-#13059

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The injected target paths are plain strings from the modules manifest with no validation, and they
are used to derive patch targets. The patcher applies removals using remove_dir_all on directories,
so an escaped target path can delete outside the workspace.

pnpm/crates/injected-deps-syncer/src/lib.rs[104-121]
pnpm/crates/modules-yaml/src/lib.rs[191-196]
pnpm/crates/injected-deps-syncer/src/dir_patcher.rs[154-166]
pnpm/crates/fs/src/remove_dirent.rs[16-29]

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

## Issue description
`sync_injected_deps` treats `modules.injected_deps[<key>]` entries as safe relative paths and does `workspace_dir.join(target_dir)`. `Path::join` allows absolute RHS paths (which discard the base) and relative paths with `..` that can escape after normalization. Those resolved paths are then passed into the patcher which performs recursive removals and hardlink writes.

## Issue Context
- `injected_deps` comes from `.modules.yaml` and is deserialized as raw `String` paths without validation.
- The patcher removes entries via `pacquet_fs::remove_dirent` (recursive for directories).

## Fix Focus Areas
- pnpm/crates/injected-deps-syncer/src/lib.rs[104-121]
- pnpm/crates/modules-yaml/src/lib.rs[191-196]

## Suggested fix
1. Before using any `target_dir` string from `.modules.yaml`, normalize it and enforce containment:
  - Reject `Path::is_absolute()`.
  - Compute `let joined = pacquet_fs::lexical_normalize(&workspace_dir.join(target_dir));`.
  - Enforce `joined.starts_with(workspace_dir.join("node_modules"))` (or at least `starts_with(workspace_dir)`), otherwise return a dedicated error (or skip with a warn).
2. Consider also validating that each resolved target is not the workspace root itself (defense-in-depth).
3. Add a unit test for containment rejection with an injected_deps entry like `../../outside` and `/tmp/outside`.

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



Remediation recommended

3. Duplicate Windows file-id logic 📘 Rule violation ⚙ Maintainability ⭐ New
Description
The new windows_file_index helper reimplements the same GetFileInformationByHandle-based file
identity logic that already exists elsewhere in the repo, increasing maintenance and divergence risk
for Windows-specific behavior.
Code

pnpm/crates/injected-deps-syncer/src/dir_patcher.rs[R312-315]

+fn windows_file_index(path: &Path) -> io::Result<u64> {
+    use std::{mem::MaybeUninit, os::windows::io::AsRawHandle as _};
+    use windows_sys::Win32::Storage::FileSystem::{
+        BY_HANDLE_FILE_INFORMATION, GetFileInformationByHandle,
Relevance

●●● Strong

Team has precedent for extracting/reusing shared helpers instead of duplicating logic across crates.

PR-#13090

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Compliance ID 713439 requires reusing existing shared functionality instead of duplicating similar
implementations across packages. The new Windows file-index code in dir_patcher.rs uses the same
Windows API (GetFileInformationByHandle) pattern that already exists in
cli/src/shim_dispatch/identity.rs, indicating duplication rather than reuse/extraction.

Rule 713439: Avoid reimplementing existing functionality; extract and reuse shared modules
pnpm/crates/injected-deps-syncer/src/dir_patcher.rs[312-327]
pnpm/crates/cli/src/shim_dispatch/identity.rs[116-133]

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

## Issue description
`pnpm/crates/injected-deps-syncer/src/dir_patcher.rs` adds a new Windows helper (`windows_file_index`) that duplicates existing Windows file-identity logic already implemented in `pnpm/crates/cli/src/shim_dispatch/identity.rs`.

## Issue Context
This violates the repo policy to avoid reimplementing existing functionality and can cause Windows-only bugs to be fixed in one location but not the other.

## Fix Focus Areas
- pnpm/crates/injected-deps-syncer/src/dir_patcher.rs[312-327]
- pnpm/crates/cli/src/shim_dispatch/identity.rs[116-133]

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


4. Windows inode open too strict 🐞 Bug ☼ Reliability ⭐ New
Description
On Windows, windows_file_index() uses fs::File::open(path), which requires read access and can fail
under restrictive ACLs or unusual file locks, aborting injected-deps sync during inode-map
construction. This can make an otherwise successful script run fail when
syncInjectedDepsAfterScripts is enabled.
Code

pnpm/crates/injected-deps-syncer/src/dir_patcher.rs[R318-319]

+    let file = fs::File::open(path)?;
+    let mut info = MaybeUninit::<BY_HANDLE_FILE_INFORMATION>::uninit();
Relevance

●● Moderate

Permission/lock robustness is valued, but Windows handle-opening semantics are nuanced; unclear if
they’ll change behavior now.

PR-#13454

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The Windows inode lookup opens the file with the standard read-open API, which can fail for
permission/lock reasons unrelated to metadata identity, causing sync failure before patch
application.

pnpm/crates/injected-deps-syncer/src/dir_patcher.rs[311-323]

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

### Issue description
`windows_file_index()` uses `fs::File::open(path)` which requests read access. On Windows, some files may be readable only for metadata (or be temporarily unreadable) while still being hardlinkable, causing the sync to fail early.

### Issue Context
This is in the inode identity calculation used by `extend_files_map()` for file comparisons.

### Fix Focus Areas
- pnpm/crates/injected-deps-syncer/src/dir_patcher.rs[312-323]

### Suggested fix
- Replace `fs::File::open(path)` with `OpenOptions` + `std::os::windows::fs::OpenOptionsExt` and request the minimum access needed to call `GetFileInformationByHandle` (typically `FILE_READ_ATTRIBUTES`) and permissive sharing (`FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE`).
- Optionally, if opening the handle fails with `AccessDenied`, fall back to a conservative behavior for that entry (e.g., treat as changed) rather than failing the entire sync.

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


5. No TS test for env 📘 Rule violation ▣ Testability
Description
A new Rust e2e test covers the PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS non-workspace
scenario, but there is no mirrored TypeScript test covering the same contract. This violates the
cross-stack requirement and risks pnpm/pacquet diverging on this edge case without detection.
Code

pnpm/crates/cli/tests/suite/sync_injected_deps_after_scripts.rs[R146-150]

+    pacquet
+        .with_env("PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS", r#"["build"]"#)
+        .with_args(["run", "build"])
+        .assert()
+        .success();
Relevance

●●● Strong

Team frequently requires Rust/TS parity via mirrored tests; similar “add mirrored TS tests”
suggestions were accepted.

PR-#13597
PR-#13773

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 2255044 requires mirrored tests across Rust and TypeScript for cross-stack behavior
contracts. The new Rust test explicitly asserts the non-workspace +
PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS scenario, while the existing TypeScript coverage for
syncInjectedDepsAfterScripts focuses on workspace setups via pnpm-workspace.yaml and does not
cover this env-var/non-workspace case.

Rule 2255044: Cross-stack behavior changes must have mirrored tests in Rust and TypeScript
pnpm/crates/cli/tests/suite/sync_injected_deps_after_scripts.rs[127-153]
pnpm11/pnpm/test/syncInjectedDepsAfterScripts.ts[55-66]

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

## Issue description
A Rust e2e test was added to assert that setting `PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS` does not break `pacquet run <script>` when the project is not in a workspace. The corresponding TypeScript pnpm tests for `syncInjectedDepsAfterScripts` do not cover this non-workspace + env-var scenario, so the cross-stack contract is not tested in both stacks.

## Issue Context
Compliance requires that cross-stack behavior changes be covered by mirrored tests in both Rust and TypeScript. This PR adds coverage on the Rust side only.

## Fix Focus Areas
- pnpm/crates/cli/tests/suite/sync_injected_deps_after_scripts.rs[127-153]
- pnpm11/pnpm/test/syncInjectedDepsAfterScripts.ts[55-66]

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


View review recommended (1)
6. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset declares a bump only for pacquet and does not include a pnpm entry. This
violates the changeset policy and can lead to incomplete or inconsistent release metadata.
Code

.changeset/pacquet-sync-injected-deps-after-scripts.md[R1-3]

+---
+"pacquet": minor
+---
Relevance

●● Moderate

Mixed precedent: some PRs added required pnpm entry, others rejected same request for pacquet-only
changesets.

PR-#13748
PR-#13549

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires changeset front-matter to include an entry for the pnpm package
with a valid bump type. The added changeset front-matter only lists pacquet, so it does not
satisfy the requirement.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/pacquet-sync-injected-deps-after-scripts.md[1-3]

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

## Issue description
The newly added changeset file is missing a `pnpm` entry in its front-matter, which is required by the compliance checklist.

## Issue Context
This PR adds `.changeset/pacquet-sync-injected-deps-after-scripts.md` with only a `"pacquet": minor` bump.

## Fix Focus Areas
- .changeset/pacquet-sync-injected-deps-after-scripts.md[1-3]

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



Informational

7. Unsupported inode fallback unsafe 🐞 Bug ≡ Correctness ⭐ New
Description
On non-unix/non-windows targets, file_inode() returns Ok(0) for every file; for any given relative
path that is a file in both source and target, diff_dir() will treat the Value::File(0) entries as
equal and skip syncing even when content differs. This makes injected-deps sync silently ineffective
on such targets.
Code

pnpm/crates/injected-deps-syncer/src/dir_patcher.rs[R304-307]

+    #[cfg(not(any(unix, windows)))]
+    {
+        let _ = (path, metadata);
+        Ok(0)
Relevance

●●● Strong

Correctness issue: constant inode breaks diff logic on unsupported OS; likely fixed or disabled on
those targets.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The fallback returns a constant inode value, and diff_dir relies on Value equality per path to
decide whether to emit changes, so same-path files compare equal and are skipped.

pnpm/crates/injected-deps-syncer/src/dir_patcher.rs[132-145]
pnpm/crates/injected-deps-syncer/src/dir_patcher.rs[304-308]

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

### Issue description
For `cfg(not(any(unix, windows)))`, `file_inode()` returns `Ok(0)`, which causes `diff_dir()` to consider same-path files identical across source/target and skip patching.

### Issue Context
`diff_dir()` only emits a change when `old_index.get(path) != Some(new_value)`. When both sides are `Value::File(0)` for the same `path`, the change is skipped even if the file contents differ.

### Fix Focus Areas
- pnpm/crates/injected-deps-syncer/src/dir_patcher.rs[132-145]
- pnpm/crates/injected-deps-syncer/src/dir_patcher.rs[304-308]

### Suggested fix
Choose one:
- (Preferred) Make this crate/platform explicitly unsupported: return a typed error or `compile_error!` for non-unix/non-windows.
- Or use a conservative identity that forces correctness (e.g., store a cheap fingerprint like `(len, mtime)` or even a per-path sentinel that always differs) so files are treated as changed rather than silently skipped.

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


8. Workspace-wide bin relink cost 🐞 Bug ➹ Performance
Description
After syncing, sync_bin_links enumerates every workspace project and runs link_bins over each
node_modules, which reads directory entries and parses manifests; this adds substantial repeated
filesystem work per script. In recursive runs (especially --parallel), multiple packages can trigger
this independently, magnifying the cost.
Code

pnpm/crates/injected-deps-syncer/src/lib.rs[R168-171]

+    let projects =
+        find_workspace_projects_no_check(workspace_dir, &FindWorkspaceProjectsOpts::default())
+            .map_err(|error| SyncInjectedDepsError::FindProjects { error })?;
+    for project in projects {
Relevance

● Weak

Similar performance requests to reduce workspace-wide bin relinking have been explicitly rejected
before.

PR-#13171

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new sync path calls find_workspace_projects_no_check and then calls link_bins for each project.
link_bins scans node_modules and reads manifests, and recursive run can execute projects
concurrently under --parallel, multiplying total work.

pnpm/crates/injected-deps-syncer/src/lib.rs[165-179]
pnpm/crates/cmd-shim/src/link_bins.rs[192-210]
pnpm/crates/cmd-shim/src/link_bins.rs[214-277]
pnpm/crates/cli/src/cli_args/run/recursive.rs[167-199]

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

## Issue description
`sync_bin_links` refreshes bins for every workspace project on every sync. `link_bins` scans the `node_modules` directory and reads/parses `package.json` for each entry. When `syncInjectedDepsAfterScripts` is enabled, this can be triggered after each named script, causing large, repeated I/O.

## Issue Context
- This runs only when the package has `bin` and `name`, and only when injected targets exist; still, in large workspaces it can dominate runtime.
- Recursive `--parallel` can run `run_stages` concurrently, so multiple syncers can be doing the same project-wide bin refresh work at once.

## Fix Focus Areas
- pnpm/crates/injected-deps-syncer/src/lib.rs[133-179]
- pnpm/crates/cmd-shim/src/link_bins.rs[192-277]
- pnpm/crates/cli/src/cli_args/run/recursive.rs[167-199]

## Suggested fix
Pick one or combine:
1. Refresh only affected `.bin` directories:
  - Keep the existing relink for each `parent_modules_dir/.bin` derived from the injected targets.
  - For workspace projects, restrict to projects that actually depend on the package (scan manifests once, or use an existing dependency graph if available).
2. Deduplicate work within a single `pacquet run` invocation:
  - Add a process-wide guard (Mutex/OnceCell) keyed by `(workspace_dir, pkg_name)` so project-wide relink runs at most once per package per command.
3. If concurrency is expected, consider serializing bin relinks with a lock in workspace root to avoid duplicate work.

Add a benchmark-style test or tracing span to quantify time spent in bin relinking vs patching.

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


Grey Divider

Context
✅ Compliance rules (platform): 26 rules

Grey Divider

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

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous review results

Review updated until commit da56cfc

Results up to commit 84ac598 ⚖️ Balanced


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


Action required
1. Sync errors outside workspace ✓ Resolved 🐞 Bug ☼ Reliability
Description
run_stages now calls sync_injected_deps based solely on the configured script name; when
Config.workspace_dir is None (no pnpm-workspace.yaml), sync_injected_deps returns NoWorkspaceDir and
the error propagates, failing an otherwise successful script run. This can break users who set
PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS globally and run pacquet in a non-workspace project.
Code

pnpm/crates/cli/src/cli_args/run.rs[R392-395]

+        sync_injected_deps(&SyncInjectedDeps {
+            pkg_name: ctx.manifest.value().get("name").and_then(Value::as_str),
+            pkg_root_dir: ctx.dir,
+            workspace_dir: ctx.config.workspace_dir.as_deref(),
Relevance

●●● Strong

Likely treated as real reliability bug: avoid failing runs outside workspaces when workspace_dir is
None.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new call site passes workspace_dir as an Option and propagates errors. The syncer explicitly
errors when workspace_dir is missing, and config documents that workspace_dir is commonly None
outside workspaces.

pnpm/crates/cli/src/cli_args/run.rs[340-400]
pnpm/crates/injected-deps-syncer/src/lib.rs[77-90]
pnpm/crates/config/src/lib.rs[1461-1468]

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

## Issue description
`run_stages` invokes `sync_injected_deps(...)?` whenever the current script name matches `sync_injected_deps_after_scripts`. If `config.workspace_dir` is `None`, `sync_injected_deps` returns `NoWorkspaceDir`, which propagates and turns a successful script into a failing command.

## Issue Context
`Config::workspace_dir` is explicitly documented as `None` when no `pnpm-workspace.yaml` exists anywhere up the tree (i.e. ordinary single-package repos). Injected deps are a workspace feature, so in that case sync should be a no-op.

## Fix Focus Areas
- pnpm/crates/cli/src/cli_args/run.rs[391-397]
- pnpm/crates/injected-deps-syncer/src/lib.rs[77-90]
- pnpm/crates/config/src/lib.rs[1461-1468]

## Suggested fix
Option A (preferred at call site):
- In `run_stages`, add `&& ctx.config.workspace_dir.is_some()` to the condition (or early-return/skip with a debug log).

Option B (defensive in syncer):
- In `sync_injected_deps`, change `None => Err(NoWorkspaceDir)` into `None => Ok(())` (possibly with a debug log), since there cannot be injected deps without a workspace.

Add an integration/unit test that sets `PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS=build` in a non-workspace temp project and asserts `pacquet run build` still succeeds.

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


2. Injected target path escape ✗ Dismissed 🐞 Bug ⛨ Security
Description
sync_injected_deps joins injected target paths from node_modules/.modules.yaml directly onto
workspace_dir and then applies recursive deletions and hardlink writes there; absolute paths or
traversal (e.g. "../../") can escape the workspace. If .modules.yaml is corrupted or
attacker-controlled, a listed script can trigger deletion/overwrite of arbitrary paths reachable by
the current user.
Code

pnpm/crates/injected-deps-syncer/src/lib.rs[R115-117]

+    let resolved_targets: Vec<PathBuf> =
+        target_dirs.iter().map(|target_dir| workspace_dir.join(target_dir)).collect();
+    for patcher in DirPatcher::from_multiple_targets(&pkg_root_dir, &resolved_targets)
Relevance

●●● Strong

Repo has accepted path-escape hardening when joining untrusted paths; this prevents arbitrary
deletion outside workspace.

PR-#13178
PR-#13059

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The injected target paths are plain strings from the modules manifest with no validation, and they
are used to derive patch targets. The patcher applies removals using remove_dir_all on directories,
so an escaped target path can delete outside the workspace.

pnpm/crates/injected-deps-syncer/src/lib.rs[104-121]
pnpm/crates/modules-yaml/src/lib.rs[191-196]
pnpm/crates/injected-deps-syncer/src/dir_patcher.rs[154-166]
pnpm/crates/fs/src/remove_dirent.rs[16-29]

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

## Issue description
`sync_injected_deps` treats `modules.injected_deps[<key>]` entries as safe relative paths and does `workspace_dir.join(target_dir)`. `Path::join` allows absolute RHS paths (which discard the base) and relative paths with `..` that can escape after normalization. Those resolved paths are then passed into the patcher which performs recursive removals and hardlink writes.

## Issue Context
- `injected_deps` comes from `.modules.yaml` and is deserialized as raw `String` paths without validation.
- The patcher removes entries via `pacquet_fs::remove_dirent` (recursive for directories).

## Fix Focus Areas
- pnpm/crates/injected-deps-syncer/src/lib.rs[104-121]
- pnpm/crates/modules-yaml/src/lib.rs[191-196]

## Suggested fix
1. Before using any `target_dir` string from `.modules.yaml`, normalize it and enforce containment:
  - Reject `Path::is_absolute()`.
  - Compute `let joined = pacquet_fs::lexical_normalize(&workspace_dir.join(target_dir));`.
  - Enforce `joined.starts_with(workspace_dir.join("node_modules"))` (or at least `starts_with(workspace_dir)`), otherwise return a dedicated error (or skip with a warn).
2. Consider also validating that each resolved target is not the workspace root itself (defense-in-depth).
3. Add a unit test for containment rejection with an injected_deps entry like `../../outside` and `/tmp/outside`.

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



Remediation recommended
3. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset declares a bump only for pacquet and does not include a pnpm entry. This
violates the changeset policy and can lead to incomplete or inconsistent release metadata.
Code

.changeset/pacquet-sync-injected-deps-after-scripts.md[R1-3]

+---
+"pacquet": minor
+---
Relevance

●● Moderate

Mixed precedent: some PRs added required pnpm entry, others rejected same request for pacquet-only
changesets.

PR-#13748
PR-#13549

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires changeset front-matter to include an entry for the pnpm package
with a valid bump type. The added changeset front-matter only lists pacquet, so it does not
satisfy the requirement.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/pacquet-sync-injected-deps-after-scripts.md[1-3]

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

## Issue description
The newly added changeset file is missing a `pnpm` entry in its front-matter, which is required by the compliance checklist.

## Issue Context
This PR adds `.changeset/pacquet-sync-injected-deps-after-scripts.md` with only a `"pacquet": minor` bump.

## Fix Focus Areas
- .changeset/pacquet-sync-injected-deps-after-scripts.md[1-3]

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



Informational
4. Workspace-wide bin relink cost 🐞 Bug ➹ Performance
Description
After syncing, sync_bin_links enumerates every workspace project and runs link_bins over each
node_modules, which reads directory entries and parses manifests; this adds substantial repeated
filesystem work per script. In recursive runs (especially --parallel), multiple packages can trigger
this independently, magnifying the cost.
Code

pnpm/crates/injected-deps-syncer/src/lib.rs[R168-171]

+    let projects =
+        find_workspace_projects_no_check(workspace_dir, &FindWorkspaceProjectsOpts::default())
+            .map_err(|error| SyncInjectedDepsError::FindProjects { error })?;
+    for project in projects {
Relevance

● Weak

Similar performance requests to reduce workspace-wide bin relinking have been explicitly rejected
before.

PR-#13171

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new sync path calls find_workspace_projects_no_check and then calls link_bins for each project.
link_bins scans node_modules and reads manifests, and recursive run can execute projects
concurrently under --parallel, multiplying total work.

pnpm/crates/injected-deps-syncer/src/lib.rs[165-179]
pnpm/crates/cmd-shim/src/link_bins.rs[192-210]
pnpm/crates/cmd-shim/src/link_bins.rs[214-277]
pnpm/crates/cli/src/cli_args/run/recursive.rs[167-199]

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

## Issue description
`sync_bin_links` refreshes bins for every workspace project on every sync. `link_bins` scans the `node_modules` directory and reads/parses `package.json` for each entry. When `syncInjectedDepsAfterScripts` is enabled, this can be triggered after each named script, causing large, repeated I/O.

## Issue Context
- This runs only when the package has `bin` and `name`, and only when injected targets exist; still, in large workspaces it can dominate runtime.
- Recursive `--parallel` can run `run_stages` concurrently, so multiple syncers can be doing the same project-wide bin refresh work at once.

## Fix Focus Areas
- pnpm/crates/injected-deps-syncer/src/lib.rs[133-179]
- pnpm/crates/cmd-shim/src/link_bins.rs[192-277]
- pnpm/crates/cli/src/cli_args/run/recursive.rs[167-199]

## Suggested fix
Pick one or combine:
1. Refresh only affected `.bin` directories:
  - Keep the existing relink for each `parent_modules_dir/.bin` derived from the injected targets.
  - For workspace projects, restrict to projects that actually depend on the package (scan manifests once, or use an existing dependency graph if available).
2. Deduplicate work within a single `pacquet run` invocation:
  - Add a process-wide guard (Mutex/OnceCell) keyed by `(workspace_dir, pkg_name)` so project-wide relink runs at most once per package per command.
3. If concurrency is expected, consider serializing bin relinks with a lock in workspace root to avoid duplicate work.

Add a benchmark-style test or tracing span to quantify time spent in bin relinking vs patching.

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


Results up to commit 0790deb ⚖️ Balanced


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


Remediation recommended
1. No TS test for env 📘 Rule violation ▣ Testability
Description
A new Rust e2e test covers the PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS non-workspace
scenario, but there is no mirrored TypeScript test covering the same contract. This violates the
cross-stack requirement and risks pnpm/pacquet diverging on this edge case without detection.
Code

pnpm/crates/cli/tests/suite/sync_injected_deps_after_scripts.rs[R146-150]

+    pacquet
+        .with_env("PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS", r#"["build"]"#)
+        .with_args(["run", "build"])
+        .assert()
+        .success();
Relevance

●●● Strong

Team frequently requires Rust/TS parity via mirrored tests; similar “add mirrored TS tests”
suggestions were accepted.

PR-#13597
PR-#13773

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 2255044 requires mirrored tests across Rust and TypeScript for cross-stack behavior
contracts. The new Rust test explicitly asserts the non-workspace +
PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS scenario, while the existing TypeScript coverage for
syncInjectedDepsAfterScripts focuses on workspace setups via pnpm-workspace.yaml and does not
cover this env-var/non-workspace case.

Rule 2255044: Cross-stack behavior changes must have mirrored tests in Rust and TypeScript
pnpm/crates/cli/tests/suite/sync_injected_deps_after_scripts.rs[127-153]
pnpm11/pnpm/test/syncInjectedDepsAfterScripts.ts[55-66]

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

## Issue description
A Rust e2e test was added to assert that setting `PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS` does not break `pacquet run <script>` when the project is not in a workspace. The corresponding TypeScript pnpm tests for `syncInjectedDepsAfterScripts` do not cover this non-workspace + env-var scenario, so the cross-stack contract is not tested in both stacks.

## Issue Context
Compliance requires that cross-stack behavior changes be covered by mirrored tests in both Rust and TypeScript. This PR adds coverage on the Rust side only.

## Fix Focus Areas
- pnpm/crates/cli/tests/suite/sync_injected_deps_after_scripts.rs[127-153]
- pnpm11/pnpm/test/syncInjectedDepsAfterScripts.ts[55-66]

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


Qodo Logo

Comment thread pnpm/crates/cli/src/cli_args/run.rs Resolved
@github-actions

github-actions Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     15.1±2.64ms    24.9 MB/sec    1.23     18.6±4.17ms    20.1 MB/sec
packument/parse                                  1.00     47.9±3.15µs  1386.2 MB/sec    1.86     89.1±1.99µs   744.3 MB/sec
tarball/download_dependency                      1.00      4.0±0.55ms  1083.1 KB/sec    1.38      5.5±0.76ms   786.8 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.00   221.7±25.85ms 72.2 KElem/sec    1.32   291.8±27.09ms 54.8 KElem/sec
workspace_resolution/hoist_heavy                 1.00   300.8±31.00ms        ? ?/sec    1.98  595.4±163.00ms        ? ?/sec

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

Every schema key also reads from `PNPM_CONFIG_*`, so the setting reaches
a project that has no `pnpm-workspace.yaml`. Erroring there failed a run
whose script had already succeeded. Nothing can be injected outside a
workspace, so there is nothing to sync: log and return.

The TypeScript CLI throws `ERR_PNPM_NO_WORKSPACE_DIR` in the same spot,
but cannot reach it — `syncInjectedDepsAfterScripts` is only readable
from `pnpm-workspace.yaml` there, and that file is what defines the
workspace dir. Verified against the built bundle.

Also restore the missing field to the `Config` literal in
deps-restorer's tests, which the workspace build caught but a
crate-scoped check did not.
Copilot AI review requested due to automatic review settings August 11, 2026 15:01

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 0790deb

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

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

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

128-153: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a TypeScript test for environment configuration outside a workspace.

The existing TypeScript tests cover configured and unlisted scripts only within a workspace. Add the non-workspace PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS scenario with the same successful script behavior as the Rust test.

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

In `@pnpm/crates/cli/tests/suite/sync_injected_deps_after_scripts.rs` around lines
128 - 153, Add a TypeScript test covering
PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS for a project outside a workspace,
matching the Rust test’s setup and behavior. Define a standalone package with a
successful script, run it with the environment variable configured for that
script, and assert the command succeeds.

Sources: Coding guidelines, Learnings

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

Nitpick comments:
In `@pnpm/crates/cli/tests/suite/sync_injected_deps_after_scripts.rs`:
- Around line 128-153: Add a TypeScript test covering
PNPM_CONFIG_SYNC_INJECTED_DEPS_AFTER_SCRIPTS for a project outside a workspace,
matching the Rust test’s setup and behavior. Define a standalone package with a
successful script, run it with the environment variable configured for that
script, and assert the command succeeds.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 82e992aa-3702-4115-9c5a-e17df222b32a

📥 Commits

Reviewing files that changed from the base of the PR and between 84ac598 and 0790deb.

📒 Files selected for processing (4)
  • pnpm/crates/cli/tests/suite/sync_injected_deps_after_scripts.rs
  • pnpm/crates/deps-restorer/src/install_package_from_registry/tests.rs
  • pnpm/crates/injected-deps-syncer/src/dir_patcher.rs
  • pnpm/crates/injected-deps-syncer/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • pnpm/crates/injected-deps-syncer/src/dir_patcher.rs
  • pnpm/crates/injected-deps-syncer/src/lib.rs

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Aug 11, 2026
@codecov-commenter

codecov-commenter commented Aug 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.08955% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.22%. Comparing base (d37f5c2) to head (da56cfc).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
pnpm/crates/injected-deps-syncer/src/lib.rs 53.84% 30 Missing ⚠️
...npm/crates/injected-deps-syncer/src/dir_patcher.rs 95.27% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13834      +/-   ##
==========================================
- Coverage   88.23%   88.22%   -0.02%     
==========================================
  Files         625      627       +2     
  Lines      102839   103004     +165     
==========================================
+ Hits        90742    90872     +130     
- Misses      12097    12132      +35     

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

`MetadataExt::file_index` sits behind the unstable `windows_by_handle`
feature, so the Windows build failed to compile while every Linux gate
stayed green. Take the index from a handle instead, via
`GetFileInformationByHandle` — the same call libuv makes to fill Node's
`Stats.ino`, and the one `shim_dispatch::identity` already makes here.

Comparing inodes is what lets an already-hardlinked file cost nothing,
so the cheaper Windows alternatives are not equivalent: `(len, mtime)`
would skip a replaced file that kept both, leaving the injected copy
stale.

Verified by compiling the helper for x86_64-pc-windows-msvc under the
pinned toolchain; the full graph cannot cross-compile because two
transitive C build scripts fail.
Copilot AI review requested due to automatic review settings August 11, 2026 15:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

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

Inline comments:
In `@pnpm/crates/injected-deps-syncer/src/dir_patcher.rs`:
- Line 251: Update file identity generation around file_inode and the
corresponding TypeScript pnpm implementation to include the filesystem or volume
identifier: use (dev, ino) on Unix and (dwVolumeSerialNumber, file_index) on
Windows. Ensure diff_dir compares these composite identities so cross-device or
cross-volume files are not treated as identical, and add fixtures covering both
scenarios.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 51b0de79-a996-4640-95e5-d34cc2fc9403

📥 Commits

Reviewing files that changed from the base of the PR and between 0790deb and 5ec7004.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock, !Cargo.lock
📒 Files selected for processing (3)
  • pnpm/crates/injected-deps-syncer/Cargo.toml
  • pnpm/crates/injected-deps-syncer/src/dir_patcher.rs
  • pnpm/crates/injected-deps-syncer/src/dir_patcher/tests.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • pnpm/crates/injected-deps-syncer/src/dir_patcher/tests.rs
  • pnpm/crates/injected-deps-syncer/Cargo.toml

@qodo-code-review

Copy link
Copy Markdown

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

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

No code suggestions found for the PR.

@github-actions

github-actions Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: da56cfc7c4de

Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm. 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.551 ± 0.144 2.431 2.855 1.50 ± 0.16
pacquet@main 2.581 ± 0.141 2.420 2.752 1.52 ± 0.16
pnpr@HEAD 1.703 ± 0.151 1.445 1.872 1.00
pnpr@main 1.711 ± 0.170 1.446 1.904 1.00 ± 0.13
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.5511752982999996,
      "stddev": 0.14374224076333436,
      "median": 2.4928937873,
      "user": 2.3127354999999996,
      "system": 1.76499374,
      "min": 2.4312050813,
      "max": 2.8550545822999998,
      "times": [
        2.4463684022999996,
        2.6144790052999998,
        2.5133015822999996,
        2.4383991443,
        2.4724859922999998,
        2.8550545822999998,
        2.4312050813,
        2.4488530033,
        2.5577531343,
        2.7338530553
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.5805501466,
      "stddev": 0.14075859431121268,
      "median": 2.5717080453,
      "user": 2.0792259999999994,
      "system": 1.59957624,
      "min": 2.4201581663,
      "max": 2.7516809572999996,
      "times": [
        2.4240421043,
        2.4201581663,
        2.6853944743,
        2.7516809572999996,
        2.7197181553,
        2.4335222773,
        2.6429054213,
        2.4827695312999998,
        2.7447997092999996,
        2.5005106692999997
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.7033309488999997,
      "stddev": 0.15116949772194374,
      "median": 1.7591753593000001,
      "user": 1.7755113999999999,
      "system": 1.6467689399999994,
      "min": 1.4448772713,
      "max": 1.8718512123,
      "times": [
        1.8215190323000001,
        1.7092351903,
        1.7998806243,
        1.5124829603,
        1.8718512123,
        1.5308128123,
        1.7524167203,
        1.7659339983000002,
        1.4448772713,
        1.8242996673
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.7105852998,
      "stddev": 0.16976336133232836,
      "median": 1.7072730833,
      "user": 1.9222629000000002,
      "system": 1.8048124399999999,
      "min": 1.4464778863,
      "max": 1.9037601653,
      "times": [
        1.9037601653,
        1.8954995793,
        1.4925498803000001,
        1.4464778863,
        1.6605205303000001,
        1.8359055063,
        1.8889189503000001,
        1.5676743333,
        1.6997104083,
        1.7148357583
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 407.0 ± 19.8 379.0 437.1 1.09 ± 0.09
pacquet@main 379.7 ± 35.5 343.9 450.1 1.02 ± 0.12
pnpr@HEAD 390.0 ± 22.3 362.8 426.6 1.05 ± 0.09
pnpr@main 372.0 ± 25.1 330.1 410.1 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.40702304264,
      "stddev": 0.01983892471874705,
      "median": 0.40554117184,
      "user": 0.37223533999999997,
      "system": 0.7383167800000001,
      "min": 0.37902646584,
      "max": 0.43713716484,
      "times": [
        0.43060685184,
        0.41716271384000003,
        0.38707293884,
        0.37902646584,
        0.39198945184,
        0.42340881384,
        0.39876740884,
        0.41231493484,
        0.43713716484,
        0.39274368184
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.37965756144,
      "stddev": 0.035515384586586415,
      "median": 0.37565248184,
      "user": 0.3324231399999999,
      "system": 0.7335242799999999,
      "min": 0.34385251084,
      "max": 0.45014944084,
      "times": [
        0.45014944084,
        0.42699642284,
        0.37903328284,
        0.38631013184,
        0.38793981384,
        0.35602050384,
        0.37227168084,
        0.34385251084,
        0.34645722384,
        0.34754460284
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.39003716933999993,
      "stddev": 0.022349364147849885,
      "median": 0.38965453084,
      "user": 0.34592243999999994,
      "system": 0.7325844800000001,
      "min": 0.36275030484,
      "max": 0.42664602584,
      "times": [
        0.39479522384,
        0.36831008984,
        0.38640380284,
        0.39290525884,
        0.42207654884,
        0.40297803984,
        0.42664602584,
        0.37574931684,
        0.36275030484,
        0.36775708184
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.37197080484000006,
      "stddev": 0.025068436514796556,
      "median": 0.37083123084,
      "user": 0.32859324,
      "system": 0.6929070799999999,
      "min": 0.33005707584,
      "max": 0.41007176584,
      "times": [
        0.38667452384,
        0.37300424984,
        0.35865317584,
        0.33005707584,
        0.36262051084,
        0.34536237184,
        0.36865821184,
        0.37781938084,
        0.40678678184,
        0.41007176584
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.937 ± 0.090 2.796 3.111 1.69 ± 0.19
pacquet@main 2.871 ± 0.171 2.691 3.140 1.66 ± 0.21
pnpr@HEAD 1.805 ± 0.148 1.562 2.057 1.04 ± 0.14
pnpr@main 1.734 ± 0.188 1.496 1.987 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.93653936342,
      "stddev": 0.08965043621193493,
      "median": 2.91374281612,
      "user": 2.7760584399999995,
      "system": 2.19104882,
      "min": 2.79603466212,
      "max": 3.11108649912,
      "times": [
        2.79603466212,
        2.8761971911199997,
        2.90168888112,
        2.98256856612,
        2.9011505081199997,
        2.96003452612,
        3.03453662612,
        2.92579675112,
        3.11108649912,
        2.87629942312
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.87050205192,
      "stddev": 0.17074414340151328,
      "median": 2.83021023262,
      "user": 2.59413394,
      "system": 2.06099932,
      "min": 2.6909109021199997,
      "max": 3.1402809021199998,
      "times": [
        2.78549942212,
        2.7468161751199998,
        2.72409764212,
        2.70840415012,
        2.6909109021199997,
        2.87675594212,
        2.8749210431199996,
        3.06468937012,
        3.1402809021199998,
        3.09264497012
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.8053988059200001,
      "stddev": 0.14824597825555677,
      "median": 1.81321815412,
      "user": 1.8411847399999999,
      "system": 1.7270801199999997,
      "min": 1.56158196212,
      "max": 2.05653429312,
      "times": [
        2.05653429312,
        1.63270980912,
        1.80731797412,
        1.91129294812,
        1.7238591441200002,
        1.72564391112,
        1.8191183341200001,
        1.9080946311200002,
        1.90783505212,
        1.56158196212
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.73428578342,
      "stddev": 0.18844646230588258,
      "median": 1.69029385612,
      "user": 1.78984514,
      "system": 1.62457712,
      "min": 1.49643788012,
      "max": 1.98675431312,
      "times": [
        1.98609324912,
        1.98675431312,
        1.62382546312,
        1.59621904512,
        1.80640946912,
        1.54900892212,
        1.59468633512,
        1.7567622491200001,
        1.49643788012,
        1.94666090812
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 699.6 ± 78.8 588.6 832.1 1.56 ± 0.18
pacquet@main 690.0 ± 41.3 648.3 776.4 1.53 ± 0.10
pnpr@HEAD 449.6 ± 14.3 427.7 472.1 1.00
pnpr@main 460.1 ± 18.0 428.6 484.6 1.02 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.6995956716600001,
      "stddev": 0.07881999081407431,
      "median": 0.70214258486,
      "user": 0.97176784,
      "system": 1.0488552800000002,
      "min": 0.58862235186,
      "max": 0.83209235686,
      "times": [
        0.66345182986,
        0.70061568786,
        0.74164253286,
        0.63324774486,
        0.77949094286,
        0.70366948186,
        0.6020484538599999,
        0.83209235686,
        0.75107533386,
        0.58862235186
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.6899858681600001,
      "stddev": 0.041260939474883705,
      "median": 0.6770587378599999,
      "user": 0.9265449400000001,
      "system": 1.04986398,
      "min": 0.64827580986,
      "max": 0.77638783286,
      "times": [
        0.66722087886,
        0.77638783286,
        0.65743371486,
        0.69230550186,
        0.68050166286,
        0.65850286486,
        0.6736158128599999,
        0.74550408786,
        0.70011051486,
        0.64827580986
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.44955993796,
      "stddev": 0.014313924317055034,
      "median": 0.4472726368600001,
      "user": 0.35351914000000006,
      "system": 0.7474228799999999,
      "min": 0.42767383986,
      "max": 0.47213652586000004,
      "times": [
        0.46446683886000006,
        0.46594090086000006,
        0.44964944986000005,
        0.44643859086000004,
        0.42767383986,
        0.43225701086,
        0.44358015686,
        0.47213652586000004,
        0.44534938286000003,
        0.44810668286000005
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.4600527447599999,
      "stddev": 0.01802664356145062,
      "median": 0.46379143336000006,
      "user": 0.34988174,
      "system": 0.7608823800000001,
      "min": 0.42856626286000005,
      "max": 0.48464444286,
      "times": [
        0.44791562086000003,
        0.42856626286000005,
        0.47441040686,
        0.46287550786000003,
        0.46470735886000003,
        0.43979123686000005,
        0.47977120286,
        0.45045208386,
        0.48464444286,
        0.46739332386000004
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.077 ± 0.047 2.010 2.159 4.03 ± 0.17
pacquet@main 2.076 ± 0.093 1.949 2.199 4.03 ± 0.23
pnpr@HEAD 0.516 ± 0.018 0.494 0.542 1.00
pnpr@main 0.534 ± 0.030 0.475 0.570 1.04 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.07748291516,
      "stddev": 0.04700424456681593,
      "median": 2.0608416853600002,
      "user": 1.4230235599999999,
      "system": 1.26896998,
      "min": 2.00981990436,
      "max": 2.1592581813600003,
      "times": [
        2.1592581813600003,
        2.1129243953600003,
        2.05259075336,
        2.0666903423600003,
        2.10891400036,
        2.05499302836,
        2.12701697436,
        2.03570993836,
        2.04691163336,
        2.00981990436
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.07622689926,
      "stddev": 0.0927173880557876,
      "median": 2.0742797153600003,
      "user": 1.45669056,
      "system": 1.21682728,
      "min": 1.94945117536,
      "max": 2.1985998383600003,
      "times": [
        1.9997876383599997,
        1.94945117536,
        1.98142130336,
        1.99918727536,
        2.08521397736,
        2.06334545336,
        2.17819417836,
        2.19199455136,
        2.1985998383600003,
        2.11507360136
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.51550616876,
      "stddev": 0.017830073018458816,
      "median": 0.50876613186,
      "user": 0.4143602599999999,
      "system": 0.76825918,
      "min": 0.49404994036000005,
      "max": 0.54199431036,
      "times": [
        0.54199431036,
        0.50203522236,
        0.53571066436,
        0.49404994036000005,
        0.49463066536000005,
        0.50672282636,
        0.50704403936,
        0.53314943236,
        0.5292363623599999,
        0.51048822436
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.5340492610600001,
      "stddev": 0.029904738663872093,
      "median": 0.5398659863599999,
      "user": 0.41583755999999994,
      "system": 0.80074768,
      "min": 0.47528651636,
      "max": 0.56972235636,
      "times": [
        0.49524185036,
        0.47528651636,
        0.5471793993599999,
        0.56972235636,
        0.53255257336,
        0.5513363783599999,
        0.52924122836,
        0.52450625236,
        0.56510818136,
        0.55031787436
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 487.7 ± 50.3 368.4 542.8 3.41 ± 0.45
pacquet@main 508.5 ± 36.5 443.7 543.2 3.56 ± 0.39
pnpr@HEAD 143.5 ± 11.9 121.3 165.4 1.00 ± 0.12
pnpr@main 143.0 ± 11.6 119.6 158.0 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.48768021696,
      "stddev": 0.05030557681297799,
      "median": 0.49854548436,
      "user": 0.46217173999999994,
      "system": 0.14147751999999997,
      "min": 0.36841660386,
      "max": 0.5427685118600001,
      "times": [
        0.52090702186,
        0.44819431986,
        0.51962770486,
        0.52222521386,
        0.47389183286000003,
        0.5084939778600001,
        0.48367999186000005,
        0.5427685118600001,
        0.36841660386,
        0.48859699086
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.5084534945600001,
      "stddev": 0.036481792781183124,
      "median": 0.5231954513600001,
      "user": 0.48082614,
      "system": 0.14798802,
      "min": 0.44371569586000004,
      "max": 0.54318425786,
      "times": [
        0.47890102086,
        0.53804184786,
        0.53578483286,
        0.51133898586,
        0.44371569586000004,
        0.53351830586,
        0.5256051608600001,
        0.45365909586000003,
        0.52078574186,
        0.54318425786
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.14348115049157895,
      "stddev": 0.011928729930460163,
      "median": 0.14749443086,
      "user": 0.04908057684210526,
      "system": 0.029002088421052633,
      "min": 0.12128885986,
      "max": 0.16543051786000001,
      "times": [
        0.14651527686000002,
        0.12973976386,
        0.13762673286000002,
        0.15482654186,
        0.12128885986,
        0.14749443086,
        0.14226834586,
        0.15164921686000002,
        0.16543051786000001,
        0.13511004386,
        0.15002657086,
        0.13192389786,
        0.15462765786000002,
        0.13060597786,
        0.14842564486,
        0.12391768686,
        0.15159961586,
        0.15264448686,
        0.15042058986
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.14301486322842105,
      "stddev": 0.01163156292334355,
      "median": 0.14623124386,
      "user": 0.05322257684210526,
      "system": 0.024741351578947367,
      "min": 0.11959635386,
      "max": 0.15798591386000002,
      "times": [
        0.14199409886,
        0.15114113986,
        0.14623124386,
        0.14987433486,
        0.11959635386,
        0.12505560086,
        0.15427486886,
        0.15798591386000002,
        0.15378923886,
        0.12557221386,
        0.14050106986000002,
        0.13071795786,
        0.13561538786000002,
        0.15124351186,
        0.14262149886,
        0.15025427486,
        0.13337908086,
        0.15106256886,
        0.15637204286
      ]
    }
  ]
}

Scenario: Isolated linker: peer-heavy resolve, hot cache, offline

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.115 ± 0.258 0.825 1.696 1.00
pacquet@main 1.252 ± 0.226 0.962 1.593 1.12 ± 0.33
pnpm@HEAD 4.523 ± 0.279 4.095 5.057 4.06 ± 0.97
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.1148370617022223,
      "stddev": 0.2577640055452791,
      "median": 1.13040921048,
      "user": 1.0922788555555554,
      "system": 0.22802145777777774,
      "min": 0.82452055548,
      "max": 1.6956152694800002,
      "times": [
        0.82452055548,
        1.0743196944800002,
        0.90342224348,
        1.2012333244800002,
        1.13040921048,
        1.1431078594800002,
        1.17339655548,
        1.6956152694800002,
        0.8875088424800001
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.2523525032577778,
      "stddev": 0.22626719999704695,
      "median": 1.27078029548,
      "user": 1.239421411111111,
      "system": 0.24513323555555555,
      "min": 0.96158943748,
      "max": 1.5928324424800002,
      "times": [
        1.06553482148,
        1.5928324424800002,
        1.4153609224800001,
        1.27078029548,
        1.1047832834800002,
        1.03906122648,
        1.2882857164800001,
        0.96158943748,
        1.5329443834800003
      ]
    },
    {
      "command": "pnpm@HEAD",
      "mean": 4.522946656924444,
      "stddev": 0.27869492668678364,
      "median": 4.5762989764799995,
      "user": 6.742607966666666,
      "system": 0.4805244577777778,
      "min": 4.095400822479999,
      "max": 5.05667538948,
      "times": [
        4.095400822479999,
        4.3644813964799996,
        5.05667538948,
        4.69363289748,
        4.625919048479999,
        4.47811253048,
        4.23833143948,
        4.5762989764799995,
        4.577667411479999
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.722 ± 0.194 4.540 5.070 1.33 ± 0.06
pacquet@main 4.538 ± 0.155 4.418 4.838 1.28 ± 0.05
pnpr@HEAD 3.543 ± 0.071 3.484 3.714 1.00
pnpr@main 3.543 ± 0.128 3.465 3.869 1.00 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.72227130738,
      "stddev": 0.1936181545871168,
      "median": 4.64017497768,
      "user": 2.8492147199999995,
      "system": 2.02876758,
      "min": 4.54041676068,
      "max": 5.06956643868,
      "times": [
        4.96781278268,
        4.69147409668,
        4.59906502868,
        4.93347864768,
        5.06956643868,
        4.67269996668,
        4.60764998868,
        4.54041676068,
        4.5912293796800006,
        4.54931998368
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.538312263980001,
      "stddev": 0.15528358676979984,
      "median": 4.483078197679999,
      "user": 1.9880923199999998,
      "system": 1.52231568,
      "min": 4.41827509068,
      "max": 4.8377803656800005,
      "times": [
        4.51378910568,
        4.48034606368,
        4.44854266068,
        4.45804666568,
        4.48581033168,
        4.41827509068,
        4.50264134568,
        4.81570925168,
        4.42218175868,
        4.8377803656800005
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.5426146214800007,
      "stddev": 0.07068928765251281,
      "median": 3.53191934118,
      "user": 1.37934372,
      "system": 1.31113288,
      "min": 3.4844693236800004,
      "max": 3.71400862668,
      "times": [
        3.5202716666800002,
        3.57905061768,
        3.5577235496800004,
        3.4844693236800004,
        3.71400862668,
        3.4860367036800004,
        3.5681053456800003,
        3.5435670156800003,
        3.4873935996800003,
        3.4855197656800003
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.54290555518,
      "stddev": 0.12759753383623976,
      "median": 3.48535743368,
      "user": 1.38999442,
      "system": 1.3067832799999999,
      "min": 3.46516231968,
      "max": 3.8691029566800004,
      "times": [
        3.52116170568,
        3.65729831468,
        3.4730512136800002,
        3.48022207068,
        3.51449933668,
        3.8691029566800004,
        3.47852840968,
        3.4795364276800003,
        3.4904927966800003,
        3.46516231968
      ]
    }
  ]
}

Copilot AI review requested due to automatic review settings August 11, 2026 16:06
@greptile-apps
greptile-apps Bot dismissed their stale review August 11, 2026 16:06

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@qodo-code-review

Copy link
Copy Markdown

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

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

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

🧹 Nitpick comments (1)
pnpm/crates/injected-deps-syncer/src/dir_patcher.rs (1)

24-29: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Correct the file-identity invariant.

Distinct files can have identical bytes. The patcher skips work only when both paths have the same FileId. It does not compare file content.

Proposed fix
-/// A file carries its identity rather than its content, because that is
-/// all a hardlink comparison needs: two paths hold the same bytes
-/// exactly when they are the same file, so an unchanged file costs no
-/// filesystem work.
+/// The patcher treats matching file identities as unchanged. It does not
+/// compare file content. Equal content in distinct files still requires
+/// replacement so the source and target share a hardlink.

As per coding guidelines, comments must document non-obvious invariants and describe current behavior.

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

In `@pnpm/crates/injected-deps-syncer/src/dir_patcher.rs` around lines 24 - 29,
Update the documentation for the InodeMap path value to state that a file stores
its FileId and that unchanged work is skipped only when both paths have the same
FileId; remove the claim that identical bytes or content comparison determine
equality.

Source: Coding guidelines

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

Nitpick comments:
In `@pnpm/crates/injected-deps-syncer/src/dir_patcher.rs`:
- Around line 24-29: Update the documentation for the InodeMap path value to
state that a file stores its FileId and that unchanged work is skipped only when
both paths have the same FileId; remove the claim that identical bytes or
content comparison determine equality.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 00f54fa2-94ed-4048-8985-7722f340d257

📥 Commits

Reviewing files that changed from the base of the PR and between 5ec7004 and da56cfc.

📒 Files selected for processing (3)
  • pnpm/crates/injected-deps-syncer/src/dir_patcher.rs
  • pnpm/crates/injected-deps-syncer/src/dir_patcher/tests.rs
  • pnpm/crates/injected-deps-syncer/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • pnpm/crates/injected-deps-syncer/src/dir_patcher/tests.rs
  • pnpm/crates/injected-deps-syncer/src/lib.rs

@zkochan

zkochan commented Aug 11, 2026

Copy link
Copy Markdown
Member Author

The red Bencher Report is testbed noise, not this PR

Two Bencher runs against the same commit (da56cfc7c4) disagree with each other by more than the regression they flag:

benchmark run 1 run 2
peer-heavy-resolve.hot-cache.offline 414 ms (−43.71%) 825 ms (+11.55%)
fresh-resolve.hot-cache.offline 205 ms (−12.61%) 368 ms (+59.41%)
fresh-restore.hot-cache.hot-store 233 ms (−22.33%) 379 ms (+26.49%)
fresh-install.hot-cache.hot-store 673 ms (+46.01%) 589 ms (+27.65%)
fresh-install.cold-cache.cold-store 2,693 ms (−0.19%) 2,796 ms (+3.67%)
fresh-restore.cold-cache.cold-store 2,348 ms (−4.58%) 2,431 ms (−1.22%)
fresh-restore.cold-cache.cold-store.cold-pnpr 4,439 ms (−2.10%) 4,540 ms (+0.13%)

Identical code, and peer-heavy-resolve swings 2x between the two runs while fresh-resolve moves +80%. Every benchmark over 2.4 s lands within ±4% in both. The instability is confined to the sub-second cases, where the run-to-run spread is far larger than any threshold could distinguish.

The mechanism agrees with the statistics. sync_injected_deps has exactly one call site — run_stages in pnpm run, gated on the script name appearing in syncInjectedDepsAfterScripts. Nothing on the install path reaches it, and these are install benchmarks. The only install-visible change in this PR is one Vec<String> field on Config, which is constructed once per process; it cannot cost 200 ms on a fresh install.

For extra context, peer-heavy-resolve.hot-cache.offline was +45.30% on #13663 — a TypeScript-only diff that could not touch the Rust engine at all — and is −43.71% here. The same benchmark swinging ±45% across unrelated PRs points at the testbed.

Not re-running a third time: two samples on one commit is already the controlled experiment, and another roll would only add a third number to the spread.


Written by an agent (Claude Code, claude-opus-5[1m]).

@zkochan
zkochan merged commit 7a2a480 into main Aug 11, 2026
40 of 41 checks passed
@zkochan
zkochan deleted the pacquet/sync-injected-deps branch August 11, 2026 23:02
zkochan added a commit that referenced this pull request Aug 12, 2026
…acing its parent (#13840)

When a workspace package replaced a directory with a file of the same
name, that path landed in `modified` while the directory's contents
landed in `removed`. The two ran concurrently, so a removal could be
issued against a path whose parent had already been relinked as a file
and come back ENOTDIR, which removeRecursive rethrows — aborting
syncInjectedDepsAfterScripts partway through.

Await the removals before applying any change. Nothing a change needs
can be removed: a path absent from the source has all its children
absent too, so no removal is ever an ancestor of an added or modified
path.

The Rust CLI reached the same ordering in #13834, where a
sequential patcher made this a deterministic failure rather than a race.
zkochan added a commit that referenced this pull request Aug 12, 2026
…ts inode (#13847)

An inode number is only unique within one filesystem, so comparing bare
inode numbers lets an unrelated file on another device collide with the
one being synced. The diff then reads the two as the same file, skips
the replacement, and leaves that path stale in the injected copy.

Carry the device alongside it, as a `<device>:<inode>` string. The
identity stays a primitive, so the comparison the inode map is built
around is still a `===` rather than a structural one; `dev` comes from
the same stat that already supplied `ino`, so this costs no extra
syscall.

Nothing changes where injection works at all: a hardlink cannot cross a
filesystem, so the device is equal on both sides and the comparison is
the one it was before. It only affects the broken cross-device case,
which now reaches a clear EXDEV from `fs.link` instead of silently
skipping the file.

Matches pacquet, which took the same identity in #13834.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pacquet reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants