Repository navigation
fix(deps-restorer): repair a shared virtual-store slot in place - #13810
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
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:
📝 WalkthroughWalkthroughThe shared-slot import path now repairs incomplete occupied virtual-store slots in place. It preserves complete slots and unrelated entries, replaces damaged entries atomically, and validates actual store contents. ChangesShared slot repair
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Importer
participant SharedSlot
participant Store
Importer->>SharedSlot: inspect occupied target
SharedSlot->>Store: compare expected contents
Store-->>Importer: report matching and damaged entries
Importer->>SharedSlot: repair entries in place
SharedSlot-->>Importer: retain complete target directory
Assessment against linked issues
Possibly related PRs
Suggested labels: Suggested reviewers: ✨ Finishing Touches🧪 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 |
Confidence Score: 5/5The PR appears safe to merge within the eligible follow-up-review scope. No blocking failure remains. Reviews (10): Last reviewed commit: "fix(indexed-pkg-importer): validate file..." | Re-trigger Greptile |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #13810 +/- ##
=========================================
Coverage 88.24% 88.25%
=========================================
Files 624 625 +1
Lines 101807 102927 +1120
=========================================
+ Hits 89837 90835 +998
- Misses 11970 12092 +122 ☔ 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.48395962958,
"stddev": 0.1794112753037104,
"median": 2.4002687431800003,
"user": 1.66380424,
"system": 1.4263624599999998,
"min": 2.3279880151800003,
"max": 2.8132844301800004,
"times": [
2.37458275118,
2.3628919021800003,
2.3279880151800003,
2.5728523881800003,
2.43220139118,
2.4061461271800004,
2.7874942121800004,
2.8132844301800004,
2.36776371918,
2.39439135918
]
},
{
"command": "pacquet@main",
"mean": 2.4994595284800005,
"stddev": 0.11840437219811455,
"median": 2.45876652568,
"user": 1.65295514,
"system": 1.34843566,
"min": 2.38357988118,
"max": 2.6947024071800003,
"times": [
2.6947024071800003,
2.6474456021800004,
2.4979035411800004,
2.6402986321800004,
2.39633317418,
2.41485714118,
2.49250363418,
2.38357988118,
2.4019418541800004,
2.42502941718
]
},
{
"command": "pnpr@HEAD",
"mean": 1.5729558020799999,
"stddev": 0.15323646531493204,
"median": 1.5648573501799998,
"user": 1.10353034,
"system": 1.17095716,
"min": 1.37994034918,
"max": 1.7825237651799999,
"times": [
1.6051142481799998,
1.76323262718,
1.4576364851799999,
1.44337497018,
1.39371069118,
1.71315032318,
1.7825237651799999,
1.37994034918,
1.66627410918,
1.5246004521799998
]
},
{
"command": "pnpr@main",
"mean": 1.5312289097799998,
"stddev": 0.15090670179674723,
"median": 1.47279765468,
"user": 1.0892032399999998,
"system": 1.16759816,
"min": 1.37810060618,
"max": 1.77542926618,
"times": [
1.7113241561800001,
1.77542926618,
1.4038712571799998,
1.37810060618,
1.59340348318,
1.3918959841799998,
1.41167840418,
1.47276144118,
1.47283386818,
1.70099063118
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.2643891923,
"stddev": 0.004979036215853874,
"median": 0.2653039627,
"user": 0.23010776000000002,
"system": 0.5361328399999999,
"min": 0.25296856570000004,
"max": 0.2692663637,
"times": [
0.2686230867,
0.26753119670000003,
0.2636594807,
0.2685443987,
0.25296856570000004,
0.2607558917,
0.2692663637,
0.26640076570000004,
0.2619350137,
0.2642071597
]
},
{
"command": "pacquet@main",
"mean": 0.26638153280000004,
"stddev": 0.011466611594665716,
"median": 0.2630272052,
"user": 0.21975276,
"system": 0.5513754399999999,
"min": 0.2539826697,
"max": 0.28486261370000004,
"times": [
0.2700044187,
0.25476585970000004,
0.2539826697,
0.2620932227,
0.2585530977,
0.2845243397,
0.2576635387,
0.28486261370000004,
0.26396118770000004,
0.27340437970000003
]
},
{
"command": "pnpr@HEAD",
"mean": 0.2869788625,
"stddev": 0.007691805125126416,
"median": 0.2850473712,
"user": 0.23976826,
"system": 0.56050894,
"min": 0.27332653370000004,
"max": 0.2998171197,
"times": [
0.28290091170000004,
0.2863436037,
0.2837511387,
0.2998171197,
0.29559482470000004,
0.2919879057,
0.27332653370000004,
0.2909210747,
0.2823252417,
0.28282027070000004
]
},
{
"command": "pnpr@main",
"mean": 0.27916155930000003,
"stddev": 0.008851027734287815,
"median": 0.27608993470000004,
"user": 0.23014465999999997,
"system": 0.5475193399999998,
"min": 0.26914061770000003,
"max": 0.2946912507,
"times": [
0.2855895077,
0.27668422470000004,
0.2842326907,
0.26914061770000003,
0.27549564470000004,
0.28992115770000004,
0.2946912507,
0.2733603277,
0.2723127607,
0.2701874107
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.7016968855199996,
"stddev": 0.06349786975802904,
"median": 2.67229429182,
"user": 1.74559124,
"system": 1.5232626599999999,
"min": 2.65719948182,
"max": 2.86885230682,
"times": [
2.86885230682,
2.66811557182,
2.69182419382,
2.66926682582,
2.67461094582,
2.6699776378199997,
2.66659382482,
2.65719948182,
2.72715788382,
2.72337018282
]
},
{
"command": "pacquet@main",
"mean": 2.75360218012,
"stddev": 0.06682626946421996,
"median": 2.7564175878199997,
"user": 2.0048897400000003,
"system": 1.6101599599999996,
"min": 2.67378305682,
"max": 2.89945350582,
"times": [
2.67387376682,
2.89945350582,
2.76063998982,
2.77712844182,
2.76652010682,
2.75219518582,
2.67378305682,
2.74274390382,
2.69410644882,
2.79557739482
]
},
{
"command": "pnpr@HEAD",
"mean": 1.6776679564199999,
"stddev": 0.15904678927291543,
"median": 1.68021952382,
"user": 1.2323849399999998,
"system": 1.3277332599999998,
"min": 1.4535319868199998,
"max": 1.98077566682,
"times": [
1.98077566682,
1.7139304278199998,
1.58009991082,
1.47249058282,
1.79892758582,
1.7880250388199999,
1.4535319868199998,
1.6228100638199998,
1.71957968082,
1.64650861982
]
},
{
"command": "pnpr@main",
"mean": 1.7490415132200003,
"stddev": 0.13020511430879966,
"median": 1.7714419508199999,
"user": 1.1690331399999998,
"system": 1.29428996,
"min": 1.51742000982,
"max": 1.89554399782,
"times": [
1.89554399782,
1.51742000982,
1.66947520082,
1.8476337698199998,
1.79106999482,
1.87556894582,
1.7518139068199998,
1.5611297788199998,
1.83990664382,
1.74085288382
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.47489737052000003,
"stddev": 0.026896883693089416,
"median": 0.48208239252000007,
"user": 0.67654938,
"system": 0.7530816399999999,
"min": 0.42935724302000006,
"max": 0.50710676802,
"times": [
0.47768608102000004,
0.49746023802000006,
0.48647870402000004,
0.49722388502000003,
0.50710676802,
0.43574648202000005,
0.47551009702,
0.45263203702000004,
0.48977217002000006,
0.42935724302000006
]
},
{
"command": "pacquet@main",
"mean": 0.49692385712,
"stddev": 0.029736308182089426,
"median": 0.5038360310200001,
"user": 0.6778667799999999,
"system": 0.7898735399999999,
"min": 0.44629559702000005,
"max": 0.5452698300200001,
"times": [
0.47655455702000005,
0.49396962602000005,
0.47931423602000006,
0.5452698300200001,
0.51415930202,
0.51370243602,
0.5158672670200001,
0.46617761602,
0.51792810402,
0.44629559702000005
]
},
{
"command": "pnpr@HEAD",
"mean": 0.38463782432,
"stddev": 0.020110206141611197,
"median": 0.38369363152,
"user": 0.29356467999999997,
"system": 0.6251649399999999,
"min": 0.35203832702000004,
"max": 0.41399592802,
"times": [
0.36314775302,
0.40266373302,
0.38309649602,
0.37804807202,
0.39948029002,
0.41399592802,
0.40300354102,
0.36661333602,
0.35203832702000004,
0.38429076702000003
]
},
{
"command": "pnpr@main",
"mean": 0.4587051535200001,
"stddev": 0.06503818855527886,
"median": 0.47151309652000006,
"user": 0.36209907999999996,
"system": 0.70194054,
"min": 0.36214787602000004,
"max": 0.5807732680200001,
"times": [
0.36214787602000004,
0.50796419502,
0.43195472702000004,
0.5807732680200001,
0.47813396002,
0.38175546102,
0.46489223302000005,
0.40629747202000005,
0.48074932302000006,
0.49238302002000006
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.2430971544399996,
"stddev": 0.05663903881217623,
"median": 2.24397185504,
"user": 1.6845323799999998,
"system": 1.2865679399999999,
"min": 2.13930824304,
"max": 2.30671385004,
"times": [
2.30406358404,
2.21209292504,
2.20071907204,
2.29785535604,
2.2645258030399997,
2.30671385004,
2.2842994980399998,
2.22341790704,
2.13930824304,
2.19797530604
]
},
{
"command": "pacquet@main",
"mean": 2.4981358655399997,
"stddev": 0.27660648576645513,
"median": 2.48770031304,
"user": 1.8885213799999998,
"system": 1.3997036399999998,
"min": 2.17707165604,
"max": 3.02636752904,
"times": [
2.41021649104,
3.02636752904,
2.69180698404,
2.56518413504,
2.74803441904,
2.60661457004,
2.27387339004,
2.23385693704,
2.17707165604,
2.2483325440399997
]
},
{
"command": "pnpr@HEAD",
"mean": 0.46315039964000004,
"stddev": 0.0322819839338396,
"median": 0.46342025854,
"user": 0.36260367999999993,
"system": 0.74400274,
"min": 0.41524493104000004,
"max": 0.50870482104,
"times": [
0.48819046204,
0.50870482104,
0.46149037204000004,
0.43238827604,
0.50459958804,
0.41524493104000004,
0.47888325404000004,
0.46535014504,
0.44905079604000003,
0.42760135104
]
},
{
"command": "pnpr@main",
"mean": 0.5415337070399999,
"stddev": 0.045389071185028274,
"median": 0.54090877004,
"user": 0.4314161799999999,
"system": 0.8223583400000001,
"min": 0.46269416104,
"max": 0.63078089804,
"times": [
0.5529407310400001,
0.51861979904,
0.46269416104,
0.58300418204,
0.55737501304,
0.50372032804,
0.52438441804,
0.63078089804,
0.54315926404,
0.53865827604
]
}
]
}Scenario: Isolated linker: fresh resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.37499162102000005,
"stddev": 0.03806195055716591,
"median": 0.37157231002,
"user": 0.37663414,
"system": 0.10328816,
"min": 0.31303989352000006,
"max": 0.42885676352,
"times": [
0.31303989352000006,
0.41940454752000006,
0.33434151452000005,
0.35023284752000006,
0.41770422552,
0.37334105052000005,
0.42885676352,
0.38118583752,
0.36980356952000004,
0.36200596052000006
]
},
{
"command": "pacquet@main",
"mean": 0.3726612402200001,
"stddev": 0.03819825363020643,
"median": 0.36681244902000004,
"user": 0.37157854,
"system": 0.11050246,
"min": 0.31941815752,
"max": 0.43511794752000005,
"times": [
0.35688368352000005,
0.43511794752000005,
0.36562621652000005,
0.36799868152000004,
0.31941815752,
0.32143783952000005,
0.37878044252000004,
0.35829081652000005,
0.42119592152,
0.40186269552000004
]
},
{
"command": "pnpr@HEAD",
"mean": 0.12951827781166672,
"stddev": 0.012122675995160825,
"median": 0.13076665152000003,
"user": 0.044932665000000004,
"system": 0.019806759999999996,
"min": 0.10958129852000001,
"max": 0.15050293252000002,
"times": [
0.11349392452000001,
0.11277763952,
0.12837578252,
0.12863850552000003,
0.13829103752000002,
0.11322808552000001,
0.11648082252,
0.13486376352,
0.13442855652000002,
0.12813291752000003,
0.11012025052,
0.10958129852000001,
0.12022036252,
0.13777105152000002,
0.12712140752,
0.15050293252000002,
0.14310027552000001,
0.14657967852000003,
0.13881414052000002,
0.13289479752000002,
0.13863512252000001,
0.14211071752,
0.13743498052000003,
0.12484061652000002
]
},
{
"command": "pnpr@main",
"mean": 0.1313797929961905,
"stddev": 0.013404141905130444,
"median": 0.12942613552,
"user": 0.041671492380952385,
"system": 0.023104640952380955,
"min": 0.11044062252,
"max": 0.16092792552000001,
"times": [
0.12936731352000003,
0.11577682952,
0.14578750052000003,
0.14936250252000002,
0.12749973752000002,
0.13802621052000003,
0.11615310652000001,
0.11906267852,
0.11044062252,
0.13918411452,
0.13036727252000002,
0.16092792552000001,
0.12647302152,
0.12942613552,
0.13338977552000003,
0.12043227952,
0.14442200752000003,
0.14376493352000003,
0.14244631852000003,
0.12383254352,
0.11283282352
]
}
]
}Scenario: Isolated linker: peer-heavy resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.2367371895155557,
"stddev": 0.26321098655932634,
"median": 1.30397984896,
"user": 1.2521644066666666,
"system": 0.2322545533333333,
"min": 0.85688030096,
"max": 1.62438054896,
"times": [
0.89407056296,
1.33147027496,
1.39510470796,
1.45237136996,
1.27214217296,
1.30397984896,
1.00023491796,
1.62438054896,
0.85688030096
]
},
{
"command": "pacquet@main",
"mean": 0.9791195856266667,
"stddev": 0.17663304351576184,
"median": 0.94265527796,
"user": 0.9629016288888889,
"system": 0.17207822,
"min": 0.76883519096,
"max": 1.2533257019600001,
"times": [
0.86675593896,
1.2533257019600001,
0.94405687796,
1.20431198296,
0.80348962496,
0.94265527796,
0.76883519096,
0.8898948049600001,
1.1387508699600002
]
},
{
"command": "pnpm@HEAD",
"mean": 3.5849615837377775,
"stddev": 0.11996724422784816,
"median": 3.60513471296,
"user": 5.492009073333333,
"system": 0.2965625533333333,
"min": 3.38851591296,
"max": 3.74326720896,
"times": [
3.38851591296,
3.53938551696,
3.70265699096,
3.4534079589599997,
3.64455810796,
3.74326720896,
3.50980264096,
3.60513471296,
3.67792520296
]
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.70881901206,
"stddev": 0.18753681352754809,
"median": 4.69033485466,
"user": 2.22078302,
"system": 1.6334487600000003,
"min": 4.47628831766,
"max": 4.96225040866,
"times": [
4.96225040866,
4.61762723166,
4.55047083466,
4.47628831766,
4.76304247766,
4.82173530266,
4.93106784766,
4.54566786566,
4.51879174666,
4.90124808766
]
},
{
"command": "pacquet@main",
"mean": 4.51963978866,
"stddev": 0.0736184219961869,
"median": 4.496287242659999,
"user": 1.85384212,
"system": 1.4395883599999997,
"min": 4.43064553266,
"max": 4.64645011266,
"times": [
4.48534969166,
4.59889634766,
4.43064553266,
4.50722479366,
4.59903164166,
4.44771419866,
4.45794021266,
4.48198115366,
4.64645011266,
4.54116420166
]
},
{
"command": "pnpr@HEAD",
"mean": 3.56131351616,
"stddev": 0.10827618613831308,
"median": 3.5299964176599996,
"user": 1.3330122199999999,
"system": 1.34219486,
"min": 3.47376340866,
"max": 3.84261734566,
"times": [
3.53645440266,
3.47376340866,
3.63548688766,
3.4979494076599997,
3.84261734566,
3.5235384326599997,
3.5528443786599997,
3.5423324036599997,
3.51330512066,
3.4948433736599998
]
},
{
"command": "pnpr@main",
"mean": 3.59330337056,
"stddev": 0.13023501953872957,
"median": 3.54874056566,
"user": 1.40057622,
"system": 1.3968342599999999,
"min": 3.49192494766,
"max": 3.91382585166,
"times": [
3.59202093966,
3.49192494766,
3.50546019166,
3.50226977566,
3.64243780766,
3.6367650446599997,
3.50030651166,
3.64449933366,
3.5035233016599996,
3.91382585166
]
}
]
} |
Repairing a shared slot in place stopped it from being destroyed under a concurrent importer, but it also stopped it from being healed: the linking tiers report EEXIST for a dirent that is already there, and the repair adopted it whatever its content. A file truncated by an interrupted copy therefore survived the repair, and the completion marker went down on top of it, so every later install saw a finished slot and never looked again. Gate the slot on pnpm's `allFilesMatch` rather than on existence, and give the repair a placement mode that swaps a fresh copy in through a temp sibling for every entry that does not match its store file. Matching entries are recognised by their shared store inode, so an intact slot still costs two stats per file and no read. The repair also clears a dirent of the wrong kind, which the previous wipe-and-swap took care of implicitly, and it now runs before the node_modules preservation dance instead of after it: a slot repaired in place keeps its nested node_modules by never removing anything, so a package with bundled dependencies no longer falls through to the destructive path the fix exists to avoid.
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
|
Pushed 5cdc49c on top of this branch. Repairing the slot in place fixed the crash but gave up the self-healing the destructive path provided as a side effect. The linking tiers ( The follow-up:
Strays are deliberately still left alone: removing files the package does not declare is the destructive behavior being retired here, and a completed build's outputs live among them. One thing for the description, now corrected there: the TypeScript CLI does have Written by an agent (Claude Code, claude-opus-5[1m]). |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
pnpm/crates/deps-restorer/src/import_indexed_dir.rs (1)
406-432: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winRepair compares every file twice.
stage_and_swapcallsall_files_matchfirst. If it returnsfalse,populate_dirwithPlacement::Repaircallsfile_matches_store_entryagain for every entry. For the copy tier, each call reads both files in full, so a single mismatched byte in the last entry costs two full reads of the whole package.Consider dropping the separate
all_files_matchpre-pass and letting the repair pass decide per entry. The repair pass already skips matching entries, so the fast path stays cheap. The only behavioral difference is that repair also runscreate_dir_alland places the marker, which are idempotent.🤖 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/deps-restorer/src/import_indexed_dir.rs` around lines 406 - 432, Remove the separate all_files_match pre-pass from stage_and_swap and let populate_dir with Placement::Repair perform per-entry matching and replacement. Preserve the existing fast path for matching entries, while allowing the repair path’s idempotent directory creation and marker placement to run.pnpm/crates/deps-restorer/src/import_indexed_dir/tests.rs (1)
777-808: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider adding a concurrent-repair test.
The added tests cover single-importer repair of missing, damaged, and wrong-type entries. The issue this PR fixes is a race between two importers on one slot. A test that spawns two threads calling
import_indexed_diron the same target withFORCE_SHAREDwould exercise the convergence guarantee directly, and it would fail against the pre-fixremove_dir_allbehavior.REVIEW_GUIDE.md asks for regression tests that fail without the fix and that cover concurrent behavior where relevant.
🤖 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/deps-restorer/src/import_indexed_dir/tests.rs` around lines 777 - 808, Add a regression test alongside safe_to_skip_repairs_incomplete_target_without_replacing_it that launches two threads concurrently calling import_indexed_dir on the same target with FORCE_SHARED, synchronizes their start, and joins both successfully. Verify the final target converges to the complete expected contents, ensuring the test fails with the prior remove_dir_all behavior and exercises the concurrent-repair guarantee.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pnpm/crates/deps-restorer/src/import_indexed_dir.rs`:
- Around line 502-535: Update the safe_to_skip branch around the
stage-to-dir_path fs::rename: classify ResourceBusy as an occupied target when
appropriate, but for any other rename failure clean up stage and immediately
return ImportIndexedDirError::Swap. Prevent unclassified rename errors from
falling through to the destructive remove_dir_all(dir_path) path, while
preserving the existing adopt-and-repair behavior for occupied targets.
---
Nitpick comments:
In `@pnpm/crates/deps-restorer/src/import_indexed_dir.rs`:
- Around line 406-432: Remove the separate all_files_match pre-pass from
stage_and_swap and let populate_dir with Placement::Repair perform per-entry
matching and replacement. Preserve the existing fast path for matching entries,
while allowing the repair path’s idempotent directory creation and marker
placement to run.
In `@pnpm/crates/deps-restorer/src/import_indexed_dir/tests.rs`:
- Around line 777-808: Add a regression test alongside
safe_to_skip_repairs_incomplete_target_without_replacing_it that launches two
threads concurrently calling import_indexed_dir on the same target with
FORCE_SHARED, synchronizes their start, and joins both successfully. Verify the
final target converges to the complete expected contents, ensuring the test
fails with the prior remove_dir_all behavior and exercises the concurrent-repair
guarantee.
🪄 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: 6a8b592b-d639-4326-85ba-b72c378abbe1
📒 Files selected for processing (3)
.changeset/repair-shared-slot-in-place.mdpnpm/crates/deps-restorer/src/import_indexed_dir.rspnpm/crates/deps-restorer/src/import_indexed_dir/tests.rs
Code Review by Qodo
1.
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Port the pacquet fix to the TypeScript CLI, whose importIndexedDir has the same safeToSkip mode and the same two problems with it. A slot that fails allFilesMatch fell through to renameOverwriteSync, which removes the directory a concurrent importer may still be writing into and that a third may be reading from. And the fast path that writes into a shared slot in place adopts whatever dirent is already there, because the linking tiers report EEXIST for it, so a file truncated by an interrupted copy survived the import and the completion marker went down on top of it. A shared slot is now populated by whoever wins an exclusive mkdir, adopted by everyone else when it already matches, and otherwise repaired entry by entry: each file that does not match its store entry is swapped in through a temp sibling, which replaces it atomically under a reader. Nothing on this path unlinks, so concurrent importers converge, a nested node_modules survives without the staging dance keepModulesDir used to need, and files the package does not declare are left to whoever put them there. Restrict safeToSkip to targets whose path pins their contents, which is what the flag has always required of its callers. A local directory is copied into the target at install time and can change with no lockfile change, so its stale files still have to be cleared by a rebuild — pacquet excludes those from the mode for the same reason.
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
|
Ported to the TypeScript CLI in ba80772 (+ b193e38 for naming), so the fix lands in both stacks.
Now: whoever wins an exclusive mkdir writes the package; everyone else adopts the directory when One thing the port turned up. Verified locally: the package's own suite (29 tests, 6 new), plus Worth a look from someone who knows the injected-local-dependency paths better than I do: that is the one behavior change beyond the shared-slot fix. Written by an agent (Claude Code, claude-opus-5[1m]). |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
pnpm11/fs/indexed-pkg-importer/src/importIndexedDir.ts (1)
145-162: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDocument why the repair path uses
importFileforpackage.json.The
Importerdoc comment on Lines 21-25 states thatpackage.jsonmust be written throughimportFileAtomic.repairIndexedDirpassesimporter.importFileinstead. The write is still atomic becausereplaceFileIfDifferentrenames a temp sibling over the destination. That reasoning is not obvious to a reader who follows theImportercontract. Add a short comment that records the invariant.📝 Proposed comment
if (packageJsonSrc !== undefined) { + // The rename in replaceFileIfDifferent is atomic on its own, so the + // completion marker does not need importFileAtomic here. replaceFileIfDifferent(importer.importFile, packageJsonSrc, path.join(newDir, 'package.json')) }🤖 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 `@pnpm11/fs/indexed-pkg-importer/src/importIndexedDir.ts` around lines 145 - 162, Add a concise comment immediately before the package.json replaceFileIfDifferent call in repairIndexedDir explaining that although the Importer contract normally requires importFileAtomic, replaceFileIfDifferent writes via a temporary sibling and atomic rename, preserving atomic package.json replacement when using importer.importFile.Source: Coding guidelines
pnpm11/fs/indexed-pkg-importer/test/importIndexedDir.test.ts (1)
63-83: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert that the matching
package.jsonis not replaced.This test proves the corrupted file is repaired. It does not prove the matching entry is left untouched. The inode check in
mismatchReasonis the mechanism that makes a shared slot converge without churn, and no TypeScript test covers it. Capture the destination inode before the import and assert it after.🧪 Proposed assertion
const filenames = new Map([ ['index.js', path.join(src, 'index.js')], ['package.json', path.join(src, 'package.json')], ]) + const packageJsonInoBefore = fs.statSync(path.join(newDir, 'package.json')).ino importIndexedDir(linkingImporter, newDir, filenames, { safeToSkip: true }) expect(fs.readFileSync(path.join(newDir, 'index.js'), 'utf8')).toBe('module.exports = 1') + // A matching entry is adopted, not swapped out from under a concurrent reader. + expect(fs.statSync(path.join(newDir, 'package.json')).ino).toBe(packageJsonInoBefore) })Note that the destination
package.jsonhere has identical content but a different inode from the source, somismatchReasonfalls through to the content comparison and returnsundefined. The assertion therefore verifies the content path, not the inode fast path. If you want to cover the inode fast path, hardlink the source into the destination instead of writing a copy.🤖 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 `@pnpm11/fs/indexed-pkg-importer/test/importIndexedDir.test.ts` around lines 63 - 83, Update the importIndexedDir() safeToSkip test to record the destination package.json inode before importing, then assert it remains unchanged afterward while retaining the existing index.js repair assertion. Use the existing destination package.json setup so the assertion verifies matching-content entries are not replaced.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pnpm11/fs/indexed-pkg-importer/src/importIndexedDir.ts`:
- Around line 145-162: Add a concise comment immediately before the package.json
replaceFileIfDifferent call in repairIndexedDir explaining that although the
Importer contract normally requires importFileAtomic, replaceFileIfDifferent
writes via a temporary sibling and atomic rename, preserving atomic package.json
replacement when using importer.importFile.
In `@pnpm11/fs/indexed-pkg-importer/test/importIndexedDir.test.ts`:
- Around line 63-83: Update the importIndexedDir() safeToSkip test to record the
destination package.json inode before importing, then assert it remains
unchanged afterward while retaining the existing index.js repair assertion. Use
the existing destination package.json setup so the assertion verifies
matching-content entries are not replaced.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 9b8db4f7-3877-42e8-b4a0-fad5f33b55d8
📒 Files selected for processing (5)
.changeset/repair-shared-slot-in-place.mdpnpm/crates/deps-restorer/src/import_indexed_dir.rspnpm11/fs/indexed-pkg-importer/src/importIndexedDir.tspnpm11/fs/indexed-pkg-importer/test/importIndexedDir.test.tspnpm11/store/controller-types/src/index.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- .changeset/repair-shared-slot-in-place.md
- pnpm/crates/deps-restorer/src/import_indexed_dir.rs
|
Code review by qodo was updated up to the latest commit b193e38 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
|
| Project | pnpm's project |
| Branch | pr/13810 |
| 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,526.79 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 286.32 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 306.47 ms |
| isolated-linker.fresh-resolve.hot-cache.offline | 📈 view plot | 85.24 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 1,376.49 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr | 📈 view plot | 3,444.04 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 274.67 ms |
Summary
When two importers reach the same global virtual-store slot at once, the first one populates it in place and only writes the completion marker at the end. The second one arrives while that is happening, sees a directory that exists but has no marker, so its non-destructive rename fails on an occupied target,
is_complete_importsays no, and it drops through toremove_dir_all. That removes the files the first importer is still writing, and the finalrmdirthen loses the race against those writes and reportsENOTEMPTY.A safe-to-skip target is content-addressed by its path, so an incomplete one does not have to be removed at all. It now takes the same in-place
populate_dirrepair that the marker-less path already uses forforce: false, which is non-destructive and converges when both importers run it.To confirm the diagnosis I ran the scenario with a 600-file package and the second thread held back until the slot appeared: 6 failures in 200 runs on
mainwith the exactRemoveExisting { ... code: 66 }from the issue, 0 in 400 runs after the change.Repairing in place has to heal the slot, not just fill in what is missing. The linking tiers report
EEXISTfor a dirent that is already there, so an in-place repair that adopts whatever it finds keeps a file truncated by an interrupted copy — and then puts the completion marker on top of it, so every later install sees a finished slot and never looks again. The destructive path used to hide this by rebuilding the tree.So the gate is now pnpm's
allFilesMatch(fs/indexed-pkg-importer/src/importIndexedDir.ts) rather than a check that each file exists, and the repair swaps a fresh copy in through a temp sibling for every entry that does not match its store file. An entry that shares the store inode is recognised without a read, so an intact slot still costs two stats per file. The repair also clears a dirent of the wrong kind, which the wipe used to take care of implicitly.The shared-slot branch moved ahead of the
node_modulespreservation step. A slot repaired in place keeps a nestednode_modules/by never removing anything, so a package with bundled dependencies no longer falls through to the destructive path this PR exists to avoid.The regression tests assert the slot directory keeps its inode across a repair, that a damaged file is restored under a linking tier (the earlier tests all used
Copy, wherefs::copyoverwrites and hides the difference), and that a file the package does not declare is left alone — removing strays from a slot other projects read is the destructive behavior being retired.The same fix in the TypeScript CLI
importIndexedDirthere has its ownsafeToSkip, and both halves of the bug: a slot that failsallFilesMatchfalls through torenameOverwriteSync, which removes the directory a concurrent importer is writing into, and the fast path that writes into a shared slot in place adopts whatever dirent it finds, so a truncated file survives and the completion marker lands on top of it.A shared target is now populated by whoever wins an exclusive mkdir, adopted by everyone else when it matches, and otherwise repaired entry by entry, each mismatching file swapped in through a temp sibling. Nothing on that path unlinks, so a nested
node_modules/survives without the staging dancekeepModulesDirneeded.One addition the Rust side already had:
safeToSkipis restricted to targets whose path pins their contents, which is what the flag has always asked of its callers.link.tsanddeps-restorerpassenableGlobalVirtualStorestraight through, so an injected local package — copied into its target at install time, and free to change with no lockfile change — was reaching the mode too. Its stale files still need a rebuild to clear, soresolvedFrom: 'local-dir'now takes the staging path, matching pacquet'ssource_is_mutableexclusion.Fixes #13806
Squash Commit Body
Checklist
already linked to it solves it.
importIndexedDirin the TypeScriptCLI has the same
safeToSkipmode and the same two problems with it, andis fixed the same way here.
pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
Bug Fixes
Tests