Skip to content

Commit 0e4fdb4

Browse files
committed
🤖 fix: delete plan file locally for local runtimes
Change-Id: I9aa88d6979c49c8e68926f85e7bc82421d67dca9 Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parent f3cfac5 commit 0e4fdb4

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

src/node/services/workspaceService.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,23 +1156,39 @@ export class WorkspaceService extends EventEmitter {
11561156
? expandTildeForSSH(legacyPlanPath)
11571157
: shellQuote(expandTilde(legacyPlanPath));
11581158

1159-
// Delete plan files through runtime (supports both local and SSH)
1160-
const runtime = createRuntime(metadata.runtimeConfig, {
1161-
projectPath: metadata.projectPath,
1162-
});
1163-
1164-
try {
1165-
// Use exec to delete files since runtime doesn't have a deleteFile method.
1166-
// Delete both paths in one command for efficiency.
1167-
const execStream = await runtime.exec(`rm -f ${quotedPlanPath} ${quotedLegacyPlanPath}`, {
1168-
cwd: metadata.projectPath,
1169-
timeout: 10,
1159+
// SSH runtime: delete via remote shell so $HOME expands on the remote.
1160+
if (isSSHRuntime(metadata.runtimeConfig)) {
1161+
const runtime = createRuntime(metadata.runtimeConfig, {
1162+
projectPath: metadata.projectPath,
11701163
});
1171-
// Wait for completion so callers can rely on the plan file actually being removed.
1172-
await execStream.exitCode;
1173-
} catch {
1174-
// Plan files don't exist or can't be deleted - ignore
1164+
1165+
try {
1166+
// Use exec to delete files since runtime doesn't have a deleteFile method.
1167+
// Delete both paths in one command for efficiency.
1168+
const execStream = await runtime.exec(
1169+
`rm -f ${quotedPlanPath} ${quotedLegacyPlanPath}`,
1170+
{
1171+
cwd: metadata.projectPath,
1172+
timeout: 10,
1173+
}
1174+
);
1175+
// Wait for completion so callers can rely on the plan file actually being removed.
1176+
await execStream.exitCode;
1177+
} catch {
1178+
// Plan files don't exist or can't be deleted - ignore
1179+
}
1180+
1181+
return;
11751182
}
1183+
1184+
// Local runtimes: delete directly on the local filesystem.
1185+
const planPathAbs = expandTilde(planPath);
1186+
const legacyPlanPathAbs = expandTilde(legacyPlanPath);
1187+
1188+
await Promise.allSettled([
1189+
fsPromises.rm(planPathAbs, { force: true }),
1190+
fsPromises.rm(legacyPlanPathAbs, { force: true }),
1191+
]);
11761192
}
11771193

11781194
async truncateHistory(workspaceId: string, percentage?: number): Promise<Result<void>> {

0 commit comments

Comments
 (0)