Skip to content

Commit 1d162e1

Browse files
MarcoDotIOclaude
andauthored
fix(server): storage cleanup keeps Windows worktrees with an open terminal regardless of path casing (#21545)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent dcf051e commit 1d162e1

2 files changed

Lines changed: 67 additions & 3 deletions

File tree

‎apps/server/src/storageCleanup.test.ts‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,22 @@ const cleanupFixture = (
461461
setOpenSessionCwd: (cwd: string | null) => {
462462
openSessionCwd = cwd;
463463
},
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,
464480
fullStatusCalls: () => fullStatusCalls,
465481
snapshotReads: () => snapshotReads,
466482
activate: (domainEvents: Stream.Stream<OrchestrationV2DomainEvent>) => {
@@ -1594,6 +1610,54 @@ describe("orphan worktree reports", () => {
15941610
}),
15951611
),
15961612
);
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+
);
15971661
});
15981662

15991663
describe("storage cleanup reports and local file policies", () => {

‎apps/server/src/storageCleanup.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ const make = Effect.gen(function* () {
248248
const cwd = path.resolve(terminal.cwd);
249249
return (
250250
(terminal.worktreePath !== null &&
251-
path.resolve(terminal.worktreePath) === worktreePath) ||
252-
cwd === worktreePath ||
251+
pathKey(terminal.worktreePath) === pathKey(worktreePath)) ||
252+
pathKey(cwd) === pathKey(worktreePath) ||
253253
inside(worktreePath, cwd)
254254
);
255255
});
@@ -987,7 +987,7 @@ const make = Effect.gen(function* () {
987987
for (const session of sessions) {
988988
const cwd = path.resolve(session.cwd);
989989
if (
990-
(cwd === worktreePath || inside(worktreePath, cwd)) &&
990+
(pathKey(cwd) === pathKey(worktreePath) || inside(worktreePath, cwd)) &&
991991
(yield* providerSessions.isLive(session.id))
992992
)
993993
return waitForStop("provider session is still open");

0 commit comments

Comments
 (0)