Repository navigation
fix(resolver): settle children ownership one level at a time - #13835
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe 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. ChangesDeterministic dependency resolution
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
Possibly related issues
Possibly related PRs
Suggested labels: Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
PR Summary by Qodofix(resolver): settle children ownership one level at a time
AI Description
Diagram
High-Level Assessment
Files changed (8)
|
Confidence Score: 5/5The 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 |
Code Review by Qodo
1. Historical rationale in walk docs
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Micro-Benchmark ResultsLinux |
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
Integrated-Benchmark Report (Linux)Commit: 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
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
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
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
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
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
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
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
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
]
}
]
} |
Correction: this branch is not fully deterministicI 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: Why. A hoist wave suppresses on average 12 contested settlings on this graph — instrumented, they are packages like Why they were suppressed. Re-recording a package's child edges mid-hoist makes So the choice today is between:
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 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]). |
The settling cannot close this on its own — tracedI 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 What the trace shows. Logging every Same depth, same importer, and 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 — What would. Either
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]>
|
Code review by qodo was updated up to the latest commit e7dcab1 |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (5)
pnpm/crates/resolving-deps-resolver/src/tests.rs (1)
202-223: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReuse the existing
optshelper instead of repeating the options literal.
pnpm/crates/resolving-deps-resolver/src/tests.rsalready definesfn opts(auto_install_peers: bool) -> ResolveDependencyTreeOptionsat 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 valueAvoid the
Stringallocation on the repeat-claim path.Every occurrence of a package calls
claim_children_warmup, but only the first insertion returnstrue.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 winDocument the ordering constraint between warmup and
assign_level_owners.
assign_level_ownersmovespending.peer_shadowedout withstd::mem::take. Line 1198 readspending.peer_shadowed. The code is correct today becauseseed_node_childrenwarms each child seed beforesettle_levelassigns owners. Nothing enforces that order.Add one sentence to the
peer_shadowedfield 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 valueMove
drop(packages)beforeregister_peer_dep_names.
register_peer_dep_namestakes theall_peer_dep_nameslock while this function still holds thepackageslock. Other call sites inresolve_node_seeddo 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
packagesguard, 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 winConfirm that every seed passed to
assign_level_ownersshares one rank prefix.The doc comment states that a level shares update policy, depth, and importer order, so only
parent_ancestorsneeds comparison.settle_levelflattens the seeds of every frontier node into one call. That is sound only while all frontier nodes of a wave hold the samedepth. If a future change lets a frontier mix depths, the winner chosen here would not matchChildrenOwner::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
📒 Files selected for processing (6)
.changeset/level-synchronous-children-ownership.mdpnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree.rspnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/reuse.rspnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rspnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rspnpm/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
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
|
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 Peer-shadowing regression test — added, and it was worth asking for. Rank drift in
Nested
Reuse the 8133 tests pass; repro still byte-identical across 8 further runs after these changes. Written by an agent (Claude Code, claude-opus-5[1m]). |
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
pnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rs (2)
1200-1208: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueReuse the
children_specs_by_idcache in the warmup path.
warm_children_resolutionscallsextract_childrendirectly.seed_node_childrencaches the same unfiltered spec list underctx.workspace.children_specs_by_idfor the samepending.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 laterseed_node_childrencall 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 valueRemove
#[async_recursion]fromwalk_from_seeds. Its callers invoke it directly, andseed_node_childrenandresolve_reused_nodere-enterresolve_node, notwalk_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 winReuse the existing
optshelper instead of repeating the options literal.
tests.rsalready definesfn opts(auto_install_peers: bool) -> ResolveDependencyTreeOptionswith 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
📒 Files selected for processing (4)
.changeset/level-synchronous-children-ownership.mdpnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/walk.rspnpm/crates/resolving-deps-resolver/src/resolve_dependency_tree/workspace_ctx.rspnpm/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
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]>
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
|
Code review by qodo was updated up to the latest commit 490ecc1 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
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]>
|
| Project | pnpm's project |
| Branch | pr/13835 |
| Testbed | pnpr |
⚠️ 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-thresholdsflag.
Click to view all benchmark results
| Benchmark | Latency | milliseconds (ms) |
|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot | 1,588.78 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 338.36 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 329.90 ms |
| isolated-linker.fresh-resolve.hot-cache.offline | 📈 view plot | 92.30 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 1,575.39 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr | 📈 view plot | 3,616.34 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 329.44 ms |
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:@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_childrenbecomes a frontier loop (walk_from_seeds→seed_node_children→assign_level_owners→settle_level);resolve_node_seedno 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:mainisolated-linker.peer-heavy-resolve.hot-cache.offline— the scenario that alerted on #13830 — run locally through the integrated-benchmark harness, 20 runs: 467 ms againstmain'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
Checklist
already linked to it solves it.
pnpm/port, or the description notes what still needs porting.pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Written by an agent (Claude Code, claude-opus-5[1m]).
Summary by CodeRabbit
Bug Fixes
Tests