Skip to content

Commit 9573ae6

Browse files
fix(web): sidebar drops a removed thread checkout once Git status says so
After an agent removes a thread's worktree and deletes its branch, the right panel offers Initialize Git but the sidebar row kept showing the stored branch and worktree icon. Rows now hide the stored branch and worktree when their existing leased vcs status reports isRepo:false, and keep them while status is unknown, loading, or failed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent f01e2d2 commit 9573ae6

3 files changed

Lines changed: 40 additions & 13 deletions

File tree

‎apps/web/src/components/LegacySidebar.tsx‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ import {
104104
useOrchestrationCommand,
105105
} from "../state/use-orchestration-command";
106106
import { previewEnvironment } from "../state/preview";
107+
import { vcsEnvironment } from "../state/vcs";
108+
import { useEnvironmentQuery } from "../state/query";
107109
import { readEnvironmentScope, useEnvironmentScope } from "../state/session";
108110
import {
109111
legacyProjectCwdPreferenceKey,
@@ -198,9 +200,11 @@ import {
198200
orderItemsByPreferredIds,
199201
shouldClearThreadSelectionOnMouseDown,
200202
sortProjectsForSidebar,
203+
useRetainedValue,
201204
useSidebarRowSubscriptionLease,
202205
useThreadJumpHintVisibility,
203206
ThreadStatusPill,
207+
withoutRemovedCheckout,
204208
} from "./Sidebar.logic";
205209
import { sortThreads } from "../lib/threadSort";
206210
import { SidebarChromeFooter, SidebarChromeHeader } from "./sidebar/SidebarChrome";
@@ -461,6 +465,19 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
461465
thread.pullRequests,
462466
thread.branchPullRequest,
463467
);
468+
const gitStatus = useEnvironmentQuery(
469+
leaseLiveStatus && thread.worktreePath !== null
470+
? vcsEnvironment.status({
471+
environmentId: thread.environmentId,
472+
input: { cwd: thread.worktreePath, includeRemote: false },
473+
})
474+
: null,
475+
);
476+
const visibleGitStatus = useRetainedValue(
477+
JSON.stringify([thread.environmentId, thread.worktreePath]),
478+
gitStatus.data,
479+
);
480+
const checkoutThread = withoutRemovedCheckout(thread, visibleGitStatus);
464481
const pr = linkedPullRequestStatus?.pr ?? null;
465482
const supportsMultiplePullRequests = useSupportsMultiplePullRequests(thread.environmentId);
466483
// Hooks must precede this ref's plain uses for the compiler to cache it.
@@ -779,7 +796,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
779796
</TooltipPopup>
780797
</Tooltip>
781798
)}
782-
<ThreadWorktreeIndicator thread={thread} />
799+
<ThreadWorktreeIndicator thread={checkoutThread} />
783800
<ThreadTerminalStatusButton
784801
threadRef={threadRef}
785802
terminalIds={runningTerminalIds}

‎apps/web/src/components/Sidebar.logic.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ export function useRetainedValue<T>(key: string | null, value: T | null): T | nu
108108
return key !== null && retained?.key === key ? retained.value : null;
109109
}
110110

111+
// A known non-repository cwd means the stored checkout was removed; unknown status keeps it.
112+
export function withoutRemovedCheckout<
113+
T extends { branch: string | null; worktreePath: string | null },
114+
>(thread: T, gitStatus: { readonly isRepo: boolean } | null): T {
115+
return gitStatus?.isRepo === false ? { ...thread, branch: null, worktreePath: null } : thread;
116+
}
117+
111118
// Sortable owns drag transforms; replaying committed order would animate drops twice.
112119
export const animateSidebarLayoutChanges: AnimateLayoutChanges = (args) =>
113120
args.isSorting ? defaultAnimateLayoutChanges(args) : false;

‎apps/web/src/components/sidebar/SidebarThreadRow.tsx‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import {
8383
shouldRecedeSidebarThread,
8484
resolveWorkingStartedAt,
8585
useRetainedValue,
86+
withoutRemovedCheckout,
8687
useSidebarRowSubscriptionLease,
8788
} from "../Sidebar.logic";
8889
import { resolveLocalCheckoutBranchMismatch } from "../BranchToolbar.logic";
@@ -629,6 +630,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
629630
JSON.stringify([thread.environmentId, gitCwd]),
630631
gitStatus.data,
631632
);
633+
const checkoutThread = withoutRemovedCheckout(thread, visibleGitStatus);
632634
const pr = linkedPullRequestStatus?.pr ?? null;
633635
const supportsMultiplePullRequests = useSupportsMultiplePullRequests(thread.environmentId);
634636
const currentLinkedPr = supportsMultiplePullRequests
@@ -710,9 +712,9 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
710712
const isWokeStatus = topStatus?.icon === "woke";
711713

712714
const branchMismatch = resolveLocalCheckoutBranchMismatch({
713-
effectiveEnvMode: thread.worktreePath === null ? "local" : "worktree",
714-
activeWorktreePath: thread.worktreePath,
715-
activeThreadBranch: thread.branch,
715+
effectiveEnvMode: checkoutThread.worktreePath === null ? "local" : "worktree",
716+
activeWorktreePath: checkoutThread.worktreePath,
717+
activeThreadBranch: checkoutThread.branch,
716718
currentGitBranch: visibleGitStatus?.refName ?? null,
717719
});
718720
const prStatus = prStatusIndicator(pr, linkedPullRequestStatus?.sourceControlProvider);
@@ -730,11 +732,11 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
730732
: thread.modelSelection.model;
731733

732734
const isRemote = thread.environmentId !== props.currentEnvironmentId;
733-
const showsScratchMachine = !thread.branch && props.scratchMachineLabel !== null;
735+
const showsScratchMachine = !checkoutThread.branch && props.scratchMachineLabel !== null;
734736

735737
const detailsTooltip = (
736738
<SidebarThreadTooltip
737-
thread={thread}
739+
thread={checkoutThread}
738740
project={props.project}
739741
projectDisplayName={props.projectDisplayName}
740742
environmentLabel={props.environmentLabel}
@@ -1451,11 +1453,11 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
14511453
) : null}
14521454
</div>
14531455
<div className="mt-0.5 flex min-w-0 items-center gap-1.5 text-secondary-label text-xs">
1454-
{thread.branch ? (
1456+
{checkoutThread.branch ? (
14551457
<>
1456-
<ThreadWorktreeIndicator thread={thread} />
1458+
<ThreadWorktreeIndicator thread={checkoutThread} />
14571459
<span className="flex min-w-0 flex-1 text-muted-foreground/40 redesign:text-inherit">
1458-
<MiddleTruncate value={thread.branch} showTitle={false} />
1460+
<MiddleTruncate value={checkoutThread.branch} showTitle={false} />
14591461
</span>
14601462
</>
14611463
) : showsScratchMachine ? (
@@ -1563,10 +1565,11 @@ export const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props
15631565
JSON.stringify([thread.environmentId, gitCwd]),
15641566
gitStatus.data,
15651567
);
1568+
const checkoutThread = withoutRemovedCheckout(thread, visibleGitStatus);
15661569
const branchMismatch = resolveLocalCheckoutBranchMismatch({
1567-
effectiveEnvMode: thread.worktreePath === null ? "local" : "worktree",
1568-
activeWorktreePath: thread.worktreePath,
1569-
activeThreadBranch: thread.branch,
1570+
effectiveEnvMode: checkoutThread.worktreePath === null ? "local" : "worktree",
1571+
activeWorktreePath: checkoutThread.worktreePath,
1572+
activeThreadBranch: checkoutThread.branch,
15701573
currentGitBranch: visibleGitStatus?.refName ?? null,
15711574
});
15721575
const modelInstanceId = thread.runtime?.providerInstanceId ?? thread.modelSelection.instanceId;
@@ -1679,7 +1682,7 @@ export const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props
16791682
</span>
16801683
</TooltipTrigger>
16811684
<SidebarThreadTooltip
1682-
thread={thread}
1685+
thread={checkoutThread}
16831686
project={props.project}
16841687
projectDisplayName={props.projectDisplayName}
16851688
environmentLabel={props.environmentLabel}

0 commit comments

Comments
 (0)