Skip to content

fix(npm_install_deps): key the node_modules cache on the manifests the lockfile depends on - #41

Merged
charlielye merged 1 commit into
mainfrom
cl/npm-cache-key-linked-packages
Nov 27, 2026
Merged

charlielye merged 1 commit into
mainfrom
cl/npm-cache-key-linked-packages

Conversation

@charlielye

Copy link
Copy Markdown
Contributor

npm_install_deps keys its node_modules cache on the package's own yarn.lock or pnpm-lock.yaml and package.json. Its lockfile also depends on two other kinds of manifest:

  • its workspace members' package.json;
  • the package.json of each package it links in from the repository (portal:, link:, file:). The lockfile records their version, dependencies and bin entries.

When one of those changes and the lockfile isn't updated, the key stays the same. CI restores the cached node_modules, and the --immutable install that would catch the stale lockfile never runs.

This happened in aztec-packages. AztecProtocol/aztec-packages#25855 removed a bin entry from ipc-runtime/ts/package.json but missed one of the lockfiles that links it. Public CI passed on a cached node_modules for two days. Builds starting from an empty cache (the private mirror, its arm64 nightly) failed until AztecProtocol/aztec-packages#25916. aztec-packages' barretenberg/ts had already worked around this by hand, by passing ipc-runtime/ts/package.json as an extra key file.

Change

  • New npm_linked_manifests: run in a package's directory, it prints cache_content_hash patterns for:

    • the workspace members' manifests, from the workspaces field in array or object form, or from pnpm-workspace.yaml, honouring ! exclusions;
    • the manifest of every package linked in from the repository, following those packages' own links;
    • for a file: dependency on an archive, the archive itself.

    Paths outside the git repository are skipped.

  • npm_install_deps: adds those patterns to the key, on the CI cache path only.

Generated manifests that git doesn't track match nothing, as cache_content_hash hashes the committed tree. A build that rewrote a committed linked manifest in place would now trip CI's dirty-tree check. aztec-packages' build doesn't do that, and its release step rewrites copies.

Testing

  • tests/npm_linked_manifests_test (new) builds a fixture repo and checks:
    • which manifests are listed, covering workspaces in all three forms, a portal, a transitive link, a file: archive, a path outside the repository and regex escaping;
    • that the key changes when a transitively linked manifest or a workspace member's manifest changes. The old key provably doesn't change in that case;
    • that an unrelated package doesn't change the key.
  • Against aztec-packages' packages: barretenberg/acir_tests lists its four workspace members, bb.js, the bb.js-api packages and ipc-runtime/ts. native-packages/wsdb lists ipc-runtime/ts, its missing workaround.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DSxF9AgGYcAcCTjXEeJT4L

…e lockfile depends on

The key covered the package's lockfile and package.json only. A lockfile also
records its workspace members' manifests and those of the packages it links
in from the repository (portal:, link:, file:). When one of those changed
without the lockfile being updated, the key stayed the same, the cached
node_modules was restored, and the immutable install that would have caught
the stale lockfile never ran.

npm_linked_manifests lists those manifests, following links transitively, and
npm_install_deps adds them to the key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DSxF9AgGYcAcCTjXEeJT4L
@charlielye
charlielye merged commit 0a396f8 into main Nov 27, 2026
1 check passed
charlielye added a commit to AztecProtocol/aztec-packages that referenced this pull request Dec 3, 2026
Pins ci3 to aztec-labs-eng/ci3#41.

`npm_install_deps` now adds two kinds of manifest to the `node_modules`
cache key: the package's workspace members' manifests, and those of the
packages it links in from this repository. A stale lockfile then misses
the cache, and the immutable install catches it instead of a cached
`node_modules` hiding it, as happened with #25855 until #25916.

**What that adds here:**
- **`barretenberg/acir_tests`:** its four workspace members, `bb.js`,
the `bb.js-api` packages and `ipc-runtime/ts`;
- **`native-packages/wsdb` and `ipc-codegen/echo_example/ts`:**
`ipc-runtime/ts`;
- **`barretenberg/ts`:** its links. Its hand-made
`ipc-runtime/ts/package.json` key entry is removed, since the new key
covers it.

The keys change, so this PR's CI runs those installs fresh, which is the
test.

ci3 is pinned to the PR's commit. I'll repin to ci3's `main` once ci3#41
merges.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01DSxF9AgGYcAcCTjXEeJT4L

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant