Repository navigation
Inspect the checkout once per new thread, and claim a warm worktree in one host call - #8121
Merged
ymichael merged 4 commits intoNov 24, 2026
Conversation
…rktree in one host call Thread create now shares one host.inspect_git_checkout result between the project-default policy and provider placement. The worktree plugin's claimPoolMember reads the remote base, checks the member and fast-forwards it in a single plugin host call, replacing readRemoteBase, checkPoolMember and fastForward. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
force-pushed
the
bb/new-worktree-thread-fewer-serial-host-calls-thr_cgsqayz78c
branch
from
November 24, 2026 20:51
2b0fd10 to
9262874
Compare
Merging the warm-pool handoff into one claimPoolMember call put the fast-forward under the 15 s handoff timeout that used to cover only reading the base and checking the member. A fast-forward that took longer, as in a large repository or one with Git LFS, cut the claim off, discarded the member and built a slower fresh worktree instead. The host now applies the 15 s budget, passed by the server as checkTimeoutMs, to reading the base and checking the member only. When that runs out the claim returns timed-out and the member stays in the pool, as it did before the merge. The call itself gets the create's 15-minute timeout, so the fast-forward has the time it had before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main (#8065) gave warm worktrees folder worktrees, each read, checked and fast-forwarded with separate readRemoteBase, checkPoolMember and fastForward calls. Those calls no longer exist on this branch, so each folder worktree is now claimed with claimPoolMember too, all at once once the main worktree's claim succeeds, reusing each folder's remote base for the next member. Because a claim can move a checkout, a member whose folder claim is busy, timed out, or has no readable base is kept only when none of its worktrees moved; otherwise it is deleted. A folder claim that throws deletes the member, and so does a refused adopt after any worktree moved. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d-fewer-serial-host-calls-thr_cgsqayz78c
ymichael
deleted the
bb/new-worktree-thread-fewer-serial-host-calls-thr_cgsqayz78c
branch
November 24, 2026 23:35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
Finding #8 of the server→daemon RPC audit. Two separate problems made creating a project-default worktree thread slow on a remote machine.
First, the create request inspected the project checkout twice, one after the other.
resolveProjectDefaultThreadEnvironmentcalledhost.inspect_git_checkoutto choose the worktree provider. Provider placement then calledresolveGitCheckoutAvailability, which sent the same RPC for the same path again. Its dedupe only covers calls that are in flight at the same moment, and these two run in sequence.Second, the worktree plugin's warm-pool handoff made separate plugin host calls in a row:
readRemoteBase, thencheckPoolMember, thenfastForwardwhen the member was behind the remote base, thennameHandedOffBranch.What changed
createGitCheckoutInspector(deps)(services/environments/provider-availability.ts) memoizeshost.inspect_git_checkoutper (host, path) for one request.thread-create.tscreates one and passes it to bothresolveCreateThreadEnvironmentandresolveThreadEnvironmentPlacement. Placement'svalidateProviderSelectionreuses the result throughgitCheckoutAvailability().completeProviderSelectioncaller gets a fresh inspector, so its behavior is unchanged.claimPoolMemberhost call replacesreadRemoteBase,checkPoolMemberandfastForward(host/handoff.ts,contract.ts,warm-pools.ts,server.ts).claimPoolMembertoo, all at once, reusing each folder's remote base for the next member. This replaces the separatereadRemoteBase,checkPoolMemberandfastForwardcalls per folder. A member whose folder claim is busy, timed out or has no readable base is kept only when none of its worktrees moved; otherwise it is deleted.checkTimeoutMsand the host applies it to those steps only. When it runs out the claim returnstimed-out, the member is kept and a fresh worktree is built. The fast-forward is not under that budget: the call gets the create's 15-minute timeout, the limit the fast-forward had before.base-unavailable. The member is kept and a fresh worktree is built, as before.nameHandedOffBranchstays a separate call. It needsbranchName(), which waits for the thread title to settle.plugins/environment-git-worktree/README.md,docs/worktrees.md, and theexperimental_adopt entry indocs/api_to_audit.mdnow describe the new order.claimPoolMemberis a plugin host method, and its code ships to the daemon in the plugin artifact. Core protocol commands are untouched, soHOST_DAEMON_PROTOCOL_VERSIONis not bumped.How you verified
Real servers, main vs this branch, same input.
pnpm startfor main (40b8939) and for this branch, each on its own/tmpdata dir. Each server had a second enrolled daemon behind a TCP proxy that adds 100 ms each way (200 ms RTT). The proxy decodes the daemon WebSocket frames and logs eachhost-rpc.request/response.POST /api/v1/threadswithenvironment: {type: "project-default"}, and polled until the environment wasready.POST /threadsresponse, median (min–max)inspect_git_checkout×2)Sequences seen in the proxy log. A background
provider.list_modelsrefresh is left out because the request doesn't await it.inspect_git_checkout > inspect_git_checkout > readRemoteBase > checkPoolMember > nameHandedOffBranch > …inspect_git_checkout > claimPoolMember > nameHandedOffBranch > …… readRemoteBase > checkPoolMember > fastForward > nameHandedOffBranch > environment.hook.run …… claimPoolMember > nameHandedOffBranch > environment.hook.run …On the local primary daemon (no proxy, 6 interleaved rounds), the create response went from a 56 ms to a 38 ms median. Time to ready was unchanged within noise: 206 vs 206 ms at base, 386 vs 374 ms behind base.
Tests
public-threads.project-default.test.tsnow asserts that a branch checkout is inspected exactly once. It fails on main, which inspects twice, and passes here.warm-pools.test.ts:host.test.tsrunsclaimPoolMemberagainst real git repos: usable, fetch then fast-forward, refused after a rewritten base, offline fallback, used placeholder, and busy lock.timed-outand leaves the member alone, and that a fast-forward slower than the check's budget still finishes. That second test fails when the fast-forward is put back under the check's budget.post-mergehook that sleeps 20 s stands in for a slow fast-forward in a large repository. Before the timeout fix, the create waited 15 s, the claim hit its deadline, the member was discarded and a fresh worktree was built. With it, the thread got the warm worktree after the 20 s fast-forward ("Moved the warm worktree from 3eb71f2 to 22a1ba1; setup runs again"), and no member was discarded.pnpm exec turbo run typecheck lint lint:type-aware --filter=@bb/server --filter=bb-plugin-environment-git-worktreevitest runfor the 5 affected server test files (204 tests)🤖 Generated with Claude Code