Skip to content

Pre-warmed worktree pool for instant thread creation (#192) - #1564

Merged
currentbits merged 2 commits into
mainfrom
coder/pre-warmed-worktree-pool-for-instant-thr-1e6a15
Oct 10, 2026
Merged

currentbits merged 2 commits into
mainfrom
coder/pre-warmed-worktree-pool-for-instant-thr-1e6a15

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Closes #192.

  • setupWorktree claims an idle pooled worktree (git worktree move + checkout -b <branch> <start>) instead of running a full git worktree add; falls back to the old path when the pool is empty or a claim fails.
  • Pool: 2 detached worktrees per project in <worktree base>/.pool/<projectId>/, topped up in the background after every setup. Same filesystem as the base, so the move is a rename.
  • worktrees-gc skips .pool, so the boot sweep / GC never reap idle pool trees.
  • Enabled only from main.js; tests and other entry points keep pool size 0.

Not included: WSL projects (skipped), pre-running project setup scripts in pooled trees, reaping pools of removed projects.

Test: electron/test/worktree-pool.test.js warms the pool, advances main, asserts the claim moved the pooled dir onto the new main with a clean tree, the pool refills, and the orphan sweep leaves it alone.

🤖 Generated with Claude Code

Keep 2 idle detached worktrees per project under userData/worktree-pool;
setupWorktree claims one with git worktree move + checkout -b, falling
back to worktree add when the pool is empty. Refilled in the background.

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

chatgpt-codex-connector Bot commented Oct 10, 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-10T07:28:05.661775Z 28c7a37 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: 28c7a3754d

ℹ️ 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 on lines +905 to +908
await gitOutAsync(
project.path,
["worktree", "add", "--detach", dir, start],
{ timeout: 120_000 },

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Suppress checkout hooks while filling the hidden pool

For repositories with an executable post-checkout hook, each background fill executes that hook inside the hidden pooled tree; Git documents that worktree add invokes it unless --no-checkout is used (githooks documentation). Claiming the tree then invokes the hook again through checkout, while hook-created untracked files are not cleaned, so a new thread can inherit stale or duplicated artifacts and arbitrary hook side effects run before the user requests that checkout. Suppress repository hooks during pool creation while retaining the hook invocation for the final claim.

Useful? React with 👍 / 👎.

Comment on lines +845 to +847
function dropPooled(repoPath, dir) {
gitTry(repoPath, ["worktree", "remove", "--force", dir]);
fs.rmSync(dir, { 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 Preserve the fallback when pooled cleanup fails

When worktree move fails because a pooled directory is locked or otherwise cannot be renamed—particularly on Windows—the following rmSync can throw despite force: true. That exception escapes claimPooledWorktree instead of returning false, so setupWorktree reports a creation failure and never attempts the normal git worktree add fallback even though its destination may be usable. Treat cleanup as best-effort or quarantine the stale pool entry so a failed claim cannot abort foreground thread creation.

Useful? React with 👍 / 👎.

…tree-pool-for-instant-thr-1e6a15

# Conflicts:
#	electron/worktrees.js
@currentbits
currentbits merged commit a8f7b36 into main Oct 10, 2026
11 of 12 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.

Pre-warmed worktree pool for instant thread creation

1 participant