Skip to content

fix(resolving-deps-resolver): stop re-walking a recorded subtree - #13575

Merged
zkochan merged 7 commits into
mainfrom
fix-13574-peer-memory
Aug 2, 2026
Merged

zkochan merged 7 commits into
mainfrom
fix-13574-peer-memory

Conversation

@zkochan

@zkochan zkochan commented Aug 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #13574: a dependency chain whose packages carry peer dependencies
made resolution cost grow exponentially with the depth of the chain. One project
with one dependency, over a graph of ~500 packages, could not finish inside
6 GB. The TypeScript CLI resolves the same input in 1.06s / 263 MB.

The mechanism

Winning the children-ownership claim is what licenses an occurrence to walk a
package's manifest children — a loser stays lazy and expands from the recorded
children_by_id. Concurrent occurrences of the same package take turns winning
that claim, and each turn re-walked the entire subtree, leaving its
occurrence nodes in the shared tree forever. Those nodes then issue claims of
their own, which is the multiplication.

Counters on the fixture, single importer, single dependency — note that the
number of claims won dwarfs the package count, while at most one occurrence
per package can be the final owner:

chain depth packages occurrence nodes claims won of which context-changing
12 200 14,955 7,304 200
14 240 111,295 49,899 240
15 260 114,607 56,298 260

Every winning claim beyond the package count re-walked a subtree that resolves
identically. The memory is all in dependencies_tree: every peer-walker
structure stays under 1,000 entries, and the tree is fully populated before
the peer pass starts.

The change

Winning the claim only means this occurrence outranks the one that recorded the
children, not that the children differ. When the displaced owner resolved them
under conditions this occurrence would reproduce, expand from the recorded
children instead — exactly what a losing occurrence does.

"Conditions this occurrence would reproduce" is a three-part test, and each part
is load-bearing:

Packages whose child specifiers pass through the importer's catalogs are
excluded too, being a property of the resolving importer rather than of the
package id.

Result

chain depth before after
15 198,023 occurrence nodes, 278 MB, 1.00s 3,211 nodes, 62 MB, 0.10s
20 4,463 MB, 17.5s 71 MB, 0.17s
24 did not finish in 180s under 6 GB 78 MB, 0.20s
26 did not finish 78 MB, 0.19s

Output is unchanged: the emitted lockfile is byte-identical before and after,
and byte-identical to the one the TypeScript CLI writes for the same input.

On the 114-project Bit workspace from pnpm/tasks#16 the change is neutral
(12.30–13.03s / 7.5–7.9 GB on main; 11.97–13.18s / 7.5–8.0 GB here) — that
workspace is wide rather than deep, so it barely takes the re-walk path. Its
~7.5 GB peak is a separate problem, and its run-to-run lockfile instability is
too: two consecutive runs of main on it still differ by 9,194 lines, so
#13567 is not fully closed. I will report that separately.

On the missing regression test

I could not build one that fails without this fix, and I would rather say so
than add a test that passes either way. The blowup needs occurrences of one
package to race for the claim; an in-process resolve_workspace test does not
produce that, at any shape I tried — a yielding resolver, a multi-threaded
runtime, and the CLI fixture's exact dimensions (12 layers x 20 packages, 4
children, 30 providers, 8 peers each) all give the same 631 occurrence nodes
with and without the fix, while the CLI on that same shape gives 23,479 without
and ~2,600 with.

The guard that would work drives the real CLI: the multi-importer hoist-heavy
scenario I have prototyped for the integrated benchmark, sized below this
blowup. I will propose it separately, with the A/B that shows it discriminates.

Squash Commit Body

Winning the children-ownership claim is what licenses an occurrence to
walk a package's manifest children. Concurrent occurrences of one
package take turns winning it — each turn re-walked the whole subtree
and left its occurrence nodes in the shared tree — so a chain of
peer-carrying packages expanded exponentially with its depth. One
project with one such dependency, over a graph of ~500 packages, could
not finish inside 6 GB; at depth 22 it peaked at 4.1 GB. The TypeScript
CLI resolves the same input in 1.06s and 263 MB.

Winning the claim only means this occurrence outranks the one that
recorded the children, not that the children differ. When the displaced
owner resolved them under conditions this occurrence would reproduce —
the same peer-shadowed set, the same update policy, the same
prior-lockfile key — expand from the recorded children instead, exactly
as a losing occurrence does. Each term of that test is load-bearing: an
update-active occurrence re-resolves what a keep-all one reused, and an
occurrence pinned by a different snapshot key resolves different
children. Packages whose child specifiers pass through the importer's
catalogs are excluded as well, being a property of the resolving
importer rather than of the package id.

On the generated chain from the issue, one project and one dependency,
depth 15 falls from 198,023 occurrence nodes / 278 MB / 1.00s to 3,211
nodes / 62 MB / 0.10s, and depths 24 and 26 — which previously did not
finish inside 6 GB — complete in 78 MB and 0.2s. The emitted lockfile is
byte-identical before and after, and byte-identical to the TypeScript
CLI's for the same input.

Closes https://github.com/pnpm/pnpm/issues/13574.

Checklist

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

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


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

Summary by CodeRabbit

  • Performance Improvements

    • Reduced memory growth when resolving deep dependency chains.
    • Avoided unnecessary reprocessing by reusing compatible dependency results.
    • Improved dependency resolution efficiency for complex workspaces.
  • Reliability Improvements

    • Preserved correct handling of peer dependencies, lockfile state, updates, and catalog-based resolutions.
    • Maintained consistent dependency trees across snapshots and preferred-version resolution.
    • Improved fallback behavior when previously resolved results cannot be reused.

Winning the children-ownership claim is what licenses an occurrence to
walk a package's manifest children. Concurrent occurrences of one
package take turns winning it — each turn re-walked the whole subtree
and left its occurrence nodes in the shared tree — so a chain of
peer-carrying packages expanded exponentially with its depth. One
project with one such dependency, over a graph of ~500 packages, could
not finish inside 6 GB; at depth 22 it peaked at 4.1 GB. The
TypeScript CLI resolves the same input in 1.06s and 263 MB.

Winning the claim only means this occurrence outranks the one that
recorded the children, not that the children differ. When the displaced
owner resolved them under conditions this occurrence would reproduce —
the same peer-shadowed set, the same update policy, the same
prior-lockfile key — expand from the recorded children instead, exactly
as a losing occurrence does. The three-part test is what keeps the reuse
sound: an update-active occurrence re-resolves what a keep-all one
reused, an occurrence pinned by a different snapshot key resolves
different children, and a different shadow set drops different
dependencies. Packages whose child specifiers pass through the
importer's catalogs are excluded as well, being a property of the
resolving importer rather than of the package id.

Measured on the generated chain from
#13574, one project, one dependency:

| chain depth | before | after |
|---|---|---|
| 15 | 198,023 occurrence nodes, 278 MB, 1.00s | 3,211 nodes, 62 MB, 0.10s |
| 20 | 4,463 MB, 17.5s | 71 MB, 0.17s |
| 24 | did not finish in 180s under 6 GB | 78 MB, 0.20s |
| 26 | did not finish | 78 MB, 0.19s |

The emitted lockfile is byte-identical before and after, and byte-identical
to the one the TypeScript CLI writes for the same input.

Closes #13574.
Copilot AI review requested due to automatic review settings August 1, 2026 23:05

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

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

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

Use the following commands to manage reviews:

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

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: edc59553-906a-418c-b1c5-99372c924866

📥 Commits

Reviewing files that changed from the base of the PR and between 0fd2424 and 4caad19.

📒 Files selected for processing (1)
  • pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx/tests.rs

📝 Walkthrough

Walkthrough

The resolver records the context used to produce dependency children. Compatible recorded children are reused during ownership claims, while catalog-dependent workspace file resolutions continue with fresh subtree walks. A changeset documents bounded peer-chain resolution.

Changes

Peer-chain subtree reuse

Layer / File(s) Summary
Ownership context and reuse eligibility
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs, pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx/tests.rs
RecordedChildrenContext tracks peer-shadowed dependencies, prior lockfile keys, and update scope. WorkspaceTreeCtx stores and compares this context. Snapshot, traversal, conversion, ownership, and matching tests use recorded child entries.
Lazy subtree reuse in dependency walking
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs, pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs, .changeset/bounded-peer-chain-resolution.md
Ownership claims reuse compatible recorded children without re-walking the subtree. Catalog-backed workspace file resolutions use the fresh-walk path. Reused nodes record their resolution context and fall back to lazy children when publication fails. The changeset documents bounded peer-chain resolution.

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

Sequence Diagram(s)

sequenceDiagram
  participant walk_node_children
  participant WorkspaceTreeCtx
  participant recorded_children
  walk_node_children->>WorkspaceTreeCtx: build peer, lockfile, and update context
  WorkspaceTreeCtx->>recorded_children: compare recorded child context
  recorded_children-->>WorkspaceTreeCtx: return match status
  WorkspaceTreeCtx-->>walk_node_children: reuse matching children lazily
  walk_node_children->>WorkspaceTreeCtx: record children for the current owner
Loading

Assessment against linked issues

Objective Addressed Explanation
Reduce exponential peer-carrying dependency-chain expansion and avoid out-of-memory resolution failures [#13574] ✅

Possibly related PRs

  • pnpm/pnpm#13562 — It modifies the same resolver components and introduces the subtree-reuse behavior extended here.
  • pnpm/pnpm#13506 — It addresses resolver subtree reuse and ownership handovers using peer-shadowing context.
  • pnpm/pnpm#13491 — It modifies WorkspaceTreeCtx ownership and recorded dependency subtree handling.

Suggested labels: product: pacquet

Suggested reviewers: copilot

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-13574-peer-memory

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

❤️ Share

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

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Fix dependency tree resolver exponential growth by reusing recorded subtrees

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Avoid re-walking already-recorded dependency subtrees when claim winner reproduces same context.
• Add reuse guard conditions (peer shadow set, update policy, prior-lockfile key) to keep reuse
 correct.
• Document the memory/perf fix via a changeset entry.
Diagram

graph TD
A["walk_node_children()"] --> B["claim_children_owner()"] --> C{Owns children?}
C -- "no" --> L["Reuse recorded children (lazy)"] --> G[("children_by_id")]
C -- "yes" --> D{"Recorded children reusable?"}
D -- "yes" --> E{"Recorded exist & not catalogs?"}
E -- "yes" --> L
E -- "no" --> F["Walk manifest children"] --> G
D -- "no" --> F
B --> H[("children_owner_by_id")]

subgraph Legend
  direction LR
  _p["Process"] ~~~ _d{"Decision"} ~~~ _db[("Shared map")]
end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Per-package async lock + await recorded children
  • ➕ Eliminates redundant subtree walks by forcing all concurrent occurrences to share one walk result
  • ➕ Makes reuse implicit (wait for completion rather than re-checking recorded presence)
  • ➖ Reduces parallelism and can increase tail latency in wide graphs
  • ➖ Adds deadlock/cancellation complexity in an async resolver
2. Generalized children cache keyed by full resolution context
  • ➕ Explicitly memoizes children resolution across occurrences and importers
  • ➕ Scales to more context dimensions if needed in the future
  • ➖ Higher memory footprint and cache invalidation complexity
  • ➖ More invasive change than leveraging the existing recorded tree

Recommendation: The PR’s approach is the best fit: it leverages existing recorded children and adds a tight, correctness-preserving reuse guard (peer-shadow set + update policy + prior-lockfile key, plus catalog exclusion). This directly targets the exponential blow-up mechanism with minimal added machinery and avoids introducing global locks or heavyweight caching.

Files changed (5) +82 / -8

Bug fix (3) +76 / -8
reuse.rsThread prior-lockfile key into children ownership claims +2/-1

Thread prior-lockfile key into children ownership claims

• Updates the call site of 'claim_children_owner' to pass the current wanted/prior key so ownership and reuse decisions can account for snapshot pinning context.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs

walk.rsReuse recorded children on safe-winning claims to avoid subtree re-walks +31/-3

Reuse recorded children on safe-winning claims to avoid subtree re-walks

• Adds a fast-path where a winning occurrence expands lazily from already-recorded children when the displaced owner’s resolution context is reproducible and children were recorded. Introduces a catalog-resolution exclusion and wires 'prior_key' into the ownership-claim inputs.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs

workspace_ctx.rsTrack prior-lockfile key and compute 'recorded_children_reusable' for claims +43/-4

Track prior-lockfile key and compute 'recorded_children_reusable' for claims

• Extends 'ChildrenOwnerEntry' to store the owner’s prior-lockfile key and extends 'ChildrenOwnerClaim' with 'recorded_children_reusable'. Updates 'claim_children_owner' to compute reuse safety based on peer-shadow match plus same update policy and same prior key, and adds 'has_recorded_children' to detect whether reuse is possible yet.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs

Tests (1) +1 / -0
tests.rsUpdate children owner test fixtures for new prior_key field +1/-0

Update children owner test fixtures for new prior_key field

• Adjusts test helpers/fixtures constructing 'ChildrenOwnerEntry' to populate the new 'prior_key' field, keeping workspace context tests compiling and valid.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx/tests.rs

Documentation (1) +5 / -0
bounded-peer-chain-resolution.mdAdd changeset documenting bounded memory for peer dependency chains +5/-0

Add changeset documenting bounded memory for peer dependency chains

• Adds a patch changeset entry describing the fix for exponential dependency resolution growth in peer-carrying chains, including the observed memory improvement.

.changeset/bounded-peer-chain-resolution.md

@greptile-apps

greptile-apps Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge because no eligible blocking failure or outstanding prior finding remains.

No blocking failure remains.

Reviews (5): Last reviewed commit: "test(resolving-deps-resolver): cover the..." | Re-trigger Greptile

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

Inline comments:
In
`@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs`:
- Around line 1145-1174: The children_context_unchanged calculation in the
workspace child-ownership flow must include the complete resolution context, not
only peer_shadowed. Require both peer_shadowed equality and
same_resolution_context to be true, preserving peer-shadowed,
owner.update_active, and prior_key semantics; add coverage for changed prior
keys and update policies.
- Around line 1177-1182: Bind each recorded children entry in workspace_ctx.rs
to the owning context or an ownership-generation token, and update
has_recorded_children to validate that identity rather than merely checking
presence. In walk.rs, create TreeChildren::Lazy only when the recorded entry
matches children_owner.owner; preserve lockfile compatibility and
prior-lockfile-key semantics, and add a deterministic test covering the
ownership handover interleaving. The workspace_ctx.rs anchor requires the
storage and validation change; the walk.rs sibling requires the matching-owner
check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 10b532cc-9b66-4487-8979-a0ddbae62997

📥 Commits

Reviewing files that changed from the base of the PR and between cc9e938 and f095301.

📒 Files selected for processing (5)
  • .changeset/bounded-peer-chain-resolution.md
  • pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx/tests.rs

@github-actions

github-actions Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     10.5±0.19ms    35.7 MB/sec    1.00     10.5±0.20ms    35.7 MB/sec
packument/parse                                  1.00     36.3±0.73µs  1826.3 MB/sec    1.01     36.6±0.62µs  1813.0 MB/sec
tarball/download_dependency                      1.00      2.8±0.10ms  1564.5 KB/sec    1.00      2.8±0.09ms  1566.2 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.00    161.3±1.06ms 99.2 KElem/sec    1.01    162.7±1.65ms 98.3 KElem/sec

@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Action required

1. Missing reuse context record ✓ Resolved 🐞 Bug ➹ Performance
Description
The lockfile-reuse path writes workspace.children_by_id without recording
children_context_by_id, so recorded_children_match() returns false and owned occurrences re-walk
children instead of reusing the recorded subtree. This disables the PR’s new performance guard for
lockfile-reused subtrees and can materially increase runtime/memory on lockfile-heavy installs.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[R570-572]

+    } else if !resolves_children_through_catalogs(&result)
+        && recorded_children_match(ctx, &id, &children_context)
+    {
Relevance

●●● Strong

Looks like concrete missed-record bug disabling intended reuse guard; such cache/reuse correctness
fixes are typically accepted.

PR-#12113
PR-#11906

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
walk_node_children skips re-walking only when recorded_children_match() is true, but that
function checks only children_context_by_id. The repo’s lockfile-reuse code path writes
children_by_id without ever writing the corresponding context entry, so the match is guaranteed to
fail for those ids and the new reuse path won’t trigger.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[543-585]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[1190-1213]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs[636-654]

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

### Issue description
`recorded_children_match()` consults `children_context_by_id`, but only the manifest-walk path records that context. The lockfile-reuse path also populates `children_by_id` and currently does **not** call `record_children_context`, so the reuse gate can never succeed for those entries.

### Issue Context
This PR’s optimization relies on `recorded_children_match(ctx, pkg_id, context)` becoming true once children are recorded; otherwise an owning occurrence will keep re-walking instead of expanding from the recorded `children_by_id`.

### Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs[636-654]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[751-753]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[1190-1213]

### Suggested fix
- When `reuse.rs` inserts into `ctx.workspace.children_by_id`, also compute and call `record_children_context(ctx, &id, ...)` with the same context fields used by `walk_node_children` (`peer_shadowed`, `prior_key`, `update_active`).
- Consider centralizing `children_by_id` + context writes into a single helper to keep the “never disagree” invariant true.

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


2. Overlay omitted from reuse 🐞 Bug ≡ Correctness
Description
walk_node_children now lets a winning claim_children_owner reuse children_by_id (stay Lazy)
when recorded_children_reusable is true, but that reuse test ignores the preferred-versions
overlay that can legitimately change which versions are picked for the same child ranges. This can
make the "deterministically better" owner inherit children resolved under a different overlay,
producing a wrong/resolution-order-dependent graph and lockfile.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[R565-580]

+    } else if children_owner.recorded_children_reusable
+        && !resolves_children_through_catalogs(&result)
+        && has_recorded_children(ctx, &id)
+    {
+        // A winning claim only means this occurrence outranks the one
+        // that recorded the children — not that the children differ.
+        // Concurrent occurrences of the same package take turns
+        // outranking each other, and each turn used to re-walk the whole
+        // subtree and leave its occurrence nodes behind, which is what
+        // made a peer-carrying chain expand exponentially with depth
+        // (https://github.com/pnpm/pnpm/issues/13574). Expand from the
+        // recorded children instead, exactly as a losing occurrence
+        // does.
+        crate::resolved_tree::TreeChildren::Lazy {
+            parent_ids: AncestorIds::from(Arc::clone(&parent_ancestors)),
+        }
Relevance

●● Moderate

Subtle resolver-context correctness concern; no close precedent on preferred-overlay being part of
recorded-children reuse gating.

PR-#13432
PR-#13196

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The resolver explicitly treats preferred-version overlays as a component of resolution context: they
are included in the per-wanted cache key because "the same range can legitimately pick different
versions under levels that resolved different siblings", and the npm resolver merges overlay
versions into version selectors used for picking. The new reuse path only checks
peer-shadow/update/prior-key, so it can reuse children resolved under a different overlay without
re-walking to pick versions under the winning occurrence’s overlay.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[556-581]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[1092-1175]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[261-316]
pnpm/crates/resolving-npm-resolver/src/preferred_overlay.rs[17-31]

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

### Issue description
The new optimization reuses recorded children when a later occurrence wins the children-ownership claim but appears to resolve under the same context as the displaced owner. However, the reuse predicate (`recorded_children_reusable`) only considers peer-shadowed set, update policy, and prior-lockfile key, while child resolution is also influenced by the preferred-versions overlay (used by the npm picker). Two occurrences of the same `pkgIdWithPatchHash` can see different overlays (different sibling levels / importer waves), so reusing recorded children can yield a graph resolved under the displaced owner’s overlay rather than the winning owner’s overlay.

### Issue Context
- `walk_node_children` now skips re-walking and stays `TreeChildren::Lazy` based on `recorded_children_reusable` + `has_recorded_children`.
- Preferred-version overlays are explicitly threaded into resolution and can change the picker’s selector set.

### Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[561-627]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[1092-1183]
- pnpm/crates/resolving-npm-resolver/src/preferred_overlay.rs[17-31]

### Suggested fix directions (pick one)
1. **Track an overlay identity for recorded children**: when recording `children_by_id` for a package, also record a small, comparable “overlay signature” representing the overlay that was in effect for resolving that package’s children; require the signature to match before treating recorded children as reusable.
2. **Conservative disablement**: if you can’t cheaply/robustly represent the overlay context, disable the new reuse path unless you can prove the overlay cannot affect this package’s child resolution (e.g., only exact/pinned child specifiers).

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



Remediation recommended

3. Orphaned walked subtrees 🐞 Bug ➹ Performance ⭐ New
Description
When an occurrence starts walking as the current owner but loses ownership before publishing, it can
still resolve/insert the entire descendant subtree and then return TreeChildren::Lazy when
record_children() rejects the publish. Those descendant occurrence nodes remain allocated in the
shared dependencies_tree but become unreachable from this parent occurrence, increasing peak
memory/CPU under ownership races.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[R750-756]

+            if record_children(ctx, &id, &children_owner.owner, by_id, children_context()) {
+                crate::resolved_tree::TreeChildren::Realized(realized)
+            } else {
+                crate::resolved_tree::TreeChildren::Lazy {
+                    parent_ids: AncestorIds::from(Arc::clone(&parent_ancestors)),
+                }
+            }
Relevance

●● Moderate

Team fixes reachability/ownership race issues, but this requires nontrivial rollback/GC design;
unclear they’ll take now.

PR-#13545
PR-#13491

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The code walks/resolves child subtrees before attempting to publish children; if publishing fails
due to ownership change, the parent is set back to Lazy, so it won’t reference the realized NodeIds
created by that walk, while insertions into the shared tree persist for the remainder of the run.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[715-775]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[1219-1244]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[1281-1310]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs[637-670]

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

### Issue description
`walk_node_children()` may fully resolve descendants, then switch the parent back to `TreeChildren::Lazy` when `record_children()` returns `false` (ownership changed). This keeps the walk’s newly created descendant occurrence nodes in the shared `dependencies_tree` for the rest of the resolution even though the parent no longer references them, increasing peak memory and wasted CPU in contention scenarios.

### Issue Context
This PR intentionally makes a losing publish keep the parent node lazy so it expands from the standing owner’s recorded children. However, the losing walk’s already-materialized subtree is not cleaned up or avoided.

### Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[750-756]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs[653-670]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[1219-1243]

### Suggested fix direction
Implement one of:
1) **Avoid doing phase-2 recursion when ownership has lapsed**: re-check ownership before starting the expensive recursive walk of grandchildren; if ownership is no longer current, return `Lazy` without walking descendants.
2) **Rollback on failed publish**: track node_ids inserted by this walk (including descendants) and remove them from `dependencies_tree`, `nodes_by_pkg_id`, and `node_parent_ids_by_id` if `record_children()` returns `false`.
3) **Defer insertion/commit**: structure the walk so occurrence-node insertion happens only after a successful publish/commit decision (harder but avoids rollback complexity).

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


4. Eager prior_key cloning ✓ Resolved 🐞 Bug ➹ Performance
Description
walk_node_children constructs RecordedChildrenContext (cloning prior_key) before branching, so
even linked nodes and non-owner occurrences pay the clone/copy cost when the context is never used.
The context is then cloned again when recording, adding avoidable per-node overhead in the resolver
hot path.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[R556-560]

+    let children_context = RecordedChildrenContext {
+        peer_shadowed: Arc::clone(&children_owner.peer_shadowed),
+        prior_key: prior_key.clone(),
+        update_active: !matches!(ctx.update_reuse_scope(), super::UpdateReuseScope::All),
+    };
Relevance

●●● Strong

Team often accepts hot-path micro-opts avoiding eager clones/allocs in resolver code.

PR-#13510
PR-#12320

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new code builds children_context immediately after destructuring PendingNode, before any
early-return branches (link / non-owner) are evaluated, and then clones it again at record time.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[543-585]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[732-754]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[124-144]

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

### Issue description
`RecordedChildrenContext` is built unconditionally at the top of `walk_node_children`, even on paths that return `TreeChildren::Realized` for links or `TreeChildren::Lazy` for non-owners. This eagerly clones `prior_key` and later clones the full context again when recording.

### Issue Context
This function is on the critical path for large dependency graphs; small per-node overheads can add up, especially when many nodes come from lockfile reuse where `prior_key` is frequently `Some(...)`.

### Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[556-560]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[570-585]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[751-753]

### Suggested fix
- Construct `RecordedChildrenContext` only inside the `children_owner.owns_children` branch where it’s actually needed (for `recorded_children_match` and/or for recording).
- Avoid the extra `children_context.clone()` on record by moving the value into `record_children_context(...)` when it’s no longer needed afterward (and only cloning when you still need it for subsequent comparisons).

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


5. Comment says used to ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
A newly added inline comment describes historical behavior using used to, rather than documenting
the current behavior/contract. This increases maintenance risk because it can become stale and is
disallowed by the comment policy.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[R569-577]

+        // A winning claim only means this occurrence outranks the one
+        // that recorded the children — not that the children differ.
+        // Concurrent occurrences of the same package take turns
+        // outranking each other, and each turn used to re-walk the whole
+        // subtree and leave its occurrence nodes behind, which is what
+        // made a peer-carrying chain expand exponentially with depth
+        // (https://github.com/pnpm/pnpm/issues/13574). Expand from the
+        // recorded children instead, exactly as a losing occurrence
+        // does.
Relevance

●●● Strong

Team often accepts rewrites removing historical phrasing in comments/rustdoc to match comment
policy.

PR-#13343
PR-#13572

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 772199 forbids comments that describe historical implementations (e.g., using
phrasing like used to). The added comment explicitly says `each turn used to re-walk the whole
subtree`, which is historical phrasing in new code comments.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[569-577]

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 added comment contains historical phrasing (`used to`) and describes prior implementation details instead of the current behavior.

## Issue Context
Comments must describe current behavior/constraints. If rationale is needed, phrase it in terms of current invariants and why the current approach is correct.

## Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[569-577]

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



Informational

6. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset declares only pacquet and omits the required pnpm package entry, which can
lead to incorrect release/versioning behavior. This violates the changeset policy requiring an
explicit pnpm bump type.
Code

.changeset/bounded-peer-chain-resolution.md[R1-3]

+---
+"pacquet": patch
+---
Relevance

● Weak

Same “add pnpm entry” changeset suggestion repeatedly rejected for pacquet-only front-matter in
recent PRs.

PR-#13549
PR-#13406
PR-#13350

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires changesets to include an explicit pnpm entry with a valid bump
type. The added changeset front-matter includes only "pacquet": patch and does not list pnpm.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/bounded-peer-chain-resolution.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 changeset `.changeset/bounded-peer-chain-resolution.md` is missing a required `pnpm` entry.

## Issue Context
Compliance requires each new/modified changeset to explicitly declare the `pnpm` package and a valid bump type (`patch`/`minor`/`major`).

## Fix Focus Areas
- .changeset/bounded-peer-chain-resolution.md[1-3]

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


Grey Divider

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

Previous review results

Review updated until commit 4caad19

Results up to commit f095301 ⚖️ Balanced


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


Action required
1. Overlay omitted from reuse 🐞 Bug ≡ Correctness
Description
walk_node_children now lets a winning claim_children_owner reuse children_by_id (stay Lazy)
when recorded_children_reusable is true, but that reuse test ignores the preferred-versions
overlay that can legitimately change which versions are picked for the same child ranges. This can
make the "deterministically better" owner inherit children resolved under a different overlay,
producing a wrong/resolution-order-dependent graph and lockfile.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[R565-580]

+    } else if children_owner.recorded_children_reusable
+        && !resolves_children_through_catalogs(&result)
+        && has_recorded_children(ctx, &id)
+    {
+        // A winning claim only means this occurrence outranks the one
+        // that recorded the children — not that the children differ.
+        // Concurrent occurrences of the same package take turns
+        // outranking each other, and each turn used to re-walk the whole
+        // subtree and leave its occurrence nodes behind, which is what
+        // made a peer-carrying chain expand exponentially with depth
+        // (https://github.com/pnpm/pnpm/issues/13574). Expand from the
+        // recorded children instead, exactly as a losing occurrence
+        // does.
+        crate::resolved_tree::TreeChildren::Lazy {
+            parent_ids: AncestorIds::from(Arc::clone(&parent_ancestors)),
+        }
Relevance

●● Moderate

Subtle resolver-context correctness concern; no close precedent on preferred-overlay being part of
recorded-children reuse gating.

PR-#13432
PR-#13196

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The resolver explicitly treats preferred-version overlays as a component of resolution context: they
are included in the per-wanted cache key because "the same range can legitimately pick different
versions under levels that resolved different siblings", and the npm resolver merges overlay
versions into version selectors used for picking. The new reuse path only checks
peer-shadow/update/prior-key, so it can reuse children resolved under a different overlay without
re-walking to pick versions under the winning occurrence’s overlay.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[556-581]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[1092-1175]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[261-316]
pnpm/crates/resolving-npm-resolver/src/preferred_overlay.rs[17-31]

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

### Issue description
The new optimization reuses recorded children when a later occurrence wins the children-ownership claim but appears to resolve under the same context as the displaced owner. However, the reuse predicate (`recorded_children_reusable`) only considers peer-shadowed set, update policy, and prior-lockfile key, while child resolution is also influenced by the preferred-versions overlay (used by the npm picker). Two occurrences of the same `pkgIdWithPatchHash` can see different overlays (different sibling levels / importer waves), so reusing recorded children can yield a graph resolved under the displaced owner’s overlay rather than the winning owner’s overlay.

### Issue Context
- `walk_node_children` now skips re-walking and stays `TreeChildren::Lazy` based on `recorded_children_reusable` + `has_recorded_children`.
- Preferred-version overlays are explicitly threaded into resolution and can change the picker’s selector set.

### Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[561-627]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[1092-1183]
- pnpm/crates/resolving-npm-resolver/src/preferred_overlay.rs[17-31]

### Suggested fix directions (pick one)
1. **Track an overlay identity for recorded children**: when recording `children_by_id` for a package, also record a small, comparable “overlay signature” representing the overlay that was in effect for resolving that package’s children; require the signature to match before treating recorded children as reusable.
2. **Conservative disablement**: if you can’t cheaply/robustly represent the overlay context, disable the new reuse path unless you can prove the overlay cannot affect this package’s child resolution (e.g., only exact/pinned child specifiers).

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



Remediation recommended
2. Comment says used to ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
A newly added inline comment describes historical behavior using used to, rather than documenting
the current behavior/contract. This increases maintenance risk because it can become stale and is
disallowed by the comment policy.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[R569-577]

+        // A winning claim only means this occurrence outranks the one
+        // that recorded the children — not that the children differ.
+        // Concurrent occurrences of the same package take turns
+        // outranking each other, and each turn used to re-walk the whole
+        // subtree and leave its occurrence nodes behind, which is what
+        // made a peer-carrying chain expand exponentially with depth
+        // (https://github.com/pnpm/pnpm/issues/13574). Expand from the
+        // recorded children instead, exactly as a losing occurrence
+        // does.
Relevance

●●● Strong

Team often accepts rewrites removing historical phrasing in comments/rustdoc to match comment
policy.

PR-#13343
PR-#13572

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 772199 forbids comments that describe historical implementations (e.g., using
phrasing like used to). The added comment explicitly says `each turn used to re-walk the whole
subtree`, which is historical phrasing in new code comments.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[569-577]

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 added comment contains historical phrasing (`used to`) and describes prior implementation details instead of the current behavior.

## Issue Context
Comments must describe current behavior/constraints. If rationale is needed, phrase it in terms of current invariants and why the current approach is correct.

## Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[569-577]

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



Informational
3. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset declares only pacquet and omits the required pnpm package entry, which can
lead to incorrect release/versioning behavior. This violates the changeset policy requiring an
explicit pnpm bump type.
Code

.changeset/bounded-peer-chain-resolution.md[R1-3]

+---
+"pacquet": patch
+---
Relevance

● Weak

Same “add pnpm entry” changeset suggestion repeatedly rejected for pacquet-only front-matter in
recent PRs.

PR-#13549
PR-#13406
PR-#13350

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires changesets to include an explicit pnpm entry with a valid bump
type. The added changeset front-matter includes only "pacquet": patch and does not list pnpm.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/bounded-peer-chain-resolution.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 changeset `.changeset/bounded-peer-chain-resolution.md` is missing a required `pnpm` entry.

## Issue Context
Compliance requires each new/modified changeset to explicitly declare the `pnpm` package and a valid bump type (`patch`/`minor`/`major`).

## Fix Focus Areas
- .changeset/bounded-peer-chain-resolution.md[1-3]

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


Results up to commit 8d46c1c ⚖️ Balanced


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


Action required
1. Missing reuse context record ✓ Resolved 🐞 Bug ➹ Performance
Description
The lockfile-reuse path writes workspace.children_by_id without recording
children_context_by_id, so recorded_children_match() returns false and owned occurrences re-walk
children instead of reusing the recorded subtree. This disables the PR’s new performance guard for
lockfile-reused subtrees and can materially increase runtime/memory on lockfile-heavy installs.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[R570-572]

+    } else if !resolves_children_through_catalogs(&result)
+        && recorded_children_match(ctx, &id, &children_context)
+    {
Relevance

●●● Strong

Looks like concrete missed-record bug disabling intended reuse guard; such cache/reuse correctness
fixes are typically accepted.

PR-#12113
PR-#11906

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
walk_node_children skips re-walking only when recorded_children_match() is true, but that
function checks only children_context_by_id. The repo’s lockfile-reuse code path writes
children_by_id without ever writing the corresponding context entry, so the match is guaranteed to
fail for those ids and the new reuse path won’t trigger.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[543-585]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[1190-1213]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs[636-654]

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

### Issue description
`recorded_children_match()` consults `children_context_by_id`, but only the manifest-walk path records that context. The lockfile-reuse path also populates `children_by_id` and currently does **not** call `record_children_context`, so the reuse gate can never succeed for those entries.

### Issue Context
This PR’s optimization relies on `recorded_children_match(ctx, pkg_id, context)` becoming true once children are recorded; otherwise an owning occurrence will keep re-walking instead of expanding from the recorded `children_by_id`.

### Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs[636-654]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[751-753]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[1190-1213]

### Suggested fix
- When `reuse.rs` inserts into `ctx.workspace.children_by_id`, also compute and call `record_children_context(ctx, &id, ...)` with the same context fields used by `walk_node_children` (`peer_shadowed`, `prior_key`, `update_active`).
- Consider centralizing `children_by_id` + context writes into a single helper to keep the “never disagree” invariant true.

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



Remediation recommended
2. Eager prior_key cloning ✓ Resolved 🐞 Bug ➹ Performance
Description
walk_node_children constructs RecordedChildrenContext (cloning prior_key) before branching, so
even linked nodes and non-owner occurrences pay the clone/copy cost when the context is never used.
The context is then cloned again when recording, adding avoidable per-node overhead in the resolver
hot path.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[R556-560]

+    let children_context = RecordedChildrenContext {
+        peer_shadowed: Arc::clone(&children_owner.peer_shadowed),
+        prior_key: prior_key.clone(),
+        update_active: !matches!(ctx.update_reuse_scope(), super::UpdateReuseScope::All),
+    };
Relevance

●●● Strong

Team often accepts hot-path micro-opts avoiding eager clones/allocs in resolver code.

PR-#13510
PR-#12320

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new code builds children_context immediately after destructuring PendingNode, before any
early-return branches (link / non-owner) are evaluated, and then clones it again at record time.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[543-585]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[732-754]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[124-144]

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

### Issue description
`RecordedChildrenContext` is built unconditionally at the top of `walk_node_children`, even on paths that return `TreeChildren::Realized` for links or `TreeChildren::Lazy` for non-owners. This eagerly clones `prior_key` and later clones the full context again when recording.

### Issue Context
This function is on the critical path for large dependency graphs; small per-node overheads can add up, especially when many nodes come from lockfile reuse where `prior_key` is frequently `Some(...)`.

### Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[556-560]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[570-585]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[751-753]

### Suggested fix
- Construct `RecordedChildrenContext` only inside the `children_owner.owns_children` branch where it’s actually needed (for `recorded_children_match` and/or for recording).
- Avoid the extra `children_context.clone()` on record by moving the value into `record_children_context(...)` when it’s no longer needed afterward (and only cloning when you still need it for subsequent comparisons).

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


Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

No code suggestions found for the PR.

@codecov-commenter

codecov-commenter commented Aug 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.25000% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.99%. Comparing base (cc9e938) to head (4caad19).

Files with missing lines Patch % Lines
...olver/src/resolve_dependency_tree/workspace_ctx.rs 89.36% 5 Missing ⚠️
...deps-resolver/src/resolve_dependency_tree/reuse.rs 76.92% 3 Missing ⚠️
...-deps-resolver/src/resolve_dependency_tree/walk.rs 85.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   pnpm/pnpm#13575   +/-   ##
=======================================
  Coverage   87.98%   87.99%           
=======================================
  Files         563      563           
  Lines       97499    97561   +62     
=======================================
+ Hits        85785    85846   +61     
- Misses      11714    11715    +1     

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

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

@github-actions

github-actions Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 4caad19d01d5

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.628 ± 0.182 2.349 2.845 1.81 ± 0.17
pacquet@main 2.593 ± 0.160 2.358 2.794 1.78 ± 0.16
pnpr@HEAD 1.453 ± 0.097 1.353 1.682 1.00
pnpr@main 1.541 ± 0.168 1.342 1.786 1.06 ± 0.14
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.62792154244,
      "stddev": 0.182188828608349,
      "median": 2.70492128444,
      "user": 1.56150806,
      "system": 1.3478228399999999,
      "min": 2.34907930444,
      "max": 2.84484821444,
      "times": [
        2.75148677744,
        2.71874562344,
        2.77834243444,
        2.65046125244,
        2.84484821444,
        2.38019916044,
        2.34907930444,
        2.69153495844,
        2.3962100884399997,
        2.71830761044
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.59268433574,
      "stddev": 0.1597562853838713,
      "median": 2.6567872584399996,
      "user": 1.5082785599999997,
      "system": 1.26090314,
      "min": 2.3582185614399997,
      "max": 2.79350401844,
      "times": [
        2.7468507884399997,
        2.6555117394399996,
        2.47780084444,
        2.68962791644,
        2.71425489844,
        2.6580627774399996,
        2.37807662244,
        2.3582185614399997,
        2.79350401844,
        2.45493519044
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.4534537253400002,
      "stddev": 0.09676473956057277,
      "median": 1.44649679544,
      "user": 1.02676626,
      "system": 1.13457604,
      "min": 1.35290109544,
      "max": 1.6824360904400002,
      "times": [
        1.48847990144,
        1.6824360904400002,
        1.51445366244,
        1.3820327304400002,
        1.3974313224400001,
        1.46063123644,
        1.43550598044,
        1.35290109544,
        1.3631776234400002,
        1.45748761044
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.54119447414,
      "stddev": 0.16770796720551967,
      "median": 1.5157960299400002,
      "user": 1.0367418599999998,
      "system": 1.11068964,
      "min": 1.3417709134400002,
      "max": 1.7860142814400002,
      "times": [
        1.5225353974400002,
        1.3724066844400002,
        1.7464669454400001,
        1.5090566624400001,
        1.40412482844,
        1.66740177244,
        1.3417709134400002,
        1.6835618754400001,
        1.7860142814400002,
        1.37860538044
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 260.2 ± 8.6 252.9 276.4 1.03 ± 0.06
pacquet@main 253.7 ± 10.9 232.6 266.7 1.00
pnpr@HEAD 271.2 ± 10.2 253.0 284.9 1.07 ± 0.06
pnpr@main 267.7 ± 9.9 251.5 284.2 1.06 ± 0.06
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.26023065720000005,
      "stddev": 0.008641614558327298,
      "median": 0.25661757900000004,
      "user": 0.19762948,
      "system": 0.5464893,
      "min": 0.252947323,
      "max": 0.276367812,
      "times": [
        0.253592205,
        0.25717898,
        0.25403997700000003,
        0.257142621,
        0.255009521,
        0.276367812,
        0.252947323,
        0.256092537,
        0.266547827,
        0.273387769
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.2537394334,
      "stddev": 0.01087580151666832,
      "median": 0.25343586100000004,
      "user": 0.21204128,
      "system": 0.5197468999999999,
      "min": 0.232633174,
      "max": 0.266661029,
      "times": [
        0.232633174,
        0.244357681,
        0.255186503,
        0.266661029,
        0.264228717,
        0.251685219,
        0.24866501100000002,
        0.262784261,
        0.263760145,
        0.247432594
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.2711662005,
      "stddev": 0.010192232923943896,
      "median": 0.2728555835,
      "user": 0.20104608000000002,
      "system": 0.5444799,
      "min": 0.252981868,
      "max": 0.284904364,
      "times": [
        0.261428631,
        0.252981868,
        0.26531015,
        0.273835061,
        0.264163764,
        0.276606151,
        0.28440783000000003,
        0.27614808,
        0.284904364,
        0.271876106
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.2677171587,
      "stddev": 0.009912463930552584,
      "median": 0.26844011,
      "user": 0.21491477999999997,
      "system": 0.530985,
      "min": 0.25149936,
      "max": 0.284225879,
      "times": [
        0.268149709,
        0.276815203,
        0.27260089,
        0.25149936,
        0.258991979,
        0.273181201,
        0.266842851,
        0.256134004,
        0.268730511,
        0.284225879
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.597 ± 0.020 2.558 2.626 1.76 ± 0.07
pacquet@main 2.597 ± 0.023 2.565 2.627 1.76 ± 0.07
pnpr@HEAD 1.478 ± 0.056 1.421 1.574 1.00
pnpr@main 1.632 ± 0.161 1.434 1.844 1.10 ± 0.12
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.5966354758000003,
      "stddev": 0.020424482267653046,
      "median": 2.5990642912,
      "user": 1.49827524,
      "system": 1.3139894,
      "min": 2.5575800222,
      "max": 2.6258072982,
      "times": [
        2.5575800222,
        2.5761253842,
        2.5832106672,
        2.6000237112,
        2.6039145382,
        2.6094388362,
        2.5925013262,
        2.5981048712,
        2.6196481032,
        2.6258072982
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.5965347268,
      "stddev": 0.023085797154861972,
      "median": 2.5880650877,
      "user": 1.4589438399999999,
      "system": 1.3126715,
      "min": 2.5646550612,
      "max": 2.6267565332,
      "times": [
        2.5792323272,
        2.5840439892,
        2.5897308182,
        2.6267565332,
        2.5863993572,
        2.6263874992,
        2.6215818472,
        2.5646550612,
        2.5742697712,
        2.6122900642
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.4780956892,
      "stddev": 0.05555497944143403,
      "median": 1.4589969767,
      "user": 1.01267554,
      "system": 1.1225060999999998,
      "min": 1.4206566962,
      "max": 1.5740113262,
      "times": [
        1.4363706772,
        1.4206566962,
        1.5740113262,
        1.4626822981999998,
        1.5546735442,
        1.5068382632,
        1.4325262042,
        1.4250906782,
        1.4553116552,
        1.5127955491999998
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.6318071092,
      "stddev": 0.16121720089415026,
      "median": 1.5988876182,
      "user": 0.9562164400000001,
      "system": 1.2019829,
      "min": 1.4339690852,
      "max": 1.8435000451999999,
      "times": [
        1.4339690852,
        1.6116566182,
        1.4885336381999998,
        1.7271969092,
        1.8435000451999999,
        1.5861186182,
        1.5245293971999998,
        1.8278971201999998,
        1.8214872082,
        1.4531824521999999
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 400.5 ± 7.4 389.5 410.4 1.33 ± 0.04
pacquet@main 394.1 ± 5.5 386.1 403.8 1.31 ± 0.03
pnpr@HEAD 303.4 ± 8.8 292.1 319.8 1.01 ± 0.04
pnpr@main 301.8 ± 6.0 294.5 313.8 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.40054153826000005,
      "stddev": 0.007383141353907032,
      "median": 0.39825395016000004,
      "user": 0.5005879999999999,
      "system": 0.7190605399999999,
      "min": 0.38945641116,
      "max": 0.41041701216000004,
      "times": [
        0.39501841116,
        0.39636028216,
        0.40979042416000006,
        0.41041701216000004,
        0.40014761816000005,
        0.40600585516000004,
        0.40767064216000004,
        0.38945641116,
        0.39486332116000006,
        0.39568540516000006
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.39407488806,
      "stddev": 0.005512723591966799,
      "median": 0.39330476216,
      "user": 0.528411,
      "system": 0.6711917399999999,
      "min": 0.38609453616000006,
      "max": 0.40379353816,
      "times": [
        0.39362934216,
        0.39708066516,
        0.38609453616000006,
        0.39084048216000006,
        0.38992264816000005,
        0.39620933916,
        0.40103982516000003,
        0.40379353816,
        0.39298018216,
        0.38915832216
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.30342168756000004,
      "stddev": 0.008811496947007953,
      "median": 0.30231046066,
      "user": 0.204683,
      "system": 0.52739344,
      "min": 0.29211887816000004,
      "max": 0.31980679716000004,
      "times": [
        0.29211887816000004,
        0.30416771416000005,
        0.29532405116000005,
        0.30045320716,
        0.29686652816000003,
        0.31113385316000003,
        0.30698364516000004,
        0.31980679716000004,
        0.31117600216,
        0.29618619916000005
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.30176247816,
      "stddev": 0.005975792955578064,
      "median": 0.30037559616000004,
      "user": 0.19418019999999997,
      "system": 0.54276444,
      "min": 0.29450701416,
      "max": 0.31379800916,
      "times": [
        0.29835496416,
        0.31379800916,
        0.30365433116,
        0.29450701416,
        0.30057323216000004,
        0.29464852116,
        0.29886479216,
        0.30604853816000005,
        0.30017796016000003,
        0.30699741916
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.733 ± 0.011 1.718 1.752 5.77 ± 0.14
pacquet@main 1.740 ± 0.006 1.727 1.749 5.79 ± 0.14
pnpr@HEAD 0.302 ± 0.005 0.294 0.309 1.00 ± 0.03
pnpr@main 0.300 ± 0.007 0.286 0.309 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.7326179263600001,
      "stddev": 0.011464616384360264,
      "median": 1.73493621076,
      "user": 0.70994916,
      "system": 0.7560375799999999,
      "min": 1.71779633526,
      "max": 1.7516898602600002,
      "times": [
        1.73712607426,
        1.73521890226,
        1.71779633526,
        1.7193142862600002,
        1.7516898602600002,
        1.7473989812600002,
        1.7231912202600002,
        1.7240158792600002,
        1.73465351926,
        1.73577420526
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.7402216638599999,
      "stddev": 0.006184041045804154,
      "median": 1.73929537926,
      "user": 0.7132006599999998,
      "system": 0.7722449799999999,
      "min": 1.72733440126,
      "max": 1.7486205052600001,
      "times": [
        1.73816481526,
        1.74684871626,
        1.73544415426,
        1.74476756726,
        1.7387869742600002,
        1.7436587462600002,
        1.73888731226,
        1.73970344626,
        1.72733440126,
        1.7486205052600001
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.3016626480599999,
      "stddev": 0.004713921522598705,
      "median": 0.30180563876,
      "user": 0.20259136,
      "system": 0.5193799799999999,
      "min": 0.29425772026,
      "max": 0.30937931526,
      "times": [
        0.29949063026,
        0.30293998926,
        0.30594649726,
        0.30067128826,
        0.29692538226,
        0.30937931526,
        0.29425772026,
        0.29747498326,
        0.30420798126,
        0.30533269326
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.30039267466,
      "stddev": 0.006948729596721635,
      "median": 0.30127339276,
      "user": 0.19952266000000002,
      "system": 0.53194008,
      "min": 0.28585990526,
      "max": 0.30871010426,
      "times": [
        0.28585990526,
        0.29407044826,
        0.30035685726,
        0.30871010426,
        0.30499944526,
        0.29707195526,
        0.29843610726,
        0.30218992826,
        0.30828280326,
        0.30394919226
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 181.2 ± 12.6 173.0 222.4 2.08 ± 0.15
pacquet@main 179.6 ± 4.3 172.0 188.5 2.06 ± 0.06
pnpr@HEAD 87.0 ± 1.6 82.5 90.7 1.00 ± 0.02
pnpr@main 87.0 ± 1.4 84.4 90.1 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.18119906164769234,
      "stddev": 0.012574168092208661,
      "median": 0.17801402634000002,
      "user": 0.16740137076923073,
      "system": 0.06727931076923077,
      "min": 0.17296189734000003,
      "max": 0.22244982134000002,
      "times": [
        0.22244982134000002,
        0.18134496334000003,
        0.17296189734000003,
        0.17812113734,
        0.18080582134,
        0.17801402634000002,
        0.17694267434000002,
        0.17664805134000003,
        0.17635630234000002,
        0.17800544134000001,
        0.17913045434000002,
        0.17851631034,
        0.17629090034000003
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.1796467924025,
      "stddev": 0.004328859924244665,
      "median": 0.17952951834000003,
      "user": 0.16746488999999995,
      "system": 0.06791339249999997,
      "min": 0.17203659934,
      "max": 0.18849703734,
      "times": [
        0.17622860334,
        0.18267859834000003,
        0.17642740734,
        0.17992916334000003,
        0.18849703734,
        0.18135379034000002,
        0.18422802934000002,
        0.17688641834000002,
        0.18384582034000002,
        0.17849863734000002,
        0.17912987334000002,
        0.17287880034000003,
        0.18215138834000003,
        0.17203659934,
        0.18209854834000003,
        0.17747996334000002
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.08701837021878789,
      "stddev": 0.001612788427583996,
      "median": 0.08728331634,
      "user": 0.02266132181818182,
      "system": 0.007140830303030303,
      "min": 0.08251706334,
      "max": 0.09070977134,
      "times": [
        0.08609146734,
        0.08706636733999999,
        0.08743647434,
        0.08744945734,
        0.08724737834,
        0.08801578034,
        0.08596326734,
        0.08335506734,
        0.08667810934,
        0.08817950934,
        0.08652920934,
        0.08251706334,
        0.08744283434,
        0.08702764534,
        0.08802022034,
        0.08719710334,
        0.08728331634,
        0.09070977134,
        0.08619569234,
        0.08523506834,
        0.08944201134,
        0.08567090734,
        0.08679666134,
        0.08893647034,
        0.08448462933999999,
        0.08846598834,
        0.08761150234,
        0.08824440034,
        0.08764490534,
        0.08563488034,
        0.08735897734,
        0.08810759334,
        0.08756648734
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.0870019400275,
      "stddev": 0.0014418201500872349,
      "median": 0.08687255984,
      "user": 0.019698796249999997,
      "system": 0.009457199999999999,
      "min": 0.08441346534,
      "max": 0.09005937934,
      "times": [
        0.08825695534,
        0.08441346534,
        0.08517333234,
        0.08766361934,
        0.08529633334,
        0.08828567833999999,
        0.08639967634,
        0.08675198734,
        0.08751829634,
        0.08789077734,
        0.08952714034,
        0.08621695334,
        0.08626561334,
        0.08927529634,
        0.08621714334,
        0.08583912234,
        0.08486322034,
        0.08622574934,
        0.08737952634,
        0.08650076634,
        0.08726381933999999,
        0.08774045434,
        0.08676173633999999,
        0.08769473834,
        0.08780256134,
        0.08698338334,
        0.09005937934,
        0.08496229634,
        0.08914918034,
        0.08840802834,
        0.08513944933999999,
        0.08613640134
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 767.5 ± 146.5 549.3 978.2 1.00
pacquet@main 1252.1 ± 247.9 846.5 1588.2 1.63 ± 0.45
pnpm@HEAD 2931.0 ± 45.7 2838.4 2974.0 3.82 ± 0.73
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.7675145068511111,
      "stddev": 0.14650661993776826,
      "median": 0.72674816574,
      "user": 0.7138951444444444,
      "system": 0.15765670666666665,
      "min": 0.5492819277400001,
      "max": 0.9782404787400001,
      "times": [
        0.5492819277400001,
        0.66234608874,
        0.9782404787400001,
        0.6714153927400001,
        0.86317374674,
        0.96633207074,
        0.80843618174,
        0.6816565087400001,
        0.72674816574
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.2520534924066669,
      "stddev": 0.24785392845040108,
      "median": 1.16017486774,
      "user": 1.1747108111111109,
      "system": 0.15684326222222222,
      "min": 0.84651737374,
      "max": 1.58815895474,
      "times": [
        1.1183598587399999,
        1.58815895474,
        1.05384322174,
        1.16017486774,
        1.4552035327400001,
        1.49349726774,
        1.43075908974,
        0.84651737374,
        1.12196726474
      ]
    },
    {
      "command": "pnpm@HEAD",
      "mean": 2.930953863517778,
      "stddev": 0.04574770001016976,
      "median": 2.95639787574,
      "user": 4.459335366666667,
      "system": 0.26324548444444446,
      "min": 2.83836864874,
      "max": 2.97401580674,
      "times": [
        2.96225025674,
        2.97401580674,
        2.95639787574,
        2.91713545174,
        2.83836864874,
        2.96306283374,
        2.96138775874,
        2.92508187574,
        2.88088426374
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.561 ± 0.161 4.403 4.866 1.30 ± 0.06
pacquet@main 4.496 ± 0.086 4.422 4.646 1.28 ± 0.05
pnpr@HEAD 3.519 ± 0.116 3.439 3.822 1.00
pnpr@main 3.606 ± 0.116 3.449 3.760 1.02 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.56101262992,
      "stddev": 0.16103246137920188,
      "median": 4.46865195062,
      "user": 1.6933780999999999,
      "system": 1.3153194999999998,
      "min": 4.40300869712,
      "max": 4.86620979012,
      "times": [
        4.43712287412,
        4.49028678912,
        4.44701711212,
        4.44333550312,
        4.67050748612,
        4.86620979012,
        4.40300869712,
        4.73875004412,
        4.66754692512,
        4.44634107812
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.49571605312,
      "stddev": 0.08556690343576721,
      "median": 4.44986980212,
      "user": 1.6496336000000003,
      "system": 1.4144425999999999,
      "min": 4.42173672612,
      "max": 4.64567267012,
      "times": [
        4.58685155712,
        4.42802569812,
        4.42248833512,
        4.64567267012,
        4.42173672612,
        4.44200453812,
        4.45773506612,
        4.42913450212,
        4.52857211012,
        4.594939328120001
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.51912849992,
      "stddev": 0.11642562273054438,
      "median": 3.47822171512,
      "user": 1.1807892,
      "system": 1.1916442,
      "min": 3.43876891812,
      "max": 3.82239465912,
      "times": [
        3.52174468412,
        3.5025562591200003,
        3.43876891812,
        3.45614982712,
        3.59572221612,
        3.4768207861200002,
        3.43886075112,
        3.82239465912,
        3.47962264412,
        3.45864425412
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.6057909414199996,
      "stddev": 0.11577727385034509,
      "median": 3.6299241166200003,
      "user": 1.1493555,
      "system": 1.2207386,
      "min": 3.44896978012,
      "max": 3.76033076712,
      "times": [
        3.6632453601200003,
        3.4550448081200003,
        3.68587585512,
        3.76033076712,
        3.59660287312,
        3.72176734612,
        3.5036846291200003,
        3.44896978012,
        3.69981094712,
        3.52257704812
      ]
    }
  ]
}

@github-actions

github-actions Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13575
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
2,557.58 ms
(-3.05%)Baseline: 2,638.00 ms
3,165.60 ms
(80.79%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
1,717.80 ms
(-3.04%)Baseline: 1,771.71 ms
2,126.05 ms
(80.80%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
389.46 ms
(-9.50%)Baseline: 430.33 ms
516.40 ms
(75.42%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
172.96 ms
(-14.08%)Baseline: 201.32 ms
241.58 ms
(71.60%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,349.08 ms
(-2.27%)Baseline: 2,403.60 ms
2,884.32 ms
(81.44%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,403.01 ms
(-1.91%)Baseline: 4,488.86 ms
5,386.64 ms
(81.74%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
252.95 ms
(-5.24%)Baseline: 266.93 ms
320.31 ms
(78.97%)
isolated-linker.peer-heavy-resolve.hot-cache.offline📈 view plot
🚷 view threshold
549.28 ms
(-51.53%)Baseline: 1,133.23 ms
1,359.88 ms
(40.39%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13575
Testbedpnpr

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

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

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,420.66 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
294.26 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
292.12 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
82.52 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,352.90 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,438.77 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
252.98 ms
🐰 View full continuous benchmarking report in Bencher

zkochan added 2 commits August 2, 2026 02:04
Review of the first version found the reuse test asking the wrong
object. It compared this occurrence against the owner standing at claim
time, but `children_by_id` is written by whichever walk completed, and
that walk need not be the standing owner's: an occurrence could inherit
children recorded under a context nobody had checked it against.

Record the context each `children_by_id` entry was produced under —
shadowed set, prior-lockfile key, update policy — and compare against
that instead of against the claim. The claim goes back to reporting only
what it can know, and `children_context_unchanged` returns to its own
job of keeping a reused subtree alive across a handover; tightening that
flag instead breaks `unchanged_shadow_ownership_handover_keeps_reused_subtree`,
which is the behaviour it exists to pin.

The preferred-versions overlay is deliberately not part of the test, and
that is a judgement rather than an oversight: `children_by_id` holds one
child list per package id, every non-owner occurrence already expands
from it whatever its own overlay says, and requiring identical overlays
means requiring identical parents — which never holds for the
occurrences that race. Measured, that requirement reinstates the
expansion in full: depth 15 goes back to 299 MB and depth 26 stops
finishing.

Related to #13574.
The reuse decision moved to the recorded-children context, so the
ownership entry no longer needs to carry it.

Related to #13574.
Copilot AI review requested due to automatic review settings August 2, 2026 00:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@zkochan

zkochan commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

All three findings were right, and two of them changed the design. Pushed as 8d46c1c.

"Bind recorded children to the ownership generation" (CodeRabbit) — taken. This was the real defect: my test compared this occurrence against the owner standing at claim time, but children_by_id is written by whichever walk completed, and that walk need not be the standing owner's. The scenario in the finding is reachable. The context each entry was recorded under — shadowed set, prior-lockfile key, update policy — is now stored alongside it and is what the reuse test compares against, so the claim no longer answers a question it cannot know.

"Include the full resolution context in children_context_unchanged" (CodeRabbit) — investigated, and not taken, because it breaks a pinned behaviour. Tightening that flag with the update policy and prior key fails unchanged_shadow_ownership_handover_keeps_reused_subtree: leaf2 re-resolves to 1.5.0 instead of the lockfile-reused 1.0.0. That flag's job is narrower than it looks — it decides whether a handover broadcasts make_non_owner_nodes_lazy, and keeping a reused subtree alive across an unchanged-shadow handover is the behaviour it exists to protect. The concern behind the finding is real, and it is addressed by not using that flag for the reuse decision at all.

"Overlay omitted from reuse" (Qodo) — real, and deliberately not fixed by requiring overlay equality. I implemented it to find out what it costs: with overlay identity in the test, depth 15 goes from 62 MB / 0.10s back to 299 MB / 1.03s, depth 20 to 3.7 GB / 12.1s, and depth 26 stops finishing. The reason is structural — occurrences that race for a claim are reached from different parents, so they never share an overlay layer, and requiring identical overlays means requiring identical parents.

The judgement I made instead, now written into the code: children_by_id holds one child list per package id, and every occurrence that does not own the children already expands from it whatever its own overlay says. The overlay therefore only ever decides which occurrence's versions get recorded — and which occurrence records them is a race today as well, since concurrent walkers each write the map when they are the current owner. This change alters which race wins; it does not introduce overlay-insensitivity, which the per-package-id record already implies.

If that trade is not acceptable, the fix that removes the race outright is to settle ownership before descending (process claims in rank order, so the first claim is the final one) rather than cleaning up after it. That is a restructuring of the concurrent walk rather than a guard, so I would want it as its own change.

Verification after the rework: 7,555 tests pass, depths 15/20/26 resolve in 62/62/83 MB and 0.10/0.12/0.20s, and the emitted lockfile is still byte-identical to the TypeScript CLI's for the same input.


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

@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/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs`:
- Around line 1195-1212: Consolidate each package’s recorded child edges and
RecordedChildrenContext into a single mutex-protected entry, replacing the
separate children_by_id and children_context_by_id coordination. Update
recorded_children_match and record_children_context to use this atomic entry,
and provide one accessor that returns the matching child-edge snapshot with its
context validation. Ensure subtree reuse only uses edges matched to the same
prior_key and update_active values, preserving resolution decisions and lockfile
output under concurrent walks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e19227d8-5d49-482f-a6fe-9486e954b86a

📥 Commits

Reviewing files that changed from the base of the PR and between f095301 and 8d46c1c.

📒 Files selected for processing (2)
  • pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs
  • pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 8d46c1c

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

No code suggestions found for the PR.

zkochan added 2 commits August 2, 2026 02:30
…t together

Review found the reuse test reading the context from one mutex and the
edges it describes from another, so a reader could accept a context one
walk recorded and then expand the edges a different walk wrote. Hold
both halves in one `children_by_id` entry and record them together, so
a matched context always describes the edges that come with it.

Also repairs the intra-doc link left behind when the reuse flag moved
off the ownership claim, which `cargo doc --document-private-items`
rejects.

Related to #13574.
… the test module

The dylint rule the pre-push hook runs rejects inline test code in a
production file.

Related to #13574.
Copilot AI review requested due to automatic review settings August 2, 2026 00:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@zkochan

zkochan commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

Pushed 2a14486, which covers both of the new findings and the two red checks.

"Store recorded child edges and their context atomically" (CodeRabbit) — taken. The two maps were written and read under separate mutexes, so a reader could accept a context one walk recorded and then expand the edges another walk wrote. children_by_id now holds a single entry carrying both halves, and one record_children helper is the only way to write it.

"Missing reuse context record" (Qodo) — real on 8d46c1c, and fixed by the same rework. The lockfile-reuse path wrote children_by_id without recording a context, so recorded_children_match could never succeed for those ids and the reuse never fired for reused subtrees. With edges and context in one entry there is no longer a way to record one without the other; the reuse path passes its own context, whose prior key is the snapshot key it reused.

Rust CI / Doc was a stale intra-doc link left behind when the reuse flag moved off the ownership claim. It only reproduces under --document-private-items, which the pre-push hook does not pass — RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --workspace --document-private-items now passes locally.

Rust CI / Test / windows was not a test failure: the job reports no failing step, and steps 12–15 (Test pacquet onward) have null conclusions, so the runner aborted rather than a test failing. Nothing in this change touches platform-specific behaviour. The fresh run on this commit will say whether it reproduces; if it does, I will chase it.

On comment conventions, one of mine broke them: the note at the reuse site narrated what the walk used to do, which belongs in the commit message. It now states the standing contract and the reason, and the overlay rationale is a statement of the invariant rather than a retelling of the experiment that produced it.

Verification after the rework: 7,555 tests pass, dylint and the private-items doc build are clean, depths 15/26 of the issue's fixture resolve in 61 MB / 0.10s and 78 MB / 0.17s, and the emitted lockfile is still byte-identical to the TypeScript CLI's.


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

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Aug 2, 2026
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 0fd2424

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

No code suggestions found for the PR.

@zkochan

zkochan commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

"Orphaned walked subtrees" (Qodo) — real, pre-existing, and bounded; not changing it here.

The observation is correct: an occurrence that starts walking as owner and loses the claim before publishing leaves its descendant occurrence nodes in the shared tree, unreachable from a parent that ends up lazy. Two things frame it:

  • It is not introduced by this PR. The children are walked before the ownership re-check on main too, so a walk that lost the claim already left its nodes behind; the atomic publish adds one more way to reach that state, not the state itself.
  • It is exactly the case this PR shrinks. Those orphans only accumulate on races that survive the reuse test, and the measurements bound what is left: the fixture that could not finish in 6 GB now resolves at depth 26 in 83 MB, and depth 15 in 61 MB with 3,211 occurrence nodes against 198,023 before. What remains is not visible at that scale.

Reclaiming them properly means tracking every node a walk materialised so a losing walk can retract its subtree — which is bookkeeping in the hot path to undo work that should not have happened. The change that removes the cause instead is settling ownership before descending, so only the eventual owner walks: it also answers the overlay question, since a single deterministic walker makes "which occurrence's versions get recorded" a settled question rather than a race. That is a restructuring of the concurrent walk and belongs in its own PR, which I would rather size against the real workspaces than bolt onto this fix.

Rust CI / Test / windows passed on this head (5m19s), confirming the earlier failure was the runner aborting rather than anything in the change.


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

…ates

Codecov flagged the new gates as uncovered. Both are testable without
the ownership race that the reuse itself needs: one pins that each field
of the recorded context can withhold reuse, the other that a walk which
lost the claim while it ran cannot overwrite the standing owner's
children. Both were checked against implementations with those
conditions removed.

Related to #13574.
Copilot AI review requested due to automatic review settings August 2, 2026 01:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@zkochan

zkochan commented Aug 2, 2026

Copy link
Copy Markdown
Member Author

Codecov flagged the new gates as uncovered, and unlike the race itself those are testable directly — pushed 4caad19 with two unit tests:

  • recorded_children_match_only_under_the_recording_context pins that each field of the recorded context can withhold reuse on its own: a different shadowed set, a different update policy, and a different snapshot key each make the match fail, and nothing matches before a walk has recorded anything.
  • children_are_published_only_by_the_standing_owner pins the publish gate: two claims are taken, the deeper one's publish is rejected because the shallower occurrence outranked it, and the shallower one's succeeds.

Both were verified against implementations with those conditions removed — dropping the ownership check in record_children and comparing only the shadowed set in produces_same_children_as — and both fail there.

That leaves the reuse path itself uncovered, for the reason given earlier in the PR: it needs occurrences of one package to race for the claim, which an in-process resolve_workspace test does not produce at any shape I tried. What is now covered is the logic that decides it.

7,557 tests pass.


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

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 4caad19

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

No code suggestions found for the PR.

@zkochan
zkochan merged commit 5644b55 into main Aug 2, 2026
33 checks passed
@zkochan
zkochan deleted the fix-13574-peer-memory branch August 2, 2026 08:35
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.

pacquet: peer-carrying dependency chains expand exponentially with depth (1 importer, 1 dependency, ~500 packages → OOM)

3 participants