The best way to control Claude Code, Codex and more from any computer or phone
fix(server): storage cleanup keeps Windows worktrees with an open terminal regardless of path casing (#21545)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
MarcoDotIO committed
Oct 30, 2026 at 16:27 UTC
1d162e19f6ad1bfba2ad28ab3eb7abf493265b0d
2 files changed
+67
-3
apps/server/src/storageCleanup.test.ts
+64
@@ -461,6 +461,22 @@ const cleanupFixture = (
461
setOpenSessionCwd: (cwd: string | null) => {
462
openSessionCwd = cwd;
463
},
464
+ openTerminal: (paths: { cwd: string; worktreePath: string | null }) =>
465
+ terminalListener?.({
466
+ type: "upsert",
467
+ terminal: {
468
+ threadId: "thread-1",
469
+ terminalId: "terminal-1",
470
+ status: "running",
471
+ pid: 1,
472
+ exitCode: null,
473
+ exitSignal: null,
474
+ hasRunningSubprocess: false,
475
+ label: "Terminal",
476
+ updatedAt: "2026-06-10T12:00:00.000Z",
477
+ ...paths,
478
+ },
479
+ }) ?? Effect.void,
480
fullStatusCalls: () => fullStatusCalls,
481
snapshotReads: () => snapshotReads,
482
activate: (domainEvents: Stream.Stream<OrchestrationV2DomainEvent>) => {
@@ -1594,6 +1610,54 @@ describe("orphan worktree reports", () => {
1610
}),
1611
),
1612
);
1613
+
1614
+ it.live.each([
1615
+ ["win32", "cwd"],
1616
+ ["win32", "worktreePath"],
1617
+ ["linux", "cwd"],
1618
+ ["linux", "worktreePath"],
1619
+ ] as const)(
1620
+ "matches a terminal at the worktree root with host casing rules (%s, %s)",
1621
+ ([platform, field]) =>
1622
+ runCleanupTest(
1623
+ Effect.gen(function* () {
1624
+ const fixture = yield* cleanupFixture().pipe(
1625
+ Effect.provideService(HostProcess.Platform, platform),
1626
+ );
1627
+ const upper = fixture.worktree.toUpperCase();
1628
+ yield* fixture.openTerminal(
1629
+ field === "cwd"
1630
+ ? { cwd: upper, worktreePath: null }
1631
+ : { cwd: fixture.repo, worktreePath: upper },
1632
+ );
1633
+ const report = yield* fixture.service.runNow;
1634
+ expect(report.entries[0]).toMatchObject(
1635
+ platform === "win32"
1636
+ ? { outcome: "kept", reason: "Open terminal" }
1637
+ : { outcome: "removed" },
1638
+ );
1639
+ }),
1640
+ ),
1641
+ );
1642
+
1643
+ it.live.each(["win32", "linux"] as const)(
1644
+ "matches a provider session at the worktree root with host casing rules (%s)",
1645
+ (platform) =>
1646
+ runCleanupTest(
1647
+ Effect.gen(function* () {
1648
+ const fixture = yield* cleanupFixture().pipe(
1649
+ Effect.provideService(HostProcess.Platform, platform),
1650
+ );
1651
+ fixture.setOpenSessionCwd(fixture.worktree.toUpperCase());
1652
+ const report = yield* fixture.service.runNow;
1653
+ expect(report.entries[0]).toMatchObject(
1654
+ platform === "win32"
1655
+ ? { outcome: "kept", reason: "Provider session is still open" }
1656
+ : { outcome: "removed" },
1657
+ );
1658
+ }),
1659
+ ),
1660
+ );
1661
});
1662
1663
describe("storage cleanup reports and local file policies", () => {
apps/server/src/storageCleanup.ts
+3
-3
@@ -248,8 +248,8 @@ const make = Effect.gen(function* () {
248
const cwd = path.resolve(terminal.cwd);
249
return (
250
(terminal.worktreePath !== null &&
251
- path.resolve(terminal.worktreePath) === worktreePath) ||
252
- cwd === worktreePath ||
251
+ pathKey(terminal.worktreePath) === pathKey(worktreePath)) ||
252
+ pathKey(cwd) === pathKey(worktreePath) ||
253
inside(worktreePath, cwd)
254
);
255
});
@@ -987,7 +987,7 @@ const make = Effect.gen(function* () {
987
for (const session of sessions) {
988
const cwd = path.resolve(session.cwd);
989
if (
990
- (cwd === worktreePath || inside(worktreePath, cwd)) &&
990
+ (pathKey(cwd) === pathKey(worktreePath) || inside(worktreePath, cwd)) &&
991
(yield* providerSessions.isLive(session.id))
992
)
993
return waitForStop("provider session is still open");