Skip to content

Give a global virtual store slot one owner of its state, and test its transitions across processes #284

Closed

Description

@zkochan

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:

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 contains started once a build has begun;
  • .pnpm-linked-archive;
  • the .pnpm-build.lock DirLock;
  • 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 in import_indexed_dir.rs), and one takes the store lock (store-dir/src/prune.rs).
  • slot_to_build.rs reads the marker, takes the lock, and reads the marker again. create_virtual_store/warm.rs and package-manager/src/install/modules_state/build_markers.rs read it without any lock.
  • gvs_slot_lock::lock_global_virtual_store_slot returns None when 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

  1. kairosci commented on Nov 11, 2026

    @kairosci

    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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions