The best way to control Claude Code, Codex and more from any computer or phone
revert: "fix(web): worktree threads warn when the checkout branch changes" (#14883) (#22225)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Oct 20, 2026 at 01:49 UTC
90c3f8350d777f09c7afdf643db63bf8135161e6
6 files changed
+67
-103
apps/web/src/components/BranchToolbar.logic.test.ts
+11
-26
@@ -13,7 +13,7 @@ import {
13
resolveBranchToolbarPrBranch,
14
resolveBranchToolbarValue,
15
resolveLockedWorkspaceLabel,
16
- resolveCheckoutBranchMismatch,
16
+ resolveLocalCheckoutBranchMismatch,
17
resolvePreviousWorktreeLabel,
18
resolvePreviousWorktreeSeed,
19
sanitizeNewRefName,
@@ -301,10 +301,10 @@ describe("resolveBranchToolbarPrBranch", () => {
301
});
302
});
303
304
-describe("resolveCheckoutBranchMismatch", () => {
304
+describe("resolveLocalCheckoutBranchMismatch", () => {
305
it("detects when a local thread is associated with a different branch than the checkout", () => {
306
expect(
307
- resolveCheckoutBranchMismatch({
307
+ resolveLocalCheckoutBranchMismatch({
308
effectiveEnvMode: "local",
309
activeWorktreePath: null,
310
activeThreadBranch: "feature/thread",
@@ -313,13 +313,12 @@ describe("resolveCheckoutBranchMismatch", () => {
313
).toEqual({
314
threadBranch: "feature/thread",
315
currentBranch: "feature/current",
316
- canRestoreThreadBranch: true,
316
});
317
});
318
319
it("ignores matching local checkout state", () => {
320
expect(
322
- resolveCheckoutBranchMismatch({
321
+ resolveLocalCheckoutBranchMismatch({
322
effectiveEnvMode: "local",
323
activeWorktreePath: null,
324
activeThreadBranch: "feature/thread",
@@ -328,34 +327,20 @@ describe("resolveCheckoutBranchMismatch", () => {
327
).toBeNull();
328
});
329
331
- it("warns about worktree branch drift without restore, but ignores a pending rename status", () => {
332
- const worktree = {
333
- effectiveEnvMode: "worktree" as const,
334
- activeWorktreePath: "/repo/.t3/worktrees/feature-thread",
335
- activeThreadBranch: "t3code/fix-sidebar",
336
- };
337
-
330
+ it("ignores dedicated worktrees because their checkout is already thread-scoped", () => {
331
expect(
339
- resolveCheckoutBranchMismatch({
340
- ...worktree,
341
- currentGitBranch: "t3code/1a2b3c4d",
332
+ resolveLocalCheckoutBranchMismatch({
333
+ effectiveEnvMode: "worktree",
334
+ activeWorktreePath: "/repo/.t3/worktrees/feature-thread",
335
+ activeThreadBranch: "feature/thread",
336
+ currentGitBranch: "feature/current",
337
}),
338
).toBeNull();
344
- expect(
345
- resolveCheckoutBranchMismatch({
346
- ...worktree,
347
- currentGitBranch: "feature/checkout",
348
- }),
349
- ).toEqual({
350
- threadBranch: worktree.activeThreadBranch,
351
- currentBranch: "feature/checkout",
352
- canRestoreThreadBranch: false,
353
- });
339
});
340
341
it("ignores new-worktree base selection before a worktree exists", () => {
342
expect(
358
- resolveCheckoutBranchMismatch({
343
+ resolveLocalCheckoutBranchMismatch({
344
effectiveEnvMode: "worktree",
345
activeWorktreePath: null,
346
activeThreadBranch: "feature/base",
apps/web/src/components/BranchToolbar.logic.ts
+5
-20
@@ -6,7 +6,7 @@ import type {
6
WorktreeSubmodules,
7
} from "@t3tools/contracts";
8
import * as Schema from "effect/Schema";
9
-import { isTemporaryWorktreeBranch, sanitizeNewRefName } from "@t3tools/shared/git";
9
+import { sanitizeNewRefName } from "@t3tools/shared/git";
10
import { toSortableTimestamp } from "../lib/threadSort";
11
export {
12
dedupeRemoteBranchesWithLocalMatches,
@@ -238,35 +238,20 @@ export function resolveBranchToolbarPrBranch(input: {
238
return input.activeThreadBranch === input.resolvedActiveBranch ? input.activeThreadBranch : null;
239
}
240
241
-export function resolveCheckoutBranchMismatch(input: {
241
+export function resolveLocalCheckoutBranchMismatch(input: {
242
effectiveEnvMode: EnvMode;
243
activeWorktreePath: string | null;
244
activeThreadBranch: string | null;
245
currentGitBranch: string | null;
246
-}) {
246
+}): { threadBranch: string; currentBranch: string } | null {
247
const { effectiveEnvMode, activeWorktreePath, activeThreadBranch, currentGitBranch } = input;
248
- const isLocalCheckout = effectiveEnvMode === "local" && activeWorktreePath === null;
249
- const isEstablishedWorktree = effectiveEnvMode === "worktree" && activeWorktreePath !== null;
250
- if (!isLocalCheckout && !isEstablishedWorktree) {
248
+ if (effectiveEnvMode !== "local" || activeWorktreePath !== null) {
249
return null;
250
}
251
if (!activeThreadBranch || !currentGitBranch || activeThreadBranch === currentGitBranch) {
252
return null;
253
}
256
- // Cached status can predate the automatic rename of a temporary worktree branch.
257
- if (
258
- isEstablishedWorktree &&
259
- !isTemporaryWorktreeBranch(activeThreadBranch) &&
260
- isTemporaryWorktreeBranch(currentGitBranch)
261
- ) {
262
- return null;
263
- }
264
- return {
265
- threadBranch: activeThreadBranch,
266
- currentBranch: currentGitBranch,
267
- // Restoring a worktree checkout could switch the branch for sibling threads.
268
- canRestoreThreadBranch: isLocalCheckout,
269
- };
254
+ return { threadBranch: activeThreadBranch, currentBranch: currentGitBranch };
255
}
256
257
export function resolveBranchSelectionTarget(input: {
apps/web/src/components/ChatView.logic.test.ts
+2
-2
@@ -261,14 +261,14 @@ describe("resolveThreadMetadataUpdateForNextTurn", () => {
261
model: "gpt-5.4",
262
};
263
264
- it("adopts the checkout branch without clearing the worktree attachment", () => {
264
+ it("updates a stale local thread branch to the active checkout", () => {
265
expect(
266
resolveThreadMetadataUpdateForNextTurn({
267
currentModelSelection: modelSelection,
268
currentBranch: "feature/thread",
269
nextBranch: "feature/checkout",
270
}),
271
- ).toEqual({ branch: "feature/checkout" });
271
+ ).toEqual({ branch: "feature/checkout", worktreePath: null });
272
});
273
274
it("does not write metadata when the model and branch are unchanged", () => {
apps/web/src/components/ChatView.logic.ts
+2
-1
@@ -474,6 +474,7 @@ export function resolveThreadMetadataUpdateForNextTurn(input: {
474
}): {
475
modelSelection?: ModelSelection;
476
branch?: string;
477
+ worktreePath?: null;
478
} | null {
479
const nextModelSelection = input.nextModelSelection;
480
const modelSelectionChanged =
@@ -488,7 +489,7 @@ export function resolveThreadMetadataUpdateForNextTurn(input: {
489
}
490
return {
491
...(modelSelectionChanged ? { modelSelection: nextModelSelection } : {}),
491
- ...(branchChanged ? { branch: input.nextBranch } : {}),
492
+ ...(branchChanged ? { branch: input.nextBranch, worktreePath: null } : {}),
493
};
494
}
495
apps/web/src/components/ChatView.tsx
+44
-51
@@ -441,7 +441,7 @@ import { ThreadDetailsPanel } from "./chat/ThreadDetailsPanel";
441
import { NoActiveThreadState } from "./NoActiveThreadState";
442
import {
443
resolveEffectiveEnvMode,
444
- resolveCheckoutBranchMismatch,
444
+ resolveLocalCheckoutBranchMismatch,
445
shouldShowComposerContextStrip,
446
shouldShowEnvironmentIndicator,
447
} from "./BranchToolbar.logic";
@@ -3456,6 +3456,26 @@ export default function ChatView(props: ChatViewProps) {
3456
scheduleComposerFocus();
3457
};
3458
const insertArtifactTemplateStable = useStableCallback(insertArtifactTemplate);
3459
+ const sendAppMessage = async (text: string) => {
3460
+ if (!isServerThread || activeThreadId === null) {
3461
+ throw new Error("Messages from apps need a started thread.");
3462
+ }
3463
+ const result = await startThreadTurn({
3464
+ environmentId,
3465
+ input: {
3466
+ threadId: activeThreadId,
3467
+ message: { messageId: newMessageId(), role: "user", text, attachments: [] },
3468
+ runtimeMode,
3469
+ interactionMode,
3470
+ dispatchMode: "queue",
3471
+ },
3472
+ });
3473
+ if (result._tag === "Failure") {
3474
+ const error = squashAtomCommandFailure(result);
3475
+ throw error instanceof Error ? error : new Error("Could not send the app's message.");
3476
+ }
3477
+ };
3478
+ const sendAppMessageStable = useStableCallback(sendAppMessage);
3479
const queuedRunsControlRef = useRef<QueuedRunsControlHandle>(null);
3480
const addTerminalContextToDraft = (selection: TerminalContextSelection) => {
3481
composerRef.current?.addTerminalContext(selection);
@@ -4769,8 +4789,8 @@ export default function ChatView(props: ChatViewProps) {
4789
requestedEnvMode: envMode,
4790
isGitRepo,
4791
});
4772
- const checkoutBranchMismatch = isServerThread
4773
- ? resolveCheckoutBranchMismatch({
4792
+ const localCheckoutBranchMismatch = isServerThread
4793
+ ? resolveLocalCheckoutBranchMismatch({
4794
effectiveEnvMode: envMode,
4795
activeWorktreePath,
4796
activeThreadBranch,
@@ -5099,10 +5119,10 @@ export default function ChatView(props: ChatViewProps) {
5119
const nowMinute = useNowMinute();
5120
const activeBranchMismatchKey = branchMismatchKey(
5121
activeThread?.id ?? null,
5102
- checkoutBranchMismatch,
5122
+ localCheckoutBranchMismatch,
5123
);
5124
const showBranchMismatchBanner = shouldShowBranchMismatchBanner({
5105
- hasMismatch: checkoutBranchMismatch !== null,
5125
+ hasMismatch: localCheckoutBranchMismatch !== null,
5126
isDismissed: isBranchMismatchDismissedForSession(activeBranchMismatchKey),
5127
composerHasContent: composerHasDraftContent,
5128
wasShownForCurrentMismatch:
@@ -5121,7 +5141,7 @@ export default function ChatView(props: ChatViewProps) {
5141
if (
5142
!activeProjectCwd ||
5143
!activeThread ||
5124
- !checkoutBranchMismatch?.canRestoreThreadBranch ||
5144
+ !localCheckoutBranchMismatch ||
5145
isRestoringThreadBranch
5146
) {
5147
return;
@@ -5131,7 +5151,7 @@ export default function ChatView(props: ChatViewProps) {
5151
environmentId,
5152
input: {
5153
cwd: activeProjectCwd,
5134
- refName: checkoutBranchMismatch.threadBranch,
5154
+ refName: localCheckoutBranchMismatch.threadBranch,
5155
},
5156
});
5157
if (checkoutResult._tag === "Failure") {
@@ -5152,7 +5172,7 @@ export default function ChatView(props: ChatViewProps) {
5172
setIsRestoringThreadBranch(false);
5173
return;
5174
}
5155
- const nextBranch = checkoutResult.value.refName ?? checkoutBranchMismatch.threadBranch;
5175
+ const nextBranch = checkoutResult.value.refName ?? localCheckoutBranchMismatch.threadBranch;
5176
if (nextBranch !== activeThread.branch) {
5177
const updateResult = await updateThreadMetadata({
5178
environmentId,
@@ -5269,37 +5289,6 @@ export default function ChatView(props: ChatViewProps) {
5289
};
5290
})() as ComposerBannerStackItem | null;
5291
5272
- const sendAppMessage = async (text: string) => {
5273
- if (!isServerThread || activeThreadId === null) {
5274
- throw new Error("Messages from apps need a started thread.");
5275
- }
5276
- const settingsResult = await persistThreadSettingsForNextTurn({
5277
- threadId: activeThreadId,
5278
- createdAt: new Date().toISOString(),
5279
- ...(checkoutBranchMismatch ? { branch: checkoutBranchMismatch.currentBranch } : {}),
5280
- runtimeMode,
5281
- interactionMode,
5282
- });
5283
- const result =
5284
- settingsResult._tag === "Failure"
5285
- ? settingsResult
5286
- : await startThreadTurn({
5287
- environmentId,
5288
- input: {
5289
- threadId: activeThreadId,
5290
- message: { messageId: newMessageId(), role: "user", text, attachments: [] },
5291
- runtimeMode,
5292
- interactionMode,
5293
- dispatchMode: "queue",
5294
- },
5295
- });
5296
- if (result._tag === "Failure") {
5297
- const error = squashAtomCommandFailure(result);
5298
- throw error instanceof Error ? error : new Error("Could not send the app's message.");
5299
- }
5300
- };
5301
- const sendAppMessageStable = useStableCallback(sendAppMessage);
5302
-
5292
const sendStandaloneCommand = async (text: string, failureMessage: string) => {
5293
if (!activeThread || !clientSettingsHydrated || sendInFlightRef.current) return;
5294
const context = composerRef.current?.getSendContext();
@@ -5328,7 +5317,7 @@ export default function ChatView(props: ChatViewProps) {
5317
const settingsResult = await persistThreadSettingsForNextTurn({
5318
threadId,
5319
createdAt,
5331
- ...(checkoutBranchMismatch ? { branch: checkoutBranchMismatch.currentBranch } : {}),
5320
+ ...(localCheckoutBranchMismatch ? { branch: localCheckoutBranchMismatch.currentBranch } : {}),
5321
runtimeMode,
5322
interactionMode: context.interactionMode,
5323
});
@@ -5612,7 +5601,7 @@ export default function ChatView(props: ChatViewProps) {
5601
].filter((item) => item !== null);
5602
const usageLimitsItems = usageLimitsBanner === null ? [] : [usageLimitsBanner];
5603
const projectCloneItems = projectCloneBannerItem === null ? [] : [projectCloneBannerItem];
5615
- if (!checkoutBranchMismatch || !showBranchMismatchBanner || !activeBranchMismatchKey) {
5604
+ if (!localCheckoutBranchMismatch || !showBranchMismatchBanner || !activeBranchMismatchKey) {
5605
return [
5606
...feedbackBannerItems,
5607
...limitRecoveryItems,
@@ -5641,18 +5630,18 @@ export default function ChatView(props: ChatViewProps) {
5630
<TooltipTrigger
5631
render={
5632
<code className="min-w-0 truncate font-medium text-foreground">
5644
- {checkoutBranchMismatch.threadBranch}
5633
+ {localCheckoutBranchMismatch.threadBranch}
5634
</code>
5635
}
5636
/>
5637
<TooltipPopup side="top">
5649
- This thread last ran on {checkoutBranchMismatch.threadBranch}. Sending will continue
5650
- on {checkoutBranchMismatch.currentBranch}.
5638
+ This thread last ran on {localCheckoutBranchMismatch.threadBranch}. Sending will
5639
+ continue on {localCheckoutBranchMismatch.currentBranch}.
5640
</TooltipPopup>
5641
</Tooltip>
5642
</span>
5643
),
5655
- actions: checkoutBranchMismatch.canRestoreThreadBranch ? (
5644
+ actions: (
5645
<Button
5646
size="xs"
5647
variant="ghost"
@@ -5661,7 +5650,7 @@ export default function ChatView(props: ChatViewProps) {
5650
>
5651
{isRestoringThreadBranch ? "Restoring..." : "Restore branch"}
5652
</Button>
5664
- ) : null,
5653
+ ),
5654
dismissLabel: "Dismiss branch change notice",
5655
onDismiss: () => {
5656
dismissBranchMismatchForSession(activeBranchMismatchKey);
@@ -6128,7 +6117,9 @@ export default function ChatView(props: ChatViewProps) {
6117
const settingsResult = await persistThreadSettingsForNextTurn({
6118
threadId,
6119
createdAt,
6131
- ...(checkoutBranchMismatch ? { branch: checkoutBranchMismatch.currentBranch } : {}),
6120
+ ...(localCheckoutBranchMismatch
6121
+ ? { branch: localCheckoutBranchMismatch.currentBranch }
6122
+ : {}),
6123
runtimeMode,
6124
interactionMode,
6125
});
@@ -7103,7 +7094,9 @@ export default function ChatView(props: ChatViewProps) {
7094
const settingsResult = await persistThreadSettingsForNextTurn({
7095
threadId: threadIdForSend,
7096
createdAt: messageCreatedAt,
7106
- ...(checkoutBranchMismatch ? { branch: checkoutBranchMismatch.currentBranch } : {}),
7097
+ ...(localCheckoutBranchMismatch
7098
+ ? { branch: localCheckoutBranchMismatch.currentBranch }
7099
+ : {}),
7100
runtimeMode,
7101
interactionMode: sendInteractionMode,
7102
});
@@ -7457,7 +7450,7 @@ export default function ChatView(props: ChatViewProps) {
7450
const settingsResult = await persistThreadSettingsForNextTurn({
7451
threadId: threadIdForSend,
7452
createdAt: messageCreatedAt,
7460
- ...(checkoutBranchMismatch ? { branch: checkoutBranchMismatch.currentBranch } : {}),
7453
+ ...(localCheckoutBranchMismatch ? { branch: localCheckoutBranchMismatch.currentBranch } : {}),
7454
runtimeMode,
7455
interactionMode: nextInteractionMode,
7456
});
@@ -7577,7 +7570,7 @@ export default function ChatView(props: ChatViewProps) {
7570
modelSelection: nextThreadModelSelection,
7571
runtimeMode: defaultRuntimeMode,
7572
interactionMode: "default",
7580
- branch: checkoutBranchMismatch?.currentBranch ?? activeThreadBranch,
7573
+ branch: activeThreadBranch,
7574
worktreePath: activeThread.worktreePath,
7575
createdAt,
7576
},
@@ -8669,7 +8662,7 @@ export default function ChatView(props: ChatViewProps) {
8662
8663
<BranchRestoreConfirmHost
8664
threadKey={activeThreadKey}
8672
- threadBranch={checkoutBranchMismatch?.threadBranch ?? ""}
8665
+ threadBranch={localCheckoutBranchMismatch?.threadBranch ?? ""}
8666
canWriteSourceControl={canWriteSourceControl}
8667
onConfirm={handleSwitchCheckoutToThreadStable}
8668
/>
apps/web/src/components/Sidebar.tsx
+3
-3
@@ -234,7 +234,7 @@ import {
234
type SidebarSection,
235
resolveSidebarRowThreadId,
236
} from "./Sidebar.logic";
237
-import { resolveCheckoutBranchMismatch } from "./BranchToolbar.logic";
237
+import { resolveLocalCheckoutBranchMismatch } from "./BranchToolbar.logic";
238
import {
239
createSidebarCollisionDetection,
240
createSidebarSortingStrategy,
@@ -1736,7 +1736,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
1736
: null;
1737
const isWokeStatus = topStatus?.icon === "woke";
1738
1739
- const branchMismatch = resolveCheckoutBranchMismatch({
1739
+ const branchMismatch = resolveLocalCheckoutBranchMismatch({
1740
effectiveEnvMode: thread.worktreePath === null ? "local" : "worktree",
1741
activeWorktreePath: thread.worktreePath,
1742
activeThreadBranch: thread.branch,
@@ -2573,7 +2573,7 @@ const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props: {
2573
JSON.stringify([thread.environmentId, gitCwd]),
2574
gitStatus.data,
2575
);
2576
- const branchMismatch = resolveCheckoutBranchMismatch({
2576
+ const branchMismatch = resolveLocalCheckoutBranchMismatch({
2577
effectiveEnvMode: thread.worktreePath === null ? "local" : "worktree",
2578
activeWorktreePath: thread.worktreePath,
2579
activeThreadBranch: thread.branch,