Repository navigation
fix(building.during-install): resolve hoisted link destinations on the main thread - #13646
Conversation
|
💖 Thanks for opening this pull request! 💖 |
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 installation build path documents hoisted destination resolution before worker execution. A regression test verifies that ChangesHoisted destination resolution
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
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. No blocking failure remains; the previously reported temporary fixture leak is fixed by unconditional recursive cleanup in the test’s finally block. Reviews (6): Last reviewed commit: "test(building.during-install): use async..." | Re-trigger Greptile |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pnpm11/building/during-install/test/hoistedLocations.test.ts`:
- Around line 23-67: Wrap the temporary fixture setup, buildModules call, and
assertions in the test’s try/finally scope, then remove lockfileDir in finally
with fs.promises.rm using recursive and force options. Keep the existing
hoistedLocations assertions unchanged.
🪄 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: a184d156-300a-432f-b5f0-0e280e1c4a22
📒 Files selected for processing (3)
.changeset/absolute-hoisted-link-destinations.mdpnpm11/building/during-install/src/index.tspnpm11/building/during-install/test/hoistedLocations.test.ts
|
Thanks — both review comments were valid and are fixed in f21c818:
Skipping the ast-grep Re-verified after the change: |
|
Tip For best results, initiate chat on the files or code changes.
The reported verification is sufficient. The regression test still distinguishes the fixed behavior from the previous relative destination behavior. The 🐇 ✅ If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! You are interacting with an AI system. |
|
Both fixes look correct:
The Tip: You can customize Greptile's behavior for this repo with |
|
The Windows leg of the test matrix caught a real bug in my fixture, fixed in 5f10677. The fixture hardcoded The fixture now derives both locations with The production change is unaffected — only the test fixture was wrong. |
|
Heads up on the one red check:
The runner died mid-step (its logs were never uploaded), so this is infrastructure rather than the change — the earlier Windows failure on f21c818 was a real fixture bug and is fixed in 5f10677. Everything else is green: Compile & Lint, ubuntu Node 22/24/26, windows chunks 1/3 and 3/3, CodeQL, Greptile, CodeRabbit. I don't have rerun rights here, so that job needs a maintainer re-run (or it will re-run on the next push) to get a clean Windows confirmation. |
5f10677 to
e64f1c6
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pnpm11/building/during-install/test/hoistedLocations.test.ts (1)
23-27: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse asynchronous filesystem APIs in this asynchronous test.
Replace
mkdtempSync,mkdirSync,writeFileSync, andrmSyncwithfs.promisescalls. This keeps filesystem work non-blocking and follows the repository convention.As per coding guidelines: “Prefer asynchronous filesystem APIs and
async/await.”Proposed change
- const lockfileDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pnpm-hoisted-')) + const lockfileDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'pnpm-hoisted-')) try { await runInstall(lockfileDir) } finally { - fs.rmSync(lockfileDir, { recursive: true, force: true }) + await fs.promises.rm(lockfileDir, { recursive: true, force: true }) } @@ - fs.mkdirSync(pkgDir, { recursive: true }) - fs.writeFileSync(path.join(pkgDir, 'package.json'), JSON.stringify({ name: 'foo', version: '1.0.0' })) + await fs.promises.mkdir(pkgDir, { recursive: true }) + await fs.promises.writeFile(path.join(pkgDir, 'package.json'), JSON.stringify({ name: 'foo', version: '1.0.0' }))Also applies to: 38-39
🤖 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/building/during-install/test/hoistedLocations.test.ts` around lines 23 - 27, Update the asynchronous test setup and cleanup around runInstall to use fs.promises equivalents for mkdtemp, mkdir, writeFile, and rm, awaiting each filesystem operation while preserving the existing temporary-directory lifecycle and cleanup behavior.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pnpm11/building/during-install/test/hoistedLocations.test.ts`:
- Around line 23-27: Update the asynchronous test setup and cleanup around
runInstall to use fs.promises equivalents for mkdtemp, mkdir, writeFile, and rm,
awaiting each filesystem operation while preserving the existing
temporary-directory lifecycle and cleanup behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 2c4f6e15-8a4d-4aaf-96b2-95d7e8899a23
📒 Files selected for processing (3)
.changeset/absolute-hoisted-link-destinations.mdpnpm11/building/during-install/src/index.tspnpm11/building/during-install/test/hoistedLocations.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- .changeset/absolute-hoisted-link-destinations.md
- pnpm11/building/during-install/src/index.ts
…e main thread `hardLinkDir()` runs on a worker thread but was handed destinations relative to lockfileDir. The cwd is process-wide and shared with worker threads, and `applyPatchToDir()` switches the cwd to the package it patches for the duration of the patch. A worker resolving a relative destination inside that window resolved it against the patched package instead of the project root, so the rename failed with ERR_PNPM_ENOENT or ERR_PNPM_ENOTEMPTY. Resolving the destinations on the main thread is safe because the cwd is only switched inside a synchronous block, so no other main-thread code observes it. The rebuild path already resolves `hoistedLocations` this way before calling `hardLinkDir()`; this makes install consistent with it. Closes pnpm#13627 Note pnpm#12880 shares the error text but is a distinct parent/child destination overlap inside `hardLinkDir` itself, which this does not address. Written by an agent (Claude Code, claude-opus-5).
… the fixture The mock had no declared signature, so `mock.calls[0][1]` failed to typecheck under the test tsconfig (TS2493). Declaring the signature also removes the need for a cast. Remove the temporary project in a `finally` block so repeated runs stop accumulating `pnpm-hoisted-*` directories in the system temporary directory. Written by an agent (Claude Code, claude-opus-5).
…with path.join The fixture hardcoded `node_modules/foo` with forward slashes, but the install code matches the current location against `path.relative(lockfileDir, depNode.dir)`, which uses backslashes on Windows. Nothing was filtered out there, so the test saw two destinations instead of one and failed on the Windows CI matrix. Real hoisted locations also come from `path.relative()`, so building the fixture's the same way keeps it faithful to the data the install path actually receives. Written by an agent (Claude Code, claude-opus-5).
e64f1c6 to
53479ea
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
pnpm11/building/during-install/test/hoistedLocations.test.ts (2)
1-3: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse asynchronous filesystem APIs in this async test.
Lines 23-39 use synchronous fixture I/O although the test and
runInstall()are asynchronous. Use promise-based filesystem APIs and await cleanup infinally.As per coding guidelines, TypeScript code should prefer asynchronous filesystem APIs and
async/await.Proposed filesystem update
-import fs from 'node:fs' +import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises' - const lockfileDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pnpm-hoisted-')) + const lockfileDir = await mkdtemp(path.join(os.tmpdir(), 'pnpm-hoisted-')) try { await runInstall(lockfileDir) } finally { - fs.rmSync(lockfileDir, { recursive: true, force: true }) + await rm(lockfileDir, { recursive: true, force: true }) } - fs.mkdirSync(pkgDir, { recursive: true }) - fs.writeFileSync(path.join(pkgDir, 'package.json'), JSON.stringify({ name: 'foo', version: '1.0.0' })) + await mkdir(pkgDir, { recursive: true }) + await writeFile(path.join(pkgDir, 'package.json'), JSON.stringify({ name: 'foo', version: '1.0.0' }))Also applies to: 23-27, 37-39
🤖 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/building/during-install/test/hoistedLocations.test.ts` around lines 1 - 3, Update the asynchronous test and its fixture setup/cleanup to use promise-based filesystem APIs from fs.promises, await directory creation and removal, and ensure cleanup is awaited in the finally block while preserving the existing runInstall() assertions.Source: Coding guidelines
18-21: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winKeep the comments current and correct.
Replace the historical incident wording in Line 21 with the current worker/cwd invariant. Fix the grammatical error in Lines 32-34.
As per coding guidelines, comments must describe current non-obvious invariants rather than historical implementation details.
Proposed comment update
-// hardLinkDir() runs on a worker thread, and the cwd is process-wide: applyPatchToDir() -// switches the cwd to the package it patches, so a worker resolving a relative -// destination during that window resolves it against the wrong directory. That surfaced as -// intermittent ERR_PNPM_ENOENT/ENOTEMPTY renames of `_tmp_*` under nodeLinker=hoisted. +// Resolve hoisted destinations on the main thread because `hardLinkDir()` runs in a worker +// and `applyPatchToDir()` can change the process-wide cwd. -// Real hoisted locations come from path.relative(), so they use the platform's -// separator. Build the fixture's the same way, otherwise on Windows the install code -// cannot match the current location against them and filters nothing out. +// `path.relative()` produces platform-specific separators. Use `path.join()` to match +// the install code's `hoistedLocations` entries on Windows.Also applies to: 32-34
🤖 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/building/during-install/test/hoistedLocations.test.ts` around lines 18 - 21, Update the comments around hardLinkDir() and applyPatchToDir() to state the current worker-thread/process-wide cwd invariant and why relative paths must not depend on the mutable cwd, removing historical incident details. Also correct the grammatical error in the related comment at lines 32-34 while preserving its intended meaning.Sources: Coding guidelines, 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/building/during-install/test/hoistedLocations.test.ts`:
- Around line 1-3: Update the asynchronous test and its fixture setup/cleanup to
use promise-based filesystem APIs from fs.promises, await directory creation and
removal, and ensure cleanup is awaited in the finally block while preserving the
existing runInstall() assertions.
- Around line 18-21: Update the comments around hardLinkDir() and
applyPatchToDir() to state the current worker-thread/process-wide cwd invariant
and why relative paths must not depend on the mutable cwd, removing historical
incident details. Also correct the grammatical error in the related comment at
lines 32-34 while preserving its intended meaning.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: d0dc84a2-7124-4200-88cd-affa45095d42
📒 Files selected for processing (3)
.changeset/absolute-hoisted-link-destinations.mdpnpm11/building/during-install/src/index.tspnpm11/building/during-install/test/hoistedLocations.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- .changeset/absolute-hoisted-link-destinations.md
- pnpm11/building/during-install/src/index.ts
Code Review by Qodo
1.
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
…tionale in one place The fixture now uses the fs.promises APIs, per the repo's preference for asynchronous filesystem calls in async code. The cwd-race rationale was spelled out twice, in buildDependency() and again above the test. Comments document a shared why once at its common home, so the source comment is now the single explanation and the test header points at it.
|
Code review by qodo was updated up to the latest commit 4f49f9b |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
|
Congrats on merging your first pull request! 🎉🎉🎉 |
|
Thank you! 🙏 |
## Problem and fix The post-merge CI run for #130 failed twice with `ERR_PNPM_ENOENT` while renaming a temporary directory into `node_modules/astro/node_modules/tsx/node_modules/esbuild`. The first attempt failed in the E2E Docker build; the retry failed in the shared CI setup. Both failures blocked commit images and the automatic release, leaving production on v0.9.0. Pin pnpm 11.25.0 instead of 11.2.1. This is the first release containing both relevant hoisted-install race fixes: - [11.22.0](https://github.com/pnpm/pnpm/releases/tag/v11.22.0): resolve hoisted copy destinations before worker threads can observe the temporary `process.chdir()` used for patched dependencies ([upstream PR #13646](pnpm/pnpm#13646)). - [11.25.0](https://github.com/pnpm/pnpm/releases/tag/v11.25.0): stop replacing parent destination directories when copying built packages to other hoisted locations, which could delete nested dependency directories during concurrent copies ([upstream issue #12880](pnpm/pnpm#12880)). Marka uses `nodeLinker: hoisted` and `patchedDependencies`. CI's Corepack setup and Docker builds both honor the root `packageManager` pin. Keep the runtime documentation and README badge consistent with that pin. No dependency versions or lockfile resolutions change. No cache purge, install retries, suppressed lifecycle scripts, or runtime workaround is introduced. ## Validation - `pnpm install --frozen-lockfile` with pnpm 11.25.0 on macOS. - `pnpm format:fix`, `pnpm lint`, and `pnpm typecheck`. - `pnpm test:release-contract`. - Four clean Linux amd64 installs passed: two each under Node 22.21.1 and Node 24.18.1. The second run on each version used an offline store. Lifecycle scripts remained enabled; the nested `astro -> tsx -> esbuild` dependency resolved after installation, and the lockfile checksum was unchanged. The race lives inside pnpm, so a repository unit test would not exercise the failing seam. The upstream fixes include regression coverage; validation here uses Marka's actual manifests, patches, lockfile, hoisted layout, and enabled dependency lifecycle scripts. [GitHub CI passed](https://github.com/absolutepraya/marka/actions/runs/38901394301), including the complete E2E Docker build, at commit `5ab104a01e52c525b276851adbff77116ae8b519`. ## LLM use Diagnosed, implemented, and validated with Codex. Documentation references to the package-manager version were updated alongside the pin.
Closes #13627.
hardLinkDir()runs on a worker thread but is handed destinations relative to lockfileDir (during-install#L327-L329).applyPatchToDir()— called for everypatchedDependenciesentry — wraps patch application in a synchronousprocess.chdir()(apply-patch#L18-L32). The cwd is process-wide and shared with worker threads, so a worker resolving a relative destination inside that window resolves it against the patched package instead of the project root, and the rename fails withERR_PNPM_ENOENT— orERR_PNPM_ENOTEMPTY, depending on what happens to be at the wrong path.Resolving the destinations on the main thread is safe because the cwd is only switched inside a synchronous block, so no other main-thread code can observe it, and
hoistedLocationsvalues are always relative (they come frompath.relative).The rebuild path (after-install#L405) already maps hoisted locations through
path.join(opts.lockfileDir, hoistedLocation)before callinghardLinkDir(), so this makes install consistent with rebuild rather than introducing a new convention.Verification
Measured on a ~2150-package workspace with two
patchedDependenciesentries and esbuild in three hoisted locations (macOS/APFS, pnpm 10.34.4 — same code shape asmain):The
+800msrows add a synchronous sleep inside the cwd window thatapplyPatchToDiralready opens — no other change — which makes the failure reproduce almost every time.With the fix applied, tracing shows worker renames still happening inside open cwd windows and simply succeeding, so this is not a timing change. Checking every path field in all six worker message types (
extract,link,add-dir,symlinkAllModules,hardLinkDir,init-store) across a full install,hardLinkDir'sdestDirsis the only relative path any worker receives.Test
Per the triage note, the race itself isn't directly testable, so the added test asserts the invariant instead: the destinations reaching
hardLinkDir()from the install path are absolute. It fails onmain(receivesnode_modules/bar/node_modules/foo) and passes with this change.jest(13 tests),eslint, andcspellpass forpnpm11/building/during-install, andtsgo --buildtypechecks clean. I could not run the repo-widecompile-only/lintlocally — pnpm's self-managed 12.0.0-beta.4 fails to install on this machine — so those are left to CI.Note on #12880
#12880 shares the error text but is a different race, and should not be closed by this. That workspace has no
patchedDependenciesat all; with this fix applied its error paths are absolute, so cwd plays no part, and its repro still fails. Tracing it shows a parent/child destination overlap insidehardLinkDiritself — two hoist-copies running concurrently where one's destination is nested inside the other's, andrenameOverwriteSyncswap-renames the parent directory aside, carrying the other worker's staged temp with it:That is presumably why a retry around the rename clears that repro; it would not fix the cwd race here, because the temp directory never existed at the resolved path to begin with.
Written by an agent (Claude Code, claude-opus-5).
Summary by CodeRabbit