The best way to control Claude Code, Codex and more from any computer or phone
fix(web): sidebar rows drop a branch and worktree that were deleted (#34878)
Julius Marminge committed
Nov 11, 2026 at 23:46 UTC
0ac41eecadd4c8e358506471219aa83391a4f2db
7 files changed
+78
-40
apps/server/src/vcs/VcsStatusBroadcaster.test.ts
+19
-11
@@ -19,6 +19,7 @@ import * as TestClock from "effect/testing/TestClock";
19
import * as Tracer from "effect/Tracer";
20
import type {
21
BackgroundScope,
22
+ VcsBranchStatus,
23
VcsStatusLocalResult,
24
VcsStatusRemoteResult,
25
VcsStatusResult,
@@ -125,6 +126,7 @@ function layerTestFor(state: {
126
Effect.as(state.currentLocalStatus),
127
);
128
}),
129
+ repositoryRoot: () => Effect.sync(() => (state.currentLocalStatus.isRepo ? "/repo" : null)),
130
currentBranch: () =>
131
state.branchRead
132
? state.branchRead()
@@ -257,14 +259,17 @@ describe("VcsStatusBroadcaster", () => {
259
return Effect.gen(function* () {
260
const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
261
const branches = yield* Stream.toPull(broadcaster.streamBranchStatus({ cwd: "/repo" }));
260
- assert.deepEqual(yield* branches, [{ refName: baseLocalStatus.refName }]);
262
+ assert.deepEqual(yield* branches, [{ refName: baseLocalStatus.refName, isRepo: true }]);
263
assert.equal(state.localStatusCalls, 0);
264
state.currentLocalStatus = { ...baseLocalStatus, refName: "external" };
265
yield* broadcaster.refreshBranchStatus({ cwd: "/repo" });
264
- assert.deepEqual(yield* branches, [{ refName: "external" }]);
266
+ assert.deepEqual(yield* branches, [{ refName: "external", isRepo: true }]);
267
state.currentLocalStatus = { ...baseLocalStatus, refName: null };
268
yield* broadcaster.refreshBranchStatus({ cwd: "/repo" });
267
- assert.deepEqual(yield* branches, [{ refName: null }]);
269
+ assert.deepEqual(yield* branches, [{ refName: null, isRepo: true }]);
270
+ state.currentLocalStatus = { ...baseLocalStatus, isRepo: false, refName: null };
271
+ yield* broadcaster.refreshBranchStatus({ cwd: "/repo" });
272
+ assert.deepEqual(yield* branches, [{ refName: null, isRepo: false }]);
273
assert.equal(state.localStatusCalls, 0);
274
const detailScope = yield* Scope.make();
275
const details = yield* Stream.toPull(
@@ -289,7 +294,7 @@ describe("VcsStatusBroadcaster", () => {
294
assert.deepEqual(yield* details, [
295
{ _tag: "localUpdated", local: state.currentLocalStatus },
296
]);
292
- assert.deepEqual(yield* branches, [{ refName: "changed" }]);
297
+ assert.deepEqual(yield* branches, [{ refName: "changed", isRepo: true }]);
298
const secondScope = yield* Scope.make();
299
const secondDetails = yield* Stream.toPull(
300
broadcaster.streamStatus({ cwd: "/alias", includeRemote: false }),
@@ -327,7 +332,7 @@ describe("VcsStatusBroadcaster", () => {
332
assert.deepEqual(yield* reopened, [
333
{ _tag: "localUpdated", local: state.currentLocalStatus },
334
]);
330
- assert.deepEqual(yield* branches, [{ refName: null }]);
335
+ assert.deepEqual(yield* branches, [{ refName: null, isRepo: false }]);
336
assert.equal(state.remoteStatusCalls, 0);
337
}).pipe(Effect.provide(layerTestFor(state)), Effect.scoped);
338
},
@@ -1345,14 +1350,14 @@ describe("VcsStatusBroadcaster", () => {
1350
yield* Effect.gen(function* () {
1351
const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
1352
const branches = yield* Stream.toPull(broadcaster.streamBranchStatus({ cwd: "/repo" }));
1348
- assert.deepEqual(yield* branches, [{ refName: "main" }]);
1353
+ assert.deepEqual(yield* branches, [{ refName: "main", isRepo: true }]);
1354
1355
state.currentLocalStatus = { ...baseLocalStatus, refName: "repro" };
1356
const lockPath = path.join(gitDir, "HEAD.lock");
1357
yield* fs.writeFileString(lockPath, "ref: refs/heads/repro\n");
1358
yield* fs.rename(lockPath, headPath);
1359
1355
- assert.deepEqual(yield* branches, [{ refName: "repro" }]);
1360
+ assert.deepEqual(yield* branches, [{ refName: "repro", isRepo: true }]);
1361
assert.equal(state.localStatusCalls, 0);
1362
}).pipe(Effect.provide(layerTestFor(state)), Effect.scoped);
1363
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
@@ -1712,7 +1717,10 @@ it.effect("publishes overlapping branch reads in checkout order", () => {
1717
yield* Deferred.succeed(resume, undefined);
1718
yield* Fiber.join(older);
1719
yield* Fiber.join(newer);
1715
- assert.deepEqual(yield* branches, [{ refName: "old" }, { refName: "new" }]);
1720
+ assert.deepEqual(yield* branches, [
1721
+ { refName: "old", isRepo: true },
1722
+ { refName: "new", isRepo: true },
1723
+ ]);
1724
}).pipe(Effect.provide(layerTestFor(state)), Effect.scoped);
1725
});
1726
@@ -1722,7 +1730,7 @@ it.effect("does not replay older queued branches after a new subscriber snapshot
1730
const b = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
1731
const entered = yield* Deferred.make<void>();
1732
const resume = yield* Deferred.make<void>();
1725
- const values = yield* Queue.unbounded<{ readonly refName: string | null }>();
1733
+ const values = yield* Queue.unbounded<VcsBranchStatus>();
1734
let reads = 0;
1735
state.branchRead = () =>
1736
++reads === 1
@@ -1741,10 +1749,10 @@ it.effect("does not replay older queued branches after a new subscriber snapshot
1749
);
1750
yield* Deferred.succeed(resume, undefined);
1751
yield* Fiber.join(older);
1744
- assert.deepEqual(yield* Queue.take(values), { refName: "new" });
1752
+ assert.deepEqual(yield* Queue.take(values), { refName: "new", isRepo: true });
1753
state.branchRead = () => Effect.succeed("latest");
1754
yield* b.refreshBranchStatus({ cwd: "/repo" });
1747
- assert.deepEqual(yield* Queue.take(values), { refName: "latest" });
1755
+ assert.deepEqual(yield* Queue.take(values), { refName: "latest", isRepo: true });
1756
yield* Fiber.join(subscriber);
1757
}).pipe(Effect.provide(layerTestFor(state)), Effect.scoped);
1758
});
apps/server/src/vcs/VcsStatusBroadcaster.ts
+31
-15
@@ -275,6 +275,7 @@ export const make = Effect.gen(function* () {
275
PubSub.unbounded<{
276
readonly cwd: string;
277
readonly refName: string | null;
278
+ readonly isRepo: boolean;
279
readonly revision: number;
280
}>(),
281
(pubsub) => PubSub.shutdown(pubsub),
@@ -285,17 +286,18 @@ export const make = Effect.gen(function* () {
286
const detailedSubscribers = new Map<string, number>();
287
const branches = new Map<
288
string,
288
- { readonly refName: string | null; readonly revision: number }
289
+ { readonly refName: string | null; readonly isRepo: boolean; readonly revision: number }
290
>();
291
let branchRevision = 0;
292
const publishBranch = Effect.fn("VcsStatusBroadcaster.publishBranch")(function* (
293
cwd: string,
293
- refName: string | null,
294
+ { refName, isRepo }: { readonly refName: string | null; readonly isRepo: boolean },
295
) {
295
- if (branches.get(cwd)?.refName === refName) return;
296
+ const previous = branches.get(cwd);
297
+ if (previous?.refName === refName && previous.isRepo === isRepo) return;
298
const revision = ++branchRevision;
297
- branches.set(cwd, { refName, revision });
298
- yield* PubSub.publish(branchChangesPubSub, { cwd, refName, revision });
299
+ branches.set(cwd, { refName, isRepo, revision });
300
+ yield* PubSub.publish(branchChangesPubSub, { cwd, refName, isRepo, revision });
301
});
302
const localRefreshLocks = yield* KeyedLock.make<string>();
303
const cacheRef = yield* Ref.make(new Map<string, CachedVcsStatus>());
@@ -325,7 +327,7 @@ export const make = Effect.gen(function* () {
327
new Map(cache).set(cwd, { local: nextLocal, remote }),
328
] as const;
329
});
328
- yield* publishBranch(cwd, local.refName);
330
+ yield* publishBranch(cwd, local);
331
if (options?.publish && remoteCleared) {
332
yield* PubSub.publish(changesPubSub, {
333
cwd,
@@ -771,9 +773,15 @@ export const make = Effect.gen(function* () {
773
Effect.gen(function* () {
774
if (detailedSubscribers.has(cwd)) {
775
const local = yield* getOrLoadLocalStatusUnlocked(cwd);
774
- return { refName: local.refName, revision: branches.get(cwd)?.revision ?? 0 };
776
+ return {
777
+ refName: local.refName,
778
+ isRepo: local.isRepo,
779
+ revision: branches.get(cwd)?.revision ?? 0,
780
+ };
781
}
782
const refName = yield* workflow.currentBranch(cwd);
783
+ // A null branch is a detached HEAD or a checkout that is gone, such as a removed worktree.
784
+ const isRepo = refName !== null || (yield* workflow.repositoryRoot(cwd)) !== null;
785
// HEAD cannot certify working-tree totals, even when it has not moved.
786
localRefreshResults.delete(cwd);
787
yield* workflow.invalidateLocalStatus(cwd);
@@ -784,10 +792,14 @@ export const make = Effect.gen(function* () {
792
if (detailedSubscribers.has(cwd)) {
793
const local = yield* workflow.localStatus({ cwd });
794
yield* updateCachedLocalStatus(cwd, local, { publish: true });
787
- return { refName: local.refName, revision: branches.get(cwd)?.revision ?? 0 };
795
+ return {
796
+ refName: local.refName,
797
+ isRepo: local.isRepo,
798
+ revision: branches.get(cwd)?.revision ?? 0,
799
+ };
800
}
789
- yield* publishBranch(cwd, refName);
790
- return { refName, revision: branches.get(cwd)?.revision ?? 0 };
801
+ yield* publishBranch(cwd, { refName, isRepo });
802
+ return { refName, isRepo, revision: branches.get(cwd)?.revision ?? 0 };
803
}),
804
),
805
);
@@ -940,10 +952,10 @@ export const make = Effect.gen(function* () {
952
const refreshBranchStatus: VcsStatusBroadcaster["Service"]["refreshBranchStatus"] = Effect.fn(
953
"VcsStatusBroadcaster.refreshBranchStatus",
954
)(function* (input) {
943
- const { refName } = yield* refreshBranchStatusCore(
955
+ const { refName, isRepo } = yield* refreshBranchStatusCore(
956
yield* withFileSystem(normalizeCwd(input.cwd)),
957
);
946
- return { refName };
958
+ return { refName, isRepo };
959
});
960
961
const streamBranchStatus: VcsStatusBroadcaster["Service"]["streamBranchStatus"] = (input) =>
@@ -954,12 +966,16 @@ export const make = Effect.gen(function* () {
966
yield* Effect.acquireRelease(retainHeadWatcher(cwd), () => releaseHeadWatcher(cwd));
967
const branch = yield* refreshBranchStatusCore(cwd);
968
return Stream.concat(
957
- Stream.make({ refName: branch.refName }),
969
+ Stream.make({ refName: branch.refName, isRepo: branch.isRepo }),
970
Stream.fromSubscription(subscription).pipe(
971
Stream.filter((event) => event.cwd === cwd && event.revision > branch.revision),
960
- Stream.map(({ refName }) => ({ refName })),
972
+ Stream.map(({ refName, isRepo }) => ({ refName, isRepo })),
973
),
962
- ).pipe(Stream.changesWith((left, right) => left.refName === right.refName));
974
+ ).pipe(
975
+ Stream.changesWith(
976
+ (left, right) => left.refName === right.refName && left.isRepo === right.isRepo,
977
+ ),
978
+ );
979
}),
980
);
981
apps/web/src/components/Sidebar.logic.ts
+7
@@ -163,6 +163,13 @@ export function useSnoozeWakeClock(
163
return clockMs;
164
}
165
166
+// Live status that says the cwd is not a repository means the checkout was removed.
167
+export function withoutRemovedCheckout<
168
+ T extends { readonly branch: string | null; readonly worktreePath: string | null },
169
+>(thread: T, gitStatus: { readonly isRepo?: boolean | undefined } | null): T {
170
+ return gitStatus?.isRepo === false ? { ...thread, branch: null, worktreePath: null } : thread;
171
+}
172
+
173
export function useRetainedValue<T>(key: string | null, value: T | null): T | null {
174
const [retained, setRetained] = React.useState<{
175
readonly key: string;
apps/web/src/components/sidebar/SidebarThreadRow.tsx
+10
-7
@@ -90,6 +90,7 @@ import {
90
shouldRecedeSidebarThread,
91
resolveWorkingStartedAt,
92
useRetainedValue,
93
+ withoutRemovedCheckout,
94
useSidebarRowSubscriptionLease,
95
setFileDragActive,
96
} from "../Sidebar.logic";
@@ -719,6 +720,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
720
JSON.stringify([thread.environmentId, gitCwd]),
721
gitStatus.data,
722
);
723
+ const checkoutThread = withoutRemovedCheckout(thread, visibleGitStatus);
724
const pr = linkedPullRequestStatus?.pr ?? null;
725
const supportsMultiplePullRequests = useSupportsMultiplePullRequests(thread.environmentId);
726
const currentLinkedPr = supportsMultiplePullRequests
@@ -824,11 +826,11 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
826
: thread.modelSelection.model;
827
828
const isRemote = thread.environmentId !== props.currentEnvironmentId;
827
- const showsScratchMachine = !thread.branch && props.scratchMachineLabel !== null;
829
+ const showsScratchMachine = !checkoutThread.branch && props.scratchMachineLabel !== null;
830
831
const detailsTooltip = (
832
<SidebarThreadTooltip
831
- thread={thread}
833
+ thread={checkoutThread}
834
project={props.project}
835
projectDisplayName={props.projectDisplayName}
836
environmentLabel={props.environmentLabel}
@@ -1157,18 +1159,18 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
1159
const diff = latestRunDiff(thread);
1160
// Only the trailing icons would remain, so the row moves them to the title line instead.
1161
const metaLineEmpty =
1160
- !thread.branch &&
1162
+ !checkoutThread.branch &&
1163
!showsScratchMachine &&
1164
prBadge === null &&
1165
diff === null &&
1166
runningTerminalIds.length === 0;
1167
const metaLine = metaLineEmpty ? null : (
1168
<div className="mt-0.5 flex min-w-0 items-center gap-1.5 text-secondary-label text-xs">
1167
- {thread.branch ? (
1169
+ {checkoutThread.branch ? (
1170
<>
1169
- <ThreadWorktreeIndicator thread={thread} />
1171
+ <ThreadWorktreeIndicator thread={checkoutThread} />
1172
<span className="flex min-w-0 flex-1">
1171
- <MiddleTruncate value={thread.branch} showTitle={false} />
1173
+ <MiddleTruncate value={checkoutThread.branch} showTitle={false} />
1174
</span>
1175
</>
1176
) : showsScratchMachine ? (
@@ -1685,6 +1687,7 @@ export const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props
1687
JSON.stringify([thread.environmentId, gitCwd]),
1688
gitStatus.data,
1689
);
1690
+ const checkoutThread = withoutRemovedCheckout(thread, visibleGitStatus);
1691
const branchMismatch = resolveLocalCheckoutBranchMismatch({
1692
effectiveEnvMode: thread.worktreePath === null ? "local" : "worktree",
1693
activeWorktreePath: thread.worktreePath,
@@ -1800,7 +1803,7 @@ export const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props
1803
</span>
1804
</TooltipTrigger>
1805
<SidebarThreadTooltip
1803
- thread={thread}
1806
+ thread={checkoutThread}
1807
project={props.project}
1808
projectDisplayName={props.projectDisplayName}
1809
environmentLabel={props.environmentLabel}
packages/client-runtime/src/rpc/client.ts
+1
-1
@@ -485,7 +485,7 @@ export const subscribeVcsBranch = (
485
includeRemote: false,
486
}).pipe(
487
Stream.filter((event) => event._tag !== "remoteUpdated"),
488
- Stream.map((event) => ({ refName: event.local.refName })),
488
+ Stream.map(({ local }) => ({ refName: local.refName, isRepo: local.isRepo })),
489
),
490
),
491
),
packages/client-runtime/src/state/vcs.test.ts
+5
-5
@@ -140,7 +140,7 @@ describe("branch subscriptions", () => {
140
return Stream.concat(
141
Stream.make(
142
branchSupported
143
- ? { refName }
143
+ ? { refName, isRepo: true }
144
: { _tag: "snapshot", local: status({ refName }), remote: null },
145
),
146
Stream.never,
@@ -183,19 +183,19 @@ describe("branch subscriptions", () => {
183
const first = yield* Stream.toPull(
184
AtomRegistry.toStreamResult(registry, atoms.branch(target)),
185
);
186
- expect(yield* first).toEqual([{ refName: "main" }]);
186
+ expect(yield* first).toEqual([{ refName: "main", isRepo: true }]);
187
const second = yield* Stream.toPull(
188
AtomRegistry.toStreamResult(registry, atoms.branch(target)),
189
);
190
- expect(yield* second).toEqual([{ refName: "main" }]);
190
+ expect(yield* second).toEqual([{ refName: "main", isRepo: true }]);
191
expect(subscriptions).toBe(1);
192
yield* SubscriptionRef.set(
193
activeSession,
194
Option.some(branchSession("external", !supported)),
195
);
196
expect(yield* Queue.take(released)).toBe("main");
197
- expect(yield* first).toEqual([{ refName: "external" }]);
198
- expect(yield* second).toEqual([{ refName: "external" }]);
197
+ expect(yield* first).toEqual([{ refName: "external", isRepo: true }]);
198
+ expect(yield* second).toEqual([{ refName: "external", isRepo: true }]);
199
registry.dispose();
200
expect(yield* Queue.take(released)).toBe("external");
201
}).pipe(Effect.scoped),
packages/contracts/src/git.ts
+5
-1
@@ -111,7 +111,11 @@ export const VcsStatusInput = Schema.Struct({
111
});
112
export type VcsStatusInput = typeof VcsStatusInput.Type;
113
114
-export const VcsBranchStatus = Schema.Struct({ refName: Schema.NullOr(Schema.String) });
114
+export const VcsBranchStatus = Schema.Struct({
115
+ refName: Schema.NullOr(Schema.String),
116
+ /** Absent from older servers, where a removed checkout looks like a detached HEAD. */
117
+ isRepo: Schema.optional(Schema.Boolean),
118
+});
119
export type VcsBranchStatus = typeof VcsBranchStatus.Type;
120
121
export const VcsStatusSubscriptionInput = Schema.Struct({