Repository navigation
Description
Part of #253.
Property
A slot of the global virtual store is never left half-written, built twice, or read while another pnpm process changes it, whatever the processes sharing it do at the same time.
Evidence
In the 90 days to 2026-11-06, many fixes in pnpm/crates/deps-restorer were about a shared slot's life across processes:
- repairing a slot in place: fix(deps-restorer): repair a shared virtual-store slot in place pnpm#13810
- a delete-pending dirent in a slot: fix(install): wait out a delete-pending dirent in a shared slot pnpm#15160
- a slot another installer finished repairing: fix(install): accept a slot another installer finished repairing pnpm#15174
- serializing builds into a slot: fix(gvs): serialize builds into a shared global virtual store slot pnpm#15634
- building a slot again when nothing is cached: fix(deps-restorer): build a shared global virtual store slot again when nothing is cached pnpm#17528
- removing a failed optional dependency from its slot: fix(build): remove a failed optional dependency from its GVS slot pnpm#15744, fix(install): remove the links of an optional dependency whose build failed pnpm#16478
- keeping built and patched slots on a repeat install: fix: keep built and patched slots on a repeat install pnpm#16709
- swap locks and concurrent replacement: fix(importer): tolerate concurrent package replacement pnpm#17091, fix(importer): take one swap lock per install instead of one per target pnpm#17113, fix(importer): coordinate non-forced private imports and bound DirLock held files pnpm#17182
They land in import_indexed_dir (17 fixes, 97 fix-on-fix blame edges) and build_modules (30 fixes in 59 commits, 46 fix-on-fix blame edges).
Flaw
A slot has no type and no module that owns its state. Its state is spread across:
- whether files exist;
- a completion file chosen by
populate_dir; .pnpm-needs-build, which is empty while a build is pending and containsstartedonce a build has begun;.pnpm-linked-archive;- the
.pnpm-build.lockDirLock; - a per-modules-dir swap lock.
"Patched" and "being repaired" have no marker at all.
Each consumer checks the markers and takes locks on its own:
- Seven sites take a slot-related lock. Three take the slot lock (
create_virtual_dir_by_snapshot.rs,build_one_snapshot/slot_to_build.rs,build_one_snapshot/side_effects.rs), three take the swap lock (staging.rs, and twice inimport_indexed_dir.rs), and one takes the store lock (store-dir/src/prune.rs). slot_to_build.rsreads the marker, takes the lock, and reads the marker again.create_virtual_store/warm.rsandpackage-manager/src/install/modules_state/build_markers.rsread it without any lock.gvs_slot_lock::lock_global_virtual_store_slotreturnsNonewhen the lock times out (10 minutes) or cannot be taken, and the caller then writes to the slot unserialized.
The concurrent tests cover concurrent imports into one slot, and one install waiting on a held slot lock. They do not cover:
- two installs building one slot at once;
- re-importing a side-effects overlay while a build runs;
- removing a failed optional dependency while another install links the slot;
- a prune racing an install;
- recovering an interrupted build while another process acts on the slot.
Plan
- Add one slot type that names the states (missing, populating, populated, build pending, building, built, linked archive) and owns every transition, each under the slot lock. Move marker reads and writes into it.
- Decide in one place what a writer does when it cannot take the slot lock, instead of proceeding unserialized at each call site.
- Add multi-process tests for the transitions listed above. Consider a model test that runs random interleavings of import, build, prune, and optional-dependency removal against one slot and checks the slot's contents afterwards.
Written by an agent (Claude Code, claude-opus-5-5).
Activity
kairosci commentedon Nov 11, 2026
The slot-lock ownership plan was superseded by pnpm/pnpm#17905, which merged a lock-free design. Builds now happen in private staging directories and the completed package is placed into its shared slot, preventing concurrent builds from rewriting a slot another install can read. The merged change also includes concurrency and recovery regression coverage in both pnpm implementations. I think this issue can be closed because the replacement addresses the underlying problem.
Written by an agent (Codex, GPT-6).