Repository navigation
perf(source-control): hard-link node_modules from a per-lockfile seed - #17170
Conversation
worktree-create.sh ran npm ci in every new worktree. On one host that was 330 copies of node_modules (median 521 MB, 154 GB in total). It now runs npm ci once per distinct package-lock.json into <root>/.npm-seed/<sha256>, under flock, and hard-links that tree into each worktree with cp -al. A later npm ci or npm install inside a worktree writes new files and leaves the seed intact. A symlink is not used because npm ci empties the target of a symlinked node_modules. Without flock, a SHA-256 tool or a working cp -al, or with WORKTREE_CREATE_NPM_SEED=0, the helper runs npm ci in the worktree as before. Seeds unused for WORKTREE_CREATE_NPM_SEED_DAYS (default 14) are pruned. The existing cap and warnings are unchanged. Closes #17084 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eaa32b463a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
claude-review reviewed Code review (incremental, blocking only): 4db2434 on top of b40e2f3This push changes
Closing issue #17084: it states no acceptance criteria. Verification: I ran nothing, because this lane has no shell. Whether the tests pass is still the author's claim and is unverified. Checks:
This review was blocking only because this lane already reviewed an earlier head. No candidates came up, and I ran no verifier subagent. Verifier dropped 0 of 0 candidates. |
|
claude-security-review reviewed Security review: PR #17170, incremental (b40e2f3..4db2434)Scope. I read every hunk of the one file in the incremental scope, What changed. The push edits two Prior finding. My SUGGESTION about the hard-linked No instruction surface changed, and there is no cost impact. I found no security issues. critical-findings: 0 |
|
The pr-verify verifier failed head What it wrote (23 lines)This pull request leaves the merge queue, and ci-status holds it out while it carries |
Review fixes for the per-lockfile seed: - A seed install that fails (not the cap) now falls back to npm ci in the worktree, and a package.json with workspaces, an install lifecycle script or a file:/link: dependency skips seeding, since the seed holds only package.json, package-lock.json and .npmrc. - The seed key hashes package-lock.json, package.json, .npmrc, the Node ABI, platform and architecture, NODE_ENV and npm_config_* variables, so a Node upgrade or a different npm configuration builds its own seed. node computes the key, replacing sha256sum/shasum. - Waiting for the seed lock and installing share one cap, so creation stays inside the WorktreeCreate hook's 60 s. - The seed's files are made read-only, so an in-place write in one worktree fails instead of changing every worktree's copy; npm ci and npm install in a worktree still replace files. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… budget The remaining budget can read one second below the cap when a second boundary falls inside the seed setup, which made the cap 08 test flaky. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes #17084
Summary
worktree-create.shrannpm ciin every new worktree. On one WSL host that was 330node_modulescopies (median 521 MB, 154 GB in total, 29% of the used disk), plus most of the filesystem's inodes. Worktrees now share one hard-linked copy per lockfile.Fix
npm ciruns once per distinct install into<root>/.npm-seed/<key>, underflock; the seed's files are made read-only andcp -alhard-links thatnode_modulesinto each worktree. The key hashes the lockfile,package.json,.npmrc, the Node ABI, platform and architecture,NODE_ENVandnpm_config_*variables. The pinned tools innode_modules/.bin(Biome, markdownlint-cli2, the pinned Claude Code) keep resolving as before.npm ciempties a symlinkednode_modules' target (npm/clilib/commands/ci.jsL122-129), which would break every worktree at once.npm ciwithoutflock,nodeor a workingcp -al(macOS, most Windows shells), for a package with workspaces, install lifecycle scripts orfile:/link:dependencies, when the seed install fails, or withWORKTREE_CREATE_NPM_SEED=0. Seeds unused forWORKTREE_CREATE_NPM_SEED_DAYS(default 14) are pruned. The lock wait and the install share the existing 45 s cap, so creation stays inside theWorktreeCreatehook's 60 s.node_modulesfail instead of changing every worktree's copy; npm itself replaces files, sonpm ciandnpm installin a worktree still work (probed below).Verification
bash plugins/source-control/scripts/worktree-create.test.sh: 388 pass, 0 fail, including 18 new cases (onenpm cifor two worktrees, hard-linked files, opt-out, pruning, read-only seed, aNODE_ENVchange builds its own seed, the shared cap, fallback after a failed seed install, no seed for a lifecycle script). The cases are skipped whereflockor a hard-linkingcp -alis absent.shellcheckon both scripts: clean.package.jsonandpackage-lock.json(Linux, ext4): two worktrees plus the seed took 528 MB in onedu(one copy); the second creation took 0 s instead of 3 s;node_modules/.bin/biome --versionprinted 2.6.7 andclaude --version2.1.327 in both from the read-only seed; afternpm ciinside one worktree the other still ran Biome.npm ciandnpm installin a hard-linked worktree write new inodes and leave the seed intact; through a symlink they empty the target.Related
🤖 Generated with Claude Code