MCPcopy
hub / github.com/coder/mux / cleanupMaterializedTaskWorkspace

Method cleanupMaterializedTaskWorkspace

src/node/services/taskService.ts:2509–2556  ·  view source on GitHub ↗
(
    runtime: Runtime,
    projectPath: string,
    workspaceName: string,
    taskId: string,
    options?: {
      /**
       * Skip physical workspace deletion. Required for isolation: "none" tasks whose runtime
       * resolves this task's name to the shared parent checkout (e.g. SSHRuntime.deleteWorkspace
       * goes through the persisted-path override) — deleting it would destroy the parent's
       * working tree. Session/config cleanup still runs.
       */
      preservePhysicalWorkspace?: boolean;
    }
  )

Source from the content-addressed store, hash-verified

2507 }
2508
2509 private async cleanupMaterializedTaskWorkspace(
2510 runtime: Runtime,
2511 projectPath: string,
2512 workspaceName: string,
2513 taskId: string,
2514 options?: {
2515 /**
2516 * Skip physical workspace deletion. Required for isolation: "none" tasks whose runtime
2517 * resolves this task's name to the shared parent checkout (e.g. SSHRuntime.deleteWorkspace
2518 * goes through the persisted-path override) — deleting it would destroy the parent's
2519 * working tree. Session/config cleanup still runs.
2520 */
2521 preservePhysicalWorkspace?: boolean;
2522 }
2523 ): Promise<void> {
2524 assert(projectPath.length > 0, "cleanupMaterializedTaskWorkspace requires projectPath");
2525 assert(workspaceName.length > 0, "cleanupMaterializedTaskWorkspace requires workspaceName");
2526 assert(taskId.length > 0, "cleanupMaterializedTaskWorkspace requires taskId");
2527
2528 if (options?.preservePhysicalWorkspace) {
2529 log.debug("Task launch cleanup: preserving shared parent checkout", { taskId });
2530 } else {
2531 try {
2532 const deleteResult = await runtime.deleteWorkspace(projectPath, workspaceName, true);
2533 if (!deleteResult.success) {
2534 log.error("Task launch cleanup: failed to delete materialized workspace", {
2535 taskId,
2536 error: deleteResult.error,
2537 });
2538 }
2539 } catch (error: unknown) {
2540 log.error("Task launch cleanup: runtime.deleteWorkspace threw", {
2541 taskId,
2542 error: getErrorMessage(error),
2543 });
2544 }
2545 }
2546
2547 try {
2548 const sessionDir = this.config.getSessionDir(taskId);
2549 await fsPromises.rm(sessionDir, { recursive: true, force: true });
2550 } catch (error: unknown) {
2551 log.error("Task launch cleanup: failed to remove session directory", {
2552 taskId,
2553 error: getErrorMessage(error),
2554 });
2555 }
2556 }
2557
2558 private async getExistingMaterializedTaskLaunch(
2559 plan: TaskLaunchPlan,

Callers 1

Calls 5

getErrorMessageFunction · 0.90
debugMethod · 0.80
deleteWorkspaceMethod · 0.65
getSessionDirMethod · 0.65
assertFunction · 0.50

Tested by

no test coverage detected