Skip to content

fix(resolver): settle children ownership one level at a time - #13835

Merged
zkochan merged 2 commits into
mainfrom
redo-13685
Aug 11, 2026
Merged

zkochan merged 2 commits into
mainfrom
redo-13685

Conversation

@zkochan

@zkochan zkochan commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #13685. Rewritten — this no longer resembles #13830 (merged, then reverted in #13833 for a 23% resolve regression). The comments below trace how that approach was measured, found to be both expensive and incomplete, and replaced.

The bug

Occurrences of a package race to claim its children. Whichever one reaches it while the claim stands vacant walks the package and records what its own level's preferred-versions overlay resolved; a better-placed occurrence arriving later keeps that recording rather than walking again — walking on every claim win is what expanded exponentially in #13574. Which occurrence gets there first is thread timing, so identical inputs produced different lockfiles run to run.

Why the first attempt could not fix it

#13830 made the later occurrence re-walk when its own level offered its child edges different versions. That settles the recording, but not which occurrences exist. Traced on the repro, [email protected] recorded its children exactly once per run, in the first walk, under a different owner each time:

run A: edges=[…, [email protected]] parent_path=[…, @teambit/aspect, jest, …, babel-plugin-istanbul]
run B: edges=[…, [email protected]] parent_path=[…, @teambit/jest,   jest, …, babel-plugin-istanbul]

@teambit/[email protected] sorts before @teambit/[email protected], so the first occurrence outranks the second — but in run B it never exists, because an ancestor on that path matched its own recording, stayed lazy, and never walked that subtree. Settling the recording makes the children the answer of the best-ranked occurrence that got walked, and the walked set is itself arrival-ordered.

What this does instead

The walk advances a depth level at a time. A level is seeded in full before any of it is settled, so every occurrence of a package at that depth is in hand when its children ownership is decided. The rank is (update policy, depth, importer order, parent path) and a level shares the first three, so the best-placed occurrence is the one whose parent path sorts first — and it is the only one that claims.

Ownership therefore never passes to an occurrence seeded later, no occurrence re-walks children another one recorded, and what a package records stops depending on which subtree reached it first. The recursion in walk_node_children becomes a frontier loop (walk_from_seeds → seed_node_children → assign_level_owners → settle_level); resolve_node_seed no longer claims, since a claim taken at seed time is exactly the arrival-ordered decision being removed.

Measurements

Repro from the issue (@teambit/[email protected], offline, warm cache), rm -rf node_modules pnpm-lock.yaml && pnpm install --lockfile-only --ignore-scripts --offline:

lockfiles produced resolve
main 3 distinct, over 4 runs 4.287 s
#13830 (reverted) 2 distinct, over 16 runs 5.256 s (+23%)
this PR 1, over 46 runs — every run byte-identical 4.29 s (±0%)

isolated-linker.peer-heavy-resolve.hot-cache.offline — the scenario that alerted on #13830 — run locally through the integrated-benchmark harness, 20 runs: 467 ms against main's 844 ms. Settling the level rather than each parent's fanout means a package's children are seeded once instead of once per occurrence that wins its claim, and the speculative child prewarm now runs once per package instead of once per occurrence.

Two regression tests cover the orderings, both on a paused clock so the ordering is a property of the runtime rather than a wall-clock margin: a deeper occurrence that resolves first must not decide (fails on main's walk), and two occurrences at the same depth are settled by parent path (fails if the assignment's comparison is inverted).

Children ownership is pacquet's own machinery, so there is nothing to mirror in resolveDependencyTree.ts.

Squash Commit Body

Occurrences of a package race to claim its children: whichever one
reaches it while the claim stands vacant records what its own level's
preferred-versions overlay resolved, and a better-placed occurrence
arriving later keeps that recording rather than walking again — walking
on every claim win is what expanded exponentially in pnpm/pnpm#13574. Which
occurrence gets there first is thread timing, so identical inputs
produced different lockfiles run to run.

Settling the recording alone does not fix it: traced on the repro, the
better-ranked occurrence of a package sometimes does not exist at all,
because an ancestor on its path matched its own recording and never
walked that subtree. The walked set is arrival-ordered too.

The walk now advances a depth level at a time. A level is seeded in full
before any of it is settled, so every occurrence of a package at that
depth is in hand when its children ownership is decided; the rank's
first three keys are shared within a level, so the occurrence whose
parent path sorts first wins, and it is the only one that claims.
Ownership never passes to an occurrence seeded later and no occurrence
re-walks children another one recorded.

Removing those handovers is why this costs nothing: the repro resolves
in 4.29s against 4.29s on main and is byte-identical across 46 runs,
where main produces 3 distinct lockfiles in 4, and the peer-heavy
resolve benchmark drops from 844ms to 467ms.

Closes pnpm/pnpm#13685.

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

Summary by CodeRabbit

  • Bug Fixes

    • Improved dependency resolution consistency when packages are reached through multiple paths.
    • Prevented lockfile differences caused by concurrent resolution order.
    • Improved handling of package aliases, peer-shadowed dependencies, and shared package versions.
    • Ensured deterministic selection of shared dependencies across traversal paths and resolution levels.
  • Tests

    • Added regression coverage for deterministic shared-package resolution, peer shadowing, and dependency path ordering.
    • Expanded coverage for aliases, version ranges, and JSR package references.

Copilot AI lite review requested due to automatic review settings August 11, 2026 15:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

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: ca7a8685-e2d5-439d-b6b5-b60ebc16210d

📥 Commits

Reviewing files that changed from the base of the PR and between 671c9f0 and 490ecc1.

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

📝 Walkthrough

Walkthrough

The resolver now settles dependency-tree sibling levels before walking descendants. Ownership, peer-shadowing, overlays, aliases, recorded-child reuse, and speculative warmup use the settled frontier. Tests cover delayed and same-depth shared-package resolution.

Changes

Deterministic dependency resolution

Layer / File(s) Summary
Alias and overlay lookup context
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs, pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse/tests.rs, pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs
Package-name and overlay lookups accept separate alias and bare-specifier values. npm alias and JSR resolution tests retain their expected results.
Level-synchronous tree walking
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree.rs, pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs, pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs
Sibling seeds are settled before descendant traversal. Ownership, peer-shadowing, child recording, overlays, aliases, and warmup claims use settled level state.
Regression coverage and release metadata
pnpm/crates/resolving-deps-resolver/src/tests.rs, pnpm/crates/resolving-deps-resolver/Cargo.toml, .changeset/level-synchronous-children-ownership.md
Paused tests cover delayed and same-depth shared-package resolution. Tokio enables test-util, and the changeset documents deterministic resolution behavior.

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

Sequence Diagram(s)

sequenceDiagram
  participant extend_tree
  participant walk_from_seeds
  participant WorkspaceTreeCtx
  participant PendingNode
  extend_tree->>walk_from_seeds: pass seeds, overlays, and alias scopes
  walk_from_seeds->>PendingNode: seed sibling level
  walk_from_seeds->>WorkspaceTreeCtx: claim ownership and child warmup
  WorkspaceTreeCtx-->>walk_from_seeds: return claim result
  walk_from_seeds->>PendingNode: settle ownership and peer-shadowing
  PendingNode-->>walk_from_seeds: return realized child state
  walk_from_seeds->>walk_from_seeds: walk the settled descendant frontier
Loading

Possibly related issues

Possibly related PRs

  • pnpm/pnpm#13830 — Directly related resolver ownership and overlay-settlement changes.
  • pnpm/pnpm#13594 — Related traversal changes for order-dependent dependency resolution.
  • pnpm/pnpm#13388 — Related child ownership and peer-shadowing changes in dependency-tree traversal.

Suggested labels: product: pacquet

Suggested reviewers: greptile-apps

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch redo-13685

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

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

Copy link
Copy Markdown

PR Summary by Qodo

fix(resolver): settle children ownership one level at a time

🐞 Bug fix 🧪 Tests ✨ Enhancement 🕐 40+ Minutes

Grey Divider

AI Description

• Seed a full depth level before settling children ownership, eliminating arrival-order lockfile
 nondeterminism.
• Replace per-node recursive walking with a frontier loop that settles ownership per level.
• Deduplicate speculative child warmups per package and reduce overlay lookup allocations.
• Add paused-clock regression tests proving ownership is rank-determined, not timing-dependent.
Diagram

graph TD
    A["walk_from_seeds"] --> B["assign_level_owners"] --> C["settle_seeds"] --> D["seed_node_children"] --> E["settle_level"] --> B
    C --> F[("children_owner_by_id")]
    E --> G[("children_by_id")]
    D --> H["resolve_node_seed"]
    subgraph Legend
        direction LR
        _mod(["Function"]) ~~~ _db[("Shared state")]
    end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Overlay-projection re-walk on ownership handover (PR #13830, reverted)
2. Serialize resolution to remove races
  • ➕ Deterministic by construction; fewer concurrency edge cases
  • ➖ Sacrifices parallelism; likely unacceptable perf regression on large graphs
  • ➖ Doesn’t address the underlying ownership correctness model

Recommendation: The level-synchronous settlement approach used here is the better strategic fix: it removes arrival-order dependence at the source by ensuring all occurrences at a depth are known before any ownership decision, so the best-ranked occurrence is always the owner. This avoids the expensive overlay-projection and selective re-walk strategy that was both incomplete for #13685 and costly enough to be reverted previously.

Files changed (8) +736 / -392

Enhancement (2) +30 / -17
reuse.rsMake real_package_name_of take borrowed edge fields +16/-17

Make real_package_name_of take borrowed edge fields

• Refactors 'real_package_name_of' to accept '(alias, bare_specifier)' directly (no temporary WantedDependency), and updates update-target detection accordingly.

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

workspace_ctx.rsTrack per-package warmup to avoid redundant speculative resolutions +14/-0

Track per-package warmup to avoid redundant speculative resolutions

• Adds 'warmed_children_by_id' and a 'claim_children_warmup' helper so child warmup runs once per package even if multiple occurrences seed in a level.

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

Bug fix (1) +481 / -317
walk.rsRewrite walk to settle children ownership per depth level +481/-317

Rewrite walk to settle children ownership per depth level

• Introduces a frontier-based loop ('walk_from_seeds') that seeds all occurrences at a depth, deterministically assigns ownership ('assign_level_owners'), records children, and advances to the next depth. Moves ownership claiming out of 'resolve_node_seed', updates peer-dependency splitting to follow the settled owner, deduplicates warmups via 'claim_children_warmup', and reduces overlay lookup allocations via 'overlay_lookup_names' returning borrowed 'Cow' slots.

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

Refactor (1) +5 / -19
resolve_dependency_tree.rsUse walk_from_seeds for phase-2 traversal +5/-19

Use walk_from_seeds for phase-2 traversal

• Replaces the old per-seed recursive child-walk join with a single call into the new level-synchronous walker.

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

Tests (2) +214 / -38
tests.rsUpdate real_package_name_of unit tests for new signature +13/-38

Update real_package_name_of unit tests for new signature

• Adjusts tests to call 'real_package_name_of(Some(alias), Some(spec))' directly and removes helper WantedDependency construction.

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

tests.rsAdd regression tests for deterministic ownership under concurrency +201/-0

Add regression tests for deterministic ownership under concurrency

• Adds an overlay-aware stub resolver and two paused-clock tokio tests asserting that children are recorded by the correctly-ranked occurrence (shallowest / parent-path winner) regardless of which resolve completes first.

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

Documentation (1) +5 / -0
level-synchronous-children-ownership.mdAdd changeset documenting deterministic lockfile behavior +5/-0

Add changeset documenting deterministic lockfile behavior

• Adds a patch changeset noting that concurrent resolution ordering no longer affects dependency recording and lockfile output.

.changeset/level-synchronous-children-ownership.md

Other (1) +1 / -1
Cargo.tomlEnable tokio test-util for paused-time tests +1/-1

Enable tokio test-util for paused-time tests

• Adds the 'test-util' feature to tokio so resolver tests can use paused time controls.

pnpm/crates/resolving-deps-resolver/Cargo.toml

@greptile-apps

greptile-apps Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains.

No blocking failure remains.

Reviews (5): Last reviewed commit: "fix(resolver): settle children ownership..." | Re-trigger Greptile

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

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

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Remediation recommended

1. Historical rationale in walk docs 📘 Rule violation ⚙ Maintainability ⭐ New
Description
The new doc comment in walk_from_seeds references historical incident context (issue 13574)
instead of only describing the current contract/invariants, which the checklist disallows. Keeping
historical implementation rationale inline increases the chance the comment becomes stale and
misleading over time.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[R547-550]

+/// happened to reach it first — the arrival-order dependence behind
+/// <https://github.com/pnpm/pnpm/issues/13685>. It is also why no
+/// occurrence ever re-walks a package another one recorded, which the
+/// exponential blowup of <https://github.com/pnpm/pnpm/issues/13574>
Relevance

●●● Strong

Team previously accepted rewriting/shortening comments to avoid historical phrasing and keep docs
contract-focused.

PR-#13572
PR-#13575

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 772199 forbids comments that describe historical implementations. The added doc
comment explains the current approach by referencing historical issues and an abandoned alternative
("exponential blowup ... made the alternative to"), which is historical rationale rather than
current contract documentation.

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

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

## Issue description
A newly added doc comment describes historical context/alternatives (e.g., referencing an earlier exponential blowup issue) rather than focusing on the current behavior/contract.

## Issue Context
Compliance requires comments to document current behavior and invariants, not historical implementations or past approaches.

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

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


2. Unbounded frontier join_all 🐞 Bug ➹ Performance ⭐ New
Description
walk_from_seeds seeds each depth by running try_join_all over the entire frontier, so the
number of in-flight tasks scales with the number of occurrences at that depth. Each frontier task
then try_join_alls all of its child edges, which can create bursty peak concurrency and memory
pressure on very wide levels.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[R566-571]

+    while !frontier.is_empty() {
+        let seeded = frontier
            .into_iter()
-            .map(|seed| {
-                let overlay = grandchild_overlay.clone();
-                let pkg_aliases = Arc::clone(&grandchild_pkg_aliases);
-                async move {
-                    match seed {
-                        NodeSeed::Done(dep) => Ok(dep),
-                        NodeSeed::Pending(pending) => {
-                            walk_node_children(ctx, resolver, *pending, overlay, pkg_aliases).await
-                        }
-                    }
-                }
-            })
+            .map(|node| seed_node_children(ctx, resolver, node))
            .pipe(future::try_join_all)
            .await?;
-        if is_current_children_owner(ctx, &id, &children_owner.owner) {
-            // Build the realized `(alias → NodeId)` map for THIS
-            // occurrence and the per-pkg `children_by_id` entry future
-            // revisits will reuse. `children_by_id` records the resolved
-            // child pkg ids (not NodeIds) plus the `optional` flag so
-            // lazy realisation can thread `current_is_optional` correctly.
-            let mut realized: BTreeMap<String, NodeId> = BTreeMap::new();
-            let mut by_id: Vec<crate::resolved_tree::ChildEdge> = Vec::new();
-            let optional_by_alias: HashMap<&str, bool> =
-                child_specs.iter().map(|(name, _, optional)| (name.as_str(), *optional)).collect();
-            for dep in child_results.into_iter().flatten() {
-                let optional = optional_by_alias.get(dep.alias.as_str()).copied().unwrap_or(false);
-                by_id.push(crate::resolved_tree::ChildEdge {
-                    alias: dep.alias.clone(),
-                    pkg_id: dep.id.clone(),
-                    optional,
-                });
-                realized.insert(dep.alias, dep.node_id);
Relevance

●● Moderate

Unbounded try_join_all concurrency is a deeper perf/architecture change; no close precedent on
adding explicit concurrency limits.

PR-#13594

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The code explicitly runs try_join_all across the full frontier, and each frontier node resolves
its child edges via another try_join_all, so concurrency scales with frontier width and child
fanout.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[563-573]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[894-947]

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 breadth-first frontier loop uses `future::try_join_all` over the entire `frontier`, which schedules all frontier nodes concurrently; each node then resolves all its children via another `try_join_all`. On wide dependency levels this can create very large bursts of in-flight work (tasks, allocations, resolver calls).

### Issue Context
The algorithm requires seeding the whole level before settling ownership, but it does not require unbounded concurrency.

### Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[563-573]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[894-947]

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


3. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset only declares a pacquet bump but describes a pnpm user-visible lockfile behavior
fix, so it does not explicitly declare the required pnpm bump entry.
Code

.changeset/level-synchronous-children-ownership.md[R1-3]

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

●●● Strong

Multiple recent PRs accepted adding explicit pnpm bump when changeset only listed pacquet.

PR-#13748
PR-#13403

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires changeset front-matter to include an explicit pnpm entry with a
valid bump type. The added changeset declares only "pacquet": patch in its front-matter.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/level-synchronous-children-ownership.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 new changeset front-matter is missing an explicit `pnpm` entry, which is required by the compliance checklist.

## Issue Context
The changeset text describes user-visible behavior affecting `pnpm-lock.yaml` determinism, so the release metadata should explicitly include a `pnpm` bump.

## Fix Focus Areas
- .changeset/level-synchronous-children-ownership.md[1-3]

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


View review recommended (2)
4. Warmup allocates every call ✓ Resolved 🐞 Bug ➹ Performance
Description
claim_children_warmup() always allocates pkg_id.to_string() even when the package was already
warmed, and warm_children_resolutions() calls it for each seeded occurrence; this adds avoidable
allocation and repeated mutex acquisition in a resolver hot path.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[R1288-1289]

+pub(super) fn claim_children_warmup(ctx: &TreeCtx, pkg_id: &str) -> bool {
+    lock_recoverable(&ctx.workspace.warmed_children_by_id).insert(pkg_id.to_string())
Relevance

●● Moderate

Team sometimes accepts small perf/alloc reductions, but has also rejected some hot-path
micro-optimizations as nonessential.

PR-#13787
PR-#13830

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
claim_children_warmup performs an unconditional to_string() before inserting into
warmed_children_by_id. warm_children_resolutions calls claim_children_warmup for every pending
seed, meaning duplicate occurrences of the same pkg_id will still allocate and lock even though
only the first call should do work.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[1285-1290]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[1186-1192]

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

## Issue description
`claim_children_warmup()` currently does `insert(pkg_id.to_string())`, which allocates a new `String` on every call (argument evaluation happens before `HashSet::insert` can short-circuit on “already present”). This is invoked from `warm_children_resolutions()` for every pending seed occurrence, so duplicate occurrences of the same package id pay the allocation cost repeatedly.

## Issue Context
This path is intended as a speculative performance optimization; it should be as low-overhead as possible when a package has already been warmed.

## Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[1285-1290]

## Suggested fix
Change `claim_children_warmup` to avoid allocating when the id is already present, e.g.:
- Lock the set once.
- Use `contains(pkg_id)` (borrowed lookup) and only call `to_owned()`/`to_string()` when missing.

Example:
```rust
pub(super) fn claim_children_warmup(ctx: &TreeCtx, pkg_id: &str) -> bool {
   let mut warmed = lock_recoverable(&ctx.workspace.warmed_children_by_id);
   if warmed.contains(pkg_id) {
       false
   } else {
       warmed.insert(pkg_id.to_owned());
       true
   }
}
```
This preserves behavior while eliminating the repeated allocation on duplicate calls.

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


5. Overlay view ignores range ✓ Resolved 🐞 Bug ➹ Performance
Description
RecordedChildrenContext::produces_same_children_as now treats overlay_view as part of the match
when settle_contested_children is enabled, but children_overlay_view records overlay versions
without intersecting them with the child edge’s semver range/pin. This can make
recorded_children_match return false and trigger redundant child re-walks even when the overlay
cannot influence the resolved child version (e.g., exact-version pins from lockfile reuse).
Code

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

+            && (!settle_contested_children || self.overlay_view == other.overlay_view)
Relevance

●● Moderate

Overlay/recorded-children reuse logic is contentious; related overlay-context change was previously
rejected, so outcome uncertain.

PR-#13575
PR-#13830

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The reuse path explicitly pins children to an exact version and records an empty overlay_view, but
the walk path’s children_overlay_view records overlay versions without checking whether they
satisfy the pinned range; since produces_same_children_as compares overlay_view when settling is
enabled, these contexts can mismatch even though the overlay cannot affect resolution, causing
redundant work.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs[605-665]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[797-816]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[164-210]

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

### Issue description
`overlay_view` is compared for equality during contested-children settling, but it is currently populated with *all* preferred versions for a child name, even if those versions do not satisfy that edge’s `bare_specifier` range (including exact-version pins). This can cause otherwise-equivalent contexts to mismatch and force avoidable re-walks/re-recordings.

### Issue Context
- Lockfile reuse records children with exact-version `bare_specifier` pins and stores an empty `overlay_view` (because the overlay cannot move a pinned edge).
- Fresh/settling walks compute a non-empty `overlay_view` for the same pinned edge if the overlay contains any versions for that name, even if those versions are outside the pinned range.
- With `settle_contested_children=true`, this mismatch prevents reuse of recorded children.

### Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[797-816]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[201-210]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs[605-665]

### Suggested fix
In `children_overlay_view`, only include overlay versions that can actually affect selection for that edge:
- Parse `child_range` as a `node_semver::Range` (or detect an exact-version pin), and filter `overlay.versions_for(name)` down to versions that satisfy the range.
- If no overlay version satisfies the edge’s range, omit the entry from `ChildrenOverlayView`.

This keeps `overlay_view` empty for exact pins where the overlay can’t move the edge (aligning reuse vs fresh contexts), reducing unnecessary re-walks.

(Optionally) add a regression test: pinned child edge + overlay preferring only out-of-range versions should not change `recorded_children_match` (no forced re-walk).

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



Informational

6. Noisy test debug output 🐞 Bug ⚙ Maintainability ⭐ New
Description
The new settlement test prints shared_children via an unconditional eprintln!, which will spam
CI logs on every run and makes failures harder to triage. This should be removed or gated to only
print on assertion failure.
Code

pnpm/crates/resolving-deps-resolver/src/tests.rs[R288-290]

+    let shared_children = tree.children_by_id.get("[email protected]").expect("shared children");
+    eprintln!("SHARED CHILDREN:\n{shared_children:#?}\n");
+    assert!(shared_children.is_empty());
Relevance

●●● Strong

Removing unconditional test debug output is a common accepted cleanup to keep CI logs clean.

PR-#13830

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The test contains an unconditional eprintln! call; this matches a previously accepted cleanup
pattern to remove debug output from concurrency regression tests.

pnpm/crates/resolving-deps-resolver/src/tests.rs[282-291]
PR-#13830

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

### Issue description
A new test prints debug output unconditionally (`eprintln!("SHARED CHILDREN...`) which will pollute CI output.

### Issue Context
This is a test-only change, but it adds noisy output on every successful run.

### Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/tests.rs[286-291]

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


Grey Divider

Context
✅ Compliance rules (platform): 26 rules

Grey Divider

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

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous review results

Review updated until commit 490ecc1

Results up to commit b73c4f9 ⚖️ Balanced


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


Remediation recommended
1. Overlay view ignores range ✓ Resolved 🐞 Bug ➹ Performance
Description
RecordedChildrenContext::produces_same_children_as now treats overlay_view as part of the match
when settle_contested_children is enabled, but children_overlay_view records overlay versions
without intersecting them with the child edge’s semver range/pin. This can make
recorded_children_match return false and trigger redundant child re-walks even when the overlay
cannot influence the resolved child version (e.g., exact-version pins from lockfile reuse).
Code

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

+            && (!settle_contested_children || self.overlay_view == other.overlay_view)
Relevance

●● Moderate

Overlay/recorded-children reuse logic is contentious; related overlay-context change was previously
rejected, so outcome uncertain.

PR-#13575
PR-#13830

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The reuse path explicitly pins children to an exact version and records an empty overlay_view, but
the walk path’s children_overlay_view records overlay versions without checking whether they
satisfy the pinned range; since produces_same_children_as compares overlay_view when settling is
enabled, these contexts can mismatch even though the overlay cannot affect resolution, causing
redundant work.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs[605-665]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[797-816]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[164-210]

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

### Issue description
`overlay_view` is compared for equality during contested-children settling, but it is currently populated with *all* preferred versions for a child name, even if those versions do not satisfy that edge’s `bare_specifier` range (including exact-version pins). This can cause otherwise-equivalent contexts to mismatch and force avoidable re-walks/re-recordings.

### Issue Context
- Lockfile reuse records children with exact-version `bare_specifier` pins and stores an empty `overlay_view` (because the overlay cannot move a pinned edge).
- Fresh/settling walks compute a non-empty `overlay_view` for the same pinned edge if the overlay contains any versions for that name, even if those versions are outside the pinned range.
- With `settle_contested_children=true`, this mismatch prevents reuse of recorded children.

### Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[797-816]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[201-210]
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs[605-665]

### Suggested fix
In `children_overlay_view`, only include overlay versions that can actually affect selection for that edge:
- Parse `child_range` as a `node_semver::Range` (or detect an exact-version pin), and filter `overlay.versions_for(name)` down to versions that satisfy the range.
- If no overlay version satisfies the edge’s range, omit the entry from `ChildrenOverlayView`.

This keeps `overlay_view` empty for exact pins where the overlay can’t move the edge (aligning reuse vs fresh contexts), reducing unnecessary re-walks.

(Optionally) add a regression test: pinned child edge + overlay preferring only out-of-range versions should not change `recorded_children_match` (no forced re-walk).

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


Results up to commit e7dcab1 ⚖️ Balanced


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


Remediation recommended
1. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset only declares a pacquet bump but describes a pnpm user-visible lockfile behavior
fix, so it does not explicitly declare the required pnpm bump entry.
Code

.changeset/level-synchronous-children-ownership.md[R1-3]

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

●●● Strong

Multiple recent PRs accepted adding explicit pnpm bump when changeset only listed pacquet.

PR-#13748
PR-#13403

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires changeset front-matter to include an explicit pnpm entry with a
valid bump type. The added changeset declares only "pacquet": patch in its front-matter.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/level-synchronous-children-ownership.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 new changeset front-matter is missing an explicit `pnpm` entry, which is required by the compliance checklist.

## Issue Context
The changeset text describes user-visible behavior affecting `pnpm-lock.yaml` determinism, so the release metadata should explicitly include a `pnpm` bump.

## Fix Focus Areas
- .changeset/level-synchronous-children-ownership.md[1-3]

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


2. Warmup allocates every call ✓ Resolved 🐞 Bug ➹ Performance
Description
claim_children_warmup() always allocates pkg_id.to_string() even when the package was already
warmed, and warm_children_resolutions() calls it for each seeded occurrence; this adds avoidable
allocation and repeated mutex acquisition in a resolver hot path.
Code

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[R1288-1289]

+pub(super) fn claim_children_warmup(ctx: &TreeCtx, pkg_id: &str) -> bool {
+    lock_recoverable(&ctx.workspace.warmed_children_by_id).insert(pkg_id.to_string())
Relevance

●● Moderate

Team sometimes accepts small perf/alloc reductions, but has also rejected some hot-path
micro-optimizations as nonessential.

PR-#13787
PR-#13830

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
claim_children_warmup performs an unconditional to_string() before inserting into
warmed_children_by_id. warm_children_resolutions calls claim_children_warmup for every pending
seed, meaning duplicate occurrences of the same pkg_id will still allocate and lock even though
only the first call should do work.

pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[1285-1290]
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs[1186-1192]

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

## Issue description
`claim_children_warmup()` currently does `insert(pkg_id.to_string())`, which allocates a new `String` on every call (argument evaluation happens before `HashSet::insert` can short-circuit on “already present”). This is invoked from `warm_children_resolutions()` for every pending seed occurrence, so duplicate occurrences of the same package id pay the allocation cost repeatedly.

## Issue Context
This path is intended as a speculative performance optimization; it should be as low-overhead as possible when a package has already been warmed.

## Fix Focus Areas
- pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs[1285-1290]

## Suggested fix
Change `claim_children_warmup` to avoid allocating when the id is already present, e.g.:
- Lock the set once.
- Use `contains(pkg_id)` (borrowed lookup) and only call `to_owned()`/`to_string()` when missing.

Example:
```rust
pub(super) fn claim_children_warmup(ctx: &TreeCtx, pkg_id: &str) -> bool {
   let mut warmed = lock_recoverable(&ctx.workspace.warmed_children_by_id);
   if warmed.contains(pkg_id) {
       false
   } else {
       warmed.insert(pkg_id.to_owned());
       true
   }
}
```
This preserves behavior while eliminating the repeated allocation on duplicate calls.

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

@github-actions

github-actions Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     12.7±0.52ms    29.4 MB/sec    1.22     15.5±1.08ms    24.2 MB/sec
packument/parse                                  1.00     41.9±1.02µs  1584.4 MB/sec    1.09     45.5±0.94µs  1458.7 MB/sec
tarball/download_dependency                      1.00      2.8±0.36ms  1573.5 KB/sec    1.05      2.9±0.31ms  1500.2 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.00   223.4±21.76ms 71.6 KElem/sec    1.18   263.0±29.56ms 60.8 KElem/sec
workspace_resolution/hoist_heavy                 1.00   274.8±18.76ms        ? ?/sec    1.37   377.8±42.30ms        ? ?/sec

@codecov-commenter

codecov-commenter commented Aug 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.89790% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.25%. Comparing base (e9a3ca3) to head (490ecc1).

Files with missing lines Patch % Lines
...-deps-resolver/src/resolve_dependency_tree/walk.rs 97.77% 7 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   pnpm/pnpm#13835   +/-   ##
=======================================
  Coverage   88.25%   88.25%           
=======================================
  Files         625      625           
  Lines      102929   103024   +95     
=======================================
+ Hits        90835    90919   +84     
- Misses      12094    12105   +11     

☔ 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 11, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 490ecc15339a

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.927 ± 0.155 2.783 3.190 1.77 ± 0.20
pacquet@main 2.795 ± 0.201 2.569 3.094 1.69 ± 0.20
pnpr@HEAD 1.767 ± 0.164 1.575 2.043 1.07 ± 0.14
pnpr@main 1.653 ± 0.160 1.472 1.901 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.9271248726,
      "stddev": 0.15474220840209643,
      "median": 2.8622600333,
      "user": 3.17076154,
      "system": 2.31948976,
      "min": 2.7825663057999996,
      "max": 3.1896682988,
      "times": [
        2.8227715877999997,
        2.9017484788,
        2.7919731158,
        3.0836205077999996,
        3.1273648348,
        2.7825663057999996,
        2.9614652057999997,
        2.7927347987999998,
        2.8173355918,
        3.1896682988
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.7947180828000002,
      "stddev": 0.20086835705927228,
      "median": 2.7458386558,
      "user": 2.99007094,
      "system": 2.1950842600000002,
      "min": 2.5691490698,
      "max": 3.0942317177999996,
      "times": [
        3.0211741198,
        3.0444212187999997,
        2.8156713458,
        2.6760059658,
        2.8584962068,
        2.6540818228,
        2.6112231367999996,
        3.0942317177999996,
        2.6027262238,
        2.5691490698
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.7672289697,
      "stddev": 0.16369134275837696,
      "median": 1.7771644388,
      "user": 2.20451834,
      "system": 1.9363385599999998,
      "min": 1.5753926358,
      "max": 2.0433859998,
      "times": [
        1.8051031428,
        1.6022245068,
        2.0433859998,
        1.7513338378,
        1.9513445798,
        1.5753926358,
        1.6395422458000002,
        1.9039989498,
        1.5969687588,
        1.8029950398
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.6529587623000004,
      "stddev": 0.1601847931856686,
      "median": 1.6120148073,
      "user": 1.95685854,
      "system": 1.7780100600000002,
      "min": 1.4721765118,
      "max": 1.9010229128,
      "times": [
        1.9010229128,
        1.7259285728000002,
        1.7470729308000001,
        1.6592181228,
        1.4721765118,
        1.8994533618000002,
        1.5135546768,
        1.5648114918,
        1.5436963468000002,
        1.5026526948
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 344.8 ± 16.4 317.5 367.7 1.00
pacquet@main 381.6 ± 83.4 335.9 614.1 1.11 ± 0.25
pnpr@HEAD 435.5 ± 83.5 329.4 556.7 1.26 ± 0.25
pnpr@main 365.6 ± 46.6 313.0 464.2 1.06 ± 0.14
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.34478064784,
      "stddev": 0.016400969141583822,
      "median": 0.34556162824000003,
      "user": 0.3047427,
      "system": 0.67961076,
      "min": 0.31751499124,
      "max": 0.36766585424,
      "times": [
        0.35060042924,
        0.32652107924,
        0.35565267023999997,
        0.34052282724,
        0.33658793523999997,
        0.33353243824,
        0.36766585424,
        0.36252405624,
        0.31751499124,
        0.35668419724
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.38159628294000003,
      "stddev": 0.08344692147487419,
      "median": 0.35502638224,
      "user": 0.37418060000000003,
      "system": 0.6972670599999999,
      "min": 0.33591105624,
      "max": 0.6141330492400001,
      "times": [
        0.34884746424,
        0.36048891824,
        0.34363905124,
        0.34956384624,
        0.36888386924,
        0.39124222724,
        0.36702426524,
        0.33622908224,
        0.6141330492400001,
        0.33591105624
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.43552877644,
      "stddev": 0.08354555185815028,
      "median": 0.41348071523999996,
      "user": 0.36288719999999997,
      "system": 0.76997096,
      "min": 0.32943674524,
      "max": 0.55670797624,
      "times": [
        0.55670797624,
        0.47619711524,
        0.44072231324,
        0.5373399472400001,
        0.35430647424,
        0.52626065724,
        0.37644190124,
        0.37163551724,
        0.32943674524,
        0.38623911724
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.36556773903999995,
      "stddev": 0.04659083660837997,
      "median": 0.36769621924,
      "user": 0.3236095,
      "system": 0.65510656,
      "min": 0.31299124124,
      "max": 0.46422953124,
      "times": [
        0.36854850224,
        0.31858699624,
        0.32811461824,
        0.31299124124,
        0.40943948424,
        0.46422953124,
        0.36684393624,
        0.37684203924,
        0.37895696423999997,
        0.33112407724
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.919 ± 0.035 2.859 2.970 1.78 ± 0.15
pacquet@main 2.887 ± 0.065 2.794 2.997 1.76 ± 0.15
pnpr@HEAD 1.810 ± 0.135 1.589 1.957 1.11 ± 0.12
pnpr@main 1.638 ± 0.135 1.545 1.924 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.9189086834599998,
      "stddev": 0.035400808039296565,
      "median": 2.91840986816,
      "user": 2.4975949599999994,
      "system": 1.9925901799999999,
      "min": 2.85932194466,
      "max": 2.96967282166,
      "times": [
        2.92328712066,
        2.95637839166,
        2.89916896966,
        2.96967282166,
        2.94294026466,
        2.91353261566,
        2.85932194466,
        2.87755259066,
        2.90150828166,
        2.94572383366
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.8868558017600003,
      "stddev": 0.06468862574398922,
      "median": 2.8706774491599996,
      "user": 2.7711795599999993,
      "system": 2.1396290799999997,
      "min": 2.79436879366,
      "max": 2.99713142866,
      "times": [
        2.89142140866,
        2.8338084386599998,
        2.79436879366,
        2.96765498866,
        2.9489539586599998,
        2.84749200566,
        2.99713142866,
        2.84637209666,
        2.8734640196599996,
        2.86789087866
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.80999959476,
      "stddev": 0.13470647490654675,
      "median": 1.84682294466,
      "user": 1.7130208599999999,
      "system": 1.62637938,
      "min": 1.58878006166,
      "max": 1.9569979076600001,
      "times": [
        1.9569979076600001,
        1.9161706146600002,
        1.6770001246600001,
        1.89220700866,
        1.62400676466,
        1.9499181366600002,
        1.58878006166,
        1.85345827366,
        1.84018761566,
        1.8012694396600002
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.63773583096,
      "stddev": 0.13458211637227277,
      "median": 1.56093128816,
      "user": 1.7505777599999999,
      "system": 1.67881258,
      "min": 1.54500536666,
      "max": 1.9243870116600001,
      "times": [
        1.56025274666,
        1.9243870116600001,
        1.72492455366,
        1.5545032836600001,
        1.54500536666,
        1.5542306406600002,
        1.80805624866,
        1.56160982966,
        1.5462963706600001,
        1.59809225766
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 554.2 ± 31.3 513.8 624.2 1.55 ± 0.12
pacquet@main 542.9 ± 52.0 465.5 621.9 1.51 ± 0.17
pnpr@HEAD 358.7 ± 18.8 329.9 397.0 1.00
pnpr@main 368.6 ± 26.3 330.8 410.0 1.03 ± 0.09
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.5542435132200001,
      "stddev": 0.03130797112054845,
      "median": 0.55505969272,
      "user": 0.7420155199999999,
      "system": 0.9308235400000001,
      "min": 0.51376986222,
      "max": 0.62421173722,
      "times": [
        0.54224497422,
        0.62421173722,
        0.53745527622,
        0.55574305322,
        0.55437633222,
        0.55744741622,
        0.51758304722,
        0.51376986222,
        0.57308702122,
        0.56651641222
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.54291602662,
      "stddev": 0.05202423198733574,
      "median": 0.54764006872,
      "user": 0.7607229200000001,
      "system": 0.90803094,
      "min": 0.46554735022000004,
      "max": 0.62188807522,
      "times": [
        0.60719798622,
        0.55090151522,
        0.54437862222,
        0.55487344722,
        0.58594696122,
        0.62188807522,
        0.46554735022000004,
        0.4895498542200001,
        0.51263702722,
        0.49623942722000003
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.35873126472000005,
      "stddev": 0.018787441294925645,
      "median": 0.3536964987200001,
      "user": 0.27116221999999995,
      "system": 0.63163454,
      "min": 0.32989797422000006,
      "max": 0.39699711122000003,
      "times": [
        0.35166512822000007,
        0.34741441722000005,
        0.34874640322000006,
        0.37100196622000003,
        0.35112162422000004,
        0.37824720522000005,
        0.39699711122000003,
        0.35572786922000005,
        0.32989797422000006,
        0.35649294822000005
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.36855988302000003,
      "stddev": 0.026349139119006142,
      "median": 0.36894971972,
      "user": 0.28023612,
      "system": 0.63398314,
      "min": 0.33080502722000005,
      "max": 0.40997257722,
      "times": [
        0.40997257722,
        0.38695775922000003,
        0.36873311222000005,
        0.36218310022000005,
        0.36916632722000003,
        0.38366235322000003,
        0.39604125622,
        0.33080502722000005,
        0.33799104822000003,
        0.34008626922000007
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.989 ± 0.031 1.933 2.025 5.44 ± 0.32
pacquet@main 1.835 ± 0.050 1.782 1.919 5.02 ± 0.32
pnpr@HEAD 0.367 ± 0.023 0.338 0.412 1.00 ± 0.08
pnpr@main 0.365 ± 0.021 0.334 0.389 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.9888279186199997,
      "stddev": 0.030839765654763138,
      "median": 1.99302590752,
      "user": 1.05470118,
      "system": 0.9871356600000001,
      "min": 1.93328331852,
      "max": 2.02482903452,
      "times": [
        2.02482903452,
        1.9618685585200002,
        2.0162599445200002,
        2.00386013652,
        1.98219167852,
        2.01952984752,
        1.93328331852,
        1.9620310385200002,
        2.01152098252,
        1.9729046465200002
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.8345511262199998,
      "stddev": 0.04972761496788422,
      "median": 1.82857803552,
      "user": 1.07617858,
      "system": 1.00734446,
      "min": 1.7815267125200003,
      "max": 1.9188672535200002,
      "times": [
        1.78758498252,
        1.81643192152,
        1.8445875265200002,
        1.8041466855200001,
        1.84748769752,
        1.7815267125200003,
        1.78900714752,
        1.9151471855200002,
        1.8407241495200002,
        1.9188672535200002
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.36729127162,
      "stddev": 0.022531906158187835,
      "median": 0.3669096740200001,
      "user": 0.27667968,
      "system": 0.6421599600000001,
      "min": 0.33836032852000003,
      "max": 0.41171197052,
      "times": [
        0.3849925765200001,
        0.38303408752000007,
        0.41171197052,
        0.35576833652000006,
        0.34145003652000006,
        0.37447263852000007,
        0.33836032852000003,
        0.37021393352000004,
        0.36360541452000006,
        0.34930339352000006
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.3654905144200001,
      "stddev": 0.020967592899768836,
      "median": 0.36478920102,
      "user": 0.26161587999999997,
      "system": 0.63506816,
      "min": 0.33439925452,
      "max": 0.38943989152,
      "times": [
        0.34182860952000005,
        0.34662796752,
        0.36131049352000005,
        0.33439925452,
        0.35399751452000006,
        0.36826790852,
        0.38125223452000007,
        0.38943989152,
        0.3888765765200001,
        0.38890469352000007
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 274.6 ± 21.7 243.7 312.4 2.68 ± 0.26
pacquet@main 237.1 ± 13.1 209.3 253.6 2.31 ± 0.18
pnpr@HEAD 102.6 ± 5.6 92.3 113.5 1.00
pnpr@main 104.1 ± 6.5 95.6 124.7 1.01 ± 0.08
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.27458930872000004,
      "stddev": 0.021669134918936045,
      "median": 0.27031403272,
      "user": 0.23581877999999995,
      "system": 0.09780148000000001,
      "min": 0.24373864322000002,
      "max": 0.31236260522000003,
      "times": [
        0.31236260522000003,
        0.30470863922,
        0.28494571022000004,
        0.26951646622000003,
        0.26836229722000005,
        0.27111159922,
        0.26366143022,
        0.27791384422000004,
        0.24957185222,
        0.24373864322000002
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.2370850266745455,
      "stddev": 0.01310197841510604,
      "median": 0.23868293322000003,
      "user": 0.20520384363636363,
      "system": 0.07613228,
      "min": 0.20929808822,
      "max": 0.25358813422000004,
      "times": [
        0.25330760122,
        0.22567438622000002,
        0.22613005022000002,
        0.24108380622000003,
        0.24715787622000002,
        0.25358813422000004,
        0.23854502022000001,
        0.23868293322000003,
        0.20929808822,
        0.24151061922000003,
        0.23295677822000002
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.10257722995333333,
      "stddev": 0.005579937448818216,
      "median": 0.10195095472000001,
      "user": 0.026869213333333326,
      "system": 0.017082646666666663,
      "min": 0.09230483222000001,
      "max": 0.11352657322000001,
      "times": [
        0.09230483222000001,
        0.10158433422000002,
        0.10214866522,
        0.11168455822000001,
        0.10737579422000001,
        0.09966542822,
        0.10305797422000001,
        0.10987171022000002,
        0.10193850722000002,
        0.10887880222000001,
        0.10765630822000001,
        0.10987026122000002,
        0.10329823922,
        0.10196340222000001,
        0.10581985222000001,
        0.09287046522,
        0.10051666322000001,
        0.11352657322000001,
        0.11024508122000001,
        0.09745699622000001,
        0.10361451322000001,
        0.09466001322,
        0.10167324722000001,
        0.10130982222000001,
        0.09544828522000001,
        0.09840305022000001,
        0.09663235622,
        0.09793399622000001,
        0.10175762622000001,
        0.10414954022000002
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.1040604524051852,
      "stddev": 0.006501714542880839,
      "median": 0.10364486922,
      "user": 0.029036739259259262,
      "system": 0.01559542814814815,
      "min": 0.09559895422,
      "max": 0.12472721022000002,
      "times": [
        0.10015169822000002,
        0.10722633022000001,
        0.11403691722,
        0.10448904022000001,
        0.10548879422000002,
        0.10748921822000002,
        0.10364486922,
        0.10598381222000001,
        0.09992240622000001,
        0.09735146622000002,
        0.09559895422,
        0.09713670822,
        0.09807442622000001,
        0.10306770822000001,
        0.09964352422000002,
        0.10105091522000001,
        0.10612537022000001,
        0.10432242422000002,
        0.09565559522000001,
        0.10800058022000002,
        0.09956156322000001,
        0.10008883822,
        0.12472721022000002,
        0.11286495922,
        0.09929428522000001,
        0.10899277522,
        0.10964182522000002
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 869.5 ± 190.0 634.2 1186.9 1.00
pacquet@main 1054.8 ± 318.0 722.9 1775.3 1.21 ± 0.45
pnpm@HEAD 4014.4 ± 229.1 3698.8 4393.7 4.62 ± 1.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.8694577806244446,
      "stddev": 0.19004700502377805,
      "median": 0.92267759518,
      "user": 0.8574959355555555,
      "system": 0.21828445333333335,
      "min": 0.6342388371800001,
      "max": 1.18687061718,
      "times": [
        0.92267759518,
        0.9812557391800001,
        0.6342388371800001,
        1.18687061718,
        0.77411013918,
        1.03672172518,
        0.9331625291800001,
        0.7175748301800001,
        0.6385080131800001
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.05479764818,
      "stddev": 0.3179560331490204,
      "median": 1.01626125718,
      "user": 1.0345014911111112,
      "system": 0.17452578666666665,
      "min": 0.72286534018,
      "max": 1.77531546218,
      "times": [
        0.72286534018,
        1.01626125718,
        1.77531546218,
        0.9687867711800001,
        1.06853833518,
        0.75293851418,
        1.2772772751800001,
        0.8846249931800001,
        1.02657088518
      ]
    },
    {
      "command": "pnpm@HEAD",
      "mean": 4.014428134624445,
      "stddev": 0.22907356089381467,
      "median": 3.96498400118,
      "user": 5.855587157777778,
      "system": 0.44367567555555554,
      "min": 3.69881604418,
      "max": 4.39368095618,
      "times": [
        3.90290272118,
        4.39368095618,
        4.367526171180001,
        3.69881604418,
        3.97576406918,
        3.94400193818,
        3.96498400118,
        3.8421419651799997,
        4.040035345180001
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.837 ± 0.103 4.652 4.970 1.32 ± 0.04
pacquet@main 4.754 ± 0.241 4.553 5.155 1.30 ± 0.07
pnpr@HEAD 3.716 ± 0.118 3.616 4.005 1.02 ± 0.04
pnpr@main 3.656 ± 0.093 3.559 3.872 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.836959075279999,
      "stddev": 0.10253846601614407,
      "median": 4.8425832706800005,
      "user": 3.13507082,
      "system": 2.35968846,
      "min": 4.65239344168,
      "max": 4.97042672168,
      "times": [
        4.97042672168,
        4.96795817968,
        4.85289956068,
        4.88713848868,
        4.90798038068,
        4.83226698068,
        4.78004327768,
        4.79410537268,
        4.65239344168,
        4.72437834868
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.753914363280001,
      "stddev": 0.24056661990726405,
      "median": 4.62078045268,
      "user": 2.79503372,
      "system": 2.16914746,
      "min": 4.55253351168,
      "max": 5.15525919968,
      "times": [
        4.58324276868,
        5.03581289868,
        4.6677824266800005,
        5.15525919968,
        4.60357026068,
        4.59789173268,
        4.55253351168,
        4.62069664468,
        4.62086426068,
        5.10148992868
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.7161154193800003,
      "stddev": 0.11781452771616746,
      "median": 3.69151859968,
      "user": 1.9953355199999998,
      "system": 1.84054346,
      "min": 3.61634191868,
      "max": 4.00510692868,
      "times": [
        3.72868451868,
        3.76411634868,
        3.69076422468,
        3.69227297468,
        3.62930956268,
        3.78118037768,
        4.00510692868,
        3.62392161468,
        3.61634191868,
        3.62945572468
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.65591704048,
      "stddev": 0.09323690588221928,
      "median": 3.64149934018,
      "user": 1.8924979199999998,
      "system": 1.7146532599999997,
      "min": 3.55898751268,
      "max": 3.87221267568,
      "times": [
        3.65499012068,
        3.63203788068,
        3.65096079968,
        3.70518456368,
        3.55898751268,
        3.56834622368,
        3.72225757468,
        3.60192372368,
        3.59226932968,
        3.87221267568
      ]
    }
  ]
}

@github-actions

github-actions Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13835
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,859.32 ms
(+6.01%)Baseline: 2,697.15 ms
3,236.58 ms
(88.34%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
1,933.28 ms
(+6.96%)Baseline: 1,807.54 ms
2,169.04 ms
(89.13%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
513.77 ms
(+11.42%)Baseline: 461.11 ms
553.33 ms
(92.85%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
243.74 ms
(+5.46%)Baseline: 231.12 ms
277.34 ms
(87.88%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,782.57 ms
(+13.06%)Baseline: 2,461.24 ms
2,953.49 ms
(94.21%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,652.39 ms
(+2.60%)Baseline: 4,534.61 ms
5,441.54 ms
(85.50%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
317.51 ms
(+5.96%)Baseline: 299.64 ms
359.57 ms
(88.30%)
isolated-linker.peer-heavy-resolve.hot-cache.offline📈 view plot
🚷 view threshold
634.24 ms
(-14.19%)Baseline: 739.14 ms
886.97 ms
(71.51%)
🐰 View full continuous benchmarking report in Bencher

@zkochan

zkochan commented Aug 11, 2026

Copy link
Copy Markdown
Member Author

Correction: this branch is not fully deterministic

I ran the repro loop further after opening this PR and have to walk back the determinism claim above. Scoping the settling to the first walk leaves a residual race, and the numbers behind both halves of the trade-off are now measured.

What still flips. 22 more runs of the repro produced one deviation: [email protected]'s minimatch edge flips 3.1.5 ↔ 3.0.5, roughly 1 run in 14. The flips the issue reported (classnames, lodash) are gone. main produces 3 distinct lockfiles in 4 runs, so this branch is a large improvement, but it is not the guarantee #13685 asks for.

Why. A hoist wave suppresses on average 12 contested settlings on this graph — instrumented, they are packages like @babel/[email protected], [email protected], [email protected]. Two of those would have landed on different child edges, which is exactly what the settling exists to correct.

Why they were suppressed. Re-recording a package's child edges mid-hoist makes sync_discovery_tree report its view unmergeable, and the peer-discovery engine answers by rebuilding that view from scratch and dropping PeerDiscoveryCaches (resolve_peers/discovery.rs). Instrumented on the repro: main rebuilds 0 times, settling in every wave rebuilds 2 — about 475 ms each, which is the whole 23% regression that got #13830 reverted. The settling itself is free: computing the overlay projection and discarding the answer measures at main's resolve time (4.192 s vs 4.214 s).

So the choice today is between:

repro determinism resolve time
main 3 distinct lockfiles in 4 runs 4.281 s
settle in every wave (#13830) 16 of 16 identical 5.256 s (+23%)
settle in the first walk (this branch) 1 deviation in 22 4.277 s (±0%)

Getting both means making the discovery engine's reaction to a children rewrite incremental — updating the changed entry and invalidating only what derives from that package — instead of rebuilding and dropping every cache. That is its own piece of work in resolve_peers/discovery.rs, and it would pay off for every other rewrite too, not just this fix.

Marking this draft rather than leaving a PR up that claims more than it delivers.


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

@zkochan
zkochan marked this pull request as draft August 11, 2026 19:37
@zkochan

zkochan commented Aug 11, 2026

Copy link
Copy Markdown
Member Author

The settling cannot close this on its own — traced

I tried to make this branch fully deterministic and found that neither it nor the merged-then-reverted version achieves it. The +23% variant flips too: 16 more runs of the repro produced one deviation, the same [email protected] → minimatch edge. My earlier "16 of 16 identical" was luck, and I have to withdraw it.

What the trace shows. Logging every record_children for that package: each run records it exactly once, during the first walk, as Published — but under a different owner.

run A: edges=[…, [email protected]] owner.parent_path=[@teambit/bit, @teambit/aspect, jest, @jest/core, @jest/transform, babel-plugin-istanbul]
run B: edges=[…, [email protected]] owner.parent_path=[@teambit/bit, @teambit/jest,   jest, @jest/core, @jest/transform, babel-plugin-istanbul]

Same depth, same importer, and @teambit/[email protected] sorts before @teambit/[email protected], so the first occurrence outranks the second and would win any contest between them. In run B it never gets the chance: an ancestor on that path matched its own recording, stayed lazy, and so that subtree was never walked. The better-ranked occurrence of test-exclude does not exist in that run.

So the invariant this PR establishes is the wrong one. It makes the recorded children the answer of the best-ranked occurrence that got walked, and which occurrences get walked is itself arrival-ordered. Settling shrinks the race — main gives 3 distinct lockfiles in 4 runs, both variants here give ~1 deviation in 8–16 — but it cannot close it.

What would. Either

  1. Level-synchronous claim assignment — seed a whole depth level, assign each package's children ownership by rank across all of that level's occurrences, then walk. Ownership never transfers, so there are no re-walks at all, no children_by_id rewrites, and nothing for the peer-discovery engine to invalidate. It also removes the re-walk cost this PR spends its second and third commits managing. It restructures the walk's concurrency, and costs some cross-level pipelining.
  2. Subtree read-sets — record per package the overlay names its whole subtree consulted, so an ancestor re-walks when anything below it is overlay-sensitive, rather than only when its own child edges are. Keeps the current structure; the read-sets are the new cost, and they grow toward the root.

Both are bigger than this PR. Leaving it in draft; the two perf commits (the allocation fix in the projection, and scoping the settling to the first walk) stand on their own and can be salvaged for whichever direction wins.


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

The overlay projection asked for each child edge's lookup names through
a throwaway `WantedDependency` and a `Vec<String>`, so a package with
eighty children paid a few hundred allocations per walk to learn that
its level prefers no version of any of them.

`overlay_lookup_names` now borrows the alias and specifier it is given
and hands back two `Cow` slots, and `real_package_name_of` takes the
same pair rather than a whole wanted dependency. The peer-heavy resolve
benchmark, whose every lookup misses, drops from +12.1% over its
pre-fix baseline to +2.6% (user time, 20 runs).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zkochan zkochan changed the title fix(resolver): settle contested children in the first walk only fix(resolver): settle children ownership one level at a time Aug 11, 2026
@zkochan
zkochan marked this pull request as ready for review August 11, 2026 21:39
Copilot AI review requested due to automatic review settings August 11, 2026 21:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

greptile-apps[bot]
greptile-apps Bot previously approved these changes Aug 11, 2026
@qodo-code-review

Copy link
Copy Markdown

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (5)
pnpm/crates/resolving-deps-resolver/src/tests.rs (1)

202-223: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse the existing opts helper instead of repeating the options literal.

pnpm/crates/resolving-deps-resolver/src/tests.rs already defines fn opts(auto_install_peers: bool) -> ResolveDependencyTreeOptions at line 3088, which builds the same literal. Call it here.

As per path instructions: "avoid unnecessary duplication."

♻️ Proposed deduplication
-        ResolveDependencyTreeOptions {
-            base_opts: ResolveOptions::default(),
-            patched_dependencies: None,
-            manifest_hook: None,
-            overrides_hook: None,
-            pnpmfile_hook: None,
-            read_package_log: None,
-            auto_install_peers: false,
-        },
+        opts(false),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pnpm/crates/resolving-deps-resolver/src/tests.rs` around lines 202 - 223,
Update resolve_settlement_tree to call the existing opts(false) helper when
constructing ResolveDependencyTreeOptions, removing the duplicated inline
options literal while preserving auto_install_peers as false.

Source: Path instructions

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

1285-1290: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Avoid the String allocation on the repeat-claim path.

Every occurrence of a package calls claim_children_warmup, but only the first insertion returns true. insert(pkg_id.to_string()) allocates on each call, including the losing ones. In a peer-heavy graph the losing calls dominate.

Check membership first, then allocate only for the first claim.

♻️ Proposed allocation guard
 pub(super) fn claim_children_warmup(ctx: &TreeCtx, pkg_id: &str) -> bool {
-    lock_recoverable(&ctx.workspace.warmed_children_by_id).insert(pkg_id.to_string())
+    let mut warmed = lock_recoverable(&ctx.workspace.warmed_children_by_id);
+    !warmed.contains(pkg_id) && warmed.insert(pkg_id.to_string())
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs`
around lines 1285 - 1290, Update claim_children_warmup to check whether pkg_id
is already present before creating an owned String, and allocate/insert only
when the package has not been claimed. Preserve the existing boolean contract:
return true only for the first claim and false for repeat claims.
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs (3)

984-996: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the ordering constraint between warmup and assign_level_owners.

assign_level_owners moves pending.peer_shadowed out with std::mem::take. Line 1198 reads pending.peer_shadowed. The code is correct today because seed_node_children warms each child seed before settle_level assigns owners. Nothing enforces that order.

Add one sentence to the peer_shadowed field comment that states warmup must read the set before the level settles.

Also applies to: 1190-1198

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

In `@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs`
around lines 984 - 996, Update the comment on the pending.peer_shadowed field to
state that warmup must read the set before the level settles and
assign_level_owners moves it out. Preserve the existing implementation and
document only this ordering constraint.

620-638: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Move drop(packages) before register_peer_dep_names.

register_peer_dep_names takes the all_peer_dep_names lock while this function still holds the packages lock. Other call sites in resolve_node_seed do the same, so the lock order is consistent today and no deadlock exists. The nesting is still avoidable here.

Assign the new value first, release the packages guard, then register the names.

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

In `@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs`
around lines 620 - 638, In install_owner_peer_dependencies, assign
peer_dependencies to existing.peer_dependencies, then release the packages lock
before calling register_peer_dep_names. Preserve the existing equality check and
record_package_write behavior, registering the names only after the packages
guard has been dropped.

579-613: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Confirm that every seed passed to assign_level_owners shares one rank prefix.

The doc comment states that a level shares update policy, depth, and importer order, so only parent_ancestors needs comparison. settle_level flattens the seeds of every frontier node into one call. That is sound only while all frontier nodes of a wave hold the same depth. If a future change lets a frontier mix depths, the winner chosen here would not match ChildrenOwner::wins_over, and the losers would silently skip their claim.

Consider asserting the shared depth, or comparing (depth, parent_ancestors) here so the local rank cannot drift from the global rank.

♻️ Proposed rank alignment
-        for (index, pending) in level.iter().enumerate() {
-            let best_so_far = *best.entry(pending.id.as_str()).or_insert(index);
-            if level[best_so_far].parent_ancestors > pending.parent_ancestors {
-                best.insert(pending.id.as_str(), index);
-            }
-        }
+        for (index, pending) in level.iter().enumerate() {
+            let best_so_far = *best.entry(pending.id.as_str()).or_insert(index);
+            let incumbent = &level[best_so_far];
+            if (incumbent.depth, &incumbent.parent_ancestors)
+                > (pending.depth, &pending.parent_ancestors)
+            {
+                best.insert(pending.id.as_str(), index);
+            }
+        }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs`
around lines 579 - 613, Ensure assign_level_owners validates or accounts for a
shared depth across all non-linked seeds before selecting winners. Align winner
selection with ChildrenOwner::wins_over by comparing the complete rank,
including depth and parent_ancestors, or assert that every seed has the same
depth while preserving the existing parent_ancestors ordering.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.changeset/level-synchronous-children-ownership.md:
- Line 5: Soften the determinism wording in the changeset description to state
that resolution reduces dependence on concurrent completion order rather than
eliminating it entirely. Accurately mention the remaining possibility of
lockfile variation, or defer the changeset until that residual case is resolved.

In `@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs`:
- Around line 533-569: Document the TypeScript parity decision for the
ownership-order behavior introduced by walk_from_seeds: either record the
equivalent TypeScript pnpm workspace implementation in this PR or explicitly
note that parity work is deferred. Add a concise statement to the PR description
or changeset, and do not leave the user-visible lockfile resolution change
undocumented.

In `@pnpm/crates/resolving-deps-resolver/src/tests.rs`:
- Around line 225-279: Add a regression test alongside the existing settlement
tests that creates two occurrences of the same package under distinct parent
alias scopes, with each occurrence’s peerDependencies shadowing a different
dependency name. Resolve them under level-synchronous settlement, then assert
the parent-path winner is selected and that the recorded children and envelope
peer split use that winner’s peer_shadowed set. Exercise assign_level_owners and
install_owner_peer_dependencies through the public settlement flow, ensuring the
test fails if peer-shadowing is taken from a later or non-winning occurrence.

---

Nitpick comments:
In `@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs`:
- Around line 984-996: Update the comment on the pending.peer_shadowed field to
state that warmup must read the set before the level settles and
assign_level_owners moves it out. Preserve the existing implementation and
document only this ordering constraint.
- Around line 620-638: In install_owner_peer_dependencies, assign
peer_dependencies to existing.peer_dependencies, then release the packages lock
before calling register_peer_dep_names. Preserve the existing equality check and
record_package_write behavior, registering the names only after the packages
guard has been dropped.
- Around line 579-613: Ensure assign_level_owners validates or accounts for a
shared depth across all non-linked seeds before selecting winners. Align winner
selection with ChildrenOwner::wins_over by comparing the complete rank,
including depth and parent_ancestors, or assert that every seed has the same
depth while preserving the existing parent_ancestors ordering.

In
`@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs`:
- Around line 1285-1290: Update claim_children_warmup to check whether pkg_id is
already present before creating an owned String, and allocate/insert only when
the package has not been claimed. Preserve the existing boolean contract: return
true only for the first claim and false for repeat claims.

In `@pnpm/crates/resolving-deps-resolver/src/tests.rs`:
- Around line 202-223: Update resolve_settlement_tree to call the existing
opts(false) helper when constructing ResolveDependencyTreeOptions, removing the
duplicated inline options literal while preserving auto_install_peers as false.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 349f0899-e299-41b4-968a-de522e17ef6e

📥 Commits

Reviewing files that changed from the base of the PR and between b73c4f9 and e7dcab1.

📒 Files selected for processing (6)
  • .changeset/level-synchronous-children-ownership.md
  • pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree.rs
  • 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/tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rs

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

@greptile-apps
greptile-apps Bot dismissed their stale review August 11, 2026 22:02

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@zkochan

zkochan commented Aug 11, 2026

Copy link
Copy Markdown
Member Author

Addressed in e40c18c. Follow-up issue for the paths this PR does not close: #13837.

Changeset overstates determinism — reworded. The "one deviation in 22 runs" it cites is from the previous approach on this branch (the re-walk, since replaced); this walk produced one lockfile across 46 runs. The note now describes the bug that is fixed rather than promising determinism outright, which is the honest bound: within a walk, ownership is now settled from the complete set of a level's occurrences and never transfers, so nothing decides on arrival order; hoist waves and the lockfile-reuse walk still claim outside that discipline, which is #13837.

TypeScript parity — the PR description records it: children ownership, the claim ranking and children_by_id are pacquet's own machinery, and resolveDependencyTree.ts has no counterpart to change. Nothing is deferred.

Peer-shadowing regression test — added, and it was worth asking for. shared declares pin as both a dependency and a peer, and is reached at the same depth down two paths; only a-parent's side resolves pin in the scope that reaches it, so only there does the peer shadow the dependency. a-parent sorts first, its edge is the delayed one, and the recorded children are empty — the winner's set filtered them. Inverting the winner comparison in assign_level_owners fails it.

Rank drift in assign_level_owners — taken. It now compares (depth, parent_ancestors), so a frontier that ever carried mixed depths could not silently disagree with ChildrenOwner::wins_over.

claim_children_warmup allocation — taken; the owned key is built only for the occurrence that takes the warmup.

Nested packages / all_peer_dep_names locks — taken; the packages guard is released before the names are registered.

peer_shadowed ordering constraint — documented on the field: it is readable up to the level's settlement, which moves the winner's set onto its claim, and the prewarm reads it while the level is still seeding.

Reuse the opts helper in the test — not applicable: that helper is private to mod peer_own_dep_shadowing. The three settlement tests share resolve_settlement_tree, so the literal appears once at this scope.

8133 tests pass; repro still byte-identical across 8 further runs after these changes.


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

greptile-apps[bot]
greptile-apps Bot previously approved these changes Aug 11, 2026
Copilot AI review requested due to automatic review settings August 11, 2026 22:05
@greptile-apps
greptile-apps Bot dismissed their stale review August 11, 2026 22:05

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

No code suggestions found for the PR.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs (2)

1200-1208: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Reuse the children_specs_by_id cache in the warmup path.

warm_children_resolutions calls extract_children directly. seed_node_children caches the same unfiltered spec list under ctx.workspace.children_specs_by_id for the same pending.id. The warmup therefore parses each manifest a second time for every package it warms. Read the cache first and populate it on a miss, so the later seed_node_children call hits it.

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

In `@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs`
around lines 1200 - 1208, Update warm_children_resolutions to read the
children_specs_by_id cache for pending.id before calling extract_children, and
insert the extracted unfiltered specs into the cache on a miss. Preserve the
existing filtering and warmup behavior while ensuring seed_node_children can
reuse the populated entry.

550-573: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Remove #[async_recursion] from walk_from_seeds. Its callers invoke it directly, and seed_node_children and resolve_reused_node re-enter resolve_node, not walk_from_seeds. Keep recursion boxing on the recursive helpers.

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

In `@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs`
around lines 550 - 573, Remove the #[async_recursion] attribute from
walk_from_seeds while leaving its async implementation and callers unchanged.
Preserve recursion boxing on the helpers that actually re-enter resolve_node,
including seed_node_children and resolve_reused_node.
pnpm/crates/resolving-deps-resolver/src/tests.rs (1)

202-223: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse the existing opts helper instead of repeating the options literal.

tests.rs already defines fn opts(auto_install_peers: bool) -> ResolveDependencyTreeOptions with the same field values (lines 3130-3140). Call it here.

♻️ Proposed refactor
     resolve_dependency_tree(
         resolver,
         &manifest,
         [DependencyGroup::Prod],
-        ResolveDependencyTreeOptions {
-            base_opts: ResolveOptions::default(),
-            patched_dependencies: None,
-            manifest_hook: None,
-            overrides_hook: None,
-            pnpmfile_hook: None,
-            read_package_log: None,
-            auto_install_peers: false,
-        },
+        opts(false),
     )
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pnpm/crates/resolving-deps-resolver/src/tests.rs` around lines 202 - 223,
Update resolve_settlement_tree to replace the repeated
ResolveDependencyTreeOptions literal with the existing opts(false) helper,
preserving the current auto_install_peers setting and all other option values.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs`:
- Around line 1200-1208: Update warm_children_resolutions to read the
children_specs_by_id cache for pending.id before calling extract_children, and
insert the extracted unfiltered specs into the cache on a miss. Preserve the
existing filtering and warmup behavior while ensuring seed_node_children can
reuse the populated entry.
- Around line 550-573: Remove the #[async_recursion] attribute from
walk_from_seeds while leaving its async implementation and callers unchanged.
Preserve recursion boxing on the helpers that actually re-enter resolve_node,
including seed_node_children and resolve_reused_node.

In `@pnpm/crates/resolving-deps-resolver/src/tests.rs`:
- Around line 202-223: Update resolve_settlement_tree to replace the repeated
ResolveDependencyTreeOptions literal with the existing opts(false) helper,
preserving the current auto_install_peers setting and all other option values.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 84f7c297-7255-4a5b-93c9-964ca9a5ab2d

📥 Commits

Reviewing files that changed from the base of the PR and between e7dcab1 and e40c18c.

📒 Files selected for processing (4)
  • .changeset/level-synchronous-children-ownership.md
  • 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/tests.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rs
  • .changeset/level-synchronous-children-ownership.md

greptile-apps[bot]
greptile-apps Bot previously approved these changes Aug 11, 2026
Occurrences of a package race to claim its children: whichever one
reaches it while the claim stands vacant walks the package and records
what its own level's preferred-versions overlay resolved, and a
better-placed occurrence arriving later keeps that recording rather than
walking again — walking on every claim win is what expanded
exponentially in #13574. Which occurrence gets there first is
thread timing, so identical inputs produced different lockfiles run to
run (issue #13685).

The walk now advances a depth level at a time: a level is seeded in full
before any of it is settled, so every occurrence of a package at that
depth is in hand when its children ownership is decided. The rank is
(update policy, depth, importer order, parent path) and a level shares
the first three, so the best-placed occurrence is the one whose parent
path sorts first, and it is the only one that claims. Ownership never
passes to an occurrence seeded later, no occurrence re-walks children
another one recorded, and what a package records stops depending on
which subtree reached it first.

Settling the level, rather than each parent's fanout, is also why this
costs nothing: the ownership handovers it removes were re-walks. The
issue's `@teambit/bit` repro resolves in 4.29s against 4.29s on main and
is byte-identical across 46 runs, where main produces 3 distinct
lockfiles in 4; the peer-heavy resolve benchmark drops from 844ms to
467ms, since a package's children are now seeded once instead of once
per occurrence that wins its claim.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings August 11, 2026 22:10
@greptile-apps
greptile-apps Bot dismissed their stale review August 11, 2026 22:10

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

No code suggestions found for the PR.

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 490ecc1

@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 a commit that referenced this pull request Aug 11, 2026
The "Rust CI / Doc" job runs `cargo doc` with `--document-private-items`
and the pre-push check did not. Nearly every item in these crates is
private or `pub(super)`, and rustdoc only resolves the doc links of the
items it documents, so a link to a renamed or deleted private item
passed the local check and failed CI.

Reproduced by pointing one doc comment at a name that does not exist:
the old command reports nothing, the CI command reports `unresolved
link`. Caught after two red `Rust CI / Doc` runs on #13835.

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13835
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,588.78 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
338.36 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
329.90 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
92.30 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,575.39 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,616.34 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
329.44 ms
🐰 View full continuous benchmarking report in Bencher

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.

Single-importer resolution is nondeterministic: recorded children depend on occurrence arrival order

3 participants