You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Package importer: coordinate in-place imports with forced swaps, and bound DirLock held files #156
Follow-ups left by pnpm/pnpm#17091 (concurrent forced imports into one node_modules/.pnpm), raised by the review bots there and verified against the code.
A non-forced private import is not coordinated with a forced swap. In pacquet, an import of an absent private target populates it in place without taking the per-target swap lock, while a concurrent forced import of the same target (holding the lock) removes the target before renaming its stage in. A forced and a non-forced install of the same project running at once can therefore interrupt the in-place import with NotFound errors, or leave its last files inside the replacement tree. This predates the PR (the old stage-and-swap removed the target the same way); the PR serializes forced swaps among themselves only. Taking the swap lock on the in-place path would put a lock acquisition on the cold-install hot path of the isolated linker, so it needs a design decision: a cheaper claim protocol for private targets, or accepting that mixed forced/non-forced installs of one project are unsupported.
DirLock leaves one held file per lock key, forever.pnpm_fs::DirLock proves a holder's liveness through an OS lock on <user lock root>/pnpm-dir-locks-<uid>/<hash>.held, keyed by the lock path, and never removes that file. The global virtual store slot lock already leaves one per built slot. The importer's swap lock (PR 17091) adds one per forced import of an occupied target, so pnpm install --force over an existing node_modules leaves one file per package per project path under $XDG_RUNTIME_DIR (a size-capped tmpfs on Linux) or LocalAppData on Windows. Options: remove the held file on release with an inode check so a waiter that opened the old inode falls back to the age-based judgement, or key the swap lock more coarsely.
Written by an agent (Claude Code, claude-fable-5-1).
Two more residuals from the same PR, both Windows-only after pnpm/pnpm#17091 landed the atomic exchange for Linux and macOS:
The move-aside fallback leaves the target absent between two renames. Windows has no atomic dirent exchange, so replace_target moves the occupied target aside and renames the stage in. An importer that found the target absent and renames its own stage in without the swap lock can land in that vacancy if it stalled with its stage ready. Its tree is equivalent and the swap that follows keeps or replaces it, but writes it makes between returning and that replacement are lost. Closing it means either a Windows exchange primitive or taking the swap lock on the absent-target path on Windows, which costs a lock and a permanent held file per package of a fresh hoisted install.
The TypeScript multi-process forced-import test is skipped on Windows.importIndexedDir.concurrent.test.ts runs four forced imports of one package in separate processes on POSIX. On Windows a rename onto an occupied directory fails with EPERM, which rename-overwrite answers by removing the target and retrying for up to a minute per process, so four contending processes exceed the test budget. That path predates the PR; concurrent forced imports on Windows go through it and deserve their own look.
Written by an agent (Claude Code, claude-fable-5-1).
pnpm/pnpm#17113 addresses items 2 (as far as the importer is concerned) and 3: the importer's swap lock becomes one lock per install, keyed by the install's modules directory, so a forced reinstall leaves one held file per install rather than one per package, and the absent-target fast path holds it too, which closes the move-aside fallback's vacancy for forced importers. DirLock itself still leaves one held file per key (item 2 for the slot build lock), and items 1 and 4 remain open.
Written by an agent (Claude Code, claude-fable-5-1).
pnpm/pnpm#17113 merged as 2e734a64cf. Status of the four items:
Forced swaps vs. non-forced in-place imports: open. Still needs a design that does not put a lock acquisition on the isolated linker's cold-install hot path.
DirLock held files: the importer now leaves one per install (keyed by the modules directory, held for the linking phase only) instead of one per package. The primitive itself still never removes a held file, so the global virtual store slot lock keeps leaving one per built slot; that part is open.
Move-aside vacancy on Windows: closed for forced importers, which now take turns for their whole linking phase. An importer outside an install (patch, deploy, cargo and config dependencies) still replaces unserialized.
The multi-process TypeScript test is still POSIX-only; rename-overwrite's EPERM path on Windows is unchanged.
Written by an agent (Claude Code, claude-fable-5-1).
Opened pnpm/pnpm#17182 to resolve this issue across both Rust (pnpm-deps-restorer and pnpm-fs) and TypeScript (@pnpm/fs.indexed-pkg-importer):
Coordinate non-forced private imports with forced swaps (pnpm-deps-restorer):
Pass swap_lock: Some(swap_lock) on all slot_import_opts branches in create_virtual_dir_by_snapshot.rs.
Stage absent private targets (!opts.safe_to_skip) and attempt a lock-free rename_with_retry(&paths.stage, dir_path) when !opts.force so uncontended cold installs never acquire ModulesSwapLock, falling back to swap_lock.hold() only when the target was concurrently occupied while staging (leaving a completed directory or non-directory dirent in place when !opts.force).
Hold swap_lock before repairing an existing incomplete private target (repair_existing_dir, re-checking marker_present under the lock) or replacing a non-directory dirent at a private target (replace_non_dir).
Bound DirLock.held files (pnpm-fs):
Unlink <hash>.held on release while holding its exclusive OS lock (LockedHeldFile::remove_and_unlock), and verify via path_still_names after try_lock() in try_lock_held_file_once that the locked descriptor still names held_path on disk so a waiter that opened a just-unlinked inode reopens the current path while dead-holder takeover stays instant.
Coordinate forced & non-forced imports on Windows (@pnpm/fs.indexed-pkg-importer):
Replace rename-overwrite in commitStagedDir with overwriteDirSync (which moves an existing directory aside on both POSIX and Windows using a swap path distinct from fastPathTemp(newDir) instead of deleting it in place and spinning for 60s on Windows EPERM), guard tryExclusiveImport's rimrafSync(newDir) cleanup with sameCreatedDirectory, and enable the multi-process concurrent forced import test on Windows.
This covers the full issue.
Written by an agent (Antigravity, Gemini 4 Argon).
Activity
zkochan commentedon Oct 18, 2026
Two more residuals from the same PR, both Windows-only after pnpm/pnpm#17091 landed the atomic exchange for Linux and macOS:
The move-aside fallback leaves the target absent between two renames. Windows has no atomic dirent exchange, so
replace_targetmoves the occupied target aside and renames the stage in. An importer that found the target absent and renames its own stage in without the swap lock can land in that vacancy if it stalled with its stage ready. Its tree is equivalent and the swap that follows keeps or replaces it, but writes it makes between returning and that replacement are lost. Closing it means either a Windows exchange primitive or taking the swap lock on the absent-target path on Windows, which costs a lock and a permanent held file per package of a fresh hoisted install.The TypeScript multi-process forced-import test is skipped on Windows.
importIndexedDir.concurrent.test.tsruns four forced imports of one package in separate processes on POSIX. On Windows a rename onto an occupied directory fails withEPERM, whichrename-overwriteanswers by removing the target and retrying for up to a minute per process, so four contending processes exceed the test budget. That path predates the PR; concurrent forced imports on Windows go through it and deserve their own look.Written by an agent (Claude Code, claude-fable-5-1).
zkochan commentedon Oct 18, 2026
pnpm/pnpm#17113 addresses items 2 (as far as the importer is concerned) and 3: the importer's swap lock becomes one lock per install, keyed by the install's modules directory, so a forced reinstall leaves one held file per install rather than one per package, and the absent-target fast path holds it too, which closes the move-aside fallback's vacancy for forced importers.
DirLockitself still leaves one held file per key (item 2 for the slot build lock), and items 1 and 4 remain open.Written by an agent (Claude Code, claude-fable-5-1).
fix(importer): take one swap lock per install instead of one per targ…
zkochan commentedon Oct 19, 2026
pnpm/pnpm#17113 merged as 2e734a64cf. Status of the four items:
DirLockheld files: the importer now leaves one per install (keyed by the modules directory, held for the linking phase only) instead of one per package. The primitive itself still never removes a held file, so the global virtual store slot lock keeps leaving one per built slot; that part is open.rename-overwrite'sEPERMpath on Windows is unchanged.Written by an agent (Claude Code, claude-fable-5-1).
zkochan commentedon Oct 21, 2026
Opened pnpm/pnpm#17182 to resolve this issue across both Rust (
pnpm-deps-restorerandpnpm-fs) and TypeScript (@pnpm/fs.indexed-pkg-importer):pnpm-deps-restorer):swap_lock: Some(swap_lock)on allslot_import_optsbranches increate_virtual_dir_by_snapshot.rs.!opts.safe_to_skip) and attempt a lock-freerename_with_retry(&paths.stage, dir_path)when!opts.forceso uncontended cold installs never acquireModulesSwapLock, falling back toswap_lock.hold()only when the target was concurrently occupied while staging (leaving a completed directory or non-directory dirent in place when!opts.force).swap_lockbefore repairing an existing incomplete private target (repair_existing_dir, re-checkingmarker_presentunder the lock) or replacing a non-directory dirent at a private target (replace_non_dir).DirLock.heldfiles (pnpm-fs):<hash>.heldon release while holding its exclusive OS lock (LockedHeldFile::remove_and_unlock), and verify viapath_still_namesaftertry_lock()intry_lock_held_file_oncethat the locked descriptor still namesheld_pathon disk so a waiter that opened a just-unlinked inode reopens the current path while dead-holder takeover stays instant.@pnpm/fs.indexed-pkg-importer):rename-overwriteincommitStagedDirwithoverwriteDirSync(which moves an existing directory aside on both POSIX and Windows using a swap path distinct fromfastPathTemp(newDir)instead of deleting it in place and spinning for 60s on WindowsEPERM), guardtryExclusiveImport'srimrafSync(newDir)cleanup withsameCreatedDirectory, and enable the multi-process concurrent forced import test on Windows.This covers the full issue.
Written by an agent (Antigravity, Gemini 4 Argon).
fix(importer): coordinate non-forced private imports and bound DirLoc…
fix(importer): coordinate non-forced private imports and bound DirLoc…