Skip to content

New worktrees reuse the main checkout's node_modules when the lockfile matches - #1711

Merged
currentbits merged 3 commits into
mainfrom
coder/setup-cache-396
Oct 24, 2026
Merged

currentbits merged 3 commits into
mainfrom
coder/setup-cache-396

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Part of #396 (setup output cached across threads).

New worktrees no longer start installs from zero. On macOS, when a new worktree's lockfile is byte-identical to the main checkout's, Solenta clones the main checkout's node_modules into it with cp -Rc (APFS copy-on-write) before setup runs. The thread logs [setup] reused node_modules from the main checkout (package-lock.json 1a2b3c4d) in 0.4s.

  • Setup still runs after the clone. An npm install / pnpm install setup then finishes as a near no-op, build steps in it still happen, and a stale main node_modules gets reconciled. npm ci wipes node_modules, so it gains nothing.
  • Clones only when it's safe: local project, an approved setup exists, the worktree has no node_modules yet, and the first lockfile found (package-lock.json, npm-shrinkwrap.json, pnpm-lock.yaml, yarn.lock, bun.lock[b]) matches. Otherwise setup runs exactly as before.
  • Failure is harmless: a failed clone removes the partial copy, logs [setup] cache miss: …, and runs the full setup.
  • Opt-out per project: "Reuse node_modules from the main checkout" checkbox in Edit Project (on by default), stored as setupCacheOff.

Not keyed on the setup command hash: setup always runs after the clone, so a changed setup is still honored.

Testing

  • electron/test/setup-cache.test.js: a hit (real cp -Rc on macOS, symlinks kept, setup sees the clone), a lockfile mismatch, an existing node_modules left alone, the opt-out round trip, and a failed clone being cleaned up.
  • Full electron suite in a CI-like env: 5039 pass, 1 fail (memory-sup 10s timeout under load; it passes on its own). Typecheck, the Edit Project renderer test and vite build pass.

🤖 Generated with Claude Code

…file matches (#396)

Before an approved setup runs, clone the main checkout's node_modules
with `cp -Rc` (APFS clonefile) when the worktree's lockfile is
byte-identical. Setup still runs after, so `npm install`-style setups
finish as a no-op and build steps still happen. Logged as
`[setup] reused …`; a failed clone is cleaned up and setup runs
normally. macOS only; per-project opt-out via `setupCacheOff`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T11:41:48.776651Z 44355da PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 44355da6a9

ℹ️ 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".

Comment thread electron/projectCommands.js Outdated
try {
await cloneDirFn(src, dest);
} catch (err) {
fs.rmSync(dest, { recursive: true, force: true });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Guard cleanup errors so a failed clone cannot skip setup

If a failed clone leaves a partial directory that cannot be removed, such as a populated read-only subdirectory, fs.rmSync throws even with force: true. This rejects reuseNodeModules, so kickWorktreeSetup never reaches runOne; the caller in worktrees-lifecycle.js silently swallows the rejection. An optional cache failure therefore prevents the configured setup from running instead of falling back to it. Handle cleanup failures explicitly and ensure the setup command still gets invoked.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6998c47: cleanup is wrapped in try/catch, and kickWorktreeSetup catches anything reuseNodeModules throws, so setup always runs. Covered by a new test that makes rmSync throw.

Willem and others added 2 commits October 24, 2026 18:12
The test resolved the previous test's stale resolver whenever the runner
was reached after the waiting step appeared, leaving that test's setup
hung and node:test cancelling the suite.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@currentbits
currentbits merged commit 0c9a963 into main Oct 24, 2026
6 checks passed
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