Skip to content

Decide whether node_modules is up to date in one place #142

Closed
pnpm/pnpm
#17181

Description

@zkochan

Found by the defect-hotspots skill (pnpm/pnpm#17021) on 2026-10-17 over 90 days of main (086165da7a). The root cause comes from reading the commits and code; it was not reproduced. The design steps are proposals for a maintainer to settle.

Related: #138, #139.

Loop: "Is node_modules up to date?" (14 fixes, 2 open)

Property. A check that skips an install skips it exactly when a full install would change nothing for the selected projects. The install it spawns must clear it.

Members. pnpm/pnpm#16211, pnpm/pnpm#16268, pnpm/pnpm#16282, pnpm/pnpm#16317, pnpm/pnpm#16324, pnpm/pnpm#16396, pnpm/pnpm#16404, pnpm/pnpm#16558, pnpm/pnpm#16566, pnpm/pnpm#16992, pnpm/pnpm#16996, pnpm/pnpm#17019 (v12 only; the v11 half was left out). Open: pnpm/pnpm#16588 and pnpm/pnpm#17012. Issues: pnpm/pnpm#16278, pnpm/pnpm#16322, pnpm/pnpm#16374, pnpm/pnpm#16583, pnpm/pnpm#16988, pnpm/pnpm#16993, pnpm/pnpm#17007, pnpm/pnpm#17011.

Flaw.

  • Five deciders in v12:
    • install_already_up_to_date (install/workspace_state.rs)
    • install/run/fast_path.rs
    • projects_have_nothing_to_install
    • check_deps_status_before_run (optimistic_repeat_install/deps_status.rs)
    • the install's own up-to-date path (lockfile_freshness.rs and prepare_modules_state/up_to_date.rs)
  • Three deciders in v11: deps/status, runDepsStatusCheck.ts, and allProjectsAreUpToDate.
  • Their shared input is a workspace-wide lastValidatedTimestamp plus a filteredInstall boolean, so the state cannot say which projects were validated. Four fixes rebuild that answer differently.
  • Three state writers that rebuild instead of merging lose fields (fix: stop the pre-run install for a dedupe baseline a frozen install cannot record pnpm#16396, fix: settle single-project lockfile checks pnpm#16996).
  • The gate guesses the install it spawns (install_args_from_state, install_would_run_frozen), which produces reinstall loops.
  • mtime is treated as truth. Content fallbacks were added one input at a time.

Design change.

  1. Tests first.
  2. One merge-style state writer.
  3. Per-project validation records: a hash of each importer's dependency fields and wanted-lockfile closure. This deletes the filtered-install reconstructions and makes the v11 half of verifyDepsBeforeRun: after a filtered install, a filtered run of another project skips the install its changed dependencies need pnpm#17011 fixable.
  4. A single freshness(InstallPlan) -> Fresh | Stale{reason, projects}. The gate spawns exactly that plan and warns instead of looping if it stays stale.

Tests.

  • Equivalence matrix: lockfile layout × linker × injected × dependency groups × previous install filtered or not × mutation. Assert verdict UpToDate ⇔ a full install with optimisticRepeatInstall: false changes nothing.
  • Convergence test.
  • Writer round-trip: state comes from real installs, never write_state. The current ~340 unit tests hand-write the state.
  • v11/v12 differential.

The shared test harnesses that cover this loop and the others are tracked in #141.


Written by an agent (Claude Code, claude-opus-5-5).

Activity

  1. added
    area: monorepo
    on Oct 17, 2026
  2. zkochan commented on Oct 17, 2026

    @zkochan
    MemberAuthor

    pnpm/pnpm#17030 (draft) implements the v12 side of this:

    • Tests first. A matrix harness (repeat_install_oracle: 14 scenarios × 8 layouts covering linker, shared/dedicated lockfiles, and injected packages) checks every gate in both directions after every step. The install fast path must be taken exactly when an optimisticRepeatInstall: false install changes nothing. A filtered run gate must pass exactly when a clean install resolves the selection the same way. Every gate must converge after its own install. On main it fails 38 of 112.
    • Per-project validation records (manifest digest plus lockfile digest per importer) replace the workspace-wide timestamp and the filteredInstall reconstructions. Content digests replace mtime ordering.
    • One state writer, recorded_workspace_state.
    • Scoping so the gate only holds what its spawned install can fix, and the gate warns instead of looping when it doesn't converge. That warning found two existing loops, both fixed in the PR.

    Not in it: the v11 half and the v11/v12 differential. I'll do those in a follow-up PR on #139, using the same state format. The ~340 unit tests still hand-write the state, but its validation records now come from the real writer.


    Written by an agent (Claude Code, claude-opus-5-5).

  3. self-assigned this
    on Oct 20, 2026
  4. zkochan commented on Oct 21, 2026

    @zkochan
    MemberAuthor

    Opened pnpm/pnpm#17181 to complete the remaining unification across both pnpm v12 (Rust) and pnpm v11 (TypeScript):

    • In Rust (pnpm-package-manager), folded the static workspace-state/filesystem checks into freshness::check_freshness so check_optimistic_repeat_install_with_state and check_deps_status_before_run share a single decider parameterized by GatePolicy (closing the configDependencies and useGitBranchLockfile drift between the two gates), consolidated gvs_build_markers_complete and check_strict_dep_builds_for_fast_path between install_already_up_to_date and repeat_install_verdict, and shared recorded_workspace_state with repeat-install test fixtures.
    • In TypeScript (@pnpm/deps.status and @pnpm/exec.commands), added the missing catalogResolutionsAreUpToDate check to assertWantedLockfileUpToDate, shared recordValidatedWorkspaceState between root-project and workspace status checks, respected opts.lockfileDir in checkRootProjectDepsStatus, and ported the post-install non-convergence warning (warnIfStillOutdated) to runDepsStatusCheck.

    Generated with Antigravity (Claude Opus 4.7)

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

Metadata

Metadata

Assignees

Labels

area: monorepotype: refactor

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions