From 25de425d67a18c93c30ed98675f121cdbad855b8 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 21 Nov 2026 14:27:50 +0000 Subject: [PATCH 1/3] fix(web): picker branch switches no longer re-read the full local status Co-Authored-By: Claude Opus 5.5 --- .../src/components/BranchToolbarBranchSelector.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/BranchToolbarBranchSelector.tsx b/apps/web/src/components/BranchToolbarBranchSelector.tsx index bb6f178ff55d7..a4cf78c372eed 100644 --- a/apps/web/src/components/BranchToolbarBranchSelector.tsx +++ b/apps/web/src/components/BranchToolbarBranchSelector.tsx @@ -444,6 +444,8 @@ export function BranchToolbarBranchSelector({ // ran itself. Only the claimed worktree's live HEAD confirms the claim; an unconfirmed one // falls back to a real checkout, which Git refuses if the branch is checked out elsewhere. const latestSelectionIdRef = useRef(0); + // The branch this picker is checking out; its own switch reloads the refs, so its status needs no refresh. + const pickerCheckoutBranchRef = useRef(null); const readSelectedRef = async (worktreePath: string, listedRef: VcsRef): Promise => { const result = await readRefs({ environmentId, @@ -505,6 +507,7 @@ export function BranchToolbarBranchSelector({ runBranchAction(async () => { const previousBranch = resolvedActiveBranch; setOptimisticBranch(selectedBranchName); + pickerCheckoutBranchRef.current = selectedBranchName; const checkoutResult = await switchRef({ environmentId, input: { @@ -549,6 +552,7 @@ export function BranchToolbarBranchSelector({ setOptimisticBranch(applied ? nextBranchName : previousBranch); return; } + pickerCheckoutBranchRef.current = null; setOptimisticBranch(previousBranch); if (!isAtomCommandInterrupted(checkoutResult)) { toastManager.add( @@ -574,6 +578,7 @@ export function BranchToolbarBranchSelector({ runBranchAction(async () => { const previousBranch = resolvedActiveBranch; setOptimisticBranch(name); + pickerCheckoutBranchRef.current = name; const createBranchResult = await createRefMutation({ environmentId, input: { @@ -595,6 +600,7 @@ export function BranchToolbarBranchSelector({ setOptimisticBranch(applied ? nextBranchName : previousBranch); return; } + pickerCheckoutBranchRef.current = null; setOptimisticBranch(previousBranch); if (!isAtomCommandInterrupted(createBranchResult)) { toastManager.add( @@ -627,7 +633,10 @@ export function BranchToolbarBranchSelector({ // A checkout made outside T3 Code, such as a clone finishing, leaves refs listed before it. const statusBranch = branchStatusQuery.data?.refName ?? null; const refreshRefsMissingStatusBranch = useEffectEvent((branch: string | null) => { - if (isInitialBranchesLoadPending || branch === null) return; + if (branch === null) return; + const pickerCheckoutBranch = pickerCheckoutBranchRef.current; + pickerCheckoutBranchRef.current = null; + if (isInitialBranchesLoadPending || branch === pickerCheckoutBranch) return; if (branchByName.get(branch)?.current !== true) refreshStaleRefs(); }); // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- reloads refs from the server once per branch live status reports that they do not list as checked out From f9f8a9e86fa0afd02700d8fa0006a6d574e4cdb0 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 21 Nov 2026 14:58:24 +0000 Subject: [PATCH 2/3] fix(web): share the picker's pending checkout across selectors on one checkout Co-Authored-By: Claude Opus 5.5 --- .../BranchToolbarBranchSelector.tsx | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/apps/web/src/components/BranchToolbarBranchSelector.tsx b/apps/web/src/components/BranchToolbarBranchSelector.tsx index a4cf78c372eed..024dd43f0e17a 100644 --- a/apps/web/src/components/BranchToolbarBranchSelector.tsx +++ b/apps/web/src/components/BranchToolbarBranchSelector.tsx @@ -101,6 +101,11 @@ interface BranchToolbarBranchSelectorProps { const WORKTREE_CHANGE_BLOCKED_MESSAGE = msg("Stop the current turn to switch worktrees."); +// Branches a picker is checking out, by environment and checkout. Shared because a draft thread +// mounts two selectors on one checkout, and the switch's own settle reloads refs for both. +const pickerCheckouts = new Map(); +const pickerCheckoutKey = (environmentId: string, cwd: string) => `${environmentId}\u0000${cwd}`; + export function BranchToolbarBranchSelector({ forceNewWorktree = false, ref, @@ -444,8 +449,6 @@ export function BranchToolbarBranchSelector({ // ran itself. Only the claimed worktree's live HEAD confirms the claim; an unconfirmed one // falls back to a real checkout, which Git refuses if the branch is checked out elsewhere. const latestSelectionIdRef = useRef(0); - // The branch this picker is checking out; its own switch reloads the refs, so its status needs no refresh. - const pickerCheckoutBranchRef = useRef(null); const readSelectedRef = async (worktreePath: string, listedRef: VcsRef): Promise => { const result = await readRefs({ environmentId, @@ -507,7 +510,8 @@ export function BranchToolbarBranchSelector({ runBranchAction(async () => { const previousBranch = resolvedActiveBranch; setOptimisticBranch(selectedBranchName); - pickerCheckoutBranchRef.current = selectedBranchName; + const checkoutKey = pickerCheckoutKey(environmentId, selectionTarget.checkoutCwd); + pickerCheckouts.set(checkoutKey, selectedBranchName); const checkoutResult = await switchRef({ environmentId, input: { @@ -552,7 +556,7 @@ export function BranchToolbarBranchSelector({ setOptimisticBranch(applied ? nextBranchName : previousBranch); return; } - pickerCheckoutBranchRef.current = null; + pickerCheckouts.delete(checkoutKey); setOptimisticBranch(previousBranch); if (!isAtomCommandInterrupted(checkoutResult)) { toastManager.add( @@ -578,7 +582,8 @@ export function BranchToolbarBranchSelector({ runBranchAction(async () => { const previousBranch = resolvedActiveBranch; setOptimisticBranch(name); - pickerCheckoutBranchRef.current = name; + const checkoutKey = pickerCheckoutKey(environmentId, branchCwd); + pickerCheckouts.set(checkoutKey, name); const createBranchResult = await createRefMutation({ environmentId, input: { @@ -600,7 +605,7 @@ export function BranchToolbarBranchSelector({ setOptimisticBranch(applied ? nextBranchName : previousBranch); return; } - pickerCheckoutBranchRef.current = null; + pickerCheckouts.delete(checkoutKey); setOptimisticBranch(previousBranch); if (!isAtomCommandInterrupted(createBranchResult)) { toastManager.add( @@ -633,10 +638,12 @@ export function BranchToolbarBranchSelector({ // A checkout made outside T3 Code, such as a clone finishing, leaves refs listed before it. const statusBranch = branchStatusQuery.data?.refName ?? null; const refreshRefsMissingStatusBranch = useEffectEvent((branch: string | null) => { - if (branch === null) return; - const pickerCheckoutBranch = pickerCheckoutBranchRef.current; - pickerCheckoutBranchRef.current = null; - if (isInitialBranchesLoadPending || branch === pickerCheckoutBranch) return; + if (branch === null || branchCwd === null) return; + // Kept until the checkout reports another branch, so every selector on it skips the refresh. + const checkoutKey = pickerCheckoutKey(environmentId, branchCwd); + if (pickerCheckouts.get(checkoutKey) === branch) return; + pickerCheckouts.delete(checkoutKey); + if (isInitialBranchesLoadPending) return; if (branchByName.get(branch)?.current !== true) refreshStaleRefs(); }); // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- reloads refs from the server once per branch live status reports that they do not list as checked out From b88235da13b638c86634299a8d2f17c67b824dca Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 21 Nov 2026 15:16:33 +0000 Subject: [PATCH 3/3] fix(web): mark the picker's checkout in flight instead of predicting its branch Co-Authored-By: Claude Opus 5.5 --- .../BranchToolbarBranchSelector.tsx | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/apps/web/src/components/BranchToolbarBranchSelector.tsx b/apps/web/src/components/BranchToolbarBranchSelector.tsx index 024dd43f0e17a..2fb938b04bb40 100644 --- a/apps/web/src/components/BranchToolbarBranchSelector.tsx +++ b/apps/web/src/components/BranchToolbarBranchSelector.tsx @@ -101,9 +101,10 @@ interface BranchToolbarBranchSelectorProps { const WORKTREE_CHANGE_BLOCKED_MESSAGE = msg("Stop the current turn to switch worktrees."); -// Branches a picker is checking out, by environment and checkout. Shared because a draft thread -// mounts two selectors on one checkout, and the switch's own settle reloads refs for both. -const pickerCheckouts = new Map(); +// Picker checkouts by environment and checkout: null while in flight, then the branch it landed +// on. Shared because a draft thread mounts two selectors on one checkout, and the switch's own +// settle reloads refs for both. +const pickerCheckouts = new Map(); const pickerCheckoutKey = (environmentId: string, cwd: string) => `${environmentId}\u0000${cwd}`; export function BranchToolbarBranchSelector({ @@ -511,7 +512,7 @@ export function BranchToolbarBranchSelector({ const previousBranch = resolvedActiveBranch; setOptimisticBranch(selectedBranchName); const checkoutKey = pickerCheckoutKey(environmentId, selectionTarget.checkoutCwd); - pickerCheckouts.set(checkoutKey, selectedBranchName); + pickerCheckouts.set(checkoutKey, null); const checkoutResult = await switchRef({ environmentId, input: { @@ -523,6 +524,7 @@ export function BranchToolbarBranchSelector({ const nextBranchName = refName.isRemote ? (checkoutResult.value.refName ?? selectedBranchName) : selectedBranchName; + pickerCheckouts.set(checkoutKey, nextBranchName); const movesCheckout = selectionTarget.checkoutCwd !== branchCwd; let hold: BranchHold | null = null; const applied = setThreadBranch( @@ -583,7 +585,7 @@ export function BranchToolbarBranchSelector({ const previousBranch = resolvedActiveBranch; setOptimisticBranch(name); const checkoutKey = pickerCheckoutKey(environmentId, branchCwd); - pickerCheckouts.set(checkoutKey, name); + pickerCheckouts.set(checkoutKey, null); const createBranchResult = await createRefMutation({ environmentId, input: { @@ -594,6 +596,7 @@ export function BranchToolbarBranchSelector({ }); if (createBranchResult._tag === "Success") { const nextBranchName = createBranchResult.value.refName; + pickerCheckouts.set(checkoutKey, nextBranchName); const applied = setThreadBranch(nextBranchName, activeWorktreePath); if (applied) { setBranchHold({ @@ -641,8 +644,11 @@ export function BranchToolbarBranchSelector({ if (branch === null || branchCwd === null) return; // Kept until the checkout reports another branch, so every selector on it skips the refresh. const checkoutKey = pickerCheckoutKey(environmentId, branchCwd); - if (pickerCheckouts.get(checkoutKey) === branch) return; - pickerCheckouts.delete(checkoutKey); + if (pickerCheckouts.has(checkoutKey)) { + const pickerBranch = pickerCheckouts.get(checkoutKey); + if (pickerBranch === null || pickerBranch === branch) return; + pickerCheckouts.delete(checkoutKey); + } if (isInitialBranchesLoadPending) return; if (branchByName.get(branch)?.current !== true) refreshStaleRefs(); });