Skip to content

Commit 481d2f0

Browse files
committed
🤖 fix: wait for plan file deletion
deletePlanFilesForWorkspace() used runtime.exec() without waiting for completion, which could race tests (and callers) that expect the plan file to be gone once replaceChatHistory resolves. Await stdin.close() + exitCode.
1 parent 7ba7831 commit 481d2f0

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/node/services/workspaceService.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,12 +1087,25 @@ export class WorkspaceService extends EventEmitter {
10871087
});
10881088

10891089
try {
1090-
// Use exec to delete files since runtime doesn't have a deleteFile method
1091-
// Delete both paths in one command for efficiency
1092-
await runtime.exec(`rm -f ${quotedPlanPath} ${quotedLegacyPlanPath}`, {
1090+
// Use exec to delete files since runtime doesn't have a deleteFile method.
1091+
// Delete both paths in one command for efficiency.
1092+
//
1093+
// IMPORTANT: runtime.exec() returns streams immediately; we must wait for completion
1094+
// so callers can safely assume the plan file is gone when this function resolves.
1095+
const stream = await runtime.exec(`rm -f ${quotedPlanPath} ${quotedLegacyPlanPath}`, {
10931096
cwd: metadata.projectPath,
10941097
timeout: 10,
10951098
});
1099+
1100+
try {
1101+
await stream.stdin.close();
1102+
} catch {
1103+
// Ignore stdin-close errors (e.g. already closed).
1104+
}
1105+
1106+
await stream.exitCode.catch(() => {
1107+
// Best-effort: ignore failures.
1108+
});
10961109
} catch {
10971110
// Plan files don't exist or can't be deleted - ignore
10981111
}

0 commit comments

Comments
 (0)