Skip to content

Commit 0b011a8

Browse files
committed
🤖 fix: wait for plan file deletion
deletePlanFilesForWorkspace() used runtime.exec() without waiting for completion.\nAwait stdin.close() + exitCode so callers can assume plan files are gone when it resolves.\n\n_Generated with mux_
1 parent cf2d4da commit 0b011a8

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/node/services/workspaceService.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ import type {
3838
} from "@/common/types/workspace";
3939
import type { MuxMessage } from "@/common/types/message";
4040
import type { RuntimeConfig } from "@/common/types/runtime";
41-
import { hasSrcBaseDir, getSrcBaseDir, isSSHRuntime } from "@/common/types/runtime";
41+
import {
42+
hasSrcBaseDir,
43+
getSrcBaseDir,
44+
isSSHRuntime,
45+
isDockerRuntime,
46+
} from "@/common/types/runtime";
4247
import { defaultModel } from "@/common/utils/ai/models";
4348
import type { StreamEndEvent, StreamAbortEvent } from "@/common/types/stream";
4449
import type { TerminalService } from "@/node/services/terminalService";
@@ -1150,17 +1155,19 @@ export class WorkspaceService extends EventEmitter {
11501155
const planPath = getPlanFilePath(metadata.name, metadata.projectName);
11511156
const legacyPlanPath = getLegacyPlanFilePath(workspaceId);
11521157

1153-
// For SSH: use $HOME expansion so remote shell resolves to remote home directory
1154-
// For local: expand tilde locally since shellQuote prevents shell expansion
1155-
const quotedPlanPath = isSSHRuntime(metadata.runtimeConfig)
1158+
const isRemoteRuntime =
1159+
isSSHRuntime(metadata.runtimeConfig) || isDockerRuntime(metadata.runtimeConfig);
1160+
1161+
// For SSH/Docker: use $HOME expansion so the runtime shell resolves to the runtime home directory.
1162+
// For local: expand tilde locally since shellQuote prevents shell expansion.
1163+
const quotedPlanPath = isRemoteRuntime
11561164
? expandTildeForSSH(planPath)
11571165
: shellQuote(expandTilde(planPath));
1158-
const quotedLegacyPlanPath = isSSHRuntime(metadata.runtimeConfig)
1166+
const quotedLegacyPlanPath = isRemoteRuntime
11591167
? expandTildeForSSH(legacyPlanPath)
11601168
: shellQuote(expandTilde(legacyPlanPath));
11611169

1162-
// SSH runtime: delete via remote shell so $HOME expands on the remote.
1163-
if (isSSHRuntime(metadata.runtimeConfig)) {
1170+
if (isRemoteRuntime) {
11641171
const runtime = createRuntime(metadata.runtimeConfig, {
11651172
projectPath: metadata.projectPath,
11661173
});
@@ -1172,8 +1179,16 @@ export class WorkspaceService extends EventEmitter {
11721179
cwd: metadata.projectPath,
11731180
timeout: 10,
11741181
});
1175-
// Wait for completion so callers can rely on the plan file actually being removed.
1176-
await execStream.exitCode;
1182+
1183+
try {
1184+
await execStream.stdin.close();
1185+
} catch {
1186+
// Ignore stdin-close errors (e.g. already closed).
1187+
}
1188+
1189+
await execStream.exitCode.catch(() => {
1190+
// Best-effort: ignore failures.
1191+
});
11771192
} catch {
11781193
// Plan files don't exist or can't be deleted - ignore
11791194
}

0 commit comments

Comments
 (0)